summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Ushakov <uwe@stderr.spb.ru>2016-06-01 14:23:27 +0300
committerValery Ushakov <uwe@stderr.spb.ru>2016-06-01 14:23:27 +0300
commit49c7e6d3dd79dc7807b70e8f149798f28319957c (patch)
treef2843b8c956427908662499b78067eeac55bdc1e
parentecdaf43c2cae919113d803376965be93e6b880af (diff)
Move fpuctl.h stuff into lib9, like on Linux. Inline asm version is
probably mis-optimized by modern gcc, but I didn't bother investigating.
-rw-r--r--NetBSD/386/include/fpuctl.h76
-rw-r--r--NetBSD/386/include/lib9.h26
-rw-r--r--lib9/setfcr-NetBSD-386.S34
3 files changed, 60 insertions, 76 deletions
diff --git a/NetBSD/386/include/fpuctl.h b/NetBSD/386/include/fpuctl.h
index 8389f6ee..e69de29b 100644
--- a/NetBSD/386/include/fpuctl.h
+++ b/NetBSD/386/include/fpuctl.h
@@ -1,76 +0,0 @@
-/*
- * Linux 386 fpu support
- * Mimic Plan9 floating point support
- */
-
-static void
-setfcr(ulong fcr)
-{
- __asm__( "xorb $0x3f, %%al\n\t"
- "pushw %%ax\n\t"
- "fwait\n\t"
- "fldcw (%%esp)\n\t"
- "popw %%ax\n\t"
- : /* no output */
- : "al" (fcr)
- );
-}
-
-static ulong
-getfcr(void)
-{
- ulong fcr = 0;
-
- __asm__( "pushl %%eax\n\t"
- "fwait\n\t"
- "fstcw (%%esp)\n\t"
- "popl %%eax\n\t"
- "xorb $0x3f, %%al\n\t"
- : "=a" (fcr)
- : "eax" (fcr)
- );
- return fcr;
-}
-
-static ulong
-getfsr(void)
-{
- ulong fsr = -1;
-
- __asm__( "fwait\n\t"
- "fstsw (%%eax)\n\t"
- "movl (%%eax), %%eax\n\t"
- "andl $0xffff, %%eax\n\t"
- : "=a" (fsr)
- : "eax" (&fsr)
- );
- return fsr;
-}
-
-static void
-setfsr(ulong fsr)
-{
- __asm__("fclex\n\t");
-}
-
-/* FCR */
-#define FPINEX (1<<5)
-#define FPUNFL ((1<<4)|(1<<1))
-#define FPOVFL (1<<3)
-#define FPZDIV (1<<2)
-#define FPINVAL (1<<0)
-#define FPRNR (0<<10)
-#define FPRZ (3<<10)
-#define FPRPINF (2<<10)
-#define FPRNINF (1<<10)
-#define FPRMASK (3<<10)
-#define FPPEXT (3<<8)
-#define FPPSGL (0<<8)
-#define FPPDBL (2<<8)
-#define FPPMASK (3<<8)
-/* FSR */
-#define FPAINEX FPINEX
-#define FPAOVFL FPOVFL
-#define FPAUNFL FPUNFL
-#define FPAZDIV FPZDIV
-#define FPAINVAL FPINVAL
diff --git a/NetBSD/386/include/lib9.h b/NetBSD/386/include/lib9.h
index 0e0222ea..e796387f 100644
--- a/NetBSD/386/include/lib9.h
+++ b/NetBSD/386/include/lib9.h
@@ -476,3 +476,29 @@ extern char *argv0;
#define setbinmode()
+/* FCR */
+#define FPINEX (1<<5)
+#define FPUNFL ((1<<4)|(1<<1))
+#define FPOVFL (1<<3)
+#define FPZDIV (1<<2)
+#define FPINVAL (1<<0)
+#define FPRNR (0<<10)
+#define FPRZ (3<<10)
+#define FPRPINF (2<<10)
+#define FPRNINF (1<<10)
+#define FPRMASK (3<<10)
+#define FPPEXT (3<<8)
+#define FPPSGL (0<<8)
+#define FPPDBL (2<<8)
+#define FPPMASK (3<<8)
+/* FSR */
+#define FPAINEX FPINEX
+#define FPAOVFL FPOVFL
+#define FPAUNFL FPUNFL
+#define FPAZDIV FPZDIV
+#define FPAINVAL FPINVAL
+
+extern void setfcr(ulong);
+extern void setfsr(ulong);
+extern ulong getfcr(void);
+extern ulong getfsr(void);
diff --git a/lib9/setfcr-NetBSD-386.S b/lib9/setfcr-NetBSD-386.S
new file mode 100644
index 00000000..d981f36a
--- /dev/null
+++ b/lib9/setfcr-NetBSD-386.S
@@ -0,0 +1,34 @@
+
+#define FN(x) .type x,@function; .global x; x
+#define ENT subl $16, %esp
+#define RET addl $16, %esp; ret
+
+ .file "setfcr-Linux-386.S"
+FN(setfcr):
+ ENT
+ xorb $0x3f, %al
+ movl %eax, (%esp)
+ fwait
+ fldcw (%esp)
+ RET
+
+FN(getfcr):
+ ENT
+ fwait
+ fstcw (%esp)
+ movw (%esp), %ax
+ andl $0xffff, %eax
+ xorb $0x3f, %al
+ RET
+
+FN(getfsr):
+ ENT
+ fwait
+ fstsw (%esp)
+ movw (%esp), %ax
+ andl $0xffff, %eax
+ RET
+
+FN(setfsr):
+ fclex
+ ret