This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug math/16209] New: feenableexcept should clear stalled exception flags


https://sourceware.org/bugzilla/show_bug.cgi?id=16209

            Bug ID: 16209
           Summary: feenableexcept should clear stalled exception flags
           Product: glibc
           Version: 2.17
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: ubizjak at gmail dot com

Following testcase

--cut here--
#include <fenv.h>

int main(void)
{
  unsigned short cw;

  /* Raise FE_DIVBYZERO */
  volatile float d = 0.0f;
  volatile float r = 1.0f / d;

#if GLIBC
  feenableexcept (FE_DIVBYZERO);
#else
  __asm__ __volatile__ ("fstcw\t%0" : "=m" (cw));

  cw |= FE_ALL_EXCEPT;
  cw &= ~FE_DIVBYZERO;

  __asm__ __volatile__ ("fnclex\n\tfldcw\t%0" : : "m" (cw));
#endif

  /* Raise FE_INEXACT */
  d = 3.0f;
  r = 1.0f / d;

  return 0;
}
-- cut here --

compiled with -O2 -lm -DGLIBC and -mfpmath=387 (or -m32) throws wrong
exception.

$ gcc -O2 -lm -g -mfpmath=387 -DGLIBC exc.c
$ ./a.out
Floating point exception (core dumped)

Without -DGLIBC, exception is not thrown.

As shown by !GLIBC code, the problem can be solved by clearing stalled x87
exception flags in feenableexcept. IMO, flags in the SSE status word should be
cleared in the same way, although -DGLIBC test won't fail for SSE math.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]