Skip to content

When a hazard happens, decide which register(s) it hits

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

A read-after-write hazard: an instruction reads a register the instruction before it writes. gen_hazard decides whether this instruction hazards at all. Given that it does, the hazard lands on src_reg_0, src_reg_1 or both, and real pipelines don’t split that evenly.

A sequence constructs a fresh instr_item per instruction, so “what the previous instruction wrote” can’t live in an ordinary member that new() resets. It has to be shared by every instance.

Fix the class below.

RequirementsAmong instructions with gen_hazard set and a previous instruction

  1. About 20% hazard on src_reg_0 only, 50% on src_reg_1 only, 30% on both; never neither.
  2. A source register that isn’t hazarding doesn’t happen to match the previous dst_reg.

Source on GitHub

risc_v_hazard_which_register.sv