DescriptionQ290
Q290ArchFollow-up to Q212ASIC interview problem
Implement best-fit allocation
TechniquesAllocatorBest fitSelection policy
DifficultyMedium
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Replace first-fit with best-fit: choose the smallest free range that can satisfy the request. Explain the one-line comparison change for worst-fit.

Function headerSystemVerilog
function bit alloc_best_fit(
int unsigned size,
output int unsigned addr
);Example input and output
Use this case to check your interpretationInput
free capacities=[64,24,40]; request size=20Output
select the 24-byte range; leave a 4-byte remainderExplanation
All ranges are sufficient, but 24 is the smallest capacity and therefore the best fit.
02
Requirements (4)
- Inspect all sufficient ranges.
- Select the minimum sufficient capacity.
- Preserve exact-fit and partial-fit behavior.
- Avoid signed sentinels for unsigned capacities.
