Skip to content

Commit

Permalink
Add ptr mod val to binop
Browse files Browse the repository at this point in the history
  • Loading branch information
krtab authored and filipeom committed Jan 25, 2024
1 parent b03bf56 commit 39a387e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ let rec simplify_binop ty (op : binop) e1 e2 =
| Sub ->
let new_offset = simplify_binop offset.ty Sub offset e2 in
Ptr (base, new_offset @: offset.ty)
| Rem ->
let rhs = Val (Value.Num (Num.I32 base)) @: ty in
let addr = (simplify_binop ty Add rhs offset) @: ty in
simplify_binop ty Rem addr e2
| _ -> Binop (op, e1, e2) )
| _, Ptr (base, offset) -> (
match op with
Expand Down
7 changes: 7 additions & 0 deletions test/regression/test_cvtop.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
open Encoding
open Ty
open Encoding.Expr

let f32 f = Num.F32 (Int32.bits_of_float f)
let f64 f = Num.F64 (Int64.bits_of_float f)

let () =
let ptr = Ptr (8390670l, Expr.Bitv.I32.v 2l) @: Ty_bitv S32 in
let rem = Binop (Rem, ptr, Expr.Bitv.I32.v 1l) @: Ty_bitv S32 in
let result = Expr.simplify rem in
assert(result.e = Val (Num (I32 0l)))

let () =
let cvtop = Eval_numeric.eval_cvtop in
assert (cvtop (Ty_bitv S32) TruncSF32 (f32 8.5) = I32 8l);
Expand Down

0 comments on commit 39a387e

Please sign in to comment.