Mail Archives: djgpp/1992/02/27/22:30:02
Dirk Zabel writes:
>Hi,
>could somebody who is lucky enough to have a REAL 387 try to compile
>this short program with "gcc -c -S test.c":
>
>------- cut here -------- test.c ---------------
>double q = 0.3e10;
>------- cut here -------------------------------
>
>If the generated assembly-language output does not contain
>the following bad constant, the 387-emulator has most probably another bug.
This bug is due to problems with rounding in emu387 (basically, there is
none!).
With the patches which I present below, you will get the following:
--------------------- snip, snip ------------------------
.file "bug.c"
gcc_compiled.:
.globl _q
.data
.align 2,144
_q:
.double 0d3.00000000000000047684e+09
--------------------- snip, snip ------------------------
Here is my patch:
--------------------- snip, snip ------------------------
*** old/rmov.cc Thu May 9 22:35:54 1991
--- rmov.cc Fri Feb 21 08:08:58 1992
***************
*** 266,273 ****
}
else
{
! l[0] = (s.sigl >> 11) | (s.sigh << 21);
! l[1] = ((s.sigh >> 11) & 0xfffff) | (((s.exp-EXP_BIAS+1023) & 0x7ff) << 20);
}
if (s.sign)
l[1] |= 0x80000000;
--- 266,300 ----
}
else
{
! if ( s.sigl & 0x400 )
! {
! if ( s.sigl >= 0xfffff800 )
! {
! /* the sigl part will -> 0, with a carry */
! if ( s.sigh == 0xffffffff )
! {
! /* The sigh part overflows */
! l[0] = 0;
! /* ***** Checking for exp overflow not yet implemented **** */
! l[1] = (((s.exp-EXP_BIAS+1023+1) & 0x7ff) << 20);
! }
! else
! {
! l[0] = (s.sigh+1) << 21;
! l[1] = (((s.sigh+1) >> 11) & 0xfffff) | (((s.exp-EXP_BIAS+1023) & 0x7ff) << 20);
! }
! }
! else
! {
! l[0] = ((s.sigl+0x800) >> 11) | (s.sigh << 21);
! l[1] = ((s.sigh >> 11) & 0xfffff) | (((s.exp-EXP_BIAS+1023) & 0x7ff) << 20);
! }
! }
! else
! {
! l[0] = (s.sigl >> 11) | (s.sigh << 21);
! l[1] = ((s.sigh >> 11) & 0xfffff) | (((s.exp-EXP_BIAS+1023) & 0x7ff) << 20);
! }
}
if (s.sign)
l[1] |= 0x80000000;
--------------------- snip, snip ------------------------
Note that this only handles conversion from the internal 80
bits or so to "double". I think that even for "double", it is
not complete because I seem to recall that the 80387 (or is it
the IEEE specification) has a means of turning rounding on and
off, etc.
A question to DJ Delorie: Is someone really working on a replacement
for emu387?
Bill Metzenthen
apm233m AT vaxc DOT cc DOT monash DOT edu DOT au
- Raw text -