Bug 53216 - fmaf() alters rounding mode of sse2 FPU
Summary: fmaf() alters rounding mode of sse2 FPU
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-03 18:02 UTC by Fred J. Tydeman
Modified: 2012-05-04 09:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fred J. Tydeman 2012-05-03 18:02:08 UTC
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
Comment 1 Marc Glisse 2012-05-03 19:47:45 UTC
This looks like a glibc issue, doesn't it? Or do you see something wrong with the code gcc produces for this example?
Comment 2 Richard Biener 2012-05-04 09:04:33 UTC
Indeed.