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