Mark Wielaard 017038
From 2c1f016e634bf79faf45e81c14c955c711bc202f Mon Sep 17 00:00:00 2001
Mark Wielaard 017038
From: Mark Wielaard <mark@klomp.org>
Mark Wielaard 017038
Date: Mon, 31 Dec 2018 22:26:31 +0100
Mark Wielaard 017038
Subject: [PATCH] Bug 402519 - POWER 3.0 addex instruction incorrectly
Mark Wielaard 017038
 implemented
Mark Wielaard 017038
Mark Wielaard 017038
addex uses OV as carry in and carry out. For all other instructions
Mark Wielaard 017038
OV is the signed overflow flag. And instructions like adde use CA
Mark Wielaard 017038
as carry.
Mark Wielaard 017038
Mark Wielaard 017038
Replace set_XER_OV_OV32 with set_XER_OV_OV32_ADDEX, which will
Mark Wielaard 017038
call calculate_XER_CA_64 and calculate_XER_CA_32, but with OV
Mark Wielaard 017038
as input, and sets OV and OV32.
Mark Wielaard 017038
Mark Wielaard 017038
Enable test_addex in none/tests/ppc64/test_isa_3_0.c and update
Mark Wielaard 017038
the expected output. test_addex would fail to match the expected
Mark Wielaard 017038
output before this patch.
Mark Wielaard 017038
---
Mark Wielaard 017038
 NEWS                                              |  1 +
Mark Wielaard 017038
 VEX/priv/guest_ppc_toIR.c                         | 52 ++++++++++++++---------
Mark Wielaard 017038
 none/tests/ppc64/test_isa_3_0.c                   |  3 +-
Mark Wielaard 017038
 none/tests/ppc64/test_isa_3_0_other.stdout.exp-LE | 36 ++++++++++------
Mark Wielaard 017038
 4 files changed, 58 insertions(+), 34 deletions(-)
Mark Wielaard 017038
Mark Wielaard 017038
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
Mark Wielaard 017038
index 18df822..d685383 100644
Mark Wielaard 017038
--- a/VEX/priv/guest_ppc_toIR.c
Mark Wielaard 017038
+++ b/VEX/priv/guest_ppc_toIR.c
Mark Wielaard 017038
@@ -2645,21 +2645,6 @@ static void copy_OV_to_OV32( void ) {
Mark Wielaard 017038
    putXER_OV32( getXER_OV() );
Mark Wielaard 017038
 }
Mark Wielaard 017038
 
Mark Wielaard 017038
-static void set_XER_OV_OV32 ( IRType ty, UInt op, IRExpr* res,
Mark Wielaard 017038
-                              IRExpr* argL, IRExpr* argR )
Mark Wielaard 017038
-{
Mark Wielaard 017038
-   if (ty == Ity_I32) {
Mark Wielaard 017038
-      set_XER_OV_OV32_32( op, res, argL, argR );
Mark Wielaard 017038
-   } else {
Mark Wielaard 017038
-      IRExpr* xer_ov_32;
Mark Wielaard 017038
-      set_XER_OV_64( op, res, argL, argR );
Mark Wielaard 017038
-      xer_ov_32 = calculate_XER_OV_32( op, unop(Iop_64to32, res),
Mark Wielaard 017038
-                                       unop(Iop_64to32, argL),
Mark Wielaard 017038
-                                       unop(Iop_64to32, argR));
Mark Wielaard 017038
-      putXER_OV32( unop(Iop_32to8, xer_ov_32) );
Mark Wielaard 017038
-   }
Mark Wielaard 017038
-}
Mark Wielaard 017038
-
Mark Wielaard 017038
 static void set_XER_OV_OV32_SO ( IRType ty, UInt op, IRExpr* res,
Mark Wielaard 017038
                                  IRExpr* argL, IRExpr* argR )
Mark Wielaard 017038
 {
Mark Wielaard 017038
@@ -3005,6 +2990,33 @@ static void set_XER_CA_CA32 ( IRType ty, UInt op, IRExpr* res,
Mark Wielaard 017038
    }
Mark Wielaard 017038
 }
Mark Wielaard 017038
 
