Skip to content

Commit

Permalink
Fix retirement + counter layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
piotro888 committed Nov 24, 2023
1 parent 41d651d commit 45f534a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions coreblocks/params/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,8 @@ def __init__(self, gen_params: GenParams):
]

self.report = self.get


class CoreInstructionCounterLayouts:
def __init__(self, gen_params: GenParams):
self.decrement = [("empty", 1)]
9 changes: 7 additions & 2 deletions coreblocks/stages/retirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def elaborate(self, platform):

fields = self.gen_params.get(CommonLayoutFields)
m.submodules.frat_fix = frat_fix = Forwarder([fields.rl_dst, fields.rp_dst])
m.submodules.fetch_continue_fwd = fetch_continue_fwd = Forwarder([fields.pc])

with Transaction().body(m):
# TODO: do we prefer single precommit call per instruction?
Expand Down Expand Up @@ -108,13 +109,17 @@ def elaborate(self, platform):
# Resume core operation from exception handler

# mtvec without mode is [mxlen-1:2], mode is two last bits. Only direct mode is supported
resume_pc = m_csr.mtvec.value & ~(0b11)
self.fetch_continue(m, {"from_pc": 0, "next_pc": resume_pc}) # TODO: add from_pc valid
resume_pc = m_csr.mtvec.read(m) & ~(0b11)
fetch_continue_fwd.write(m, pc=resume_pc)

m.d.sync += side_fx.eq(1)

with Transaction().body(m):
data = frat_fix.read(m)
self.rename(m, rl_s1=0, rl_s2=0, rl_dst=data["rl_dst"], rp_dst=data["rp_dst"])

with Transaction().body(m):
pc = fetch_continue_fwd.read(m).pc
self.fetch_continue(m, from_pc=0, next_pc=pc, resume_from_exception=1)

return m
9 changes: 7 additions & 2 deletions coreblocks/structs_common/instr_counter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from amaranth import *
from coreblocks.params.genparams import GenParams
from coreblocks.params.layouts import FetchLayouts
from coreblocks.params.layouts import CoreInstructionCounterLayouts, FetchLayouts
from transactron.core import Method, TModule, def_method


class CoreInstructionCounter(Elaboratable):
"""
Counts instructions currently processed in core.
Used in exception handling, to wait for core flush to finsh.
"""

def __init__(self, gp: GenParams):
self.increment = Method(i=gp.get(FetchLayouts).raw_instr)
self.decrement = Method(o=[("empty", 1)])
self.decrement = Method(o=gp.get(CoreInstructionCounterLayouts).decrement)

self.count = Signal(gp.rob_entries_bits + 1)

Expand Down
17 changes: 16 additions & 1 deletion test/stages/test_retirement.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from coreblocks.params.layouts import ExceptionRegisterLayouts
from coreblocks.params.layouts import CoreInstructionCounterLayouts, ExceptionRegisterLayouts, FetchLayouts
from coreblocks.stages.retirement import *
from coreblocks.structs_common.csr_generic import GenericCSRRegisters

Expand All @@ -24,6 +24,8 @@ def elaborate(self, platform):
lsu_layouts = self.gen_params.get(LSULayouts)
scheduler_layouts = self.gen_params.get(SchedulerLayouts)
exception_layouts = self.gen_params.get(ExceptionRegisterLayouts)
fetch_layouts = self.gen_params.get(FetchLayouts)
core_instr_counter_layouts = self.gen_params.get(CoreInstructionCounterLayouts)

m.submodules.r_rat = self.rat = RRAT(gen_params=self.gen_params)
m.submodules.f_rat = self.frat = FRAT(gen_params=self.gen_params)
Expand All @@ -43,6 +45,14 @@ def elaborate(self, platform):
m.submodules.generic_csr = self.generic_csr = GenericCSRRegisters(self.gen_params)
self.gen_params.get(DependencyManager).add_dependency(GenericCSRRegistersKey(), self.generic_csr)

m.submodules.mock_fetch_stall = self.mock_fetch_stall = TestbenchIO(Adapter())
m.submodules.mock_fetch_continue = self.mock_fetch_continue = TestbenchIO(
Adapter(i=fetch_layouts.branch_verify)
)
m.submodules.mock_instr_decrement = self.mock_instr_decrement = TestbenchIO(
Adapter(o=core_instr_counter_layouts.decrement)
)

m.submodules.retirement = self.retirement = Retirement(
self.gen_params,
rob_retire=self.mock_rob_retire.adapter.iface,
Expand All @@ -53,6 +63,9 @@ def elaborate(self, platform):
precommit=self.mock_precommit.adapter.iface,
exception_cause_get=self.mock_exception_cause.adapter.iface,
frat_rename=self.frat.rename,
fetch_stall=self.mock_fetch_stall.adapter.iface,
fetch_continue=self.mock_fetch_continue.adapter.iface,
instr_decrement=self.mock_instr_decrement.adapter.iface,
)

m.submodules.free_rf_fifo_adapter = self.free_rf_adapter = TestbenchIO(AdapterTrans(self.free_rf.read))
Expand Down Expand Up @@ -93,6 +106,8 @@ def setUp(self):
def test_rand(self):
retc = RetirementTestCircuit(self.gen_params)

yield from retc.mock_fetch_stall.enable()

@def_method_mock(lambda: retc.mock_rob_retire, enable=lambda: bool(self.submit_q), sched_prio=1)
def retire_process():
return self.submit_q.popleft()
Expand Down

0 comments on commit 45f534a

Please sign in to comment.