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:

  1. Push. On a rising edge where st_valid is 1 and full is 0, st_addr and st_data are stored as the youngest entry. If full is 1 the store is ignored (the buffer never overwrites). full is 1 whenever all 4 entries are in use.
  2. Drain. While the buffer holds anything, drain_valid is 1 and drain_addr / drain_data show the oldest entry. On a rising edge where drain_ack is 1 and drain_valid is 1, that entry is removed. A push and a drain can happen on the same edge.
  3. Forward. ld_addr is a load address. fwd_hit is 1 when at least one entry in the buffer has that address, and fwd_data is the data of the youngest such entry. With no match, fwd_hit and fwd_data are 0. Both are combinational on the current contents (a store pushed on this very edge is not visible until after it).
  4. Reset. rst_n is 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.