delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/02/01/16:30:34

Date: Sun, 1 Feb 1998 20:56:34 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: NPX setup in v2.02
Message-ID: <Pine.SUN.3.91.980201205354.16669F-100000@is>
MIME-Version: 1.0

The changed default setup of the x87 requires changes to some docs.

I believe the first diff below is a bug: we don't want to leave the 
Invalid Operation exception unmasked when they set 387=y, do we?

*** src/libc/emu387/npxsetup.c~0	Sat Nov 15 01:26:28 1997
--- src/libc/emu387/npxsetup.c	Sat Jan 31 14:16:38 1998
*************** void _npxsetup(char *argv0)
*** 67,73 ****
--- 67,76 ----
  
    cp = getenv("387");
    if (cp && (tolower(cp[0]) == 'y'))
+   {
+     _control87(0x033f, 0xffff);	/* mask all numeric exceptions */
      return;
+   }
    if (cp && (tolower(cp[0]) == 'n'))
      have_80387 = 0;
    else
*** src/libc/pc_hw/fpu/libm.t~0	Sat Nov 15 01:22:48 1997
--- src/libc/pc_hw/fpu/libm.txh	Sat Jan 31 14:27:02 1998
*************** versions of mathematical functions than 
*** 27,35 ****
  @file{libc.a} library.  It also allows to create programs with
  well-defined and standard-compliant behavior when numerical errors
  occur.  In contrast, the functions in the default @file{libc.a} will
! usually generate FP exceptions in such cases, which will cause signal
! @code{SIGFPE} to be delivered to the program.  The default handler for
! @code{SIGFPE} aborts the program.  @xref{signal}.
  
  To use the alternate math library with your program, you need to do the
  following:
--- 27,33 ----
  @file{libc.a} library.  It also allows to create programs with
  well-defined and standard-compliant behavior when numerical errors
  occur.  In contrast, the functions in the default @file{libc.a} will
! not set @code{errno} in such cases, and will not call @code{matherr}.
  
  To use the alternate math library with your program, you need to do the
  following:
*************** below.
*** 51,61 ****
  @item
  At the beginning of your @code{main} function, set the FPU to a
  predictable state by calling @code{_clear87} (@pxref{_clear87}) and
! @code{_fpreset} (@pxref{_fpreset}) library functions, and then mask the
! Invalid Operation exception bit in the FPU control word
! (@pxref{_control87}).  (Another possibility is to make these calls in a
! function declared with @code{__attribute__((constructor))}, so it will
! be called before @code{main}.)
  
  @item
  Link your program with the @file{libm.a} library, e.g. by specifying
--- 49,58 ----
  @item
  At the beginning of your @code{main} function, set the FPU to a
  predictable state by calling @code{_clear87} (@pxref{_clear87}) and
! @code{_fpreset} (@pxref{_fpreset}) library functions.  (Another
! possibility is to make these calls in a function declared with
! @code{__attribute__((constructor))}, so it will be called before
! @code{main}.)
  
  @item
  Link your program with the @file{libm.a} library, e.g. by specifying
*************** _LIB_VERSION_TYPE _LIB_VERSION = _POSIX_
*** 119,143 ****
  
  int main (void)
  @{
-   unsigned cw = EM_INVALID;	/* mask the Invalid Operation exception */
-   unsigned cw_mask = EM_INVALID; /* only care about INVALID bit in cw */
-   unsigned old_cw;
- 
    /* Reset the FPU (possible previous FP problems).  */
    _clear87 ();
    _fpreset ();
  
-   /* Set the FPU to not generate SIGFPE on Invalid Operation.  */
-   old_cw = _control87 (cw, cw_mask);
- 
    /* Run the test.  */
    errno = 0;
    assert(errno == 0);
    sqrt(-1.0);
    assert(errno == EDOM); /* this line should NOT cause the assertion to fail */
  
-   /* Restore previous FPU state.  */
-   _control87 (old_cw, 0x0000FFFFU);
    return(0);
  @}
  
--- 116,131 ----
*** src/libc/pc_hw/fpu/cntrl87.t~0	Sat Nov 15 01:16:12 1997
--- src/libc/pc_hw/fpu/cntrl87.txh	Sat Jan 31 14:23:08 1998
*************** compute a square root of a negative numb
*** 61,72 ****
  case of underflow), or infinity (e.g., in the case of division by zero,
  or when the result overflows).
  
! By default, DJGPP startup code masks all exceptions except Invalid
! Operation.  This setting will cause your program to crash with
! @code{SIGFPE} if it tries to compute e.g. @code{sqrt (-1)}.  If you want
! your program to set @code{errno} and continue, you will need to make
! sure the @code{EM_INVALID} bit in the control word is set (you will also
! need to link with the alternate math library, @samp{-lm}).
  
  The precision-control field @code{MCW_PC} (bits 8 and 9) controls the
  internal precision of the coprocessor by selecting the number of
--- 61,67 ----
  case of underflow), or infinity (e.g., in the case of division by zero,
  or when the result overflows).
  
! By default, DJGPP startup code masks all FP exceptions.
  
  The precision-control field @code{MCW_PC} (bits 8 and 9) controls the
  internal precision of the coprocessor by selecting the number of

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019