Skip to content

Commit

Permalink
add StartCycle to free monad, so that we can set nextPc
Browse files Browse the repository at this point in the history
at beginning of cycle and don't need to thread it through
an invariant from the previous cycle
  • Loading branch information
samuelgruetter committed Mar 4, 2022
1 parent 8d9b63f commit eb444af
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/riscv/Platform/MaterializeRiscvProgram.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Section Riscv.
| Fence (_ : MachineInt) (_ : MachineInt)
| GetPC
| SetPC (_ : word)
| StartCycle
| EndCycleNormal
| EndCycleEarly (_ : Type)
.
Expand All @@ -53,6 +54,7 @@ Section Riscv.
| Fence _ _ => unit
| GetPC => word
| SetPC _ => unit
| StartCycle => unit
| EndCycleNormal => unit
| EndCycleEarly T => T
end.
Expand Down Expand Up @@ -82,4 +84,9 @@ Section Riscv.
endCycleEarly A := act (EndCycleEarly A) ret;
|}.

(* Not (yet) in Riscv monad, but added here because it's useful to initialize
nextPc to pc+4 at the beginning of each cycle instead of having to maintain
a nextPc=pc+4 invariant everywhere *)
Definition startCycle: FreeMonad.free riscv_primitive primitive_result unit :=
FreeMonad.free.act StartCycle FreeMonad.free.ret.
End Riscv.
1 change: 1 addition & 0 deletions src/riscv/Platform/MetricMinimalNoMul.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Section Riscv.
| Fence a b => id
| GetPC => id
| SetPC a => addMetricJumps 1
| StartCycle => id
| EndCycleNormal => addMetricInstructions 1
| EndCycleEarly A => addMetricInstructions 1
end.
Expand Down
2 changes: 2 additions & 0 deletions src/riscv/Platform/MinimalCSRs.v
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Section Riscv.
| StoreHalf ctxid a v => fun postF postA => store 2 ctxid a v mach (postF tt)
| StoreWord ctxid a v => fun postF postA => store 4 ctxid a v mach (postF tt)
| StoreDouble ctxid a v => fun postF postA => store 8 ctxid a v mach (postF tt)
| StartCycle => fun postF postA =>
postF tt { mach with nextPc := word.add mach.(pc) (word.of_Z 4) }
| EndCycleNormal => fun postF postA => postF tt (updatePc mach)
| EndCycleEarly _ => fun postF postA => postA (updatePc mach) (* ignores postF containing the continuation *)
| GetCSRField f => fun postF postA =>
Expand Down
2 changes: 2 additions & 0 deletions src/riscv/Platform/MinimalMMIO.v
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Section Riscv.
| StoreHalf ctxid a v => fun postF postA => store 2 ctxid a v mach (postF tt)
| StoreWord ctxid a v => fun postF postA => store 4 ctxid a v mach (postF tt)
| StoreDouble ctxid a v => fun postF postA => store 8 ctxid a v mach (postF tt)
| StartCycle => fun postF postA =>
postF tt (withNextPc (word.add mach.(getPc) (word.of_Z 4)) mach)
| EndCycleNormal => fun postF postA => postF tt (updatePc mach)
| EndCycleEarly _ => fun postF postA => postA (updatePc mach) (* ignores postF containing the continuation *)
| MakeReservation _
Expand Down
2 changes: 2 additions & 0 deletions src/riscv/Platform/MinimalNoMul.v
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Section Riscv.
| StoreHalf ctxid a v => fun postF postA => store 2 ctxid a v mach (postF tt)
| StoreWord ctxid a v => fun postF postA => store 4 ctxid a v mach (postF tt)
| StoreDouble ctxid a v => fun postF postA => store 8 ctxid a v mach (postF tt)
| StartCycle => fun postF postA =>
postF tt (withNextPc (word.add mach.(getPc) (word.of_Z 4)) mach)
| EndCycleNormal => fun postF postA => postF tt (updatePc mach)
| EndCycleEarly _ => fun postF postA => postA (updatePc mach) (* ignores postF containing the continuation *)
| MakeReservation _
Expand Down

0 comments on commit eb444af

Please sign in to comment.