RTL Design #55 · 2026-11-17 · Free list · Medium · about 25 min

A free list of 8 tags

Write freelist, a pool of 8 tags (0 to 7) that a pipeline hands out and takes back, such as physical register numbers or buffer slots.

  • After reset all 8 tags are free.
  • alloc_valid is 1 while at least one tag is free. alloc_id shows the lowest-numbered free tag. Both are plain functions of the stored state, so they are valid in the same clock, with no waiting. alloc_id only matters while alloc_valid is 1.
  • An allocation happens on a rising edge where alloc_req = 1 and alloc_valid = 1: the tag in alloc_id becomes busy. With no free tag, alloc_req does nothing.
  • A free happens on a rising edge where free_req = 1: tag free_id becomes free. Freeing a tag that is already free changes nothing.
  • An allocation and a free can happen on the same edge. Both are applied, with the free applied last, so a tag that is freed on an edge ends that edge free.
  • free_cnt is the number of free tags, 0 to 8, again straight from the stored state.
  • rst_n is a synchronous, active-low reset that beats everything else.

Example, after reset: alloc_id = 0 and free_cnt = 8. Holding alloc_req = 1 for three edges gives out tags 0, 1 and 2, so alloc_id is then 3 and free_cnt is 5. Pulsing free_req with free_id = 1 for one edge makes alloc_id = 1 again, and free_cnt = 6.

Fill in freelist.sv. Run uses testbench.sv, a short scenario. Submit runs hidden tests.

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