From owner-freebsd-bugs Thu Jun 20 8:40:14 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 608C437B400 for ; Thu, 20 Jun 2002 08:40:04 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g5KFe4007185; Thu, 20 Jun 2002 08:40:04 -0700 (PDT) (envelope-from gnats) Date: Thu, 20 Jun 2002 08:40:04 -0700 (PDT) Message-Id: <200206201540.g5KFe4007185@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Andreas Haakh" Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results Reply-To: "Andreas Haakh" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR kern/38170; it has been noted by GNATS. From: "Andreas Haakh" To: "Bruce Evans" Cc: Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results Date: Thu, 20 Jun 2002 17:32:44 +0200 Hi, today I installed floatingpoint.h from HEAD and now the functions fp[sg]etmask yield the desired results. 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. 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. 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. The current setting silently ignores them and give strange (wrong!!!) results. 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.. Andreas ----- Original Message ----- From: "Andreas Haakh" To: "Bruce Evans" Cc: Sent: Wednesday, June 12, 2002 10:54 AM Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results > > ----- Original Message ----- > From: "Bruce Evans" > To: "Andreas Haakh" > Cc: > Sent: Saturday, June 01, 2002 7:54 PM > Subject: Re: kern/38170: fpgetmask, fpsetmask yield strange results > > > > On Fri, 17 May 2002, Andreas Haakh wrote: > > > > > >Description: > > > I tried to modify the default fp_exception-mask. The results from > fpgetmask and fpsetmask (and probably some other fp[sg]et-routines) are > buggy. > > > > fpsetmask() is fixed in -current. The complement of the mask (ANDed with > > the mask bitfield) was being returned. The other routines seem to be OK. > > > > > >How-To-Repeat: > > > The following codeexample shows this strange behaviour: > > > > > > #include > > > #include > > > > > > int main (void) { > > > > > > fp_except_t except, res; > > > > > > res=fpgetmask(); > > > > > > printf ("fp_except from fpgetmask: \t0x%02x!\n", res); > > > > > > except = FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_STK; > > > > Note that FP_X_STK is output-only. Attempts to set it are ignored by > > fpsetmask(), and fpgetmask() returns whatever the hardware gives for > > attempts to set it in other initializations that don't mask it. It > > is documented as "reserved" in at least the i486 manual, so strictly > > it should not be set unconditionally, but the kernel just tries to > > write 0 to it. I wish that this bit controlled stack exceptions > > independently of invalid operand exceptions, so that SIGFPEs could > > be generated for the programming error of stack overflow without > > generating them for invalid operands which might not even be an error > > in programs that generate NaNs intentionally. > > > > Is it already MFC'd or when will this happen? > > There should be a note in fpsetask(3) that FP_X_STK is reserved... > > Andreas > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message