Module Name: src Committed By: christos Date: Fri Sep 30 23:42:01 UTC 2011
Modified Files: src/lib/libc/arch/i386/gen: flt_rounds.S fpgetround.S fpsetround.S Log Message: make rounding work To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/lib/libc/arch/i386/gen/flt_rounds.S cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/i386/gen/fpgetround.S cvs rdiff -u -r1.3 -r1.4 src/lib/libc/arch/i386/gen/fpsetround.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/arch/i386/gen/flt_rounds.S diff -u src/lib/libc/arch/i386/gen/flt_rounds.S:1.8 src/lib/libc/arch/i386/gen/flt_rounds.S:1.9 --- src/lib/libc/arch/i386/gen/flt_rounds.S:1.8 Thu Sep 29 18:53:13 2011 +++ src/lib/libc/arch/i386/gen/flt_rounds.S Fri Sep 30 19:42:00 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: flt_rounds.S,v 1.8 2011/09/29 22:53:13 christos Exp $ */ +/* $NetBSD: flt_rounds.S,v 1.9 2011/09/30 23:42:00 christos Exp $ */ #include <machine/asm.h> @@ -12,8 +12,10 @@ _ALIGN_TEXT ENTRY(__flt_rounds) fnstcw -4(%esp) - movl -4(%esp), %eax - shrl $10, %eax + movl -4(%esp), %ecx + shrl $9, %ecx + andl $6, %ecx + movl $0x2d, %eax /* 0x2d = 00.10.11.01 */ + sarl %cl, %eax /* 0,1,2,3 -> 1,3,2,0 */ andl $3, %eax - xorl $1, %eax /* map 0,1,2,3 -> 1,0,3,2 */ ret Index: src/lib/libc/arch/i386/gen/fpgetround.S diff -u src/lib/libc/arch/i386/gen/fpgetround.S:1.5 src/lib/libc/arch/i386/gen/fpgetround.S:1.6 --- src/lib/libc/arch/i386/gen/fpgetround.S:1.5 Sun Jan 13 16:45:43 2002 +++ src/lib/libc/arch/i386/gen/fpgetround.S Fri Sep 30 19:42:00 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetround.S,v 1.5 2002/01/13 21:45:43 thorpej Exp $ */ +/* $NetBSD: fpgetround.S,v 1.6 2011/09/30 23:42:00 christos Exp $ */ /* * Written by J.T. Conklin, Apr 4, 1995 @@ -7,16 +7,17 @@ #include <machine/asm.h> +/* + * XXX load only x87 state. + */ + #ifdef WEAK_ALIAS WEAK_ALIAS(fpgetround, _fpgetround) ENTRY(_fpgetround) #else ENTRY(fpgetround) #endif - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - rorl $10,%eax - andl $3,%eax - addl $4,%esp + fnstcw -4(%esp) + movl -4(%esp), %eax + andl $0x00000c00, %eax ret Index: src/lib/libc/arch/i386/gen/fpsetround.S diff -u src/lib/libc/arch/i386/gen/fpsetround.S:1.3 src/lib/libc/arch/i386/gen/fpsetround.S:1.4 --- src/lib/libc/arch/i386/gen/fpsetround.S:1.3 Sun Jan 13 16:45:43 2002 +++ src/lib/libc/arch/i386/gen/fpsetround.S Fri Sep 30 19:42:00 2011 @@ -1,34 +1,33 @@ -/* $NetBSD: fpsetround.S,v 1.3 2002/01/13 21:45:43 thorpej Exp $ */ +/* $NetBSD: fpsetround.S,v 1.4 2011/09/30 23:42:00 christos Exp $ */ /* - * Written by Charles M. Hannum, Apr 9, 1995 + * Written by Frank van der Linden at Wasabi Systems for NetBSD. * Public domain. */ #include <machine/asm.h> +/* + * XXX set both the x87 control word + * Applications should only set exception and round flags + */ + + #ifdef WEAK_ALIAS WEAK_ALIAS(fpsetround, _fpsetround) ENTRY(_fpsetround) #else ENTRY(fpsetround) #endif - subl $4,%esp - - fnstcw (%esp) - movl (%esp),%eax - rorl $10,%eax - movl %eax,%edx - andl $3,%eax - - subl %eax,%edx - movl 8(%esp),%ecx - andl $3,%ecx - orl %ecx,%edx - roll $10,%edx - movl %edx,(%esp) - fldcw (%esp) + fnstcw -4(%esp) + movl -4(%esp), %edx + movl %edx, %eax + andl $0x00000c00, %eax + andl $0xfffff3ff, %edx + movl 4(%esp), %edi + orl %edi, %edx + movl %edx, -4(%esp) + fldcw -4(%esp) - addl $4,%esp ret