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