Q292FreeSystemVerilog
Predict a strict round-robin grant
Interview prompt
Question
Build a stateful predictor for an N-port strict round-robin arbiter. Given a request vector, return the winning port, return -1 when idle, and move priority to the port immediately after each accepted winner.

Starting point
Question code
class RRPredictor #(int N = 8);
function int predict_next(bit [N-1:0] reqs);
function void update_state(int grant_idx);
function void reset();
endclassReviewed example
Trace one case
Input
N=4,next_priority=0; active request ports={1,3}; predict twiceExpected output
grant port1 then port3; next_priority returns to0The strict circular scan begins at the saved pointer and moves priority to the port immediately after each accepted winner.
What to cover
Requirements
- Give port zero first priority after reset.
- Search circularly from the current next-priority port.
- Return one winning index or -1 when no request is active.
- Update state only for a valid grant index.
- Preserve fairness for continuously asserted requesters.

