1) Bug description =============================================
authorNate Willams <nate@FreeBSD.org>
Fri, 2 Jul 1993 09:16:49 +0000 (09:16 +0000)
committerNate Willams <nate@FreeBSD.org>
Fri, 2 Jul 1993 09:16:49 +0000 (09:16 +0000)
Programs compiled on 386bsd using the stock gcc 1.39 do not cast
doubles to ints correctly.  K&R says: "When the value of a
floating type is converted to integral type, the fractional part
is discarded...".  However, under 386bsd, doubles get ROUNDED to
the nearest int during a cast (instead of getting truncated).
This did not seem to occur under gcc 2.3.3 (on ref.tfs.com).

2) Fix by steve@robobar.co.uk (Steve Bleazard) ==================

"...the bug appears to be in the __fix{uns}dfsi routines that
convert from double to long.  The 386 versions of these routines
do not appear to set the rounding mode.  [...] gcc 2.3.3 appears to
have it's own C version of these routines...."

gnu/usr.bin/gcc1/gnulib/i386/fixdfsi.s
gnu/usr.bin/gcc1/gnulib/i386/fixunsdfsi.s

index 4704fa6..a264e83 100644 (file)
@@ -1,46 +1,19 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-       .asciz "@(#)fixdfsi.s   5.4 (Berkeley) 5/13/91"
-#endif /* LIBC_SCCS and not lint */
-
-       .globl ___fixdfsi
+       .file   "__fixdfsi.s"
+.text
+       .align 2
+.globl ___fixdfsi
 ___fixdfsi:
 ___fixdfsi:
-       fldl    4(%esp)
-       fistpl  4(%esp)
-       movl    4(%esp),%eax
+       pushl %ebp
+       movl %esp,%ebp
+       subl    $12,%esp
+       fstcw   -4(%ebp)  
+       movw    -4(%ebp),%ax
+       orw     $0x0c00,%ax  
+       movw    %ax,-2(%ebp) 
+       fldcw   -2(%ebp)     
+       fldl    8(%ebp)
+       fistpl  -12(%ebp)    
+       fldcw   -4(%ebp)     
+       movl    -12(%ebp),%eax
+       leave
        ret
        ret
index d3486c4..9f31df3 100644 (file)
@@ -1,47 +1,36 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
+       .file   "__fixdfsi.s"
+.text
+       .align 2
+.globl ___fixunsdfsi
+___fixunsdfsi:
+       pushl   %ebp
+       movl    %esp,%ebp
+       subl    $12,%esp
+       fstcw   -4(%ebp)  
+       movw    -4(%ebp),%ax
+       orw     $0x0c00,%ax  
+       movw    %ax,-2(%ebp) 
+       fldcw   -2(%ebp)     
+       fldl    8(%ebp)
+
+       fcoml   fbiggestsigned  /* bigger than biggest signed? */
+       fstsw   %ax
+       sahf
+       jnb     1f
+       
+       fistpl  -12(%ebp)    
+       movl    -12(%ebp),%eax
+       jmp     2f
+
+1:     fsubl   fbiggestsigned  /* reduce for proper conversion */
+       fistpl  -12(%ebp)               /* convert */
+       movl    -12(%ebp),%eax
+       orl     $0x80000000,%eax        /* restore bias */
 
 
-#if defined(LIBC_SCCS) && !defined(lint)
-       .asciz "@(#)fixunsdfsi.s        5.1     12/17/90"
-#endif /* LIBC_SCCS and not lint */
+2:     fldcw   -4(%ebp)     
+       leave
+       ret
 
 
-       .globl ___fixunsdfsi
-___fixunsdfsi:
-       fldl    4(%esp)         /* argument double to accum stack */
-       frndint                 /* create integer */
        fcoml   fbiggestsigned  /* bigger than biggest signed? */
        fstsw   %ax
        sahf
        fcoml   fbiggestsigned  /* bigger than biggest signed? */
        fstsw   %ax
        sahf
@@ -57,4 +46,5 @@ ___fixunsdfsi:
        orl     $0x80000000,%eax        /* restore bias */
        ret
 
        orl     $0x80000000,%eax        /* restore bias */
        ret
 
+       .data
 fbiggestsigned:        .double 0r2147483648.0
 fbiggestsigned:        .double 0r2147483648.0