------- Additional Comments From Thomas dot Koenig at online dot de  2005-02-14 
20:06 -------
Same thing for complex division, where the performance
penalty is probably also pretty severe:


$ cat c-div.c
#include <math.h>
#include <complex.h>

int main()
{
    float a;
    complex float b,c;
    foo(&a,&b);
    c = b/a;
    return creal(c) + cimag(c) < 0;
}
$ gcc -fdump-tree-all-all -O3 -S c-div.c
$ tail -20 c-div.c.t65.optimized
  complex floatD.25 c.20D.2363;
  complex floatD.25 c.19D.2362;
  intD.0 D.2361;
  complex floatD.25 D.2360;
  complex floatD.25 D.2359;
  floatD.21 a.18D.2358;

  # BLOCK 0
  # PRED: ENTRY [100.0%]  (fallthru,exec)
  #   aD.2354_25 = V_MAY_DEF <aD.2354_1>;
  #   bD.2355_26 = V_MAY_DEF <bD.2355_5>;
  foo (&aD.2354, &bD.2355);
  #   D.2360_11 = V_MUST_DEF <D.2360_10>;
  D.2360 = __divsc3 (REALPART_EXPR <bD.2355>, IMAGPART_EXPR <bD.2355>, 
aD.2354,0.0);
  return (doubleD.22) REALPART_EXPR <D.2360> + (doubleD.22) IMAGPART_EXPR
<D.2360> < 0.0;
  # SUCC: EXIT [100.0%]

}

Addition has the same problem. Here, a floating point register is
carefully zeroed in order to add something to it:

$ cat c-add.c
#include <math.h>
#include <complex.h>

int main()
{
    float a;
    complex float b,c;
    foo(&a,&b);
    c = b+a;
    return creal(c) + cimag(c) < 0;
}
$ gcc -fdump-tree-all-all -O3 -S c-add.c
$ tail -20 c-add.c.t65.optimized
  doubleD.22 D.2365;
  floatD.21 D.2364;
  complex floatD.25 c.20D.2363;
  complex floatD.25 c.19D.2362;
  intD.0 D.2361;
  complex floatD.25 D.2360;
  complex floatD.25 D.2359;
  floatD.21 a.18D.2358;

  # BLOCK 0
  # PRED: ENTRY [100.0%]  (fallthru,exec)
  #   aD.2354_27 = V_MAY_DEF <aD.2354_1>;
  #   bD.2355_28 = V_MAY_DEF <bD.2355_7>;
  foo (&aD.2354, &bD.2355);
  return (doubleD.22) (aD.2354 + REALPART_EXPR <bD.2355>) + (doubleD.22)
(IMAGPART_EXPR <bD.2355> + 0.0) < 0.0;
  # SUCC: EXIT [100.0%]

}


$ tail -20 c-add.s
        leal    -4(%ebp), %eax
        movl    %eax, (%esp)
        call    foo
        flds    -12(%ebp)
        fldz
        fadds   -8(%ebp)
        fxch    %st(1)
        fadds   -4(%ebp)
        leave
        faddp   %st, %st(1)
        fldz
        fucompp
        fnstsw  %ax
        testb   $69, %ah
        sete    %al
        movzbl  %al, %eax
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.0.0 20050212 (experimental)"
        .section        .note.GNU-stack,"",@progbits

If somebody tackles this, it would also be nice if purely
imaginary numbers were also special-cased.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Special-case real*complex   |Special-case real + complex
                   |multiplication for          |arithmetic operation
                   |flag_complex_method=2       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19953

Reply via email to