target/ppc: bcdsub fix sign when result is zero
authorYasmin Beatriz <yasmins@linux.ibm.com>
Mon, 16 Jul 2018 19:03:12 +0000 (19:03 +0000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Tue, 21 Aug 2018 04:28:45 +0000 (14:28 +1000)
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 <yasmins@linux.ibm.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
target/ppc/int_helper.c

index d52338ed71ce66b386b4ce9b21974dab020826e9..ac7f92d7aef7bcf9b5832625ffad095535939428 100644 (file)
@@ -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);