-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrisc.v
139 lines (118 loc) · 4.89 KB
/
risc.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(******************************************************************************)
(* PipeCheck: Specifying and Verifying Microarchitectural *)
(* Enforcement of Memory Consistency Models *)
(* *)
(* Copyright (c) 2014 Daniel Lustig, Princeton University *)
(* All rights reserved. *)
(* *)
(* This library is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Lesser General Public *)
(* License as published by the Free Software Foundation; either *)
(* version 2.1 of the License, or (at your option) any later version. *)
(* *)
(* This library is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Lesser General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Lesser General Public *)
(* License along with this library; if not, write to the Free Software *)
(* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *)
(* USA *)
(******************************************************************************)
Require Import Ensembles.
Require Import Arith.
Require Import Bool.
Require Import List.
Import ListNotations.
Require Import wmm.
Require Import util2.
Require Import dot.
Require Import topsort.
Require Import stages.
(** * Traditional Five-Stage RISC Pipeline *)
(** ** Local Reorderings at different stages *)
(** [FIFO]: any ordering guaranteed at the input is also guaranteed at the
output. This is the common case. *)
Definition FIFO : LocalReordering :=
fun _ ordering => ordering.
(** [NoOrderGuarantees]: Operations can leave the stage in any order; nothing
is guaranteed. *)
Definition NoOrderGuarantees : LocalReordering :=
fun _ _ => [].
(** ** Special Edge Maps *)
(** In most cases, we don't need to add any special edges *)
Definition NoSpecialEdges : SpecialEdgeMap :=
fun _ _ _ => [].
(** The store buffer only allows one outstanding unacknowledged store at a
time. *)
Fixpoint StoreBufferSpecialEdges
(c n : nat)
(e_before : list Event)
(e : Event)
(e_after : list Event)
: GlobalGraph :=
match e_after with
| h::t =>
match dirn h with
| R => StoreBufferSpecialEdges c n e_before e t
| W => [((6 * n, eiid e), (5 + 6 * c, eiid h), "StoreBuffer")]
end
| _ => []
end.
(** * Pipeline Definition *)
(** ** Pipeline Stages *)
(** Each pipeline stage is defined by a name, a number, a [LocalReordering],
and a function adding any special edges (in this case, only at the store
buffer). *)
Definition RISC_PipelineStages n c := [
mkStage "Fetch" FIFO NoSpecialEdges;
mkStage "Decode" FIFO NoSpecialEdges;
mkStage "Execute" FIFO NoSpecialEdges;
mkStage "Memory" FIFO NoSpecialEdges;
mkStage "Writeback" FIFO NoSpecialEdges;
mkStage "StoreBuffer" FIFO (StoreBufferSpecialEdges c n)
].
Definition RISC_SharedStages := [
mkStage "MainMemory" NoOrderGuarantees NoSpecialEdges;
mkStage "Retire" FIFO NoSpecialEdges
].
Fixpoint RISC_AllStages (n : nat) :=
fold_left (app (A:=_)) (map (RISC_PipelineStages n) [0 ... n-1]) []
++ RISC_SharedStages.
Definition StagesOfCore
(c : nat)
(l : list nat)
: list nat :=
map (fun x => x + 6 * c) l.
(** ** Pipeline Paths *)
Definition RISC_PathOptions
(n : nat)
(e : Event)
: PathOptions :=
let c := proc (iiid e) in
match dirn e with
| R => [
mkPathOption (String.append "Read" (stringOfNat (loc e))) e
(StagesOfCore c [0 ... 4])
[mkPerformStages (3 + 6 * c) [0 ... n-1] [0 ... n-1] None true]
NoSpecialEdges;
mkPathOption (String.append "STBFwd" (stringOfNat (loc e))) e
(StagesOfCore c [0 ... 4])
[mkPerformStages (3 + 6 * c) [0 ... n-1] [c] None false]
NoSpecialEdges
]
| W => [
mkPathOption (String.append "Write" (stringOfNat (loc e))) e
(StagesOfCore c [0 ... 5] ++ StagesOfCore n [0; 1])
[mkPerformStages (3 + 6 * c) [c] [c] None false;
mkPerformStages (6 * n) [0 ... n-1] [0 ... n-1] None true]
NoSpecialEdges
]
end.
(** ** Pipeline Definition *)
Definition RISC_Pipeline (n : nat) :=
mkPipeline
"RISC"
(RISC_AllStages n)
(RISC_PathOptions n).