mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
powerpc: fix e500 SPE float rounding inexactness detection
The e500 SPE floating-point emulation code for the rounding modes rounding to positive or negative infinity (which may not be implemented in hardware) tries to avoid emulating rounding if the result was inexact. However, it tests inexactness using the sticky bit with the cumulative result of previous operations, rather than with the non-sticky bits relating to the operation that generated the interrupt. Furthermore, when a vector operation generates the interrupt, it's possible that only one of the low and high parts is inexact, and so only that part should have rounding emulated. This results in incorrect rounding of exact results in these modes when the sticky bit is set from a previous operation. (I'm not sure why the rounding interrupts are generated at all when the result is exact, but empirically the hardware does generate them.) This patch checks for inexactness using the correct bits of SPEFSCR, and ensures that rounding only occurs when the relevant part of the result was actually inexact. Signed-off-by: Joseph Myers <joseph@codesourcery.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
This commit is contained in:
parent
640e922501
commit
28414a6def
@ -680,7 +680,8 @@ int speround_handler(struct pt_regs *regs)
|
|||||||
{
|
{
|
||||||
union dw_union fgpr;
|
union dw_union fgpr;
|
||||||
int s_lo, s_hi;
|
int s_lo, s_hi;
|
||||||
unsigned long speinsn, type, fc;
|
int lo_inexact, hi_inexact;
|
||||||
|
unsigned long speinsn, type, fc, fptype;
|
||||||
|
|
||||||
if (get_user(speinsn, (unsigned int __user *) regs->nip))
|
if (get_user(speinsn, (unsigned int __user *) regs->nip))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
@ -693,8 +694,12 @@ int speround_handler(struct pt_regs *regs)
|
|||||||
__FPU_FPSCR = mfspr(SPRN_SPEFSCR);
|
__FPU_FPSCR = mfspr(SPRN_SPEFSCR);
|
||||||
pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR);
|
pr_debug("speinsn:%08lx spefscr:%08lx\n", speinsn, __FPU_FPSCR);
|
||||||
|
|
||||||
|
fptype = (speinsn >> 5) & 0x7;
|
||||||
|
|
||||||
/* No need to round if the result is exact */
|
/* No need to round if the result is exact */
|
||||||
if (!(__FPU_FPSCR & FP_EX_INEXACT))
|
lo_inexact = __FPU_FPSCR & (SPEFSCR_FG | SPEFSCR_FX);
|
||||||
|
hi_inexact = __FPU_FPSCR & (SPEFSCR_FGH | SPEFSCR_FXH);
|
||||||
|
if (!(lo_inexact || (hi_inexact && fptype == VCT)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fc = (speinsn >> 21) & 0x1f;
|
fc = (speinsn >> 21) & 0x1f;
|
||||||
@ -705,7 +710,7 @@ int speround_handler(struct pt_regs *regs)
|
|||||||
|
|
||||||
pr_debug("round fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]);
|
pr_debug("round fgpr: %08x %08x\n", fgpr.wp[0], fgpr.wp[1]);
|
||||||
|
|
||||||
switch ((speinsn >> 5) & 0x7) {
|
switch (fptype) {
|
||||||
/* Since SPE instructions on E500 core can handle round to nearest
|
/* Since SPE instructions on E500 core can handle round to nearest
|
||||||
* and round toward zero with IEEE-754 complied, we just need
|
* and round toward zero with IEEE-754 complied, we just need
|
||||||
* to handle round toward +Inf and round toward -Inf by software.
|
* to handle round toward +Inf and round toward -Inf by software.
|
||||||
@ -728,11 +733,15 @@ int speround_handler(struct pt_regs *regs)
|
|||||||
|
|
||||||
case VCT:
|
case VCT:
|
||||||
if (FP_ROUNDMODE == FP_RND_PINF) {
|
if (FP_ROUNDMODE == FP_RND_PINF) {
|
||||||
if (!s_lo) fgpr.wp[1]++; /* Z_low > 0, choose Z1 */
|
if (lo_inexact && !s_lo)
|
||||||
if (!s_hi) fgpr.wp[0]++; /* Z_high word > 0, choose Z1 */
|
fgpr.wp[1]++; /* Z_low > 0, choose Z1 */
|
||||||
|
if (hi_inexact && !s_hi)
|
||||||
|
fgpr.wp[0]++; /* Z_high word > 0, choose Z1 */
|
||||||
} else { /* round to -Inf */
|
} else { /* round to -Inf */
|
||||||
if (s_lo) fgpr.wp[1]++; /* Z_low < 0, choose Z2 */
|
if (lo_inexact && s_lo)
|
||||||
if (s_hi) fgpr.wp[0]++; /* Z_high < 0, choose Z2 */
|
fgpr.wp[1]++; /* Z_low < 0, choose Z2 */
|
||||||
|
if (hi_inexact && s_hi)
|
||||||
|
fgpr.wp[0]++; /* Z_high < 0, choose Z2 */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user