Q293FreeSystemVerilog
Select round-robin winners with rotate and isolate
Interview prompt
Question
Optimize round-robin winner selection with vector operations rather than a procedural N-entry scan while preserving the predictor's priority semantics.
Starting point
Question code
function int predict_next(bit [N-1:0] reqs);Reviewed example
Trace one case
Input
N=4,next_priority=2; request vector has ports {0,3} activeExpected output
rotated isolate selects original port3; next_priority becomes0Rotating port2 to bit zero makes port3 the lowest active offset; one-hot isolation maps it back without a procedural scan.
What to cover
Requirements
- Rotate the current next-priority position to bit zero.
- Isolate the lowest set bit of the rotated request vector.
- Encode that one-hot offset and map it back to the original port domain.
- Return -1 before performing one-hot decode when no request is active.
- Keep state update behavior identical to the strict round-robin predictor.

