Skip to content

Three forwarding paths deep, not one

write-from-scratch / statistical / cross-call-state / multi-constraint / tool-limitation

risc_v_hazard_which_register looked one instruction back: the EX forward. A real pipeline also forwards from MEM (2 back) and WB (3 back). Here a hazard targets one of those three slots, weighted EX 40%, MEM 40%, WB 20%.

The history of recent dst_regs is shared across instances again, now as a static 3-deep window that post_randomize() shifts on every call.

Two points of the spec need care:

  • x0 is hardwired to zero in RISC-V, so a slot holding x0 isn’t a real hazard target. Rule such slots out of the choice in the constraint, not by skipping them afterward.
  • If two slots hold the same nonzero value, hitting one also matches the other. That’s the same register twice in the window, not a leak.

dist{} directly on an enum-typed rand variable doesn’t reproduce its weights reliably on this toolchain (README, “Real, current tool limitations”). Weight a plain rand field and map it onto the enum with an equality constraint.

Fix the class below.

Requirements

  1. history is a static 3-deep window: history[0] is EX (1 back), history[1] MEM (2 back), history[2] WB (3 back). post_randomize() shifts it and puts the new dst_reg in history[0].
  2. With gen_hazard set, the target is EX 40%, MEM 40%, WB 20%, except that a slot holding x0 (5’d0) is never targeted; its share drops out rather than being redistributed.
  3. With a target, at least one of src_reg_0/src_reg_1 equals that slot’s value, and neither matches a slot holding a different value.
  4. With gen_hazard clear, neither source register matches any nonzero slot.

Source on GitHub

risc_v_forwarding_window.sv