RTL Design #67 · 2026-11-29 · Store-to-load forwarding · Medium · about 30 min
Store buffer with load forwarding
store_buf is a 4-entry store buffer in front of a memory. The CPU pushes stores into it, the memory side drains them oldest first, and a load looks into it first so it can pick up the newest value that has not reached memory yet (store-to-load forwarding).
Requirements:
- Push. On a rising edge where
st_validis 1 andfullis 0,st_addrandst_dataare stored as the youngest entry. Iffullis 1 the store is ignored (the buffer never overwrites).fullis 1 whenever all 4 entries are in use. - Drain. While the buffer holds anything,
drain_validis 1 anddrain_addr/drain_datashow the oldest entry. On a rising edge wheredrain_ackis 1 anddrain_validis 1, that entry is removed. A push and a drain can happen on the same edge. - Forward.
ld_addris a load address.fwd_hitis 1 when at least one entry in the buffer has that address, andfwd_datais the data of the youngest such entry. With no match,fwd_hitandfwd_dataare 0. Both are combinational on the current contents (a store pushed on this very edge is not visible until after it). - Reset.
rst_nis a synchronous, active-low reset that empties the buffer.
Example (addresses and data in hex), looking at ld_addr = 10 after each edge:
| after edge | action on that edge | fwd_hit, fwd_data |
drain_addr, drain_data |
|---|---|---|---|
| 1 | push (10, AA) | 1, AA | 10, AA |
| 2 | push (20, BB) | 1, AA | 10, AA |
| 3 | push (10, CC) | 1, CC | 10, AA |
| 4 | drain_ack |
1, CC | 20, BB |
Write and run your answer in the browser. The hidden tests check it, and it’s free.