Mark Wielaard 017038
+/* Used only by addex instruction, which uses and sets OV as carry.  */
Mark Wielaard 017038
+static void set_XER_OV_OV32_ADDEX ( IRType ty, IRExpr* res,
Mark Wielaard 017038
+                                    IRExpr* argL, IRExpr* argR,
Mark Wielaard 017038
+                                    IRExpr* old_ov )
Mark Wielaard 017038
+{
Mark Wielaard 017038
+   if (ty == Ity_I32) {
Mark Wielaard 017038
+      IRTemp xer_ov = newTemp(Ity_I32);
Mark Wielaard 017038
+      assign ( xer_ov, unop(Iop_32to8,
Mark Wielaard 017038
+                            calculate_XER_CA_32( PPCG_FLAG_OP_ADDE,
Mark Wielaard 017038
+                                                 res, argL, argR, old_ov ) ) );
Mark Wielaard 017038
+      putXER_OV( mkexpr (xer_ov) );
Mark Wielaard 017038
+      putXER_OV32( mkexpr (xer_ov) );
Mark Wielaard 017038
+   } else {
Mark Wielaard 017038
+      IRExpr *xer_ov;
Mark Wielaard 017038
+      IRExpr* xer_ov_32;
Mark Wielaard 017038
+      xer_ov = calculate_XER_CA_64( PPCG_FLAG_OP_ADDE,
Mark Wielaard 017038
+                                    res, argL, argR, old_ov );
Mark Wielaard 017038
+      putXER_OV( unop(Iop_32to8, xer_ov) );
Mark Wielaard 017038
+      xer_ov_32 = calculate_XER_CA_32( PPCG_FLAG_OP_ADDE,
Mark Wielaard 017038
+                                       unop(Iop_64to32, res),
Mark Wielaard 017038
+                                       unop(Iop_64to32, argL),
Mark Wielaard 017038
+                                       unop(Iop_64to32, argR),
Mark Wielaard 017038
+                                       unop(Iop_64to32, old_ov) );
Mark Wielaard 017038
+      putXER_OV32( unop(Iop_32to8, xer_ov_32) );
Mark Wielaard 017038
+   }
Mark Wielaard 017038
+}
Mark Wielaard 017038
+
Mark Wielaard 017038
 
Mark Wielaard 017038
 
Mark Wielaard 017038
 /*------------------------------------------------------------*/
Mark Wielaard 017038
@@ -5094,16 +5106,18 @@ static Bool dis_int_arith ( UInt theInstr )
Mark Wielaard 017038
       }
Mark Wielaard 017038
 
Mark Wielaard 017038
       case 0xAA: {// addex (Add Extended alternate carry bit Z23-form)
Mark Wielaard 017038
+         IRTemp old_xer_ov = newTemp(ty);
Mark Wielaard 017038
          DIP("addex r%u,r%u,r%u,%d\n", rD_addr, rA_addr, rB_addr, (Int)flag_OE);
Mark Wielaard 017038
+         assign( old_xer_ov, mkWidenFrom32(ty, getXER_OV_32(), False) );
Mark Wielaard 017038
          assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA),
Mark Wielaard 017038
                             binop( mkSzOp(ty, Iop_Add8), mkexpr(rB),
Mark Wielaard 017038
-                                   mkWidenFrom8( ty, getXER_OV(), False ) ) ) );
Mark Wielaard 017038
+                                   mkexpr(old_xer_ov) ) ) );
Mark Wielaard 017038
 
Mark Wielaard 017038
          /* CY bit is same as OE bit */
