Commit afc0a07d authored by Shan Hai's avatar Shan Hai Committed by Kumar Gala

powerpc/85xx: Fix SPE float to integer conversion failure

Conversion from float to integer should based on both the instruction
encoding and the sign of the operand.

A simple testcase to show the issue:

static float fm;
static signed int si_min = (-2147483647 - 1);
static unsigned int ui;
int main()
{
       fm = (float) si_min; ;
       ui = (unsigned int)fm;
       printf("ui=%d, should be %d\n", ui, si_min);

       return 0;
}
Result: ui=-1, should be -2147483648
Signed-off-by: default avatarShan Hai <shan.hai@windriver.com>
Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent cf773702
...@@ -322,7 +322,8 @@ int do_spe_mathemu(struct pt_regs *regs) ...@@ -322,7 +322,8 @@ int do_spe_mathemu(struct pt_regs *regs)
} else { } else {
_FP_ROUND_ZERO(1, SB); _FP_ROUND_ZERO(1, SB);
} }
FP_TO_INT_S(vc.wp[1], SB, 32, ((func & 0x3) != 0)); FP_TO_INT_S(vc.wp[1], SB, 32,
(((func & 0x3) != 0) || SB_s));
goto update_regs; goto update_regs;
default: default:
...@@ -460,7 +461,8 @@ int do_spe_mathemu(struct pt_regs *regs) ...@@ -460,7 +461,8 @@ int do_spe_mathemu(struct pt_regs *regs)
} else { } else {
_FP_ROUND_ZERO(2, DB); _FP_ROUND_ZERO(2, DB);
} }
FP_TO_INT_D(vc.wp[1], DB, 32, ((func & 0x3) != 0)); FP_TO_INT_D(vc.wp[1], DB, 32,
(((func & 0x3) != 0) || DB_s));
goto update_regs; goto update_regs;
default: default:
...@@ -591,8 +593,10 @@ int do_spe_mathemu(struct pt_regs *regs) ...@@ -591,8 +593,10 @@ int do_spe_mathemu(struct pt_regs *regs)
_FP_ROUND_ZERO(1, SB0); _FP_ROUND_ZERO(1, SB0);
_FP_ROUND_ZERO(1, SB1); _FP_ROUND_ZERO(1, SB1);
} }
FP_TO_INT_S(vc.wp[0], SB0, 32, ((func & 0x3) != 0)); FP_TO_INT_S(vc.wp[0], SB0, 32,
FP_TO_INT_S(vc.wp[1], SB1, 32, ((func & 0x3) != 0)); (((func & 0x3) != 0) || SB0_s));
FP_TO_INT_S(vc.wp[1], SB1, 32,
(((func & 0x3) != 0) || SB1_s));
goto update_regs; goto update_regs;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment