summaryrefslogtreecommitdiffstats
path: root/libm/amd64
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-06-09 14:29:25 -0700
committerElliott Hughes <enh@google.com>2014-06-09 15:20:59 -0700
commit43bf81e54427ac7ae55dc79c057cca62f94c5f77 (patch)
tree583366efb33b55f0789799be9782177ef692cd30 /libm/amd64
parent8c054c51c3324d36dc9ed1cf50229bae8a3f875c (diff)
downloadbionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.zip
bionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.tar.gz
bionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.tar.bz2
Move x86 fenv implementation details into fenv.c.
Change-Id: I6cb8c730483c325dc3cb75c2b2fbdd2d8455a54c
Diffstat (limited to 'libm/amd64')
-rwxr-xr-xlibm/amd64/fenv.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/libm/amd64/fenv.c b/libm/amd64/fenv.c
index b058de2..4b24ff9 100755
--- a/libm/amd64/fenv.c
+++ b/libm/amd64/fenv.c
@@ -30,6 +30,15 @@
#include <fenv.h>
#include <machine/fpu.h>
+#define SSE_MASK_SHIFT 7
+
+/*
+ * The following symbol is simply the bitwise-inclusive OR of all floating-point
+ * rounding direction constants defined above.
+ */
+#define X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+#define SSE_ROUND_SHIFT 3
+
/*
* The following constant represents the default floating-point environment
* (that is, the one installed at program startup) and has type pointer to
@@ -203,7 +212,7 @@ fegetround(void)
*/
__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
- return (control & _X87_ROUND_MASK);
+ return (control & X87_ROUND_MASK);
}
/*
@@ -218,14 +227,14 @@ fesetround(int round)
unsigned int mxcsr;
/* Check whether requested rounding direction is supported */
- if (round & ~_X87_ROUND_MASK)
+ if (round & ~X87_ROUND_MASK)
return (-1);
/* Store the current x87 control word register */
__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
/* Set the rounding direction */
- control &= ~_X87_ROUND_MASK;
+ control &= ~X87_ROUND_MASK;
control |= round;
/* Load the x87 control word register */
@@ -233,8 +242,8 @@ fesetround(int round)
/* Same for the SSE environment */
__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
- mxcsr &= ~(_X87_ROUND_MASK << _SSE_ROUND_SHIFT);
- mxcsr |= round << _SSE_ROUND_SHIFT;
+ mxcsr &= ~(X87_ROUND_MASK << SSE_ROUND_SHIFT);
+ mxcsr |= round << SSE_ROUND_SHIFT;
__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
return (0);
@@ -291,7 +300,7 @@ feholdexcept(fenv_t *envp)
mxcsr &= ~FE_ALL_EXCEPT;
/* Mask all exceptions */
- mxcsr |= FE_ALL_EXCEPT << _SSE_MASK_SHIFT;
+ mxcsr |= FE_ALL_EXCEPT << SSE_MASK_SHIFT;
/* Store the MXCSR register */
__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
@@ -362,11 +371,11 @@ feenableexcept(int mask)
__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
- omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+ omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
control &= ~mask;
__asm__ __volatile__ ("fldcw %0" : : "m" (control));
- mxcsr &= ~(mask << _SSE_MASK_SHIFT);
+ mxcsr &= ~(mask << SSE_MASK_SHIFT);
__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
return (omask);
@@ -383,11 +392,11 @@ fedisableexcept(int mask)
__asm__ __volatile__ ("fnstcw %0" : "=m" (control));
__asm__ __volatile__ ("stmxcsr %0" : "=m" (mxcsr));
- omask = ~(control | (mxcsr >> _SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
+ omask = ~(control | (mxcsr >> SSE_MASK_SHIFT)) & FE_ALL_EXCEPT;
control |= mask;
__asm__ __volatile__ ("fldcw %0" : : "m" (control));
- mxcsr |= mask << _SSE_MASK_SHIFT;
+ mxcsr |= mask << SSE_MASK_SHIFT;
__asm__ __volatile__ ("ldmxcsr %0" : : "m" (mxcsr));
return (omask);