Mapping NAN to ZERO / When does gcc generate MOVcc and FCMOVcc instructions?

Uros Bizjak ubizjak@gmail.com
Fri Nov 3 22:43:00 GMT 2006


Michael James wrote:

> And recompiled with the same flags. The assembly code for the loop
> portion is identical to the one I posted above. Now though the code is
> actually capable of producing NANs.
>
> Just to be sure, I also tested this on my modified loop:
>
> int main(void) {
>        printf("test(4, 6, 0) = %f\n", test(4,6,0));
>        printf("test(0, 2, 0) = %f\n", test(0,2,0));
>        printf("test(-2, 3, 0) = %f\n", test(-2,3,0));
>        return 0;
> }
>
> james@recoil:~/project/cf/util$ /home/james/local/gcc/bin/gcc -O2
> -march=i686 -funsafe-math-optimizations -fno-math-errno uros-test.c -o
> test
>
> james@recoil:~/project/cf/util$ ./test
> test(4, 6, 0) = 2.995732
> test(0, 2, 0) = -inf
> test(-2, 3, 0) = nan
>
> james@recoil:~/project/cf/util$ /home/james/local/gcc/bin/gcc -O2
> -march=i686 uros-test.c -o test -lm
>
> james@recoil:~/project/cf/util$ ./uros
> test(4, 6, 0) = 2.995732
> test(0, 2, 0) = -inf
> test(-2, 3, 0) = -inf
>
> james@recoil:~/project/cf/util$ /home/james/local/gcc/bin/gcc -v
> Using built-in specs.
> Target: i686-pc-linux-gnu
> Configured with: ../gcc-4-2/configure --prefix=/home/james/local/gcc
> Thread model: posix
> gcc version 4.2.0 20061103 (prerelease)
>
> Perhaps I have not replicated your working environment closely enough,
> or you have a different macro in place of the isnan call. I compiled
> all code above both with and without include headers <math.h>,
> <stdio.h>. I get the same results either way.
>
No, I'm working with gcc version 4.3.0 20061103 (experimental), and the 
results are as expected:
gcc -O2 -funsafe-math-optimizations -fno-math-errno -march=i686 
-mfpmath=387 -m32 mj.c
[-m32 is not needed on 32bit compiler]

test(4, 6, 0) = 2.995732
test(0, 2, 0) = -inf
test(-2, 3, 0) = -inf

This is the exact testcase I used:
--cut here--
double test(int i0, int n, double a)
{
 double sum = 0.0;
 int i;

 for(i=i0; i<n; ++i)
   {
     float x = logf((float)i);
     sum += isnan(x) ? 0 : x;
   }

 return sum;
}

int main(void) {
       printf("test(4, 6, 0) = %f\n", test(4,6,0));
       printf("test(0, 2, 0) = %f\n", test(0,2,0));
       printf("test(-2, 3, 0) = %f\n", test(-2,3,0));
       return 0;
}

--cut here--
Inspecting the code, there is fucomi insn present just after "log" insn 
sequence.

Unfortunatelly, I have no 4.2 installed here, but it looks like a bug to 
me. Perhaps could you open a bugreport for this issue?

Thanks,
Uros.



More information about the Gcc mailing list