target/ppc: bcdsub fix sign when result is zero
PATCH 1/1 target/ppc: bcdsub fix sign when result is zero
When the result of bcdsub is equal to zero, the result sign may be set to negative in some cases, and this does not follow the Power ISA specifications as to decimal integer arithmetic instructions.
--- target/ppc/int_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/ppc/int_helper.c +3 -0
@@ -2747,6 +2747,9 @@ uint32_t helper_bcdadd(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgna, ps); zero =bcd_sub_mag (&result, a, b, &invalid, &overflow); cr = (sgna >0 ) ?CRF_GT :CRF_LT ; + }else if (bcd_cmp_mag (a, b) ==0 ) { + result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (0 , ps); + zero =bcd_sub_mag (&result, b, a, &invalid, &overflow); }else { result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgnb, ps); zero =bcd_sub_mag (&result, b, a, &invalid, &overflow);
Signature · 1 line
1.8.3.1
Quoted 5 lines · Yasmin Beatriz
When the result of bcdsub is equal to zero, the result sign may be set to negative in some cases, and this does not follow the Power ISA specifications as to decimal integer arithmetic instructions.
Signed-off-by Yasmin Beatriz <[email protected]>
The fix looks correct, but since this has been broken forever and we're in hard freeze I'm going to apply for 3.1, not 3.0.
Fwiw, I think the surrounding logic can probably be simplified a little as well - I think this is now the only case with a zero result, so I think the 'zero' local can probably be removed.
Quoted 18 lines
--- target/ppc/int_helper.c | 3 +++ 1 file changed, 3 insertions(+)target/ppc/int_helper.c +3
-0@@ -2747,6 +2747,9 @@ uint32_t helper_bcdadd(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgna, ps); zero =bcd_sub_mag (&result, a, b, &invalid, &overflow); cr = (sgna >0 ) ?CRF_GT :CRF_LT ; + }else if (bcd_cmp_mag (a, b) ==0 ) { + result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (0 , ps); + zero =bcd_sub_mag (&result, b, a, &invalid, &overflow); }else { result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgnb, ps); zero =bcd_sub_mag (&result, b, a, &invalid, &overflow);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 5 lines · David Gibson
Quoted 4 lines · Yasmin Beatriz
When the result of bcdsub is equal to zero, the result sign may be set to negative in some cases, and this does not follow the Power ISA specifications as to decimal integer arithmetic instructions.
Quoted 8 lines
Quoted 1 line
Signed-off-by Yasmin Beatriz <[email protected]>The fix looks correct, but since this has been broken forever and we're in hard freeze I'm going to apply for 3.1, not 3.0.
Fwiw, I think the surrounding logic can probably be simplified a little as well - I think this is now the only case with a zero result, so I think the 'zero' local can probably be removed.
You are right. I am working on this and will send a new patch very soon. Thank you for the note.
Quoted 24 lines
Quoted 18 lines
--- target/ppc/int_helper.c | 3 +++ 1 file changed, 3 insertions(+)target/ppc/int_helper.c +3
-0@@ -2747,6 +2747,9 @@ uint32_t helper_bcdadd(ppc_avr_t *r, ppc_avr_t *a, ppc_avr_t *b, uint32_t ps) result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgna, ps); zero =bcd_sub_mag (&result, a, b, &invalid, &overflow); cr = (sgna >0 ) ?CRF_GT :CRF_LT ; + }else if (bcd_cmp_mag (a, b) ==0 ) { + result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (0 , ps); + zero =bcd_sub_mag (&result, b, a, &invalid, &overflow); }else { result.u8[BCD_DIG_BYTE (0 )] =bcd_preferred_sgn (sgnb, ps); zero =bcd_sub_mag (&result, b, a, &invalid, &overflow);Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson