This discussion is archived
4 Replies Latest reply: Aug 1, 2011 3:06 PM by Darryl Gove RSS

inlining creal/cimag

marc1842fr Explorer
Currently Being Moderated
Hello,

I noticed (with studio 12.3 on x86) that cc never inlines creal and cimag.
#include <complex.h>
double f(double complex x){return cimag(x);}
generates with -fast the surprising code:
{ int[ 1]           2  }        subl    $28,%esp                
{  fp[ 4]           2  }        movupd  32(%esp),%xmm0          / sym=x
{ int[ 1]           2  }        subl    $16,%esp                
{  fp[ 3]           2  }        movupd  %xmm0,(%esp)            
{                   2  }        call    cimag           
{ int[ 1]           2  }        addl    $16,%esp                

/ BLOCK: 4, pred: 3, succ: 2, count: 1.00000

{                   2  }        fstpl   8(%esp)         / sym=.CV0
{  fp[ 4]           2  }        movsd   8(%esp),%xmm0           / sym=.CV0
{  fp[ 3]           2  }        movsd   %xmm0,8(%esp)           / sym=.CV0
{                   2  }        fldl    8(%esp)         / sym=.CV0
{ int[ 1]           2  }        addl    $28,%esp                
{                   2  }        ret                     
Any idea what is going on?
  • 1. Re: inlining creal/cimag
    Darryl Gove Newbie
    Currently Being Moderated
    Thanks for pointing that out. We'd need to recognise the functions - it's not a straight-forward inlining optimisation as the functions are not defined in the header file.

    $ cc -fast -S -H im.c
    /usr/include/complex.h
    $ more /usr/include/complex.h
    ...
    extern double cimag(double complex);
    extern double creal(double complex);
    ...

    You can file an rfe here:
    http://bugreport.sun.com/bugreport/
    It's more compelling if you know which applications will suffer because of this.

    Thanks,

    Darryl.
  • 2. Re: inlining creal/cimag
    Darryl Gove Newbie
    Currently Being Moderated
    We have an rfe for this now. Let me know if you have examples of where this would help particular apps.

    Darryl.
  • 3. Re: inlining creal/cimag
    marc1842fr Explorer
    Currently Being Moderated
    Darryl Gove wrote:
    Thanks for pointing that out. We'd need to recognise the functions - it's not a straight-forward inlining optimisation as the functions are not defined in the header file.
    Even without inlining, calling cimag should be a single jmp instruction, not 10 instructions surrounding a call.
    You can file an rfe here:
    Thanks for filing it for me.
    It's more compelling if you know which applications will suffer because of this.
    I noticed the non-inlining because creal/cimag were the only functions forcing to link libmpc.so with libm (seems a bit of a waste to bring in the whole libm for those). I have no idea what applications use libc complex numbers and thus might be affected.
  • 4. Re: inlining creal/cimag
    Darryl Gove Newbie
    Currently Being Moderated
    Thanks for pointing out the problems. I agree the overhead looks crazy for what the work will be. We'll be taking a look at how these are handled!

    Regards,

    Darryl.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points