What you practice
Load-use stall flush (4.6). Implement load-use stall and branch flush logic in the RV32I hazard unit to control the IF/ID register. It is in Load-use stall & flush — Part 4 · Pipeline of the RISC-V on SoC & System Masterclass.
The core and the mini-SoC simulate as one workspace in the IDE. Follow MMIO, interrupts, and the program on the Verilator waveform, not only a pass line.
What you will learn
This lesson teaches how to detect load-use hazards and flush the pipeline on taken branches. You will implement the logic in the hazard unit to control the IF/ID register. This is critical for maintaining correct program state in a pipelined RISC-V core.
Learning objectives
- Detect RAW hazards between EX stage destination and ID stage source registers.
- Assert stall signals to hold the IF/ID register during a load-use hazard.
- Assert flush signals to inject NOPs when a branch is taken.
- Verify behavior using the provided testbench stimulus.
Theory
A load-use hazard occurs when an instruction in the EX stage loads data into a register, and the next instruction in the ID stage needs that register as a source. Without intervention, the ID stage would read stale data. The hazard unit must detect this condition and assert a stall signal. The stall signal prevents the IF/ID register from updating, effectively inserting a bubble. A taken branch requires a flush signal. The flush signal forces the IF/ID register to a NOP, discarding the mispredicted or subsequent instruction. The hazard unit logic combines these conditions to control the pipeline flow.
Practice
- Open RtlStudio and select this chapter.
- Open
student/rtl/ip/riscv/rv32i_hazard_unit.svin the editor. - Implement the
raw_rs1andraw_rs2logic to detect register conflicts. - Implement the
stalllogic to hold the pipeline on load-use hazards. - Implement the
flushlogic to clear the pipeline on taken branches. - Open
student/tb/tb_top.svto review the testbench stimulus. - Run Simulation from the sidebar.
- Check the Log panel for
INFO:lines andINFO: PASS.
Summary
You implemented the hazard detection logic to identify RAW dependencies between load instructions and subsequent dependent instructions. You added control signals to stall the pipeline when a load-use hazard is detected and to flush the pipeline on taken branches. This ensures data integrity by preventing the execution of instructions that rely on unready data. The provided testbench verified that your design correctly handles these pipeline hazards.
© 2026 RtlStudio. Licensed under CC BY-NC-ND 4.0. Commercial use and modifications by third parties are not permitted.
Run it in the Verilog IDE
- Open the system lesson in the IDE. The RV32I core and the mini-SoC fabric simulate together.
- Run Verilator and trace the program through MMIO: address, load/store data, and the peripheral response.
- Interrupts and DMA belong on the waveform next to the instruction stream, not only in a pass/fail line.
- Edit the integration RTL, resimulate, and run Yosys on the structural block when you want a netlist.
The lesson is done when the simulation matches Load-use stall flush. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.