diff options
| author | charles forsyth <charles.forsyth@gmail.com> | 2014-05-18 14:19:01 +0100 |
|---|---|---|
| committer | charles forsyth <charles.forsyth@gmail.com> | 2014-05-18 14:19:01 +0100 |
| commit | 37e9221a5d1905cba45c96ac44dbe26d947bc4af (patch) | |
| tree | 87bf6a76dc94bc638418883e0ca21afcfa2ad78f /lib9 | |
| parent | 7e479951464b9bb71e87aeef19d908e9fb9be494 (diff) | |
20140518-1419
Diffstat (limited to 'lib9')
| -rw-r--r-- | lib9/setfcr-DragonFly-386.c | 56 | ||||
| -rw-r--r-- | lib9/setfcr-Linux-arm.c | 32 | ||||
| -rw-r--r-- | lib9/setfcr-Linux-power.S | 20 | ||||
| -rw-r--r-- | lib9/setfcr-MacOSX-386.c | 56 | ||||
| -rw-r--r-- | lib9/setfcr-MacOSX-power.c | 39 | ||||
| -rw-r--r-- | lib9/setfcr-NetBSD-386.c | 55 | ||||
| -rw-r--r-- | lib9/setfcr-OpenBSD-386.c | 57 | ||||
| -rw-r--r-- | lib9/setfcr-Solaris-sparc.c | 42 |
8 files changed, 357 insertions, 0 deletions
diff --git a/lib9/setfcr-DragonFly-386.c b/lib9/setfcr-DragonFly-386.c new file mode 100644 index 00000000..3589dd80 --- /dev/null +++ b/lib9/setfcr-DragonFly-386.c @@ -0,0 +1,56 @@ +/* + * Linux 386 fpu support + * Mimic Plan9 floating point support + */ + +#include "lib9.h" + +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) + ); +} + +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; +} + +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; +} + +void +setfsr(ulong fsr) +{ + __asm__("fclex\n\t"); +} diff --git a/lib9/setfcr-Linux-arm.c b/lib9/setfcr-Linux-arm.c new file mode 100644 index 00000000..eb77b872 --- /dev/null +++ b/lib9/setfcr-Linux-arm.c @@ -0,0 +1,32 @@ +/* + * Linux arm fpu support + * Mimic Plan9 floating point support + */ + +#include "lib9.h" + +#include <fenv.h> + +void +setfcr(ulong fcr) +{ +} + +ulong +getfcr(void) +{ + ulong fcr = 0; + return fcr; +} + +ulong +getfsr(void) +{ + ulong fsr = -1; + return fsr; +} + +void +setfsr(ulong fsr) +{ +} diff --git a/lib9/setfcr-Linux-power.S b/lib9/setfcr-Linux-power.S new file mode 100644 index 00000000..dee67528 --- /dev/null +++ b/lib9/setfcr-Linux-power.S @@ -0,0 +1,20 @@ + +#define FN(x) .type x,@function; .global x; x + +FN(getfcr): + mffs %f0 + cvtfl %r3,%f0 + blr + +FN(getfsr): + mffs %f0 + cvtfl %r3,%f0 + blr + +FN(setfsr): + mtfsf 0xff, %f0 + blr + +FN(setfcr): + mtfsf 0xff, %f0 + blr diff --git a/lib9/setfcr-MacOSX-386.c b/lib9/setfcr-MacOSX-386.c new file mode 100644 index 00000000..3589dd80 --- /dev/null +++ b/lib9/setfcr-MacOSX-386.c @@ -0,0 +1,56 @@ +/* + * Linux 386 fpu support + * Mimic Plan9 floating point support + */ + +#include "lib9.h" + +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) + ); +} + +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; +} + +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; +} + +void +setfsr(ulong fsr) +{ + __asm__("fclex\n\t"); +} diff --git a/lib9/setfcr-MacOSX-power.c b/lib9/setfcr-MacOSX-power.c new file mode 100644 index 00000000..17b76a88 --- /dev/null +++ b/lib9/setfcr-MacOSX-power.c @@ -0,0 +1,39 @@ +/* + * MacOSX/Darwin ppc fpu support + * Mimic Plan9 floating point support + */ + +#include "lib9.h" +#include <architecture/ppc/fp_regs.h> + +__inline__ ulong +getfcr(void) +{ + ppc_fp_scr_t fpscr = get_fp_scr(); + return ((ulong *)&fpscr)[1]; +} + +ulong +getfsr(void) +{ + ppc_fp_scr_t fpscr = get_fp_scr(); + return ((ulong *)&fpscr)[1]; +} + +void +setfsr(ulong fsr) +{ + ppc_fp_scr_t fpscr; + // fpscr = get_fp_scr(); + (((ulong *)&fpscr)[1]) = fsr; + set_fp_scr(fpscr); +} + +void +setfcr(ulong fcr) +{ + ppc_fp_scr_t fpscr; + // fpscr = get_fp_scr(); + (((ulong *)&fpscr)[1]) = fcr; + set_fp_scr(fpscr); +} diff --git a/lib9/setfcr-NetBSD-386.c b/lib9/setfcr-NetBSD-386.c new file mode 100644 index 00000000..e58171a3 --- /dev/null +++ b/lib9/setfcr-NetBSD-386.c @@ -0,0 +1,55 @@ +/* + * Linux 386 fpu support + * Mimic Plan9 floating point support + */ +#include "lib9.h" + +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) + ); +} + +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; +} + +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; +} + +void +setfsr(ulong fsr) +{ + __asm__("fclex\n\t"); +} diff --git a/lib9/setfcr-OpenBSD-386.c b/lib9/setfcr-OpenBSD-386.c new file mode 100644 index 00000000..c512f033 --- /dev/null +++ b/lib9/setfcr-OpenBSD-386.c @@ -0,0 +1,57 @@ +/* + * 386 fpu support + * Mimic Plan9 floating point support + */ + +#include "lib9.h" + + +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) + ); +} + +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; +} + +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; +} + +void +setfsr(ulong fsr) +{ + __asm__("fclex\n\t"); +} diff --git a/lib9/setfcr-Solaris-sparc.c b/lib9/setfcr-Solaris-sparc.c new file mode 100644 index 00000000..405e9cf2 --- /dev/null +++ b/lib9/setfcr-Solaris-sparc.c @@ -0,0 +1,42 @@ +/* This code is a little awkward. If somebody who understands Solaris + better would tell me an idiomatic way to invoke equivalent + behavior, I'd be grateful. ehg@bell-labs.com */ + +#include "lib9.h" + +ulong +getfcr(void) +{ + ulong v; + + asm(" st %fsr, [%fp-8]"); + return v; +} + +void +setfcr(ulong v) +{ + ulong vv; + + vv = (getfcr() & ~FPFCR) | (v & FPFCR); + asm(" ld [%fp-4], %fsr"); +} + +ulong +getfsr(void) +{ + ulong v; + + asm(" st %fsr, [%fp-8]"); + return v; +} + +void +setfsr(ulong v) +{ + ulong vv; + + vv = (getfsr() & ~FPFSR) | (v & FPFSR); + asm(" ld [%fp-4], %fsr"); +} + |
