Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Add Fifo spec and proof (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaxill authored Sep 6, 2021
1 parent 81e3d5f commit f51c81a
Show file tree
Hide file tree
Showing 3 changed files with 417 additions and 4 deletions.
17 changes: 17 additions & 0 deletions cava/Cava/Util/List.v
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ Section Misc.
rewrite app_comm_cons, !removelast_last. reflexivity.
Qed.

Lemma removelast_cons {A} (x0 x1:A) xs : removelast (x0 :: x1 :: xs) = x0 :: removelast (x1 :: xs).
Proof. reflexivity. Qed.

Lemma removelast_cons1 {A} (x:A) xs : xs <> [] -> removelast (x :: xs) = x :: removelast xs.
Proof. destruct xs; [contradiction|]. intros; apply removelast_cons. Qed.

Lemma length_removelast_cons {A} xs (x:A) : length (removelast (x :: xs)) = length xs.
Proof.
revert x.
induction xs; [reflexivity|].

intros x.
rewrite removelast_cons.
cbn [length].
now rewrite (IHxs _).
Qed.

Lemma list_unit_equiv (l : list unit) : l = repeat tt (length l).
Proof.
induction l; [ reflexivity | ].
Expand Down
7 changes: 3 additions & 4 deletions cava2/Fifo.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Require Import Coq.Strings.String.
Require Import Coq.Strings.HexString.
Require Import Coq.Lists.List.
Require Import Coq.NArith.NArith.
Require Import Coq.Arith.PeanoNat.
Require Import Cava.Util.List.

Require Import Cava.Types.
Expand All @@ -38,7 +39,7 @@ Section Var.
Definition fifo {T} fifo_size: Circuit _ [Bit; T; Bit]
(* out_valid, out, full *)
(Bit ** T ** Bit ** Bit) :=
let fifo_bits := BitVec (Nat.log2 (fifo_size) + 1) in
let fifo_bits := BitVec (Nat.log2_up (fifo_size + 1)) in
{{
fun data_valid data accepted_output =>

Expand All @@ -57,7 +58,7 @@ Section Var.
initially (false,(default,(@default (Vec T fifo_size), 0)))
: denote_type (Bit ** T ** Vec T fifo_size ** fifo_bits) in

( valid, output
( valid, if valid then output else `Constant T default`
(* Will be empty if accepted_output is asserted next cycle *)
, (count == `Constant fifo_bits 0` )
(* We are full, does not assume output this cycle has been accepted yet *)
Expand Down Expand Up @@ -160,6 +161,4 @@ Section Var.
(out_valid, out_data, out_length, is_last, fifo_full)
}}.


End Var.

Loading

0 comments on commit f51c81a

Please sign in to comment.