fix broken modf family functions
authorRich Felker <dalias@aerifal.cx>
Mon, 19 Mar 2012 10:22:54 +0000 (06:22 -0400)
committerRich Felker <dalias@aerifal.cx>
Mon, 19 Mar 2012 10:22:54 +0000 (06:22 -0400)
src/math/i386/modf.s
src/math/i386/modff.s
src/math/i386/modfl.s

index b88e784..8e3ea50 100644 (file)
@@ -1,15 +1,28 @@
 .global modf
 .type modf,@function
 modf:
 .global modf
 .type modf,@function
 modf:
-       mov 12(%esp),%eax
+       mov 12(%esp),%ecx
        fldl 4(%esp)
        fldl 4(%esp)
-       fld1
-       fld %st(1)
-1:     fprem
-       fstsw %ax
+       fxam
+       fnstsw %ax
        sahf
        sahf
-       jp 1b
-       fstp %st(1)
-       fsubr %st(1)
-       fstpl (%eax)
+        jnp 1f
+        jc 2f
+1:      fld1
+        fld %st(1)
+1:      fprem
+        fnstsw %ax
+        sahf
+        jp 1b
+        fstp %st(1)
+        fsubr %st(0),%st(1)
+        fxch %st(1)
+        fstpl (%ecx)
+        ret
+
+2:     fstpl (%ecx)
+       mov 4(%ecx),%eax
+       and $0x80000000,%eax
+       mov %eax,4(%esp)
+       flds 4(%esp)
        ret
        ret
index d29b4b6..35a08ca 100644 (file)
@@ -1,15 +1,28 @@
 .global modff
 .type modff,@function
 modff:
 .global modff
 .type modff,@function
 modff:
-       mov 8(%esp),%eax
+       mov 8(%esp),%ecx
        flds 4(%esp)
        flds 4(%esp)
-       fld1
-       fld %st(1)
-1:     fprem
-       fstsw %ax
+       fxam
+       fnstsw %ax
        sahf
        sahf
-       jp 1b
-       fstp %st(1)
-       fsubr %st(1)
-       fstps (%eax)
+        jnp 1f
+        jc 2f
+1:      fld1
+        fld %st(1)
+1:      fprem
+        fnstsw %ax
+        sahf
+        jp 1b
+        fstp %st(1)
+        fsubr %st(0),%st(1)
+        fxch %st(1)
+        fstps (%ecx)
+        ret
+
+2:     fstps (%ecx)
+       mov (%ecx),%eax
+       and $0x80000000,%eax
+       mov %eax,4(%esp)
+       flds 4(%esp)
        ret
        ret
index f938008..d650deb 100644 (file)
@@ -1,15 +1,28 @@
 .global modfl
 .type modfl,@function
 modfl:
 .global modfl
 .type modfl,@function
 modfl:
-       mov 16(%esp),%eax
+       mov 16(%esp),%ecx
        fldt 4(%esp)
        fldt 4(%esp)
-       fld1
-       fld %st(1)
-1:     fprem
-       fstsw %ax
+       fxam
+       fnstsw %ax
        sahf
        sahf
-       jp 1b
-       fstp %st(1)
-       fsubr %st(1)
-       fstpt (%eax)
+        jnp 1f
+        jc 2f
+1:      fld1
+        fld %st(1)
+1:      fprem
+        fnstsw %ax
+        sahf
+        jp 1b
+        fstp %st(1)
+        fsubr %st(0),%st(1)
+        fxch %st(1)
+        fstpt (%ecx)
+        ret
+
+2:     fstpt (%ecx)
+       mov 6(%ecx),%eax
+       and $0x80000000,%eax
+       mov %eax,4(%esp)
+       flds 4(%esp)
        ret
        ret