Module Name:    src
Committed By:   christos
Date:           Fri Sep 30 17:42:35 UTC 2011

Modified Files:
        src/lib/libc/arch/x86_64/gen: flt_rounds.S fpgetround.S fpsetround.S

Log Message:
PR/44293: Paul Goyette: Fix the mess of the rounding code.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/arch/x86_64/gen/flt_rounds.S
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/arch/x86_64/gen/fpgetround.S \
    src/lib/libc/arch/x86_64/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/x86_64/gen/flt_rounds.S
diff -u src/lib/libc/arch/x86_64/gen/flt_rounds.S:1.5 src/lib/libc/arch/x86_64/gen/flt_rounds.S:1.6
--- src/lib/libc/arch/x86_64/gen/flt_rounds.S:1.5	Thu Sep 29 18:55:45 2011
+++ src/lib/libc/arch/x86_64/gen/flt_rounds.S	Fri Sep 30 13:42:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: flt_rounds.S,v 1.5 2011/09/29 22:55:45 christos Exp $	*/
+/*	$NetBSD: flt_rounds.S,v 1.6 2011/09/30 17:42:34 christos Exp $	*/
 
 #include <machine/asm.h>
 
@@ -12,8 +12,10 @@
 	_ALIGN_TEXT
 ENTRY(__flt_rounds)
 	fnstcw	-4(%rsp)
-	movl	-4(%rsp), %eax
-	shrl	$10, %eax
+	movl	-4(%rsp), %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/x86_64/gen/fpgetround.S
diff -u src/lib/libc/arch/x86_64/gen/fpgetround.S:1.3 src/lib/libc/arch/x86_64/gen/fpgetround.S:1.4
--- src/lib/libc/arch/x86_64/gen/fpgetround.S:1.3	Wed Jun 12 15:17:22 2002
+++ src/lib/libc/arch/x86_64/gen/fpgetround.S	Fri Sep 30 13:42:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpgetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $	*/
+/*	$NetBSD: fpgetround.S,v 1.4 2011/09/30 17:42:34 christos Exp $	*/
 
 /*
  * Written by J.T. Conklin, Apr 4, 1995
@@ -8,7 +8,7 @@
 #include <machine/asm.h>
 
 /*
- * XXX store only x87 state. If an application only uses the fp*
+ * XXX load only x87 state. If an application only uses the fp*
  * interface, this should be in sync with the SSE mxcsr register.
  */
 
@@ -19,7 +19,6 @@ ENTRY(_fpgetround)
 ENTRY(fpgetround)
 #endif
 	fnstcw -4(%rsp)
-	movl -4(%rsp),%eax
-	rorl $10,%eax
-	andl $3,%eax
+	movl -4(%rsp), %eax
+	andl $0x00000c00, %eax
 	ret
Index: src/lib/libc/arch/x86_64/gen/fpsetround.S
diff -u src/lib/libc/arch/x86_64/gen/fpsetround.S:1.3 src/lib/libc/arch/x86_64/gen/fpsetround.S:1.4
--- src/lib/libc/arch/x86_64/gen/fpsetround.S:1.3	Wed Jun 12 15:17:22 2002
+++ src/lib/libc/arch/x86_64/gen/fpsetround.S	Fri Sep 30 13:42:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpsetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $	*/
+/*	$NetBSD: fpsetround.S,v 1.4 2011/09/30 17:42:34 christos Exp $	*/
 
 /*
  * Written by Frank van der Linden at Wasabi Systems for NetBSD.
@@ -21,28 +21,22 @@ ENTRY(_fpsetround)
 #else
 ENTRY(fpsetround)
 #endif
-	fnstcw	-4(%rsp)
-	stmxcsr	-8(%rsp)
-
-	andl	$3,%edi
 
-	movl	-4(%rsp),%edx
-	rorl	$10,%edx
-	movl	%edx,%eax
-	andl	$3,%eax
+	fnstcw	-4(%rsp)
+	movl	-4(%rsp), %edx
+	movl	%edx, %eax
+	andl	$0x00000c00, %eax	
+	andl	$0xfffff3ff, %edx
+	orl	%edi, %edx
+	movl	%edx, -4(%rsp)
+	fldcw	-4(%rsp)
 
-	andl	$~3,%edx
+	stmxcsr	-4(%rsp)
+	movl	-4(%rsp), %edx
+	andl	$0xffff9fff, %edx
+	sall	$3, %edi
 	orl	%edi,%edx
-	roll	$10,%edx
 	movl	%edx,-4(%rsp)
+	ldmxcsr	-4(%rsp)
 
-	movl	-8(%rsp),%edx
-	rorl	$13,%edx
-	andl	$~3,%edx
-	orl	%edi,%edx
-	roll	$13,%edx
-	movl	%edx,-8(%rsp)
-
-	ldmxcsr	-8(%rsp)
-	fldcw	-4(%rsp)
 	ret

Reply via email to