Difficulty: Easy · Puzzle 1 of 6 · Topic: Analysis, Scoreboards and RAL
UVM 1.2. A scoreboard waits for the next clock edge inside the analysis imp's write() to line up the compare. What happens when it is compiled, and what are two correct structures?
class my_sb extends uvm_scoreboard;
`uvm_component_utils(my_sb)
uvm_analysis_imp #(bus_item, my_sb) imp;
virtual bus_if vif;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
function void write(bus_item t);
@(posedge vif.clk);
compare(t);
endfunction
endclassWhich kind of subroutine is write(), and which constructs may it contain?
1) write() is a function (analysis ports broadcast with a non-blocking function call), so it can not contain `@`, `#` or `wait`: the compiler rejects it.
2) Making it a task does not help: the imp requires a function with the matching prototype.
3) Fix A: write() only stores the item (`fifo.write(t)` into a `uvm_tlm_analysis_fifo`, or push into a queue); a run_phase task does `fifo.get(t); @(posedge vif.clk); compare(t);`.
4) Fix B: keep write() as a pure function that does the compare immediately in zero time, when the compare does not need a clock.Answer: Compile error: timing control in a function. Store in write() and compare in a run_phase task (tlm analysis FIFO), or compare in zero time.
Not run here: The UVM library is not installed here, so this cannot be executed; the claim is a language rule plus the uvm_analysis_imp interface; nothing to emulate without the library.. The answer follows the language rules and the solution steps above.
Changing write to a task is the tempting fix and does not work: the imp calls a function write(), and the declaration no longer matches the imp's interface.
Why is write() deliberately a function? Model answer: one monitor write() fans out to every subscriber in the same time step; if any subscriber could block, it would stall the monitor and every subscriber after it, so analysis is broadcast-only and non-blocking, with buffering (a FIFO) where a subscriber needs time.