Compare commits

...

1 Commits

Author SHA1 Message Date
Leonardo de Moura
50eeb79e7e feat: add simproc for BitVec.signExtend 2024-02-19 14:49:34 -08:00
2 changed files with 17 additions and 6 deletions

View File

@@ -77,6 +77,15 @@ Helper function for reducing homogenous binary bitvector operators.
else
return .continue
/-- Simplification procedure for `zeroExtend` and `signExtend` on `BitVec`s. -/
@[inline] def reduceExtend (declName : Name)
(op : {n : Nat} (m : Nat) BitVec n BitVec m) (e : Expr) : SimpM Step := do
unless e.isAppOfArity declName 3 do return .continue
let some v fromExpr? e.appArg! | return .continue
let some n Nat.fromExpr? e.appFn!.appArg! | return .continue
let lit : Literal := { n, value := op n v.value }
return .done { expr := lit.toExpr }
/--
Helper function for reducing bitvector functions such as `getLsb` and `getMsb`.
-/
@@ -275,12 +284,10 @@ builtin_simproc [simp, seval] reduceReplicate (replicate _ _) := fun e => do
return .done { expr := lit.toExpr }
/-- Simplification procedure for `zeroExtend` on `BitVec`s. -/
builtin_simproc [simp, seval] reduceZeroExtend (zeroExtend _ _) := fun e => do
unless e.isAppOfArity ``zeroExtend 3 do return .continue
let some v fromExpr? e.appArg! | return .continue
let some n Nat.fromExpr? e.appFn!.appArg! | return .continue
let lit : Literal := { n, value := v.value.zeroExtend n }
return .done { expr := lit.toExpr }
builtin_simproc [simp, seval] reduceZeroExtend (zeroExtend _ _) := reduceExtend ``zeroExtend zeroExtend
/-- Simplification procedure for `signExtend` on `BitVec`s. -/
builtin_simproc [simp, seval] reduceSignExtend (signExtend _ _) := reduceExtend ``signExtend signExtend
/-- Simplification procedure for `allOnes` -/
builtin_simproc [simp, seval] reduceAllOnes (allOnes _) := fun e => do

View File

@@ -109,3 +109,7 @@ example (h : x = (9: Std.BitVec 6)) : x = (1#3).replicate 2 := by
simp; guard_target = x = 9#6; assumption
example (h : x = (5 : Std.BitVec 7)) : x = (5#3).zeroExtend 7 := by
simp; guard_target = x = 5#7; assumption
example (h : -5#10 = x) : signExtend 10 (-5#8) = x := by
simp; guard_target =1019#10 = x; assumption
example (h : 5#10 = x) : -signExtend 10 (-5#8) = x := by
simp; guard_target =5#10 = x; assumption