FPU: Check for rounding overflow in 32-bit convert-to-integer operations

Without this, rounding a value of 0xFFFFFFFF up, giving 0x100000000, will
yield an incorrect result of zero.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
pull/457/head
Paul Mackerras 1 week ago
parent 6fe4b549f5
commit f8a11420ca

@ -2356,10 +2356,13 @@ begin
-- Check for possible overflows
case r.insn(9 downto 8) is
when "00" => -- fctiw[z]
-- check bit 32 in case of rounding overflow
need_check := r.r(31) or (r.r(30) and not r.result_sign);
when "01" => -- fctiwu[z]
need_check := r.r(31);
-- check bit 32 in case of rounding overflow
need_check := r.r(31) or r.r(31);
when "10" => -- fctid[z]
-- can't get rounding overflow for 64-bit conversion
need_check := r.r(63) or (r.r(62) and not r.result_sign);
when others => -- fctidu[z]
need_check := r.r(63);
@ -2380,7 +2383,8 @@ begin
msb := r.r(63);
end if;
if (r.insn(8) = '0' and msb /= r.result_sign) or
(r.insn(8) = '1' and msb /= '1') then
(r.insn(8) = '1' and msb /= '1') or
(r.insn(9) = '0' and r.r(32) /= r.result_sign) then
v.state := INT_OFLOW;
else
if r.fpscr(FPSCR_FI) = '1' then

@ -756,6 +756,8 @@ struct cvtivals {
{ 0x7ff923456789abcd, 0x8000000000000000, 0, 0x80000000, 0, { 1, 1, 1, 1 } },
{ 0xfff923456789abcd, 0x8000000000000000, 0, 0x80000000, 0, { 1, 1, 1, 1 } },
{ 0xbfd123456789abcd, 0, 0, 0, 0, {0, 0, 0, 0} },
{ 0x41effffffff00081, 0x100000000, 0x100000000, 0x7fffffff, 0xffffffff, { 0, 0, 1, 1 } },
{ 0xc1e0000000000000, 0xffffffff80000000, 0x0000000000000000, 0x80000000, 0x00000000, { 0, 1, 0, 1 } },
};

#define GET_VXCVI() ((get_fpscr() >> 8) & 1)
@ -830,6 +832,7 @@ struct cvtivals cvtizvals[] = {
{ 0xfff0000000000000, 0x8000000000000000, 0, 0x80000000, 0, { 1, 1, 1, 1 } },
{ 0x7ff923456789abcd, 0x8000000000000000, 0, 0x80000000, 0, { 1, 1, 1, 1 } },
{ 0xfff923456789abcd, 0x8000000000000000, 0, 0x80000000, 0, { 1, 1, 1, 1 } },
{ 0xc1e0000000000000, 0xffffffff80000000, 0x0000000000000000, 0x80000000, 0x00000000, { 0, 1, 0, 1 } },
};

int test10(long arg)

Binary file not shown.
Loading…
Cancel
Save