This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/53216] New: fmaf() alters rounding mode of sse2 FPU
- From: "tydeman at tybor dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 May 2012 18:02:08 +0000
- Subject: [Bug c/53216] New: fmaf() alters rounding mode of sse2 FPU
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53216
Bug #: 53216
Summary: fmaf() alters rounding mode of sse2 FPU
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: tydeman@tybor.com
The following code shows that the rounding mode of the sse2 FPU is altered by a
call to fmaf().
#include <stdio.h>
#include <float.h>
#include <math.h>
static float res0, res1, res2, res3;
static float half = 0.5f;
void chk( void ){
res2 = res0 + half; /* should round down to even */
if( res2 == res0 ){ puts("OK1"); }else{ puts("Bad1"); }
res3 = res1 + half; /* should round up to even */
if( res3 != res1 ){ puts("OK2"); }else{ puts("Bad2"); }
}
int main(void){
res0 = FLT_EPSILON;
res0++;
res0--;
res0 = 1.f / res0; /* even; 1/EPSILON is a magic number */
res1 = res0 + 1.f; /* odd */
chk();
res2 = sinf( 1.f ); /* sse2 rounding is not altered */
chk();
res2 = fmaf( 1.f, 1.f, 1.f ); /* this messes up sse2 rounding */
chk();
return 0;
}
Hardware: Intel Core 2 Duo in 32-bit mode
O.S. : Fedora Core 17 in 32-bit mode
Compiler: gcc 4.7.0-2
Library : glibc 2.15-32
Compiler options: -std=gnu11 -O0 -mfpmath=sse -msse2 -fno-builtin
-frounding-math -mieee-fp -ffloat-store -fexcess-precision=standard