aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-02-15 00:06:29 +0000
committerYann Herklotz <git@yannherklotz.com>2021-02-15 00:06:29 +0000
commit171b326ade18ab77eb155a9d203f2f523708b29b (patch)
treedf9f02bc68c7dc539a67ac376ad7a5d4435c07c3
parent5f1e7aa8fbc4a0e04d0b137410c13f3d8da4d987 (diff)
downloadvericert-kvx-171b326ade18ab77eb155a9d203f2f523708b29b.tar.gz
vericert-kvx-171b326ade18ab77eb155a9d203f2f523708b29b.zip
Add beginning to scheduling division
-rw-r--r--src/hls/HTL.v12
-rw-r--r--src/hls/HTLPargen.v155
-rw-r--r--src/hls/HTLgen.v1
-rw-r--r--src/hls/HTLgenspec.v2
-rw-r--r--src/hls/PrintVerilog.ml20
-rw-r--r--src/hls/Verilog.v300
-rw-r--r--src/hls/Veriloggen.v1
7 files changed, 181 insertions, 310 deletions
diff --git a/src/hls/HTL.v b/src/hls/HTL.v
index c8a0041..d91a340 100644
--- a/src/hls/HTL.v
+++ b/src/hls/HTL.v
@@ -27,16 +27,19 @@ Require compcert.lib.Integers.
Require Import compcert.lib.Maps.
Require Import vericert.common.Vericertlib.
-Require Import vericert.hls.ValueInt.
-Require Import vericert.hls.AssocMap.
Require Import vericert.hls.Array.
+Require Import vericert.hls.AssocMap.
+Require Import vericert.hls.FunctionalUnits.
+Require Import vericert.hls.ValueInt.
Require vericert.hls.Verilog.
-(** The purpose of the hardware transfer language (HTL) is to create a more
+(*|
+The purpose of the hardware transfer language (HTL) is to create a more
hardware-like layout that is still similar to the register transfer language
(RTL) that it came from. The main change is that function calls become module
instantiations and that we now describe a state machine instead of a
-control-flow graph. *)
+control-flow graph.
+|*)
Local Open Scope assocmap.
@@ -65,6 +68,7 @@ Record module: Type :=
mod_start : reg;
mod_reset : reg;
mod_clk : reg;
+ mod_funct_units: funct_units;
mod_scldecls : AssocMap.t (option Verilog.io * Verilog.scl_decl);
mod_arrdecls : AssocMap.t (option Verilog.io * Verilog.arr_decl);
mod_wf : (map_well_formed mod_controllogic /\ map_well_formed mod_datapath);
diff --git a/src/hls/HTLPargen.v b/src/hls/HTLPargen.v
index fcd4441..88fb9b4 100644
--- a/src/hls/HTLPargen.v
+++ b/src/hls/HTLPargen.v
@@ -27,6 +27,7 @@ Require Import compcert.lib.Maps.
Require Import vericert.common.Statemonad.
Require Import vericert.common.Vericertlib.
Require Import vericert.hls.AssocMap.
+Require Import vericert.hls.FunctionalUnits.
Require Import vericert.hls.HTL.
Require Import vericert.hls.RTLBlockInstr.
Require Import vericert.hls.RTLPar.
@@ -47,6 +48,7 @@ Record state: Type := mkstate {
st_arrdecls: AssocMap.t (option io * arr_decl);
st_datapath: datapath;
st_controllogic: controllogic;
+ st_funct_units: funct_units;
}.
Definition init_state (st : reg) : state :=
@@ -56,7 +58,8 @@ Definition init_state (st : reg) : state :=
(AssocMap.empty (option io * scl_decl))
(AssocMap.empty (option io * arr_decl))
(AssocMap.empty stmnt)
- (AssocMap.empty stmnt).
+ (AssocMap.empty stmnt)
+ initial_funct_units.
Module HTLState <: State.
@@ -126,7 +129,8 @@ Lemma declare_reg_state_incr :
(AssocMap.set r (i, VScalar sz) s.(st_scldecls))
s.(st_arrdecls)
s.(st_datapath)
- s.(st_controllogic)).
+ s.(st_controllogic)
+ s.(st_funct_units)).
Proof. auto with htlh. Qed.
Definition declare_reg (i : option io) (r : reg) (sz : nat) : mon unit :=
@@ -137,7 +141,8 @@ Definition declare_reg (i : option io) (r : reg) (sz : nat) : mon unit :=
(AssocMap.set r (i, VScalar sz) s.(st_scldecls))
s.(st_arrdecls)
s.(st_datapath)
- s.(st_controllogic))
+ s.(st_controllogic)
+ s.(st_funct_units))
(declare_reg_state_incr i s r sz).
Lemma add_instr_state_incr :
@@ -151,7 +156,8 @@ Lemma add_instr_state_incr :
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n st s.(st_datapath))
- (AssocMap.set n (state_goto s.(st_st) n') s.(st_controllogic))).
+ (AssocMap.set n (state_goto s.(st_st) n') s.(st_controllogic))
+ s.(st_funct_units)).
Proof.
constructor; intros;
try (simpl; destruct (peq n n0); subst);
@@ -169,7 +175,8 @@ Definition add_instr (n : node) (n' : node) (st : stmnt) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n st s.(st_datapath))
- (AssocMap.set n (state_goto s.(st_st) n') s.(st_controllogic)))
+ (AssocMap.set n (state_goto s.(st_st) n') s.(st_controllogic))
+ s.(st_funct_units))
(add_instr_state_incr s n n' st TRANS)
| _ => Error (Errors.msg "HTL.add_instr")
end.
@@ -185,7 +192,8 @@ Lemma add_instr_skip_state_incr :
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n st s.(st_datapath))
- (AssocMap.set n Vskip s.(st_controllogic))).
+ (AssocMap.set n Vskip s.(st_controllogic))
+ s.(st_funct_units)).
Proof.
constructor; intros;
try (simpl; destruct (peq n n0); subst);
@@ -203,7 +211,8 @@ Definition add_instr_skip (n : node) (st : stmnt) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n st s.(st_datapath))
- (AssocMap.set n Vskip s.(st_controllogic)))
+ (AssocMap.set n Vskip s.(st_controllogic))
+ s.(st_funct_units))
(add_instr_skip_state_incr s n st TRANS)
| _ => Error (Errors.msg "HTL.add_instr_skip")
end.
@@ -219,7 +228,8 @@ Lemma add_node_skip_state_incr :
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n Vskip s.(st_datapath))
- (AssocMap.set n st s.(st_controllogic))).
+ (AssocMap.set n st s.(st_controllogic))
+ s.(st_funct_units)).
Proof.
constructor; intros;
try (simpl; destruct (peq n n0); subst);
@@ -237,7 +247,8 @@ Definition add_node_skip (n : node) (st : stmnt) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n Vskip s.(st_datapath))
- (AssocMap.set n st s.(st_controllogic)))
+ (AssocMap.set n st s.(st_controllogic))
+ s.(st_funct_units))
(add_node_skip_state_incr s n st TRANS)
| _ => Error (Errors.msg "HTL.add_node_skip")
end.
@@ -325,6 +336,32 @@ Definition check_address_parameter_signed (p : Z) : bool :=
Definition check_address_parameter_unsigned (p : Z) : bool :=
Z.leb p Integers.Ptrofs.max_unsigned.
+Lemma create_reg_state_incr:
+ forall s sz i,
+ st_incr s (mkstate
+ s.(st_st)
+ (Pos.succ (st_freshreg s))
+ (st_freshstate s)
+ (AssocMap.set s.(st_freshreg) (i, VScalar sz) s.(st_scldecls))
+ s.(st_arrdecls)
+ (st_datapath s)
+ (st_controllogic s)
+ s.(st_funct_units)).
+Proof. constructor; simpl; auto with htlh. Qed.
+
+Definition create_reg (i : option io) (sz : nat) : mon reg :=
+ fun s => let r := s.(st_freshreg) in
+ OK r (mkstate
+ s.(st_st)
+ (Pos.succ r)
+ (st_freshstate s)
+ (AssocMap.set s.(st_freshreg) (i, VScalar sz) s.(st_scldecls))
+ (st_arrdecls s)
+ (st_datapath s)
+ (st_controllogic s)
+ s.(st_funct_units))
+ (create_reg_state_incr s sz i).
+
Definition translate_eff_addressing (a: Op.addressing) (args: list reg)
: mon expr :=
match a, args with (* TODO: We should be more methodical here; what are the possibilities?*)
@@ -353,7 +390,7 @@ Definition translate_eff_addressing (a: Op.addressing) (args: list reg)
end.
(** Translate an instruction to a statement. FIX mulhs mulhu *)
-Definition translate_instr (op : Op.operation) (args : list reg) : mon expr :=
+Definition translate_instr (op : Op.operation) (args : list reg) : mon stmnt :=
match op, args with
| Op.Omove, r::nil => ret (Vvar r)
| Op.Ointconst n, _ => ret (Vlit (intToValue n))
@@ -363,7 +400,19 @@ Definition translate_instr (op : Op.operation) (args : list reg) : mon expr :=
| Op.Omulimm n, r::nil => ret (boplit Vmul r n)
| Op.Omulhs, r1::r2::nil => error (Errors.msg "Htlgen: Instruction not implemented: mulhs")
| Op.Omulhu, r1::r2::nil => error (Errors.msg "Htlgen: Instruction not implemented: mulhu")
- | Op.Odiv, r1::r2::nil => ret (bop Vdiv r1 r2)
+ | Op.Odiv, r1::r2::nil =>
+ do s <- get;
+ match sdiv_present s.(st_funct_units) 32%positive with
+ | SignedDiv s n d q r :: _ =>
+ ret (Vseq (Vnonblock (Vvar n) (Vvar r1)) (Vnonblock (Vvar d) (Vvar r2)))
+ | _ =>
+ do n <- create_reg None 32;
+ do d <- create_reg None 32;
+ do q <- create_reg None 32;
+ do r <- create_reg None 32;
+ do _ <- add_funct_unit (SignedDiv 32%positive n d q r);
+ ret (Vseq (Vnonblock (Vvar n) (Vvar r1)) (Vnonblock (Vvar d) (Vvar r2)))
+ end
| Op.Odivu, r1::r2::nil => ret (bop Vdivu r1 r2)
| Op.Omod, r1::r2::nil => ret (bop Vmod r1 r2)
| Op.Omodu, r1::r2::nil => ret (bop Vmodu r1 r2)
@@ -406,7 +455,8 @@ Lemma add_branch_instr_state_incr:
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n Vskip (st_datapath s))
- (AssocMap.set n (state_cond s.(st_st) e n1 n2) (st_controllogic s))).
+ (AssocMap.set n (state_cond s.(st_st) e n1 n2) (st_controllogic s))
+ s.(st_funct_units)).
Proof.
intros. apply state_incr_intro; simpl;
try (intros; destruct (peq n0 n); subst);
@@ -424,7 +474,8 @@ Definition add_branch_instr (e: expr) (n n1 n2: node) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n Vskip (st_datapath s))
- (AssocMap.set n (state_cond s.(st_st) e n1 n2) (st_controllogic s)))
+ (AssocMap.set n (state_cond s.(st_st) e n1 n2) (st_controllogic s))
+ s.(st_funct_units))
(add_branch_instr_state_incr s e n n1 n2 NTRANS)
| _ => Error (Errors.msg "Htlgen: add_branch_instr")
end.
@@ -466,30 +517,6 @@ Definition tbl_to_case_expr (st : reg) (ns : list node) : list (expr * stmnt) :=
Definition stack_correct (sz : Z) : bool :=
(0 <=? sz) && (sz <? Integers.Ptrofs.modulus) && (Z.modulo sz 4 =? 0).
-Lemma create_reg_state_incr:
- forall s sz i,
- st_incr s (mkstate
- s.(st_st)
- (Pos.succ (st_freshreg s))
- (st_freshstate s)
- (AssocMap.set s.(st_freshreg) (i, VScalar sz) s.(st_scldecls))
- s.(st_arrdecls)
- (st_datapath s)
- (st_controllogic s)).
-Proof. constructor; simpl; auto with htlh. Qed.
-
-Definition create_reg (i : option io) (sz : nat) : mon reg :=
- fun s => let r := s.(st_freshreg) in
- OK r (mkstate
- s.(st_st)
- (Pos.succ r)
- (st_freshstate s)
- (AssocMap.set s.(st_freshreg) (i, VScalar sz) s.(st_scldecls))
- (st_arrdecls s)
- (st_datapath s)
- (st_controllogic s))
- (create_reg_state_incr s sz i).
-
Lemma create_arr_state_incr:
forall s sz ln i,
st_incr s (mkstate
@@ -499,7 +526,8 @@ Lemma create_arr_state_incr:
s.(st_scldecls)
(AssocMap.set s.(st_freshreg) (i, VArray sz ln) s.(st_arrdecls))
(st_datapath s)
- (st_controllogic s)).
+ (st_controllogic s)
+ s.(st_funct_units)).
Proof. constructor; simpl; auto with htlh. Qed.
Definition create_arr (i : option io) (sz : nat) (ln : nat) : mon (reg * nat) :=
@@ -511,7 +539,8 @@ Definition create_arr (i : option io) (sz : nat) (ln : nat) : mon (reg * nat) :=
s.(st_scldecls)
(AssocMap.set s.(st_freshreg) (i, VArray sz ln) s.(st_arrdecls))
(st_datapath s)
- (st_controllogic s))
+ (st_controllogic s)
+ s.(st_funct_units))
(create_arr_state_incr s sz ln i).
Definition max_pc_map (m : Maps.PTree.t stmnt) :=
@@ -574,7 +603,8 @@ Lemma add_data_instr_state_incr :
s.(st_arrdecls)
(AssocMap.set n (Vseq (AssocMapExt.get_default
_ Vskip n s.(st_datapath)) st) s.(st_datapath))
- s.(st_controllogic)).
+ s.(st_controllogic)
+ s.(st_funct_units)).
Proof.
constructor; intros;
try (simpl; destruct (peq n n0); subst);
@@ -590,7 +620,8 @@ Definition add_data_instr (n : node) (st : stmnt) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
(AssocMap.set n (Vseq (AssocMapExt.get_default _ Vskip n s.(st_datapath)) st) s.(st_datapath))
- s.(st_controllogic))
+ s.(st_controllogic)
+ s.(st_funct_units))
(add_data_instr_state_incr s n st).
Lemma add_control_instr_state_incr :
@@ -604,7 +635,8 @@ Lemma add_control_instr_state_incr :
s.(st_scldecls)
s.(st_arrdecls)
s.(st_datapath)
- (AssocMap.set n st s.(st_controllogic))).
+ (AssocMap.set n st s.(st_controllogic))
+ s.(st_funct_units)).
Proof.
constructor; intros;
try (simpl; destruct (peq n n0); subst);
@@ -622,38 +654,13 @@ Definition add_control_instr (n : node) (st : stmnt) : mon unit :=
s.(st_scldecls)
s.(st_arrdecls)
s.(st_datapath)
- (AssocMap.set n st s.(st_controllogic)))
+ (AssocMap.set n st s.(st_controllogic))
+ s.(st_funct_units))
(add_control_instr_state_incr s n st CTRL)
| _ =>
Error (Errors.msg "HTLPargen.add_control_instr: control logic is not empty")
end.
-Definition add_control_instr_force_state_incr :
- forall s n st,
- st_incr s
- (mkstate
- s.(st_st)
- s.(st_freshreg)
- (st_freshstate s)
- s.(st_scldecls)
- s.(st_arrdecls)
- s.(st_datapath)
- (AssocMap.set n st s.(st_controllogic))).
-Admitted.
-
-Definition add_control_instr_force (n : node) (st : stmnt) : mon unit :=
- fun s =>
- OK tt (mkstate
- s.(st_st)
- s.(st_freshreg)
- (st_freshstate s)
- s.(st_scldecls)
- s.(st_arrdecls)
- s.(st_datapath)
- (AssocMap.set n st s.(st_controllogic)))
- (add_control_instr_force_state_incr s n st).
-
-
Fixpoint pred_expr (preg: reg) (p: pred_op) :=
match p with
| Pvar pred =>
@@ -707,7 +714,8 @@ Lemma create_new_state_state_incr:
s.(st_scldecls)
s.(st_arrdecls)
s.(st_datapath)
- s.(st_controllogic)).
+ s.(st_controllogic)
+ s.(st_funct_units)).
Admitted.
Definition create_new_state (p: node): mon node :=
@@ -719,7 +727,8 @@ Definition create_new_state (p: node): mon node :=
s.(st_scldecls)
s.(st_arrdecls)
s.(st_datapath)
- s.(st_controllogic))
+ s.(st_controllogic)
+ s.(st_funct_units))
(create_new_state_state_incr s p).
Definition translate_inst_list (fin rtrn stack preg: reg) (ni : node * node * list instr) :=
@@ -816,6 +825,7 @@ Definition transf_module (f: function) : mon HTL.module :=
start
rst
clk
+ nil
current_state.(st_scldecls)
current_state.(st_arrdecls)
(conj (max_pc_wf _ LECTRL) (max_pc_wf _ LEDATA)))
@@ -831,7 +841,8 @@ Definition max_state (f: function) : state :=
(AssocMap.set st (None, VScalar 32) (st_scldecls (init_state st)))
(st_arrdecls (init_state st))
(st_datapath (init_state st))
- (st_controllogic (init_state st)).
+ (st_controllogic (init_state st))
+ (st_funct_units (init_state st)).
Definition transl_module (f : function) : Errors.res HTL.module :=
run_mon (max_state f) (transf_module f).
diff --git a/src/hls/HTLgen.v b/src/hls/HTLgen.v
index f1e6b2a..b323a65 100644
--- a/src/hls/HTLgen.v
+++ b/src/hls/HTLgen.v
@@ -610,6 +610,7 @@ Definition transf_module (f: function) : mon HTL.module :=
start
rst
clk
+ nil
current_state.(st_scldecls)
current_state.(st_arrdecls)
(conj (max_pc_wf _ LECTRL) (max_pc_wf _ LEDATA)))
diff --git a/src/hls/HTLgenspec.v b/src/hls/HTLgenspec.v
index 845b1d5..ae7917f 100644
--- a/src/hls/HTLgenspec.v
+++ b/src/hls/HTLgenspec.v
@@ -183,7 +183,7 @@ Inductive tr_module (f : RTL.function) : module -> Prop :=
data
control
f.(RTL.fn_entrypoint)
- st stk stk_len fin rtrn start rst clk scldecls arrdecls wf) ->
+ st stk stk_len fin rtrn start rst clk nil scldecls arrdecls wf) ->
(forall pc i, Maps.PTree.get pc f.(RTL.fn_code) = Some i ->
tr_code f.(RTL.fn_code) pc i data control fin rtrn st stk) ->
stk_len = Z.to_nat (f.(RTL.fn_stacksize) / 4) ->
diff --git a/src/hls/PrintVerilog.ml b/src/hls/PrintVerilog.ml
index e67b567..e9020ac 100644
--- a/src/hls/PrintVerilog.ml
+++ b/src/hls/PrintVerilog.ml
@@ -28,6 +28,7 @@ open Clflags
open Printf
open VericertClflags
+open FunctionalUnits
module PMap = Map.Make (struct
type t = P.t
@@ -149,10 +150,10 @@ let declarearr t =
" ["; sprintf "%d" (Nat.to_int ln - 1); ":0];\n" ]
let print_io = function
- | Some Vinput -> "input"
- | Some Voutput -> "output reg"
- | Some Vinout -> "inout"
- | None -> "reg"
+ | Some Vinput -> "input logic"
+ | Some Voutput -> "output logic"
+ | Some Vinout -> "inout logic"
+ | None -> "logic"
let decl i = function
| Vdecl (io, r, sz) -> concat [indent i; declare (print_io io) (r, sz)]
@@ -175,6 +176,16 @@ let rec intersperse c = function
let make_io i io r = concat [indent i; io; " "; register r; ";\n"]
+let print_funct_units clk = function
+ | SignedDiv (stages, numer, denom, quot, rem) ->
+ sprintf "div_signed #(.stages(%d)) divs(.clk(%s), .clken(1'b1), .numer(%s), .denom(%s), .quotient(%s), .remain(%s))\n"
+ (P.to_int stages)
+ (register clk) (register numer) (register denom) (register quot) (register rem)
+ | UnsignedDiv (stages, numer, denom, quot, rem) ->
+ sprintf "div_unsigned #(.stages(%d)) divs(.clk(%s), .clken(1'b1), .numer(%s), .denom(%s), .quotient(%s), .remain(%s))\n"
+ (P.to_int stages)
+ (register clk) (register numer) (register denom) (register quot) (register rem)
+
let compose f g x = g x |> f
let testbench = "module testbench;
@@ -233,6 +244,7 @@ let pprint_module debug i n m =
concat [ indent i; "module "; (extern_atom n);
"("; concat (intersperse ", " (List.map register (inputs @ outputs))); ");\n";
fold_map (pprint_module_item (i+1)) m.mod_body;
+ concat (List.map (print_funct_units m.mod_clk) m.mod_funct_units);
if !option_initial then print_initial i (Nat.to_int m.mod_stk_len) m.mod_stk else "";
if debug then debug_always i m.mod_clk m.mod_st else "";
indent i; "endmodule\n\n"
diff --git a/src/hls/Verilog.v b/src/hls/Verilog.v
index a7db3ba..779b05c 100644
--- a/src/hls/Verilog.v
+++ b/src/hls/Verilog.v
@@ -17,27 +17,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
-From Coq Require Import
- Structures.OrderedTypeEx
- FSets.FMapPositive
- Program.Basics
- PeanoNat
- ZArith
- Lists.List
- Program.
+Set Implicit Arguments.
-Require Import Lia.
+Require Import Coq.Structures.OrderedTypeEx.
+Require Import Coq.FSets.FMapPositive.
+Require Import Coq.Arith.PeanoNat.
+Require Import Coq.ZArith.ZArith.
+Require Import Coq.Lists.List.
+Require Import Coq.micromega.Lia.
+
+Require Import compcert.common.Errors.
+Require Import compcert.common.Globalenvs.
+Require Import compcert.common.Smallstep.
+Require Import compcert.lib.Integers.
+Require compcert.common.Events.
+
+Require Import vericert.common.Show.
+Require Import vericert.common.Vericertlib.
+Require Import vericert.hls.Array.
+Require Import vericert.hls.AssocMap.
+Require Import vericert.hls.FunctionalUnits.
+Require Import vericert.hls.ValueInt.
Import ListNotations.
-From vericert Require Import Vericertlib Show ValueInt AssocMap Array.
-From compcert Require Events.
-From compcert Require Import Integers Errors Smallstep Globalenvs.
-
Local Open Scope assocmap.
-Set Implicit Arguments.
-
Definition reg : Type := positive.
Definition node : Type := positive.
Definition szreg : Type := reg * nat.
@@ -103,23 +108,30 @@ Definition nonblock_reg (r : reg) (asr : reg_associations) (v : value) :=
Inductive scl_decl : Type := VScalar (sz : nat).
Inductive arr_decl : Type := VArray (sz : nat) (ln : nat).
-(** * Verilog AST
+(*|
+Verilog AST
+===========
The Verilog AST is defined here, which is the target language of the
compilation.
-** Value
+Value
+-----
The Verilog [value] is a bitvector containg a size and the actual bitvector. In
this case, the [Word.word] type is used as many theorems about that bitvector
-have already been proven. *)
+have already been proven.
+|*)
-(** ** Binary Operators
+(*|
+Binary Operators
+----------------
These are the binary operations that can be represented in Verilog. Ideally,
multiplication and division would be done by custom modules which could al so be
scheduled properly. However, for now every Verilog operator is assumed to take
-one clock cycle. *)
+one clock cycle.
+|*)
Inductive binop : Type :=
| Vadd : binop (** addition (binary [+]) *)
@@ -147,13 +159,19 @@ Inductive binop : Type :=
| Vshru : binop. (** shift right unsigned ([>>]) *)
(*| Vror : binop (** shift right unsigned ([>>]) *)*)
-(** ** Unary Operators *)
+(*|
+Unary Operators
+---------------
+|*)
Inductive unop : Type :=
| Vneg (** negation ([-]) *)
| Vnot. (** not operation [!] *)
-(** ** Expressions *)
+(*|
+Expressions
+-----------
+|*)
Inductive expr : Type :=
| Vlit : value -> expr
@@ -168,7 +186,10 @@ Inductive expr : Type :=
Definition posToExpr (p : positive) : expr :=
Vlit (posToValue p).
-(** ** Statements *)
+(*|
+Statements
+----------
+|*)
Inductive stmnt : Type :=
| Vskip : stmnt
@@ -178,14 +199,17 @@ Inductive stmnt : Type :=
| Vblock : expr -> expr -> stmnt
| Vnonblock : expr -> expr -> stmnt.
-(** ** Edges
+(*|
+Edges
+-----
These define when an always block should be triggered, for example if the always
block should be triggered synchronously at the clock edge, or asynchronously for
combinational logic.
[edge] is not part of [stmnt] in this formalisation because is closer to the
-semantics that are used. *)
+semantics that are used.
+|*)
Inductive edge : Type :=
| Vposedge : reg -> edge
@@ -193,11 +217,14 @@ Inductive edge : Type :=
| Valledge : edge
| Voredge : edge -> edge -> edge.
-(** ** Module Items
+(*|
+Module Items
+------------
Module items can either be declarations ([Vdecl]) or always blocks ([Valways]).
The declarations are always register declarations as combinational logic can be
-done using combinational always block instead of continuous assignments. *)
+done using combinational always block instead of continuous assignments.
+|*)
Inductive io : Type :=
| Vinput : io
@@ -214,7 +241,8 @@ Inductive module_item : Type :=
| Valways_ff : edge -> stmnt -> module_item
| Valways_comb : edge -> stmnt -> module_item.
-(** The main module type containing all the important control signals
+(*|
+The main module type containing all the important control signals
- [mod_start] If set, starts the computations in the module.
- [mod_reset] If set, reset the state in the module.
@@ -223,7 +251,7 @@ Inductive module_item : Type :=
- [mod_finish] Bit that is set if the result is ready.
- [mod_return] The return value that was computed.
- [mod_body] The body of the module, including the state machine.
-*)
+|*)
Record module : Type := mkmodule {
mod_start : reg;
@@ -235,6 +263,7 @@ Record module : Type := mkmodule {
mod_stk : reg;
mod_stk_len : nat;
mod_args : list reg;
+ mod_funct_units: funct_units;
mod_body : list module_item;
mod_entrypoint : node;
}.
@@ -243,15 +272,18 @@ Definition fundef := AST.fundef module.
Definition program := AST.program fundef unit.
-(** Convert a [positive] to an expression directly, setting it to the right
- size. *)
+(*|
+Convert a [positive] to an expression directly, setting it to the right size.
+|*)
Definition posToLit (p : positive) : expr :=
Vlit (posToValue p).
Definition fext := unit.
Definition fextclk := nat -> fext.
-(** ** State
+(*|
+State
+-----
The [state] contains the following items:
n
@@ -270,7 +302,8 @@ retrieved and set appropriately.
Verilog, as the Verilog was generated by the RTL, which means that we have to
make an assumption about how it looks. In this case, that it contains state
which determines which part of the Verilog is executed. This is then the part
- of the Verilog that should match with the RTL. *)
+ of the Verilog that should match with the RTL.
+|*)
Inductive stackframe : Type :=
Stackframe :
@@ -390,41 +423,9 @@ Definition handle_def {A : Type} (a : A) (val : option A)
Local Open Scope error_monad_scope.
-(*Definition access_fext (f : fext) (r : reg) : res value :=
- match AssocMap.get r f with
- | Some v => OK v
- | _ => OK (ZToValue 0)
- end.*)
-
-(* TODO FIX Vvar case without default *)
-(*Fixpoint expr_run (assoc : assocmap) (e : expr)
- {struct e} : res value :=
- match e with
- | Vlit v => OK v
- | Vvar r => match s with
- | State _ assoc _ _ _ => handle_def (ZToValue 32 0) assoc!r
- | _ => Error (msg "Verilog: Wrong state")
- end
- | Vvari _ _ => Error (msg "Verilog: variable indexing not modelled")
- | Vinputvar r => access_fext s r
- | Vbinop op l r =>
- let lv := expr_run s l in
- let rv := expr_run s r in
- let oper := binop_run op in
- do lv' <- lv;
- do rv' <- rv;
- handle_opt (msg "Verilog: sizes are not equal")
- (eq_to_opt lv' rv' (oper lv' rv'))
- | Vunop op e =>
- let oper := unop_run op in
- do ev <- expr_run s e;
- OK (oper ev)
- | Vternary c te fe =>
- do cv <- expr_run s c;
- if valueToBool cv then expr_run s te else expr_run s fe
- end.*)
-
-(** Return the location of the lhs of an assignment. *)
+(*|
+Return the location of the lhs of an assignment.
+|*)
Inductive location : Type :=
| LocReg (_ : reg)
@@ -436,80 +437,6 @@ Inductive location_is : fext -> assocmap -> assocmap_arr -> expr -> location ->
expr_runp f asr asa iexp iv ->
location_is f asr asa (Vvari r iexp) (LocArray r (valueToNat iv)).
-(* Definition assign_name (f : fext) (asr: assocmap) (asa : assocmap_l) (e : expr) : res reg := *)
-(* match e with *)
-(* | Vvar r => OK r *)
-(* | _ => Error (msg "Verilog: expression not supported on lhs of assignment") *)
-(* end. *)
-
-(*Fixpoint stmnt_height (st : stmnt) {struct st} : nat :=
- match st with
- | Vseq s1 s2 => S (stmnt_height s1 + stmnt_height s2)
- | Vcond _ s1 s2 => S (Nat.max (stmnt_height s1) (stmnt_height s2))
- | Vcase _ ls (Some st) =>
- S (fold_right (fun t acc => Nat.max acc (stmnt_height (snd t))) 0%nat ls)
- | _ => 1
- end.
-
-Fixpoint find_case_stmnt (s : state) (v : value) (cl : list (expr * stmnt))
- {struct cl} : option (res stmnt) :=
- match cl with
- | (e, st)::xs =>
- match expr_run s e with
- | OK v' =>
- match eq_to_opt v v' (veq v v') with
- | Some eq => if valueToBool eq then Some (OK st) else find_case_stmnt s v xs
- | None => Some (Error (msg "Verilog: equality check sizes not equal"))
- end
- | Error msg => Some (Error msg)
- end
- | _ => None
- end.
-
-Fixpoint stmnt_run' (n : nat) (s : state) (st : stmnt) {struct n} : res state :=
- match n with
- | S n' =>
- match st with
- | Vskip => OK s
- | Vseq s1 s2 =>
- do s' <- stmnt_run' n' s s1;
- stmnt_run' n' s' s2
- | Vcond c st sf =>
- do cv <- expr_run s c;
- if valueToBool cv
- then stmnt_run' n' s st
- else stmnt_run' n' s sf
- | Vcase e cl defst =>
- do v <- expr_run s e;
- match find_case_stmnt s v cl with
- | Some (OK st') => stmnt_run' n' s st'
- | Some (Error msg) => Error msg
- | None => do s' <- handle_opt (msg "Verilog: no case was matched")
- (option_map (stmnt_run' n' s) defst); s'
- end
- | Vblock lhs rhs =>
- match s with
- | State m assoc nbassoc f c =>
- do name <- assign_name lhs;
- do rhse <- expr_run s rhs;
- OK (State m (PositiveMap.add name rhse assoc) nbassoc f c)
- | _ => Error (msg "Verilog: Wrong state")
- end
- | Vnonblock lhs rhs =>
- match s with
- | State m assoc nbassoc f c =>
- do name <- assign_name lhs;
- do rhse <- expr_run s rhs;
- OK (State m assoc (PositiveMap.add name rhse nbassoc) f c)
- | _ => Error (msg "Verilog: Wrong state")
- end
- end
- | _ => OK s
- end.
-
-Definition stmnt_run (s : state) (st : stmnt) : res state :=
- stmnt_run' (stmnt_height st) s st. *)
-
Inductive stmnt_runp: fext -> reg_associations -> arr_associations ->
stmnt -> reg_associations -> arr_associations -> Prop :=
| stmnt_runp_Vskip:
@@ -580,20 +507,6 @@ Inductive stmnt_runp: fext -> reg_associations -> arr_associations ->
asr (nonblock_arr r i asa rhsval).
Hint Constructors stmnt_runp : verilog.
-(*Fixpoint mi_step (s : state) (m : list module_item) {struct m} : res state :=
- let run := fun st ls =>
- do s' <- stmnt_run s st;
- mi_step s' ls
- in
- match m with
- | (Valways _ st)::ls => run st ls
- | (Valways_ff _ st)::ls => run st ls
- | (Valways_comb _ st)::ls => run st ls
- | (Vdecl _ _)::ls => mi_step s ls
- | (Vdeclarr _ _ _)::ls => mi_step s ls
- | nil => OK s
- end.*)
-
Inductive mi_stepp : fext -> reg_associations -> arr_associations ->
module_item -> reg_associations -> arr_associations -> Prop :=
| mi_stepp_Valways :
@@ -625,80 +538,8 @@ Inductive mis_stepp : fext -> reg_associations -> arr_associations ->
mis_stepp f sr sa nil sr sa.
Hint Constructors mis_stepp : verilog.
-(*Definition mi_step_commit (s : state) (m : list module_item) : res state :=
- match mi_step s m with
- | OK (State m assoc nbassoc f c) =>
- OK (State m (merge_assocmap nbassoc assoc) empty_assocmap f c)
- | Error msg => Error msg
- | _ => Error (msg "Verilog: Wrong state")
- end.
-
-Fixpoint mi_run (f : fextclk) (assoc : assocmap) (m : list module_item) (n : nat)
- {struct n} : res assocmap :=
- match n with
- | S n' =>
- do assoc' <- mi_run f assoc m n';
- match mi_step_commit (State assoc' empty_assocmap f (Pos.of_nat n')) m with
- | OK (State assoc _ _ _) => OK assoc
- | Error m => Error m
- end
- | O => OK assoc
- end.*)
-
-(** Resets the module into a known state, so that it can be executed. This is
-assumed to be the starting state of the module, and may have to be changed if
-other arguments to the module are also to be supported. *)
-
-(*Definition initial_fextclk (m : module) : fextclk :=
- fun x => match x with
- | S O => (AssocMap.set (mod_reset m) (ZToValue 1) empty_assocmap)
- | _ => (AssocMap.set (mod_reset m) (ZToValue 0) empty_assocmap)
- end.*)
-
-(*Definition module_run (n : nat) (m : module) : res assocmap :=
- mi_run (initial_fextclk m) empty_assocmap (mod_body m) n.*)
-
Local Close Scope error_monad_scope.
-(*Theorem value_eq_size_if_eq:
- forall lv rv EQ,
- vsize lv = vsize rv -> value_eq_size lv rv = left EQ.
-Proof. intros. unfold value_eq_size.
-
-Theorem expr_run_same:
- forall assoc e v, expr_run assoc e = OK v <-> expr_runp assoc e v.
-Proof.
- split; generalize dependent v; generalize dependent assoc.
- - induction e.
- + intros. inversion H. constructor.
- + intros. inversion H. constructor. assumption.
- + intros. inversion H. destruct (expr_run assoc e1) eqn:?. destruct (expr_run assoc e2) eqn:?.
- unfold eq_to_opt in H1. destruct (value_eq_size v0 v1) eqn:?. inversion H1.
- constructor. apply IHe1. assumption. apply IHe2. assumption. reflexivity. discriminate. discriminate.
- discriminate.
- + intros. inversion H. destruct (expr_run assoc e) eqn:?. unfold option_map in H1.
- inversion H1. constructor. apply IHe. assumption. reflexivity. discriminate.
- + intros. inversion H. destruct (expr_run assoc e1) eqn:?. destruct (valueToBool v0) eqn:?.
- eapply erun_Vternary_true. apply IHe1. eassumption. apply IHe2. eassumption. assumption.
- eapply erun_Vternary_false. apply IHe1. eassumption. apply IHe3. eassumption. assumption.
- discriminate.
- - induction e.
- + intros. inversion H. reflexivity.
- + intros. inversion H. subst. simpl. assumption.
- + intros. inversion H. subst. simpl. apply IHe1 in H4. rewrite H4.
- apply IHe2 in H6. rewrite H6. unfold eq_to_opt. assert (vsize lv = vsize rv).
- apply EQ. apply (value_eq_size_if_eq lv rv EQ) in H0. rewrite H0. reflexivity.
- + intros. inversion H. subst. simpl. destruct (expr_run assoc e) eqn:?. simpl.
- apply IHe in H3. rewrite Heqo in H3.
- inversion H3. subst. reflexivity. apply IHe in H3. rewrite Heqo in H3. discriminate.
- + intros. inversion H. subst. simpl. apply IHe1 in H4. rewrite H4. rewrite H7.
- apply IHe2 in H6. rewrite H6. reflexivity.
- subst. simpl. apply IHe1 in H4. rewrite H4. rewrite H7. apply IHe3.
- assumption.
-Qed.
-
- *)
-
Fixpoint init_params (vl : list value) (rl : list reg) {struct rl} :=
match rl, vl with
| r :: rl', v :: vl' => AssocMap.set r v (init_params vl' rl')
@@ -886,7 +727,8 @@ Lemma semantics_determinate :
Proof.
intros. constructor; set (ge := Globalenvs.Genv.globalenv p); simplify.
- invert H; invert H0; constructor. (* Traces are always empty *)
- - invert H; invert H0; crush. assert (f = f0) by (destruct f; destruct f0; auto); subst.
+ - invert H; invert H0; crush.
+ assert (f = f0) by (destruct f; destruct f0; auto); subst.
pose proof (mis_stepp_determinate H5 H15).
crush.
- constructor. invert H; crush.
diff --git a/src/hls/Veriloggen.v b/src/hls/Veriloggen.v
index 80c0669..6ea00e0 100644
--- a/src/hls/Veriloggen.v
+++ b/src/hls/Veriloggen.v
@@ -61,6 +61,7 @@ Definition transl_module (m : HTL.module) : Verilog.module :=
m.(HTL.mod_stk)
m.(HTL.mod_stk_len)
m.(HTL.mod_params)
+ m.(HTL.mod_funct_units)
body
m.(HTL.mod_entrypoint).