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_validis 1 while at least one tag is free.alloc_idshows 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_idonly matters whilealloc_validis 1.- An allocation happens on a rising edge where
alloc_req= 1 andalloc_valid= 1: the tag inalloc_idbecomes busy. With no free tag,alloc_reqdoes nothing. - A free happens on a rising edge where
free_req= 1: tagfree_idbecomes 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_cntis the number of free tags, 0 to 8, again straight from the stored state.rst_nis 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.