Skip to content

Commit

Permalink
Make the request and the response transactions independent
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Urbanczyk committed Mar 28, 2024
1 parent 30928f6 commit fecfb14
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions coreblocks/cache/refiller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@ def elaborate(self, platform):

m.submodules.resp_fwd = resp_fwd = Forwarder(self.layouts.accept_refill)

request_now = Signal()
request_address = Signal(self.bus_master.params.addr_width)
cache_line_address = Signal(self.params.word_width - self.params.offset_bits)

refill_active = Signal()
flushing = Signal()

def request(address):
m.d.comb += request_now.eq(1)
m.d.comb += request_address.eq(address)
sending_requests = Signal()
req_word_counter = Signal(range(self.params.words_in_line))

with Transaction().body(m, request=request_now):
with Transaction().body(m, request=sending_requests):
self.bus_master.request_read(
m,
addr=request_address,
addr=Cat(req_word_counter, cache_line_address),
sel=C(1).replicate(self.bus_master.params.data_width // self.bus_master.params.granularity),
)

refill_active = Signal()
cache_line_address = Signal(self.params.word_width - self.params.offset_bits)
m.d.sync += req_word_counter.eq(req_word_counter + 1)
with m.If(req_word_counter == (self.params.words_in_line - 1)):
m.d.sync += sending_requests.eq(0)

word_counter = Signal(range(self.params.words_in_line))
resp_word_counter = Signal(range(self.params.words_in_line))
block_buffer = Signal(self.params.word_width * (self.params.words_in_fetch_block - 1))

# The transaction reads responses from the bus, builds the fetch block and when
Expand All @@ -56,47 +58,47 @@ def request(address):
m.d.sync += block_buffer.eq(block[self.params.word_width :])

words_in_fetch_block_log = exact_log2(self.params.words_in_fetch_block)
current_fetch_block = word_counter[words_in_fetch_block_log:]
word_in_fetch_block = word_counter[:words_in_fetch_block_log]

last_word = Signal()
m.d.av_comb += last_word.eq((word_counter == self.params.words_in_line - 1) | bus_response.err)

with m.If((word_in_fetch_block == self.params.words_in_fetch_block - 1) | bus_response.err):
fetch_block_addr = Cat(
C(0, exact_log2(self.params.word_width_bytes)),
C(0, words_in_fetch_block_log),
current_fetch_block,
cache_line_address,
)

resp_fwd.write(
m,
addr=fetch_block_addr,
fetch_block=block,
error=bus_response.err,
last=last_word,
)

word_counter_plus_one = Signal.like(word_counter)
m.d.av_comb += word_counter_plus_one.eq(word_counter + 1)

with m.If(last_word):
m.d.sync += refill_active.eq(0)
with m.Else():
request(Cat(word_counter_plus_one, cache_line_address))

m.d.sync += word_counter.eq(word_counter_plus_one)
current_fetch_block = resp_word_counter[words_in_fetch_block_log:]
word_in_fetch_block = resp_word_counter[:words_in_fetch_block_log]

with m.If(~flushing):
with m.If((word_in_fetch_block == self.params.words_in_fetch_block - 1) | bus_response.err):
fetch_block_addr = Cat(
C(0, exact_log2(self.params.word_width_bytes)),
C(0, words_in_fetch_block_log),
current_fetch_block,
cache_line_address,
)

resp_fwd.write(
m,
addr=fetch_block_addr,
fetch_block=block,
error=bus_response.err,
last=(resp_word_counter == self.params.words_in_line - 1) | bus_response.err,
)

with m.If(resp_word_counter == self.params.words_in_line - 1):
m.d.sync += refill_active.eq(0)
with m.Elif(bus_response.err):
m.d.sync += sending_requests.eq(0)
m.d.sync += flushing.eq(1)

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

with m.If(flushing & (resp_word_counter == req_word_counter)):
m.d.sync += refill_active.eq(0)
m.d.sync += flushing.eq(0)

@def_method(m, self.start_refill, ready=~refill_active)
def _(addr) -> None:
line_addr = addr[self.params.offset_bits :]
m.d.sync += cache_line_address.eq(line_addr)
m.d.sync += cache_line_address.eq(addr[self.params.offset_bits :])
m.d.sync += req_word_counter.eq(0)
m.d.sync += sending_requests.eq(1)

m.d.sync += word_counter.eq(0)
m.d.sync += refill_active.eq(1)
m.d.sync += resp_word_counter.eq(0)

request(Cat(C(0, word_counter.shape()), line_addr))
m.d.sync += refill_active.eq(1)

@def_method(m, self.accept_refill)
def _():
Expand Down

0 comments on commit fecfb14

Please sign in to comment.