Mark Wielaard 017038
          if (flag_OE == 0) {
Mark Wielaard 017038
-            /* Exception, do not set SO bit */
Mark Wielaard 017038
-            set_XER_OV_OV32( ty, PPCG_FLAG_OP_ADDE,
Mark Wielaard 017038
-                             mkexpr(rD), mkexpr(rA), mkexpr(rB) );
Mark Wielaard 017038
+            /* Exception, do not set SO bit and set OV from carry. */
Mark Wielaard 017038
+            set_XER_OV_OV32_ADDEX( ty, mkexpr(rD), mkexpr(rA), mkexpr(rB),
Mark Wielaard 017038
+                                   mkexpr(old_xer_ov) );
Mark Wielaard 017038
          } else {
Mark Wielaard 017038
             /* CY=1, 2 and 3 (AKA flag_OE) are reserved */
Mark Wielaard 017038
             vex_printf("addex instruction, CY = %d is reserved.\n", flag_OE);
Mark Wielaard 017038
diff --git a/none/tests/ppc64/test_isa_3_0.c b/none/tests/ppc64/test_isa_3_0.c
Mark Wielaard 017038
index 2d13505..1c2cda3 100644
Mark Wielaard 017038
--- a/none/tests/ppc64/test_isa_3_0.c
Mark Wielaard 017038
+++ b/none/tests/ppc64/test_isa_3_0.c
Mark Wielaard 017038
@@ -286,7 +286,7 @@ static test_list_t testgroup_ia_ops_two[] = {
Mark Wielaard 017038
    { &test_moduw, "moduw" },
Mark Wielaard 017038
    { &test_modsd, "modsd" },
Mark Wielaard 017038
    { &test_modud, "modud" },
Mark Wielaard 017038
-   //{ &test_addex, "addex" },
Mark Wielaard 017038
+   { &test_addex, "addex" },
Mark Wielaard 017038
    { NULL       , NULL             },
Mark Wielaard 017038
 };
Mark Wielaard 017038
 
Mark Wielaard 017038
@@ -2741,7 +2741,6 @@ static void testfunction_gpr_vector_logical_one (const char* instruction_name,
Mark Wielaard 017038
     *   rt, xa
Mark Wielaard 017038
     */
Mark Wielaard 017038
    int i;
Mark Wielaard 017038
-   int t;
Mark Wielaard 017038
    volatile HWord_t res;
Mark Wielaard 017038
 
Mark Wielaard 017038
    VERBOSE_FUNCTION_CALLOUT
Mark Wielaard 017038
diff --git a/none/tests/ppc64/test_isa_3_0_other.stdout.exp-LE b/none/tests/ppc64/test_isa_3_0_other.stdout.exp-LE
Mark Wielaard 017038
index 152ff28..cc0e88e 100644
Mark Wielaard 017038
--- a/none/tests/ppc64/test_isa_3_0_other.stdout.exp-LE
Mark Wielaard 017038
+++ b/none/tests/ppc64/test_isa_3_0_other.stdout.exp-LE
Mark Wielaard 017038
@@ -40,7 +40,17 @@ modud ffffffffffffffff, 0000000000000000 => 0000000000000000 (00000000)
Mark Wielaard 017038
 modud ffffffffffffffff, 0000001cbe991def => 000000043eb0c0b2 (00000000)
Mark Wielaard 017038
 modud ffffffffffffffff, ffffffffffffffff => 0000000000000000 (00000000)
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 4 different instructions
Mark Wielaard 017038
+addex 0000000000000000, 0000000000000000 => 0000000000000000 (00000000)
Mark Wielaard 017038
+addex 0000000000000000, 0000001cbe991def => 0000001cbe991def (00000000)
Mark Wielaard 017038
+addex 0000000000000000, ffffffffffffffff => ffffffffffffffff (00000000)
Mark Wielaard 017038
+addex 0000001cbe991def, 0000000000000000 => 0000001cbe991def (00000000)
Mark Wielaard 017038
+addex 0000001cbe991def, 0000001cbe991def => 000000397d323bde (00000000) OV32
Mark Wielaard 017038
+addex 0000001cbe991def, ffffffffffffffff => 0000001cbe991dee (00000000) OV OV32
Mark Wielaard 017038
+addex ffffffffffffffff, 0000000000000000 => 0000000000000000 (00000000) OV OV32
Mark Wielaard 017038
+addex ffffffffffffffff, 0000001cbe991def => 0000001cbe991def (00000000) OV OV32
Mark Wielaard 017038
+addex ffffffffffffffff, ffffffffffffffff => ffffffffffffffff (00000000) OV OV32
Mark Wielaard 017038
+
Mark Wielaard 017038
+All done. Tested 5 different instructions
Mark Wielaard 017038
 ppc one argument plus shift:
Mark Wielaard 017038
 Test instruction group [ppc one argument plus shift]
Mark Wielaard 017038
 extswsli  aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa 0 ffffffffffffffff => aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa 0 ffffffffffffffff
Mark Wielaard 017038
@@ -85,7 +95,7 @@ extswsli. aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa 0 ffaa5599113377cc => aaaaaaaaaaaaaa
Mark Wielaard 017038
 extswsli. 5152535455565758 5152535455565758 0 ffaa5599113377cc => 5152535455565758 5152535455565758 0 ffaa5599113377cc
Mark Wielaard 017038
 extswsli. 0000000000000000 0000000000000000 0 ffaa5599113377cc => 0000000000000000 0000000000000000 0 ffaa5599113377cc
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 6 different instructions
Mark Wielaard 017038
+All done. Tested 7 different instructions
Mark Wielaard 017038
 ppc three parameter ops:
Mark Wielaard 017038
 Test instruction group [ppc three parameter ops]
Mark Wielaard 017038
 maddhd  0000000000000000, 0000000000000000, 0000000000000000  => 0000000000000000 (00000000)
Mark Wielaard 017038
@@ -172,7 +182,7 @@ maddld  ffffffffffffffff, ffffffffffffffff, 0000000000000000  => 000000000000000
Mark Wielaard 017038
 maddld  ffffffffffffffff, ffffffffffffffff, 0000001cbe991def  => 0000001cbe991df0 (00000000)
Mark Wielaard 017038
 maddld  ffffffffffffffff, ffffffffffffffff, ffffffffffffffff  => 0000000000000000 (00000000)
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 9 different instructions
Mark Wielaard 017038
+All done. Tested 10 different instructions
Mark Wielaard 017038
 ppc count zeros:
Mark Wielaard 017038
 Test instruction group [ppc count zeros]
Mark Wielaard 017038
 cnttzw 0000000000000000 => 0000000000000020
Mark Wielaard 017038
@@ -197,7 +207,7 @@ cnttzd. 0000001cbe991def => 0000000000000000 Expected cr0 to be zero, it is (200
Mark Wielaard 017038
 cnttzd. ffffffffffffffff => 0000000000000000 Expected cr0 to be zero, it is (20000000)
Mark Wielaard 017038
 
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 13 different instructions
Mark Wielaard 017038
+All done. Tested 14 different instructions
Mark Wielaard 017038
 ppc set boolean:
Mark Wielaard 017038
 Test instruction group [ppc set boolean]
Mark Wielaard 017038
 setb cr_field:0 cr_value::00000000 =>  0000000000000000
Mark Wielaard 017038
@@ -265,7 +275,7 @@ setb cr_field:7 cr_value::00000005 =>  0000000000000001
Mark Wielaard 017038
 setb cr_field:7 cr_value::00000006 =>  0000000000000001
Mark Wielaard 017038
 setb cr_field:7 cr_value::00000007 =>  0000000000000001
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 14 different instructions
Mark Wielaard 017038
+All done. Tested 15 different instructions
Mark Wielaard 017038
 ppc char compare:
Mark Wielaard 017038
 Test instruction group [ppc char compare]
Mark Wielaard 017038
 cmprb l=0 0x61 (a) (cmpeq:0x5b427b625a417a61) (cmprb:src22(a-z) src21(A-Z)) => in range/found
Mark Wielaard 017038
@@ -1711,7 +1721,7 @@ cmpeqb 0x5d (]) (cmpeq:0x4642666245416561) (cmprb:src22(a-e) src21(A-E)) =>
Mark Wielaard 017038
 cmpeqb 0x60 (`) (cmpeq:0x4642666245416561) (cmprb:src22(a-e) src21(A-E)) =>
Mark Wielaard 017038
 cmpeqb 0x5f (_) (cmpeq:0x4642666245416561) (cmprb:src22(a-e) src21(A-E)) =>
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 17 different instructions
Mark Wielaard 017038
+All done. Tested 18 different instructions
Mark Wielaard 017038
 ppc vector scalar move to/from:
Mark Wielaard 017038
 Test instruction group [ppc vector scalar move to/from]
Mark Wielaard 017038
 mfvsrld aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa 0 ffffffffffffffff => aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa ffffffffffffffff
Mark Wielaard 017038
@@ -1777,7 +1787,7 @@ mtvsrws aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa 0 ffaa5599113377cc => 113377cc113377cc
Mark Wielaard 017038
 mtvsrws 5152535455565758 5152535455565758 0 ffaa5599113377cc => 113377cc113377cc 113377cc113377cc 0 ffaa5599113377cc
Mark Wielaard 017038
 mtvsrws 0000000000000000 0000000000000000 0 ffaa5599113377cc => 113377cc113377cc 113377cc113377cc 0 ffaa5599113377cc
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 20 different instructions
Mark Wielaard 017038
+All done. Tested 21 different instructions
Mark Wielaard 017038
 ppc dfp significance:
Mark Wielaard 017038
 Test instruction group [ppc dfp significance]
Mark Wielaard 017038
 dtstsfi significance(0x00) +Finite                  0 * 10 ^ -12 (GT) (4)
Mark Wielaard 017038
@@ -1862,7 +1872,7 @@ dtstsfiq significance(0x20) -inf      (GT) (4)
Mark Wielaard 017038
 dtstsfiq significance(0x30) -inf      (GT) (4)
Mark Wielaard 017038
 dtstsfiq significance(0x3f) -inf      (GT) (4)
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 22 different instructions
Mark Wielaard 017038
+All done. Tested 23 different instructions
Mark Wielaard 017038
 ppc bcd misc:
Mark Wielaard 017038
 Test instruction group [ppc bcd misc]
Mark Wielaard 017038
 bcdadd. p0 xa:0000000000000000 000000000000000c (+|0) xb:0000000000000000 000000000000000c (+|0) => (EQ) (2) xt:0000000000000000 000000000000000c(+|0)
Mark Wielaard 017038
@@ -33338,12 +33348,12 @@ bcdcfsq. p1 xa:0000000000000000 000000000000000c (+|0) xb:9999999999999999 99999
Mark Wielaard 017038
 bcdcfsq. p1 xa:0000000000000000 000000000000000c (+|0) xb:0000000000000000 000000001234567d ( - ) => (GT) (4) xt:0000000000000000 000000305419901f(+|0)
Mark Wielaard 017038
 
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 51 different instructions
Mark Wielaard 017038
+All done. Tested 52 different instructions
Mark Wielaard 017038
 ppc noop misc:
Mark Wielaard 017038
 Test instruction group [ppc noop misc]
Mark Wielaard 017038
 wait   =>
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 52 different instructions
Mark Wielaard 017038
+All done. Tested 53 different instructions
Mark Wielaard 017038
 ppc addpc_misc:
Mark Wielaard 017038
 Test instruction group [ppc addpc_misc]
Mark Wielaard 017038
 addpcis   0000000000000000  =>  0000000000000000
Mark Wielaard 017038
@@ -33380,7 +33390,7 @@ subpcis   000000000000000d  =>  0000000000000000
Mark Wielaard 017038
 subpcis   000000000000000e  =>  0000000000000000
Mark Wielaard 017038
 subpcis   000000000000000f  =>  0000000000000000
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 54 different instructions
Mark Wielaard 017038
+All done. Tested 55 different instructions
Mark Wielaard 017038
 ppc mffpscr:
Mark Wielaard 017038
 Test instruction group [ppc mffpscr]
Mark Wielaard 017038
 mffsce  =>  000000000.000000
Mark Wielaard 017038
@@ -33395,7 +33405,7 @@ mffs  =>  000000000.000000
Mark Wielaard 017038
  fpscr: f14 
Mark Wielaard 017038
  local_fpscr: 
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 57 different instructions
Mark Wielaard 017038
+All done. Tested 58 different instructions
Mark Wielaard 017038
 ppc mffpscr:
Mark Wielaard 017038
 Test instruction group [ppc mffpscr]
Mark Wielaard 017038
 mffscdrni  0  =>  0X0
Mark Wielaard 017038
@@ -33426,4 +33436,4 @@ mffscrn  f15 0X1   =>  0X200000000
Mark Wielaard 017038
 mffscrn  f15 0X2   =>  0X200000000
Mark Wielaard 017038
  fpscr: f14  local_fpscr:  30-DRN1 RN-bit62
Mark Wielaard 017038
 
Mark Wielaard 017038
-All done. Tested 61 different instructions
Mark Wielaard 017038
+All done. Tested 62 different instructions
Mark Wielaard 017038
-- 
Mark Wielaard 017038
1.8.3.1
Mark Wielaard 017038