|
16 | 16 | :conclusion (= (repeat n a) b)
|
17 | 17 | )
|
18 | 18 |
|
| 19 | +;;;;; ProofRewriteRule::BV_SMULO_ELIM |
| 20 | + |
| 21 | +; define: $bv_smulo_elim |
| 22 | +; args: |
| 23 | +; - xa (BitVec n): An xor term involving the first argument to bvsmulo |
| 24 | +; - xb (BitVec n): An xor term involving the second argument to bvsmulo |
| 25 | +; - ppc (BitVec 1): An intermediate bitvector term accumulated to help construct the result. |
| 26 | +; - res (BitVec 1): The current accumulated result. |
| 27 | +; - i Int: The current bit we are processing. |
| 28 | +; - nm2 Int: The bitwidth of a and b minus 2. |
| 29 | +; return: > |
| 30 | +; A portion of the result of eliminating (bvsmulo a b). |
| 31 | +(program $bv_smulo_elim_rec ((n Int) (xa (BitVec n)) (xb (BitVec n)) |
| 32 | + (ppc (BitVec 1)) (res (BitVec 1)) (i Int) (nm2 Int)) |
| 33 | + ((BitVec n) (BitVec n) (BitVec 1) (BitVec 1) Int Int) (BitVec 1) |
| 34 | + ( |
| 35 | + (($bv_smulo_elim_rec xa xb ppc res nm2 nm2) res) |
| 36 | + (($bv_smulo_elim_rec xa xb ppc res i nm2) |
| 37 | + (eo::define ((ia (eo::add nm2 (eo::neg i)))) |
| 38 | + (eo::define ((ip1 (eo::add i 1))) |
| 39 | + (eo::define ((ppcn (bvor ppc (extract ia ia xa)))) |
| 40 | + ($bv_smulo_elim_rec xa xb ppcn (bvor res (bvand (extract ip1 ip1 xb) ppcn)) ip1 nm2))))) |
| 41 | + ) |
| 42 | +) |
| 43 | + |
| 44 | +; define: $bv_smulo_elim |
| 45 | +; args: |
| 46 | +; - a (BitVec n): The first argument to bvsmulo |
| 47 | +; - b (BitVec n): The second argument to bvsmulo |
| 48 | +; return: > |
| 49 | +; The result of eliminating (bvsmulo a b). |
| 50 | +(define $bv_smulo_elim ((n Int :implicit) (a (BitVec n)) (b (BitVec n))) |
| 51 | + (eo::define ((w ($bv_bitwidth (eo::typeof a)))) |
| 52 | + (eo::define ((wm1 (eo::add w -1))) |
| 53 | + (eo::define ((one (eo::to_bin 1 1))) |
| 54 | + (eo::ite (eo::is_eq w 1) |
| 55 | + (= (bvand a b) one) |
| 56 | + (eo::define ((mul (bvmul (sign_extend 1 a) (sign_extend 1 b)))) |
| 57 | + (eo::ite (eo::is_eq w 2) |
| 58 | + (= (bvxor (extract w w mul) (extract wm1 wm1 mul)) one) |
| 59 | + (eo::define ((xa (bvxor a (sign_extend wm1 (extract wm1 wm1 a))))) |
| 60 | + (eo::define ((xb (bvxor b (sign_extend wm1 (extract wm1 wm1 b))))) |
| 61 | + (eo::define ((wm2 (eo::add w -2))) |
| 62 | + (eo::define ((ppc (extract wm2 wm2 xa))) |
| 63 | + (eo::define ((res ($bv_smulo_elim_rec xa xb ppc (bvand (extract 1 1 xb) ppc) 1 wm2))) |
| 64 | + (= (bvor res (bvxor (extract w w mul) (extract wm1 wm1 mul))) one)))))))))))) |
| 65 | +) |
| 66 | + |
| 67 | +; rule: bv-smulo-elim |
| 68 | +; implements: ProofRewriteRule::BV_SMULO_ELIM |
| 69 | +; args: |
| 70 | +; - eq Bool: The equality to prove with this rule. |
| 71 | +; requires: c is the result of eliminating the left hand side. |
| 72 | +; conclusion: the given equality. |
| 73 | +(declare-rule bv-smulo-elim ((n Int) (a (BitVec n)) (b (BitVec n)) (c Bool)) |
| 74 | + :args ((= (bvsmulo a b) c)) |
| 75 | + :requires ((($bv_smulo_elim a b) c)) |
| 76 | + :conclusion (= (bvsmulo a b) c) |
| 77 | +) |
| 78 | + |
| 79 | +;;;;; ProofRewriteRule::BV_UMULO_ELIM |
| 80 | + |
| 81 | +; define: $bv_umulo_elim_rec |
| 82 | +; args: |
| 83 | +; - xa (BitVec n): An xor term involving the first argument to bvumulo |
| 84 | +; - xb (BitVec n): An xor term involving the second argument to bvumulo |
| 85 | +; - ppc (BitVec 1): An intermediate bitvector term accumulated to help construct the result. |
| 86 | +; - res (BitVec 1): The current accumulated result. |
| 87 | +; - i Int: The current bit we are processing. |
| 88 | +; - nm2 Int: The bitwidth of a and b minus 2. |
| 89 | +; return: > |
| 90 | +; A portion of the result of eliminating (bvsmulo a b). |
| 91 | +(program $bv_umulo_elim_rec ((n Int) (a (BitVec n)) (b (BitVec n)) |
| 92 | + (uppc (BitVec 1)) (res (BitVec 1)) (i Int)) |
| 93 | + ((BitVec n) (BitVec n) (BitVec 1) (BitVec 1) Int Int) (BitVec 1) |
| 94 | + ( |
| 95 | + (($bv_umulo_elim_rec a b uppc res n n) res) |
| 96 | + (($bv_umulo_elim_rec a b uppc res i n) |
| 97 | + (eo::define ((ia (eo::add n -1 (eo::neg i)))) |
| 98 | + (eo::define ((ip1 (eo::add i 1))) |
| 99 | + (eo::define ((uppcn (bvor (extract ia ia a) uppc))) |
| 100 | + (eo::cons bvor (bvand (extract i i b) uppc) ($bv_umulo_elim_rec a b uppcn res ip1 n)))))) |
| 101 | + ) |
| 102 | +) |
| 103 | + |
| 104 | +; define: $bv_umulo_elim |
| 105 | +; args: |
| 106 | +; - a (BitVec n): The first argument to bvumulo |
| 107 | +; - b (BitVec n): The second argument to bvumulo |
| 108 | +; return: > |
| 109 | +; The result of eliminating (bvumulo a b). |
| 110 | +(define $bv_umulo_elim ((n Int :implicit) (a (BitVec n)) (b (BitVec n))) |
| 111 | + (eo::define ((w ($bv_bitwidth (eo::typeof a)))) |
| 112 | + (eo::ite (eo::is_eq w 1) |
| 113 | + false |
| 114 | + (eo::define ((wm1 (eo::add w -1))) |
| 115 | + (eo::define ((zero (eo::to_bin 1 0))) |
| 116 | + (eo::define ((uppc (extract wm1 wm1 a))) |
| 117 | + (eo::define ((mul (bvmul (concat zero a) (concat zero b)))) |
| 118 | + (eo::define ((res ($bv_umulo_elim_rec a b uppc (bvor (extract w w mul)) 1 w))) |
| 119 | + (= res (eo::to_bin 1 1)))))))))) |
| 120 | + |
| 121 | +; rule: bv-umulo-elim |
| 122 | +; implements: ProofRewriteRule::BV_UMULO_ELIM |
| 123 | +; args: |
| 124 | +; - eq Bool: The equality to prove with this rule. |
| 125 | +; requires: c is the result of eliminating the left hand side. |
| 126 | +; conclusion: the given equality. |
| 127 | +(declare-rule bv-umulo-elim ((n Int) (a (BitVec n)) (b (BitVec n)) (c Bool)) |
| 128 | + :args ((= (bvumulo a b) c)) |
| 129 | + :requires ((($bv_umulo_elim a b) c)) |
| 130 | + :conclusion (= (bvumulo a b) c) |
| 131 | +) |
| 132 | + |
19 | 133 | ;;;;; ProofRewriteRule::BV_BITWISE_SLICING
|
20 | 134 |
|
21 | 135 | ; program: $bv_mk_bitwise_slicing_rec
|
|
0 commit comments