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:
- Allocate. If
allocis 1 and the buffer is notfull, the next slot is taken as the youngest entry, and it starts out not done.alloc_tagalways shows the tag the next allocation will get. Anallocwhilefullis ignored. A slot that is being re-used must not remember it was done in an earlier life. - Complete. If
cpl_vis 1, the entrycpl_tagis marked done and rememberscpl_val. (Only tags of live, not-yet-done entries are ever completed.) - Commit.
commit_vis a combinational output: it is 1 when the buffer is notempty, the oldest entry is done, andflushis 0.commit_valshows that oldest entry's value. Whencommit_vis 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. - Flush. If
flushis 1 at an edge, every entry is discarded: the buffer becomes empty andalloc_taggoes back to 0.allocandcpl_vat 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.