www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/03/19/20:13:56

Sender: nate AT cartsys DOT com
Message-ID: <36F2F520.4AAA2AC@cartsys.com>
Date: Fri, 19 Mar 1999 17:08:48 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.3 i586)
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
CC: beyonder69 AT geocities DOT com
Subject: Re: sin(acos((float)i/1024))*0x10000L
References: <199903142305 DOT RAA16482 AT x15 DOT dejanews DOT com> <36EC443E DOT EFFA47B5 AT cartsys DOT com>
Reply-To: djgpp-workers AT delorie DOT com

I wrote:
> 
> The Beyonder <beyonder69 AT geocities DOT com> wrote:
> 
> > Now during compilation it just gets stuck on "Generating Tri table...".
> > SIN alone works, and so does COS... but ACOS alone just stalls (I can
> > quit using CTRL-C).
> >
> > Is it ACOS or my programming?
> 
> This appears to be a bug in the FPU emulation.  I can reproduce it on an
> FPU-less machine; any call to `acos' appears to enter some kind of
> infinite loop.

It turns out this is due to a compiler bug that breaks the emulator in
`fsqrt'.  It compiles the test for the main loop into

xorl %edx, %edx
testl %edx, %edx
je loop_top

(!!!!)

It was probably never noticed before because GCC 2.7.2.1 did not have
this bug.  It seems to be fixed in EGCS 1.1.2 (but not 1.1.1.)

Here is a patch which works around it.

*** src/libemu/src/emu387.cc    Fri Mar 19 16:53:54 1999
--- src/libemu/src/emu387.new   Fri Mar 19 16:54:44 1999
***************
*** 2033,2038 ****
--- 2033,2041 ----
    int exp = (st().exp - EXP_BIAS - 1)/2 - 64;
    while (!(((long *)&result)[1] & 0x80000000))
    {
+     /* GCC between 2.8 and EGCS 1.1.1 optimizes this loop
+        all wrong; the asm works around it. */
+     asm volatile("" : : : "memory");
      left = (left << 2) + (((unsigned *)&val)[1] >> 30);
      djshld(&val);
      djshld(&val);


-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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