This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: i386 FP comparsion bug (and sollution)


>I think I've tracked down quite important bug in condition code in i386.c/md.
>The problem happends often when -mno-ieee-fp is set (that should be purpose
>why it is considered as buggy) but happends rarely in normal comparsions too.

[snip]

>It is tricky to construct testcase, so I don't have any working with
>latest snapshots without my patches, but hope description is clear.

Hi,

By coincidence, I was just constructing such a testcase. It hope it is
useful (and that we are talking about the same bug :)

Basically, if I switch on the '-mno-ieee-fp' flag
together with '-O2', a double-comparison returns 
1 instead of 0 !?!?!?!

Best regards,

	Hans

------------------Details---------------------------------------------
Setup:

Compiler built from egcs-1.0.3a sources with [gcc/g++/g77] diffs
to egcs-1.1b.

Specs:

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

config.guess: i686-pc-linux-gnulibc1


Code: ----------------------------------------------------

#include <math.h>
#include <stdio.h>

int main(void)
{
	int i2;

	float bf = sqrt(3.0);

	i2 = (sqrt((double)bf) >2)?5:6; 

	printf("bf = %g\n",bf);
	printf("sqrt((double)bf) = %g\n",sqrt((double)bf));
	printf("(sqrt((double)bf) >2) = %d\n", (sqrt((double)bf) >2.0) );
	
	return 0;
}

Output:

----------------- 1 -----------------
Compile : gcc -mno-ieee-fp -o t bug.i686.c -lm
Run     : t
Output  :

bf = 1.73205
sqrt((double)bf) = 1.31607
(sqrt((double)bf) >2) = 0             <======= OK
----------------- 2 -----------------

Compile : gcc -O2 -mno-ieee-fp -o t bug.i686.c -lm
Run     : t
Output  :

bf = 1.73205
sqrt((double)bf) = 1.31607
(sqrt((double)bf) >2) = 1             <======= ?????

----------------- 3 -----------------

Compile : gcc -O2 -o t bug.i686.c -lm
Run     : t
Output  :

bf = 1.73205
sqrt((double)bf) = 1.31607
(sqrt((double)bf) >2) = 0             <======= OK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]