summaryrefslogtreecommitdiffstats
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
parent8c054c51c3324d36dc9ed1cf50229bae8a3f875c (diff)
downloadbionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.zip
bionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.tar.gz
bionic-43bf81e54427ac7ae55dc79c057cca62f94c5f77.tar.bz2
Move x86 fenv implementation details into fenv.c.
Change-Id: I6cb8c730483c325dc3cb75c2b2fbdd2d8455a54c
-rwxr-xr-xlibm/amd64/fenv.c29
-rw-r--r--libm/i387/fenv.c10
-rw-r--r--libm/include/amd64/machine/fenv.h9
-rw-r--r--libm/include/i387/machine/fenv.h2
4 files changed, 25 insertions, 25 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);
diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c
index 3ab9c58..f64f8dc 100644
--- a/libm/i387/fenv.c
+++ b/libm/i387/fenv.c
@@ -31,6 +31,8 @@
#include "npx.h"
#include "fenv.h"
+#define ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)
+
/*
* As compared to the x87 control word, the SSE unit's control word
* has the rounding control bits offset by 3 and the exception mask
@@ -327,7 +329,7 @@ fegetround(void)
* unit on an Opteron 244.
*/
__fnstcw(&control);
- return (control & _ROUND_MASK);
+ return (control & ROUND_MASK);
}
int
@@ -336,16 +338,16 @@ fesetround(int round)
__uint32_t mxcsr;
__uint16_t control;
- if (round & ~_ROUND_MASK) {
+ if (round & ~ROUND_MASK) {
return (-1);
} else {
__fnstcw(&control);
- control &= ~_ROUND_MASK;
+ control &= ~ROUND_MASK;
control |= round;
__fldcw(control);
if (__HAS_SSE()) {
__stmxcsr(&mxcsr);
- mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT);
+ mxcsr &= ~(ROUND_MASK << _SSE_ROUND_SHIFT);
mxcsr |= round << _SSE_ROUND_SHIFT;
__ldmxcsr(mxcsr);
}
diff --git a/libm/include/amd64/machine/fenv.h b/libm/include/amd64/machine/fenv.h
index 79a4120..c2b25ed 100644
--- a/libm/include/amd64/machine/fenv.h
+++ b/libm/include/amd64/machine/fenv.h
@@ -51,7 +51,6 @@ __BEGIN_DECLS
*/
#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
-#define _SSE_MASK_SHIFT 7
/*
* Each symbol representing the rounding direction, expands to an integer
@@ -65,14 +64,6 @@ __BEGIN_DECLS
#define FE_TOWARDZERO 0xc00
/*
- * 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
-
-/*
* fenv_t represents the entire floating-point environment.
*/
typedef struct {
diff --git a/libm/include/i387/machine/fenv.h b/libm/include/i387/machine/fenv.h
index f3fabb6..de45add 100644
--- a/libm/include/i387/machine/fenv.h
+++ b/libm/include/i387/machine/fenv.h
@@ -63,8 +63,6 @@ typedef __uint16_t fexcept_t;
#define FE_DOWNWARD 0x0400
#define FE_UPWARD 0x0800
#define FE_TOWARDZERO 0x0c00
-#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
- FE_UPWARD | FE_TOWARDZERO)
__END_DECLS