x86_64: floating-point environment (i.e. fenv.h). BUG.

Houder houder@xs4all.nl
Wed Aug 1 10:22:00 GMT 2018


Hi Corinna,

Short version of my report (as there is more to say about the 
implementation of
"fenv") in Cygwin; this time I restrict myself to a bug in fegetenv() ).

(Note to myself: attach STC)

I am reporting a bug in fegetenv() in winsup/cygwin/fenv.cc. There is no 
hurry
in repairing this bug, as "fenv" is hardly ever (never?) used by anyone.

fegetenv() should be modified as follows:

from:
   __asm__ volatile ("fnstenv %0" : "=m" (envp->_fpu) : );
   if (use_sse)
     __asm__ volatile ("stmxcsr %0" : "=m" (envp->_sse_mxcsr) : );
   return 0

to:
// Henri: copying glibc ...
   __asm__ volatile ("fnstenv %0\n"
                     "fldenv %0" : "=m" (envp->_fpu) : );
   if (use_sse)
     __asm__ volatile ("stmxcsr %0" : "=m" (envp->_sse_mxcsr) : );
   return 0;

Yes, you can verify my modification here:

     https://sourceware.org/git/?p=glibc.git

(sysdeps/x86_64/fpu/fegetenv.c)

The fnstenv statement "copies" the state of the x87 FPU to memory, at 
the same
time MASKING all exceptions ...
However, masking the exceptions is NOT what we desire at this point. For 
this
reason fnstenv must be followed by fldenv, which copies "what has been 
copied
from the FPU" back to the FPU.

The stc is as follows:

  feenableexcept()
  ...
  fegetenv(&fpenv) // save state of fenv (the "control and status 
register")
  //fesetenv(FE_DFL_ENV) // set default environment: would mask all 
exceptions
  provoke exception
  fesetenv(&fpenv) // restore the previous state of fenv
Note: provoke exception, using
  - either feraiseexcept()
  - or double d = 1.0; long l = d + 0.4;

Using feraiseexcept() should trigger an exception; it does not.

Regards,

Henri
-------------- next part --------------
A non-text attachment was scrubbed...
Name: STC-FENV.c
Type: text/x-c
Size: 6193 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20180801/30e47261/attachment.bin>
-------------- next part --------------

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list