RTL Design #65 · 2026-11-27 · Reorder buffer with in-order commit · Medium · about 35 min

A four-entry reorder buffer

Write rob in rob.sv: a small reorder buffer with four entries. Instructions are allocated in program order, may complete in any order, and are committed strictly in the order they were allocated.

The entries form a circular buffer of four slots, tagged 0 to 3. Behaviour on each rising edge:

  1. Allocate. If alloc is 1 and the buffer is not full, the next slot is taken as the youngest entry, and it starts out not done. alloc_tag always shows the tag the next allocation will get. An alloc while full is ignored. A slot that is being re-used must not remember it was done in an earlier life.
  2. Complete. If cpl_v is 1, the entry cpl_tag is marked done and remembers cpl_val. (Only tags of live, not-yet-done entries are ever completed.)
  3. Commit. commit_v is a combinational output: it is 1 when the buffer is not empty, the oldest entry is done, and flush is 0. commit_val shows that oldest entry's value. When commit_v is 1 the oldest entry leaves at this edge. At most one entry commits per clock. An entry that completes at an edge can commit from the next cycle at the earliest.
  4. Flush. If flush is 1 at an edge, every entry is discarded: the buffer becomes empty and alloc_tag goes back to 0. alloc and cpl_v at that edge are ignored, and nothing commits.

full is 1 when four entries are live and empty when none are; both depend only on stored state, not on alloc. rst_n is a synchronous active-low reset that empties the buffer like a flush.

Example, after reset: allocate twice (tags 0 and 1), complete tag 1 with 0xB1, then complete tag 0 with 0xA0. The outputs after each edge:

after edge what happened at the edge alloc_tag commit_v commit_val
1 alloc 1 0
2 alloc 2 0
3 complete tag 1 2 0 (the oldest, tag 0, is not done)
4 complete tag 0 2 1 0xA0
5 tag 0 committed 2 1 0xB1
6 tag 1 committed 2 0

Fill in rob.sv. Run performs this example.

Write and run your answer in the browser. The hidden tests check it, and it’s free.