b9a197ac3cca9b248dd6464d50a65e24bd9b9c34
1 """ Mitch Alsup 6600-style LD/ST Memory Scoreboard Matrix (sparse vector)
3 6600 LD/ST Dependency Table Matrix inputs / outputs
4 ---------------------------------------------------
7 * http://bugs.libre-riscv.org/show_bug.cgi?id=81
11 from nmigen
.compat
.sim
import run_simulation
12 from nmigen
.cli
import verilog
, rtlil
13 from nmigen
import Module
, Signal
, Elaboratable
, Array
, Cat
, Const
15 from ldst_dep_cell
import LDSTDepCell
18 class LDSTDepMatrix(Elaboratable
):
19 """ implements 11.4.12 mitch alsup LD/ST Dependency Matrix, p46
20 actually a sparse matrix along the diagonal.
22 load-hold-store and store-hold-load accumulate in a priority-picking
23 fashion, ORing together. the OR gate from the dependency cell is
26 def __init__(self
, n_ldst
):
27 self
.n_ldst
= n_ldst
# X and Y (FUs)
28 self
.load_i
= Signal(n_ldst
, reset_less
=True) # load pending in
29 self
.stor_i
= Signal(n_ldst
, reset_less
=True) # store pending in
30 self
.issue_i
= Signal(n_ldst
, reset_less
=True) # Issue in
32 self
.load_hit_i
= Signal(n_ldst
, reset_less
=True) # load hit in
33 self
.stwd_hit_i
= Signal(n_ldst
, reset_less
=True) # store w/data hit in
36 self
.ld_hold_st_o
= Signal(n_ldst
, reset_less
=True) # load holds st out
37 self
.st_hold_ld_o
= Signal(n_ldst
, reset_less
=True) # st holds load out
39 def elaborate(self
, platform
):
43 # matrix of dependency cells
45 dm
= Array(LDSTDepCell() for f
in range(self
.n_ldst
))
46 for fu
in range(self
.n_ldst
):
47 setattr(m
.submodules
, "dm_fu%d" % (fu
), dm
[fu
])
50 # connect Function Unit vector
52 lhs
= Const(0) # start at const 0
53 shl
= Const(0) # (does no harm)
61 for fu
in range(self
.n_ldst
):
63 # connect up the load/hold/store cell in/out (starts as a const)
64 m
.d
.comb
+= [dc
.ld_hold_st_i
.eq(lhs
),
65 dc
.st_hold_ld_i
.eq(shl
)
69 # accumulate load-hold-store / store-hold-load bits
72 # accumulate inputs (for Cat'ing later) - TODO: must be a better way
73 load_l
.append(dc
.load_i
)
74 stor_l
.append(dc
.stor_i
)
75 issue_l
.append(dc
.issue_i
)
76 lh_l
.append(dc
.load_hit_i
)
77 sh_l
.append(dc
.stwd_hit_i
)
79 # connect cell inputs using Cat(*list_of_stuff)
80 m
.d
.comb
+= [Cat(*load_l
).eq(self
.load_i
),
81 Cat(*stor_l
).eq(self
.stor_i
),
82 Cat(*issue_l
).eq(self
.issue_i
),
83 Cat(*lh_l
).eq(self
.load_hit_i
),
84 Cat(*sh_l
).eq(self
.stwd_hit_i
),
86 # set the load-hold-store / store-hold-load OR-accumulated outputs
87 m
.d
.comb
+= self
.ld_hold_st_o
.eq(Cat(*lhs_l
))
88 m
.d
.comb
+= self
.st_hold_ld_o
.eq(Cat(*shl_l
))
98 yield self
.ld_hold_st_o
99 yield self
.st_hold_ld_o
104 def d_matrix_sim(dut
):
107 yield dut
.dest_i
.eq(1)
108 yield dut
.issue_i
.eq(1)
110 yield dut
.issue_i
.eq(0)
112 yield dut
.src1_i
.eq(1)
113 yield dut
.issue_i
.eq(1)
115 yield dut
.issue_i
.eq(0)
117 yield dut
.go_read_i
.eq(1)
119 yield dut
.go_read_i
.eq(0)
121 yield dut
.go_write_i
.eq(1)
123 yield dut
.go_write_i
.eq(0)
127 dut
= LDSTDepMatrix(n_ldst
=4)
128 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
129 with
open("test_ld_st_matrix.il", "w") as f
:
132 run_simulation(dut
, d_matrix_sim(dut
), vcd_name
='test_ld_st_matrix.vcd')
134 if __name__
== '__main__':