Skip to content

Commit 967bd8e

Browse files
committed
Fixes for CVA6 Formal Verification
1 parent e2e8e77 commit 967bd8e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

shell.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
pkgs.mkShell {
4+
buildInputs = with pkgs; [
5+
# OCaml toolchain
6+
ocaml
7+
opam
8+
dune_3
9+
10+
# Dependencies
11+
gmp
12+
z3
13+
zlib
14+
15+
# Build tools
16+
pkg-config
17+
m4
18+
19+
# For generated C emulators
20+
gcc
21+
22+
# Optional: for documentation
23+
asciidoctor
24+
25+
# To run the binary
26+
bash
27+
];
28+
29+
shellHook = ''
30+
export SAIL_DIR=$PWD
31+
echo "Sail development environment"
32+
echo "Run 'opam install . --deps-only' to install OCaml dependencies"
33+
'';
34+
}

src/lib/smt_gen.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ module Make (Config : CONFIG) (Primop_gen : PRIMOP_GEN) = struct
449449
| CT_fbits n, CT_lbits ->
450450
let* x = unsigned_size ~into:lbits_size ~from:n x in
451451
return (Fn ("Bits", [bvint lbits_index (Big_int.of_int n); x]))
452+
| CT_vector elem_ctyp, CT_fvector (len, elem_ctyp') when ctyp_equal elem_ctyp elem_ctyp' ->
453+
(* Vector to fixed vector conversion - assume lengths match *)
454+
return x
455+
| CT_fvector (len, elem_ctyp), CT_vector elem_ctyp' when ctyp_equal elem_ctyp elem_ctyp' ->
456+
(* Fixed vector to vector conversion *)
457+
return x
452458
| _, _ ->
453459
let* l = current_location in
454460
Reporting.unreachable l __POS__
@@ -1018,6 +1024,15 @@ module Make (Config : CONFIG) (Primop_gen : PRIMOP_GEN) = struct
10181024
let contents = bvor (bvand bv (bvnot mask)) (bvand (bvshl x j) mask) in
10191025
let* index = signed_size ~into:lbits_index ~from:sz len in
10201026
return (Fn ("Bits", [index; contents]))
1027+
| bv_ctyp, ctyp_i, ctyp_j, ctyp_x, CT_fbits n ->
1028+
let* sz, bv = fmap (to_fbits bv_ctyp) (smt_cval vec) in
1029+
let* i = bind (smt_cval i) (signed_size ~into:sz ~from:(int_size ctyp_i)) in
1030+
let* j = bind (smt_cval j) (signed_size ~into:sz ~from:(int_size ctyp_j)) in
1031+
let* x = bind (smt_cval x) (smt_conversion ~into:(CT_fbits sz) ~from:ctyp_x) in
1032+
let len = bvadd (bvadd i (bvneg j)) (bvpint sz (Big_int.of_int 1)) in
1033+
let mask = bvshl (fbits_mask sz len) j in
1034+
let contents = bvor (bvand bv (bvnot mask)) (bvand (bvshl x j) mask) in
1035+
smt_conversion ~into:(CT_fbits n) ~from:(CT_fbits sz) contents
10211036
| _ -> builtin_type_error "vector_update_subrange" [vec; i; j; x] (Some ret_ctyp)
10221037

10231038
let builtin_get_slice_int v1 v2 v3 ret_ctyp =
@@ -1051,6 +1066,18 @@ module Make (Config : CONFIG) (Primop_gen : PRIMOP_GEN) = struct
10511066
let* v = smt_cval v in
10521067
(* TODO: Check we haven't shifted too far *)
10531068
return (bvshl (bvone lint_size) v)
1069+
| CT_fint sz, CT_fint ret_sz ->
1070+
let* v = smt_cval v in
1071+
let* v = signed_size ~into:ret_sz ~from:sz v in
1072+
return (bvshl (bvone ret_sz) v)
1073+
| CT_fint sz, CT_lint ->
1074+
let* v = smt_cval v in
1075+
let* v = signed_size ~into:lint_size ~from:sz v in
1076+
return (bvshl (bvone lint_size) v)
1077+
| CT_lint, CT_fint ret_sz ->
1078+
let* v = smt_cval v in
1079+
let* v = signed_size ~into:ret_sz ~from:lint_size v in
1080+
return (bvshl (bvone ret_sz) v)
10541081
| _ -> builtin_type_error "pow2" [v] (Some ret_ctyp)
10551082

10561083
(* Technically, there's no bvclz in SMTLIB, but we can't generate

0 commit comments

Comments
 (0)