Date: Sat, 22 Jun 2002 07:40:04 -0700 (PDT) From: Bruce Evans <bde@zeta.org.au> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results Message-ID: <200206221440.g5MEe4e57398@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/38170; it has been noted by GNATS. From: Bruce Evans <bde@zeta.org.au> To: Andreas Haakh <ah@haakh.de> Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results Date: Sun, 23 Jun 2002 00:40:47 +1000 (EST) On Thu, 20 Jun 2002, Andreas Haakh wrote: > The reason, why I found the bug is, that somewhere in the past the default > setting for npxcw was silently changed. > > Investigating the sources revealed, that > http://www.freebsd.org/cgi/query-pr.cgi?pr=17984 changed the default > floating point precision to 53 bits and masked _ALL_ exceptions in > /sys/i386/include/npx.h! There was no note in UPDATING and this change > caused quite some trouble. I opposed this change for many years because I think not masking the exceptions is a better default, at least with the old C standard (C90) which doesn't specify any usable exception handling, but eventually gave up. > Since this PR we have > #define __INITIAL_NPXCW__ 0x127F > > I think it would be better to have the initial value set to > #define __INITIAL_NPXCW__ 0x1272 > which would force a trap on > FP_X_INV, FP_X_DZ and FP_X_OFL. > This is a better behaviour for floatingpoint exceptions if you don't catch > them at all and complies with the sample code in fpsetmask(3). This manpage > should also describe the default settings. It's too late to change this back now :-). The change was made over 2 years ago just before FreeBSD-4 was released. The C standard (C99) finally specified usuable (but optional) exception handling just a few months before that. I believe that POSIX.1-2001 (which came out about 18 months later) makes the usable exception handling non-optional and requires either all exceptions to be masked by default, or all math functions to break the C standard by delivering SIGFPEs when they raise a floating point exception. This is all rather complicated and not really supported yet. > Whoever wants to prevent floating point exceptions should check and/or reset > the sticky flags if needed and for those programs its not a big deal to set > the exception mask to the desired value. This argument can easily be inverted to "Whoever doesn't want ..." :-). > The current setting silently ignores them and give strange (wrong!!!) > results. In theory you are supposed to get a NaN or Inf result, and check for this or the exception flags at appropriate times. I prefer to get an exception because programs that actually do the checks can easily set the exception mask. > If you don't agree to change the initial npxcw to my proposed value, it > would be nice to have either a kernel configuration option or a > sysctl-variable holding the initial npxcw for new processes.. I think it's too late for any of this now. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206221440.g5MEe4e57398>