Module Name:    src
Committed By:   isaki
Date:           Sat Apr 20 09:32:28 UTC 2013

Modified Files:
        src/sys/arch/m68k/fpe: fpu_subr.c

Log Message:
Rewrite around BFFFO inline asm.
o Prepare C version of BFFFO (from XM6i).
  It is helpful in running FPE on other platforms (for example, for a
  test).  It is also helpful in porting to non-m68k 3rd party :)
o A BFFFO is supported on 68020 or later (though I'm not sure whether
  sun2/68010 uses this FPE correctly or not).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/m68k/fpe/fpu_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/m68k/fpe/fpu_subr.c
diff -u src/sys/arch/m68k/fpe/fpu_subr.c:1.10 src/sys/arch/m68k/fpe/fpu_subr.c:1.11
--- src/sys/arch/m68k/fpe/fpu_subr.c:1.10	Tue Mar 26 11:30:21 2013
+++ src/sys/arch/m68k/fpe/fpu_subr.c	Sat Apr 20 09:32:28 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_subr.c,v 1.10 2013/03/26 11:30:21 isaki Exp $ */
+/*	$NetBSD: fpu_subr.c,v 1.11 2013/04/20 09:32:28 isaki Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu_subr.c,v 1.10 2013/03/26 11:30:21 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_subr.c,v 1.11 2013/04/20 09:32:28 isaki Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -56,6 +56,25 @@ __KERNEL_RCSID(0, "$NetBSD: fpu_subr.c,v
 #include "fpu_arith.h"
 
 /*
+ * m68020 or later has a BFFFO instruction, therefore use it.
+ * Otherwise, use C version.
+ */
+static inline int
+bfffo(uint32_t src)
+{
+	int offset;
+#if defined(__m68k__) && !defined(M68010)
+	__asm volatile("bfffo %1{#0:#32},%0" : "=d"(offset) : "g"(src));
+#else
+	int width = 32;
+	for (offset = 0; width-- > 0 && (int)src >= 0; src <<= 1) {
+		offset++;
+	}
+#endif
+	return offset;
+}
+
+/*
  * Shift the given number right rsh bits.  Any bits that `fall off' will get
  * shoved into the sticky field; we return the resulting sticky.  Note that
  * shifting NaNs is legal (this will never shift all bits out); a NaN's
@@ -165,7 +184,7 @@ fpu_norm(struct fpn *fp)
 		 * We have a supernormal number.  We need to shift it right.
 		 * We may assume m2==0.
 		 */
-		__asm volatile("bfffo %1{#0:#32},%0" : "=d"(rsh) : "g"(m0));
+		rsh = bfffo(m0);
 		rsh = 31 - rsh - FP_LG;
 		exp += rsh;
 		lsh = 32 - rsh;
@@ -177,7 +196,7 @@ fpu_norm(struct fpn *fp)
 		 * We have a regular denorm (a subnormal number), and need
 		 * to shift it left.
 		 */
-		__asm volatile("bfffo %1{#0:#32},%0" : "=d"(lsh) : "g"(m0));
+		lsh = bfffo(m0);
 		lsh = FP_LG - 31 + lsh;
 		exp -= lsh;
 		rsh = 32 - lsh;

Reply via email to