Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 167576

Summary: GCC floating point behavior
Product: Gentoo Linux Reporter: eipi <pierre>
Component: [OLD] DevelopmentAssignee: Gentoo Linux bug wranglers <bug-wranglers>
Status: RESOLVED INVALID    
Severity: normal CC: truedfx
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: FVector code used to check the GCC bug
emerge --info output

Description eipi 2007-02-19 05:11:33 UTC
When compiling a very simple application with floating points operations (see attachment), gcc has different output depending on the optimisation level used.

Reproducible: Always

Steps to Reproduce:
1.Compile the files in attachment using the following command:
$ gcc -Wall -o fvector fvector-main.c fvector-std-op.c rnd.c
2. Execute the binary:
$ ./fvector 10 1

Operation on vectors of 10 floats each, 1 times
(This is the normal output)
3. Recompile the same application using any optimisation level
$ gcc -Wall -o fvector fvector-main.c fvector-std-op.c rnd.c -O
4. Re-execute the new binary
$ ./fvector 10 1
Operation on vectors of 10 floats each, 1 times
-4293.442871 -4293.442720 -0.000151
-2813.923828 -2813.923728 -0.000100
-132.770966 -132.770966  0.000000
-96.568428 -96.568427 -0.000001
-2401.144043 -2401.144088  0.000045
-181.916946 -181.916947  0.000001
-6943.734863 -6943.734788 -0.000075
-8834.229492 -8834.229784  0.000291
-573.046448 -573.046459  0.000011
-14.049199 -14.049199 -0.000000
(this shows the rounded differences between two normally identical computations and thus it is a bug)

Actual Results:  
A difference between two source-based identical operations when compiled without any optimisations and with some of them.

Expected Results:  
We have basically two functions: 
fvector_op(v1, v2, r) that returns in vector r the result of some floating points operations on vectors v1 and v2;

and fvector_check(v1, v2, r) that performs exactly the same computation than fvector_op(v1, v2, r) between v1 and v2 (at source code level) and check that r holds the correct expected result. Is something differs, it is printed on the screen, otherwise, nothing is printed.

(This example is used to show vector SIMD instructions such as SSE and so on....).

The expected result should hence be: nothing is printed since exactly the same source code operations (copy/paste) are performed in fvector_op() and in fvector_check().
Comment 1 eipi 2007-02-19 05:14:16 UTC
Created attachment 110601 [details]
FVector code used to check the GCC bug
Comment 2 eipi 2007-02-19 05:16:56 UTC
Created attachment 110603 [details]
emerge --info output
Comment 3 Harald van Dijk (RETIRED) gentoo-dev 2007-02-19 07:27:26 UTC
Floating-point arithmetic is not exact. The compiler is allowed to be inconsistent in when it rounds results, depending on whether it sees that certain optimisations are available. Please also see <http://gcc.gnu.org/PR323>