Skip to content

Commit

Permalink
Check for sh == 0 and skip rotations where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Aug 10, 2022
1 parent a88f962 commit 1ac86d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions librz/analysis/arch/ppc/ppc_il_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ static RzILOpEffect *shift_and_rotate(RZ_BORROW csh handle, RZ_BORROW cs_insn *i
n = U8(sH);
}
n = LOGAND(U8(0x3f), n);
r = ROTL64(VARG(rS), n);
r = LET("n", n, ITE(EQ(VARLP("n"), U8(0)), VARG(rS), ROTL64(VARG(rS), VARLP("n"))));
if (id == PPC_INS_RLDICR || id == PPC_INS_RLDCR || id == PPC_INS_ROTLDI || id == PPC_INS_ROTLD) {
b = 0;
if (id == PPC_INS_ROTLDI || id == PPC_INS_ROTLD) {
Expand Down Expand Up @@ -1156,8 +1156,7 @@ static RzILOpEffect *shift_and_rotate(RZ_BORROW csh handle, RZ_BORROW cs_insn *i
break;
case PPC_INS_CLRLDI:
case PPC_INS_CLRLWI:
n = U8(0);
r = ROTL64(VARG(rS), n);
r = VARG(rS);
b = (id == PPC_INS_CLRLWI) ? INSOP(2).imm + 32 : INSOP(2).imm;
e = 63;
all_bits_set = (((b - 1) & 0x3f) == e);
Expand Down
18 changes: 9 additions & 9 deletions test/db/asm/ppc_64
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,19 @@ dE "srawi r10, r22, 4" 7eca2670 0x340 (seq empty (set ca (ite (&& (msb (cast 32
dE "slwi r10, r20, 0x10" 568a801e 0x344 (seq empty empty (set result (& (<< (var r20) (& (bv 64 0x3f) (bv 64 0x10)) false) (bv 64 0xffffffff))) (set r10 (var result)) empty)
dE "srwi r10, r20, 0x10" 568a843e 0x348 (seq empty empty (set result (& (>> (& (var r20) (bv 64 0xffffffff)) (& (bv 64 0x3f) (bv 64 0x10)) false) (bv 64 0xffffffff))) (set r10 (var result)) empty)
dE "rlwimi r10, r20, 8, 5, 5" 528a414a 0x34c (seq (set mstart (bv 8 0x25)) (set mstop (bv 8 0x25)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (| (& (let rotl32_x (cast 32 false (var r20)) (let rotl32_y (bv 8 0x8) (let rotl64_x (append (var rotl32_x) (var rotl32_x)) (let rotl64_y (var rotl32_y) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask)) (& (var r10) (~ (var mask))))) (set r10 (var result)) empty)
dE "rldicl r10, r20, 4, 0x10" 7a8a2400 0x350 (seq (set mstart (bv 8 0x10)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (bv 8 0x4)) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) empty)
dE "rldimi r10, r20, 4, 8" 7a8a220c 0x354 (seq (set mstart (bv 8 0x8)) (set mstop (bv 8 0x3b)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (| (& (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (bv 8 0x4)) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask)) (& (var r10) (~ (var mask))))) (set r10 (var result)) empty)
dE "rotld r10, r20, r4" 7a8a2010 0x358 (seq empty empty (set result (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (cast 8 false (var r4))) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false))))) (set r10 (var result)) empty)
dE "rldicl r10, r20, 4, 0x10" 7a8a2400 0x350 (seq (set mstart (bv 8 0x10)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let n (& (bv 8 0x3f) (bv 8 0x4)) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rldimi r10, r20, 4, 8" 7a8a220c 0x354 (seq (set mstart (bv 8 0x8)) (set mstop (bv 8 0x3b)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (| (& (let n (& (bv 8 0x3f) (bv 8 0x4)) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask)) (& (var r10) (~ (var mask))))) (set r10 (var result)) empty)
dE "rotld r10, r20, r4" 7a8a2010 0x358 (seq empty empty (set result (let n (& (bv 8 0x3f) (cast 8 false (var r4))) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false))))))) (set r10 (var result)) empty)
dE "rotlw r10, r20, r4" 5e8a203e 0x35c (seq (set mstart (bv 8 0x20)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl32_x (cast 32 false (var r20)) (let rotl32_y (cast 6 false (& (var r4) (bv 64 0x1f))) (let rotl64_x (append (var rotl32_x) (var rotl32_x)) (let rotl64_y (var rotl32_y) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rotlwi r10, r2, 4" 544a203e 0x360 (seq (set mstart (bv 8 0x20)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl32_x (cast 32 false (var r2)) (let rotl32_y (bv 8 0x4) (let rotl64_x (append (var rotl32_x) (var rotl32_x)) (let rotl64_y (var rotl32_y) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "clrlwi r10, r20, 0xc" 568a033e 0x364 (seq (set mstart (bv 8 0x2c)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (bv 8 0x0) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) empty)
dE "clrldi. r10, r20, 0x3c" 7a8a0721 0x368 (seq (set mstart (bv 8 0x3c)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (bv 8 0x0) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) (set l (var result)) (set r (bv 64 0x0)) (set so_flag (ite (var so) (bv 1 0x1) (bv 1 0x0))) (branch (&& (sle (var l) (var r)) (! (== (var l) (var r)))) (set cr0 (append (bv 3 0x4) (var so_flag))) (branch (! (sle (var l) (var r))) (set cr0 (append (bv 3 0x2) (var so_flag))) (set cr0 (append (bv 3 0x1) (var so_flag))))))
dE "rldcl r10, r20, r4, 0x10" 7a8a2410 0x36c (seq (set mstart (bv 8 0x10)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (cast 8 false (var r4))) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) empty)
dE "rldcr r10, r20, r4, 0x10" 7a8a2412 0x370 (seq (set mstart (bv 8 0x0)) (set mstop (bv 8 0x10)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (cast 8 false (var r4))) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) empty)
dE "rldicr r10, r20, 4, 0x10" 7a8a2404 0x374 (seq (set mstart (bv 8 0x0)) (set mstop (bv 8 0x10)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (bv 8 0x4)) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))) (var mask))) (set r10 (var result)) empty)
dE "clrlwi r10, r20, 0xc" 568a033e 0x364 (seq (set mstart (bv 8 0x2c)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (var r20) (var mask))) (set r10 (var result)) empty)
dE "clrldi. r10, r20, 0x3c" 7a8a0721 0x368 (seq (set mstart (bv 8 0x3c)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (var r20) (var mask))) (set r10 (var result)) (set l (var result)) (set r (bv 64 0x0)) (set so_flag (ite (var so) (bv 1 0x1) (bv 1 0x0))) (branch (&& (sle (var l) (var r)) (! (== (var l) (var r)))) (set cr0 (append (bv 3 0x4) (var so_flag))) (branch (! (sle (var l) (var r))) (set cr0 (append (bv 3 0x2) (var so_flag))) (set cr0 (append (bv 3 0x1) (var so_flag))))))
dE "rldcl r10, r20, r4, 0x10" 7a8a2410 0x36c (seq (set mstart (bv 8 0x10)) (set mstop (bv 8 0x3f)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let n (& (bv 8 0x3f) (cast 8 false (var r4))) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rldcr r10, r20, r4, 0x10" 7a8a2412 0x370 (seq (set mstart (bv 8 0x0)) (set mstop (bv 8 0x10)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let n (& (bv 8 0x3f) (cast 8 false (var r4))) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rldicr r10, r20, 4, 0x10" 7a8a2404 0x374 (seq (set mstart (bv 8 0x0)) (set mstop (bv 8 0x10)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let n (& (bv 8 0x3f) (bv 8 0x4)) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rlwinm r10, r20, 4, 0x1b, 0x1b" 568a26f6 0x378 (seq (set mstart (bv 8 0x3b)) (set mstop (bv 8 0x3b)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl32_x (cast 32 false (var r20)) (let rotl32_y (bv 8 0x4) (let rotl64_x (append (var rotl32_x) (var rotl32_x)) (let rotl64_y (var rotl32_y) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rlwnm r10, r20, r4, 0x1b, 0x1b" 5e8a26f6 0x37c (seq (set mstart (bv 8 0x3b)) (set mstop (bv 8 0x3b)) (set m (bv 64 0x0)) (repeat (! (== (var mstart) (var mstop))) (seq (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstart) false))) (set mstart (smod (+ (var mstart) (bv 8 0x1)) (bv 8 0x40))))) (set m (| (var m) (>> (>> (bv 64 0x0) (bv 8 0x1) true) (var mstop) false))) (set mask (cast 64 false (var m))) empty (set result (& (let rotl32_x (cast 32 false (var r20)) (let rotl32_y (cast 6 false (& (var r4) (bv 64 0x1f))) (let rotl64_x (append (var rotl32_x) (var rotl32_x)) (let rotl64_y (var rotl32_y) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false)))))) (var mask))) (set r10 (var result)) empty)
dE "rotldi r10, r20, 4" 7a8a2000 0x380 (seq empty empty (set result (let rotl64_x (var r20) (let rotl64_y (& (bv 8 0x3f) (bv 8 0x4)) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false))))) (set r10 (var result)) empty)
dE "rotldi r10, r20, 4" 7a8a2000 0x380 (seq empty empty (set result (let n (& (bv 8 0x3f) (bv 8 0x4)) (ite (== (var n) (bv 8 0x0)) (var r20) (let rotl64_x (var r20) (let rotl64_y (var n) (| (<< (var rotl64_x) (var rotl64_y) false) (>> (var rotl64_x) (- (bv 8 0x40) (cast 8 false (var rotl64_y))) false))))))) (set r10 (var result)) empty)
dE "divd r4, r6, r7" 7c863bd2 0x384 (seq (set r4 (cast 64 false (sdiv (cast 128 (msb (var r6)) (var r6)) (cast 128 (msb (var r7)) (var r7))))) empty)
dE "divdu r4, r6, r7" 7c863b92 0x388 (seq (set r4 (cast 64 false (div (cast 128 false (var r6)) (cast 128 false (var r7))))) empty)
dE "divw r4, r6, r7" 7c863bd6 0x38c (seq (set r4 (cast 64 false (sdiv (cast 64 (msb (cast 32 false (var r6))) (cast 32 false (var r6))) (cast 64 (msb (cast 32 false (var r7))) (cast 32 false (var r7)))))) empty)
Expand Down

0 comments on commit 1ac86d5

Please sign in to comment.