delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/11/16/11:25:13

Date: Mon, 16 Nov 1998 09:21:07 -0600
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: Inlining math functions and ANSI/Posix
To: djgpp-workers AT delorie DOT com
Message-id: <365042E3.7C507F42@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
X-Mailer: Mozilla 4.05 [en] (Win95; U)
References: <Pine DOT SUN DOT 3 DOT 91 DOT 981104110411 DOT 25255M-100000 AT is>
Reply-To: djgpp-workers AT delorie DOT com

Eli Zaretskii wrote:

> Clever!  What that code does is this:
>
>          1. Call FSQRT.
>          2. FUCOM compares ST with the operand, in this case ST(0) is
>             compared to itself.  Depending on the result of FSQRT in
>             ST(0), this sets certain SW_Ci bits in the status word
>             (see below).
>          3. It then retrieves the FPU status word into AX and looks at
>             its high 8 bits.
>          4. AH is ANDed with 45h (69 decimal).  This masks off any
>             bits but SW_C0, SW_C2 and SW_C3 (see the docs of
>             `_status87' in libc.inf).
>          5. Next, if only SW_C3 is set, meaning that ST(0) is equal to
>             itself, everything's okay and it accepts the result of
>             FSQRT.
>          6. If not, this means SW_C0 and SW_C2 are also set, which can
>             only happen if ST(0) cannot be compared with itself, which
>             in turn means ST(0) is either a NaN or an Infinity, and
>             the code then falls back to the library function.

I apologize for being so far behind in my correspondence.

According to the gcc docs, the math functions that are inlined are sqrt, sin,
cos and fabs.  In DJGPP v2.02 the clever mechanism works if the exceptions are
masked.  In other words, if the inline routine realizes it's in trouble, it
passes control to the subroutine.  I don't know whether this worked in earlier
versions of DJGPP.

To disable the inlining of these functions (thus forcing a call to the
subroutines), one uses -fno-builtin.  The problem with this approach is that
*none* of the builti-in functions are used.

-Eric Rudd
rudd AT cyberoptics DOT com

- Raw text -


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