aboutsummaryrefslogtreecommitdiffstats
path: root/src/translation/HTLgen.v
diff options
context:
space:
mode:
authorJames Pollard <james@pollard.dev>2020-07-06 21:05:05 +0100
committerJames Pollard <james@pollard.dev>2020-07-06 21:05:05 +0100
commitb0e1a1383890d9b0a14ffaabce4c3d6453eb0a9c (patch)
tree729be898d7e1314e8988dc8d6c3a18411357d810 /src/translation/HTLgen.v
parente1d9c228bece9926d42e49d3d8b7f4a1fe726b44 (diff)
downloadvericert-kvx-b0e1a1383890d9b0a14ffaabce4c3d6453eb0a9c.tar.gz
vericert-kvx-b0e1a1383890d9b0a14ffaabce4c3d6453eb0a9c.zip
Reduce number of array addressing modes.
Diffstat (limited to 'src/translation/HTLgen.v')
-rw-r--r--src/translation/HTLgen.v16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v
index 04de548..35203f8 100644
--- a/src/translation/HTLgen.v
+++ b/src/translation/HTLgen.v
@@ -402,6 +402,18 @@ Definition add_branch_instr (e: expr) (n n1 n2: node) : mon unit :=
(* | _, _, _ => error (Errors.msg "HTLgen: translate_arr_access unsuported addressing") *)
(* end. *)
+Definition translate_arr_addressing (a: Op.addressing) (args: list reg) : mon expr :=
+ match a, args with (* TODO: We should be more methodical here; what are the possibilities?*)
+ | Op.Aindexed off, r1::nil =>
+ ret (boplitz Vadd r1 off)
+ | Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *)
+ ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale))
+ | Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *)
+ let a := Integers.Ptrofs.unsigned a in
+ ret (Vlit (ZToValue a))
+ | _, _ => error (Errors.msg "Veriloggen: translate_arr_addressing unsuported addressing")
+ end.
+
Fixpoint enumerate (i : nat) (ns : list node) {struct ns} : list (nat * node) :=
match ns with
| n :: ns' => (i, n) :: enumerate (i+1) ns'
@@ -446,7 +458,7 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni
match chunk with
| Mint32 =>
if Z.leb (Z.pos n') Integers.Int.max_unsigned
- then do addr' <- translate_eff_addressing addr args;
+ then do addr' <- translate_arr_addressing addr args;
do _ <- declare_reg None dst 32;
add_instr n n' $ create_single_cycle_load stack addr' dst
else error (Errors.msg "State is larger than 2^32.")
@@ -456,7 +468,7 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni
match chunk with
| Mint32 =>
if Z.leb (Z.pos n') Integers.Int.max_unsigned
- then do addr' <- translate_eff_addressing addr args;
+ then do addr' <- translate_arr_addressing addr args;
add_instr n n' $ create_single_cycle_store stack addr' src
else error (Errors.msg "State is larger than 2^32.")
| _ => error (Errors.msg "Istore invalid chunk size.")