|
|
dfa500 |
commit cd7ce12a027656ad3cda774454088de5a2c7fbfa
|
|
|
dfa500 |
Author: Paul A. Clarke <pc@us.ibm.com>
|
|
|
dfa500 |
Date: Fri Jul 12 20:13:58 2019 -0500
|
|
|
dfa500 |
|
|
|
dfa500 |
[powerpc] fe{en,dis}ableexcept optimize bit translations
|
|
|
dfa500 |
|
|
|
dfa500 |
The exceptions passed to fe{en,dis}ableexcept() are defined in the ABI
|
|
|
dfa500 |
as a bitmask, a combination of FE_INVALID, FE_OVERFLOW, etc.
|
|
|
dfa500 |
Within the functions, these bits must be translated to/from the corresponding
|
|
|
dfa500 |
enable bits in the Floating Point Status Control Register (FPSCR).
|
|
|
dfa500 |
This translation is currently done bit-by-bit. The compiler generates
|
|
|
dfa500 |
a series of conditional bit operations. Nicely, the "FE" exception
|
|
|
dfa500 |
bits are all a uniform offset from the FPSCR enable bits, so the bit-by-bit
|
|
|
dfa500 |
operation can instead be performed by a shift with appropriate masking.
|
|
|
dfa500 |
|
|
|
dfa500 |
diff --git a/sysdeps/powerpc/fpu/fedisblxcpt.c b/sysdeps/powerpc/fpu/fedisblxcpt.c
|
|
|
dfa500 |
index 2daed44a419301e8..90bc3d12c6d8558c 100644
|
|
|
dfa500 |
--- a/sysdeps/powerpc/fpu/fedisblxcpt.c
|
|
|
dfa500 |
+++ b/sysdeps/powerpc/fpu/fedisblxcpt.c
|
|
|
dfa500 |
@@ -33,16 +33,7 @@ fedisableexcept (int excepts)
|
|
|
dfa500 |
excepts = (excepts | FE_INVALID) & ~ FE_ALL_INVALID;
|
|
|
dfa500 |
|
|
|
dfa500 |
/* Sets the new exception mask. */
|
|
|
dfa500 |
- if (excepts & FE_INEXACT)
|
|
|
dfa500 |
- fe.l &= ~(1 << (31 - FPSCR_XE));
|
|
|
dfa500 |
- if (excepts & FE_DIVBYZERO)
|
|
|
dfa500 |
- fe.l &= ~(1 << (31 - FPSCR_ZE));
|
|
|
dfa500 |
- if (excepts & FE_UNDERFLOW)
|
|
|
dfa500 |
- fe.l &= ~(1 << (31 - FPSCR_UE));
|
|
|
dfa500 |
- if (excepts & FE_OVERFLOW)
|
|
|
dfa500 |
- fe.l &= ~(1 << (31 - FPSCR_OE));
|
|
|
dfa500 |
- if (excepts & FE_INVALID)
|
|
|
dfa500 |
- fe.l &= ~(1 << (31 - FPSCR_VE));
|
|
|
dfa500 |
+ fe.l &= ~ fenv_exceptions_to_reg (excepts);
|
|
|
dfa500 |
|
|
|
dfa500 |
if (fe.l != curr.l)
|
|
|
dfa500 |
fesetenv_register (fe.fenv);
|
|
|
dfa500 |
diff --git a/sysdeps/powerpc/fpu/feenablxcpt.c b/sysdeps/powerpc/fpu/feenablxcpt.c
|
|
|
dfa500 |
index 19cfe28e7aa307d4..e029971b9a460c28 100644
|
|
|
dfa500 |
--- a/sysdeps/powerpc/fpu/feenablxcpt.c
|
|
|
dfa500 |
+++ b/sysdeps/powerpc/fpu/feenablxcpt.c
|
|
|
dfa500 |
@@ -33,16 +33,7 @@ feenableexcept (int excepts)
|
|
|
dfa500 |
excepts = (excepts | FE_INVALID) & ~ FE_ALL_INVALID;
|
|
|
dfa500 |
|
|
|
dfa500 |
/* Sets the new exception mask. */
|
|
|
dfa500 |
- if (excepts & FE_INEXACT)
|
|
|
dfa500 |
- fe.l |= (1 << (31 - FPSCR_XE));
|
|
|
dfa500 |
- if (excepts & FE_DIVBYZERO)
|
|
|
dfa500 |
- fe.l |= (1 << (31 - FPSCR_ZE));
|
|
|
dfa500 |
- if (excepts & FE_UNDERFLOW)
|
|
|
dfa500 |
- fe.l |= (1 << (31 - FPSCR_UE));
|
|
|
dfa500 |
- if (excepts & FE_OVERFLOW)
|
|
|
dfa500 |
- fe.l |= (1 << (31 - FPSCR_OE));
|
|
|
dfa500 |
- if (excepts & FE_INVALID)
|
|
|
dfa500 |
- fe.l |= (1 << (31 - FPSCR_VE));
|
|
|
dfa500 |
+ fe.l |= fenv_exceptions_to_reg (excepts);
|
|
|
dfa500 |
|
|
|
dfa500 |
if (fe.l != curr.l)
|
|
|
dfa500 |
fesetenv_register (fe.fenv);
|
|
|
dfa500 |
diff --git a/sysdeps/powerpc/fpu/fenv_libc.h b/sysdeps/powerpc/fpu/fenv_libc.h
|
|
|
dfa500 |
index 9dca6e760cc51946..f9634a64d186c076 100644
|
|
|
dfa500 |
--- a/sysdeps/powerpc/fpu/fenv_libc.h
|
|
|
dfa500 |
+++ b/sysdeps/powerpc/fpu/fenv_libc.h
|
|
|
dfa500 |
@@ -129,60 +129,108 @@ __fesetround_inline_nocheck (const int round)
|
|
|
dfa500 |
asm volatile ("mtfsfi 7,%0" : : "i" (round));
|
|
|
dfa500 |
}
|
|
|
dfa500 |
|
|
|
dfa500 |
+#define FPSCR_MASK(bit) (1 << (31 - (bit)))
|
|
|
dfa500 |
+
|
|
|
dfa500 |
/* Definitions of all the FPSCR bit numbers */
|
|
|
dfa500 |
enum {
|
|
|
dfa500 |
FPSCR_FX = 0, /* exception summary */
|
|
|
dfa500 |
+#define FPSCR_FX_MASK (FPSCR_MASK (FPSCR_FX))
|
|
|
dfa500 |
FPSCR_FEX, /* enabled exception summary */
|
|
|
dfa500 |
+#define FPSCR_FEX_MASK (FPSCR_MASK FPSCR_FEX))
|
|
|
dfa500 |
FPSCR_VX, /* invalid operation summary */
|
|
|
dfa500 |
+#define FPSCR_VX_MASK (FPSCR_MASK (FPSCR_VX))
|
|
|
dfa500 |
FPSCR_OX, /* overflow */
|
|
|
dfa500 |
+#define FPSCR_OX_MASK (FPSCR_MASK (FPSCR_OX))
|
|
|
dfa500 |
FPSCR_UX, /* underflow */
|
|
|
dfa500 |
+#define FPSCR_UX_MASK (FPSCR_MASK (FPSCR_UX))
|
|
|
dfa500 |
FPSCR_ZX, /* zero divide */
|
|
|
dfa500 |
+#define FPSCR_ZX_MASK (FPSCR_MASK (FPSCR_ZX))
|
|
|
dfa500 |
FPSCR_XX, /* inexact */
|
|
|
dfa500 |
+#define FPSCR_XX_MASK (FPSCR_MASK (FPSCR_XX))
|
|
|
dfa500 |
FPSCR_VXSNAN, /* invalid operation for sNaN */
|
|
|
dfa500 |
+#define FPSCR_VXSNAN_MASK (FPSCR_MASK (FPSCR_VXSNAN))
|
|
|
dfa500 |
FPSCR_VXISI, /* invalid operation for Inf-Inf */
|
|
|
dfa500 |
+#define FPSCR_VXISI_MASK (FPSCR_MASK (FPSCR_VXISI))
|
|
|
dfa500 |
FPSCR_VXIDI, /* invalid operation for Inf/Inf */
|
|
|
dfa500 |
+#define FPSCR_VXIDI_MASK (FPSCR_MASK (FPSCR_VXIDI))
|
|
|
dfa500 |
FPSCR_VXZDZ, /* invalid operation for 0/0 */
|
|
|
dfa500 |
+#define FPSCR_VXZDZ_MASK (FPSCR_MASK (FPSCR_VXZDZ))
|
|
|
dfa500 |
FPSCR_VXIMZ, /* invalid operation for Inf*0 */
|
|
|
dfa500 |
+#define FPSCR_VXIMZ_MASK (FPSCR_MASK (FPSCR_VXIMZ))
|
|
|
dfa500 |
FPSCR_VXVC, /* invalid operation for invalid compare */
|
|
|
dfa500 |
+#define FPSCR_VXVC_MASK (FPSCR_MASK (FPSCR_VXVC))
|
|
|
dfa500 |
FPSCR_FR, /* fraction rounded [fraction was incremented by round] */
|
|
|
dfa500 |
+#define FPSCR_FR_MASK (FPSCR_MASK (FPSCR_FR))
|
|
|
dfa500 |
FPSCR_FI, /* fraction inexact */
|
|
|
dfa500 |
+#define FPSCR_FI_MASK (FPSCR_MASK (FPSCR_FI))
|
|
|
dfa500 |
FPSCR_FPRF_C, /* result class descriptor */
|
|
|
dfa500 |
+#define FPSCR_FPRF_C_MASK (FPSCR_MASK (FPSCR_FPRF_C))
|
|
|
dfa500 |
FPSCR_FPRF_FL, /* result less than (usually, less than 0) */
|
|
|
dfa500 |
+#define FPSCR_FPRF_FL_MASK (FPSCR_MASK (FPSCR_FPRF_FL))
|
|
|
dfa500 |
FPSCR_FPRF_FG, /* result greater than */
|
|
|
dfa500 |
+#define FPSCR_FPRF_FG_MASK (FPSCR_MASK (FPSCR_FPRF_FG))
|
|
|
dfa500 |
FPSCR_FPRF_FE, /* result equal to */
|
|
|
dfa500 |
+#define FPSCR_FPRF_FE_MASK (FPSCR_MASK (FPSCR_FPRF_FE))
|
|
|
dfa500 |
FPSCR_FPRF_FU, /* result unordered */
|
|
|
dfa500 |
+#define FPSCR_FPRF_FU_MASK (FPSCR_MASK (FPSCR_FPRF_FU))
|
|
|
dfa500 |
FPSCR_20, /* reserved */
|
|
|
dfa500 |
FPSCR_VXSOFT, /* invalid operation set by software */
|
|
|
dfa500 |
+#define FPSCR_VXSOFT_MASK (FPSCR_MASK (FPSCR_VXSOFT))
|
|
|
dfa500 |
FPSCR_VXSQRT, /* invalid operation for square root */
|
|
|
dfa500 |
+#define FPSCR_VXSQRT_MASK (FPSCR_MASK (FPSCR_VXSQRT))
|
|
|
dfa500 |
FPSCR_VXCVI, /* invalid operation for invalid integer convert */
|
|
|
dfa500 |
+#define FPSCR_VXCVI_MASK (FPSCR_MASK (FPSCR_VXCVI))
|
|
|
dfa500 |
FPSCR_VE, /* invalid operation exception enable */
|
|
|
dfa500 |
+#define FPSCR_VE_MASK (FPSCR_MASK (FPSCR_VE))
|
|
|
dfa500 |
FPSCR_OE, /* overflow exception enable */
|
|
|
dfa500 |
+#define FPSCR_OE_MASK (FPSCR_MASK (FPSCR_OE))
|
|
|
dfa500 |
FPSCR_UE, /* underflow exception enable */
|
|
|
dfa500 |
+#define FPSCR_UE_MASK (FPSCR_MASK (FPSCR_UE))
|
|
|
dfa500 |
FPSCR_ZE, /* zero divide exception enable */
|
|
|
dfa500 |
+#define FPSCR_ZE_MASK (FPSCR_MASK (FPSCR_ZE))
|
|
|
dfa500 |
FPSCR_XE, /* inexact exception enable */
|
|
|
dfa500 |
+#define FPSCR_XE_MASK (FPSCR_MASK (FPSCR_XE))
|
|
|
dfa500 |
#ifdef _ARCH_PWR6
|
|
|
dfa500 |
FPSCR_29, /* Reserved in ISA 2.05 */
|
|
|
dfa500 |
+#define FPSCR_NI_MASK (FPSCR_MASK (FPSCR_29))
|
|
|
dfa500 |
#else
|
|
|
dfa500 |
- FPSCR_NI /* non-IEEE mode (typically, no denormalised numbers) */
|
|
|
dfa500 |
+ FPSCR_NI, /* non-IEEE mode (typically, no denormalised numbers) */
|
|
|
dfa500 |
+#define FPSCR_NI_MASK (FPSCR_MASK (FPSCR_NI))
|
|
|
dfa500 |
#endif /* _ARCH_PWR6 */
|
|
|
dfa500 |
/* the remaining two least-significant bits keep the rounding mode */
|
|
|
dfa500 |
+ FPSCR_RN_hi,
|
|
|
dfa500 |
+#define FPSCR_RN_hi_MASK (FPSCR_MASK (FPSCR_RN_hi))
|
|
|
dfa500 |
+ FPSCR_RN_lo
|
|
|
dfa500 |
+#define FPSCR_RN_lo_MASK (FPSCR_MASK (FPSCR_RN_lo))
|
|
|
dfa500 |
};
|
|
|
dfa500 |
|
|
|
dfa500 |
+#define FPSCR_RN_MASK (FPSCR_RN_hi_MASK|FPSCR_RN_lo_MASK)
|
|
|
dfa500 |
+#define FPSCR_ENABLES_MASK \
|
|
|
dfa500 |
+ (FPSCR_VE_MASK|FPSCR_OE_MASK|FPSCR_UE_MASK|FPSCR_ZE_MASK|FPSCR_XE_MASK)
|
|
|
dfa500 |
+#define FPSCR_BASIC_EXCEPTIONS_MASK \
|
|
|
dfa500 |
+ (FPSCR_VX_MASK|FPSCR_OX_MASK|FPSCR_UX_MASK|FPSCR_ZX_MASK|FPSCR_XX_MASK)
|
|
|
dfa500 |
+
|
|
|
dfa500 |
+#define FPSCR_CONTROL_MASK (FPSCR_ENABLES_MASK|FPSCR_NI_MASK|FPSCR_RN_MASK)
|
|
|
dfa500 |
+
|
|
|
dfa500 |
+/* The bits in the FENV(1) ABI for exceptions correspond one-to-one with bits
|
|
|
dfa500 |
+ in the FPSCR, albeit shifted to different but corresponding locations.
|
|
|
dfa500 |
+ Similarly, the exception indicator bits in the FPSCR correspond one-to-one
|
|
|
dfa500 |
+ with the exception enable bits. It is thus possible to map the FENV(1)
|
|
|
dfa500 |
+ exceptions directly to the FPSCR enables with a simple mask and shift,
|
|
|
dfa500 |
+ and vice versa. */
|
|
|
dfa500 |
+#define FPSCR_EXCEPT_TO_ENABLE_SHIFT 22
|
|
|
dfa500 |
+
|
|
|
dfa500 |
static inline int
|
|
|
dfa500 |
fenv_reg_to_exceptions (unsigned long long l)
|
|
|
dfa500 |
{
|
|
|
dfa500 |
- int result = 0;
|
|
|
dfa500 |
- if (l & (1 << (31 - FPSCR_XE)))
|
|
|
dfa500 |
- result |= FE_INEXACT;
|
|
|
dfa500 |
- if (l & (1 << (31 - FPSCR_ZE)))
|
|
|
dfa500 |
- result |= FE_DIVBYZERO;
|
|
|
dfa500 |
- if (l & (1 << (31 - FPSCR_UE)))
|
|
|
dfa500 |
- result |= FE_UNDERFLOW;
|
|
|
dfa500 |
- if (l & (1 << (31 - FPSCR_OE)))
|
|
|
dfa500 |
- result |= FE_OVERFLOW;
|
|
|
dfa500 |
- if (l & (1 << (31 - FPSCR_VE)))
|
|
|
dfa500 |
- result |= FE_INVALID;
|
|
|
dfa500 |
- return result;
|
|
|
dfa500 |
+ return (((int)l) & FPSCR_ENABLES_MASK) << FPSCR_EXCEPT_TO_ENABLE_SHIFT;
|
|
|
dfa500 |
+}
|
|
|
dfa500 |
+
|
|
|
dfa500 |
+static inline unsigned long long
|
|
|
dfa500 |
+fenv_exceptions_to_reg (int excepts)
|
|
|
dfa500 |
+{
|
|
|
dfa500 |
+ return (unsigned long long)
|
|
|
dfa500 |
+ (excepts & FE_ALL_EXCEPT) >> FPSCR_EXCEPT_TO_ENABLE_SHIFT;
|
|
|
dfa500 |
}
|
|
|
dfa500 |
|
|
|
dfa500 |
#ifdef _ARCH_PWR6
|