Bug 17907 - fma modifies and does not reset SSE rounding mode on 32bit machines
Summary: fma modifies and does not reset SSE rounding mode on 32bit machines
Status: RESOLVED DUPLICATE of bug 16064
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-30 11:59 UTC by Simon Byrne
Modified: 2015-02-06 09:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
fma rounding mode test function (198 bytes, text/x-csrc)
2015-01-30 11:59 UTC, Simon Byrne
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Byrne 2015-01-30 11:59:41 UTC
Created attachment 8091 [details]
fma rounding mode test function

The software fma function modifies the rounding mode for SSE floating point instructions (to round-toward-zero), but does not reset it correctly, on 32bit (686) processors. The x87 rounding mode is unaffected.

Attached is a sample program: compile on a 32bit machine with gcc:

$ gcc fmacheck.c -o fmacheck -lm -msse2 -mfpmath=sse

or clang:

$ clang fmacheck.c -o fmacheck -lm

When run as

$ ./fmacheck 0x1.0000000000001p+0

it should give
0x1.ffffffffffffep-1
if rounding mode is the default (round-to-nearest). If the rounding mode has been incorrectly modified to be round-toward-zero, then you will get
0x1.ffffffffffffdp-1
Comment 1 Joseph Myers 2015-01-30 15:14:18 UTC
This looks like it would have been a consequence of bug 16064, fixed for 2.20.

*** This bug has been marked as a duplicate of bug 16064 ***
Comment 2 joseph@codesourcery.com 2015-01-30 15:21:53 UTC
(More specifically: i386 uses sysdeps/ieee754/ldbl-96/s_fma.c, which saves 
state with feholdexcept, sets the rounding mode (twice) with fesetround, 
and then restores state, with exceptions merged, with feupdateenv.  This 
was the sort of pattern that was mishandled before bug 16064 was fixed, 
because fesetround sets the SSE rounding mode but the fenv_t functions 
used not to handle it.)
Comment 3 Simon Byrne 2015-01-30 16:15:06 UTC
Great, thanks for letting me know.