RTL Studio Open IDE

4.5 · RV SYS CLASS

Forwarding unit

Implement the forwarding unit logic to select EX operands from MEM or WB stages, handling priority and x0 exceptions.

Video coming soon. This lesson page stays at the same URL when the lecture publishes.

What you practice

Forwarding unit (4.5). Implement the forwarding unit logic to select EX operands from MEM or WB stages, handling priority and x0 exceptions. It is in Forwarding unit — 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

Today you will implement the forwarding unit logic for the RV32I pipeline. This unit selects operands from the MEM or WB stage instead of the register file. Forwarding prevents pipeline stalls when data dependencies exist between adjacent instructions.

Learning objectives

  • Understand how to detect data hazards between EX, MEM, and WB stages.
  • Implement logic to select the correct source for fwd_a and fwd_b.
  • Handle priority rules where MEM stage forwarding takes precedence over WB stage forwarding.
  • Ensure that register x0 is never forwarded.

Theory

Forwarding bypasses the register file by routing data directly from pipeline registers to the ALU inputs. This technique reduces the number of cycles required for dependent instructions. The forwarding unit must compare destination registers with source registers to identify hazards.

The forwarding unit outputs two 2-bit signals: fwd_a and fwd_b. These signals select the source for each ALU operand.

ValueSource
2'd0Register File
2'd1MEM Stage Result
2'd2WB Stage Result

The logic follows a strict priority order to resolve conflicts. The MEM stage result has higher priority than the WB stage result. This ensures that the most recent data is used. The register x0 is hardcoded to zero and must never be forwarded. If a hazard involves x0, the forwarding unit should default to the register file value.

Practice

  1. Open RtlStudio and select this chapter from the Examples list.
  2. Confirm that student/rtl/ip/riscv/rv32i_forward_unit.sv and student/tb/tb_top.sv appear in the Explore tree.
  3. Open student/rtl/ip/riscv/rv32i_forward_unit.sv in the editor.
  4. Replace the __TODO__ placeholders with the correct logic to select forwarding sources.
  5. Ensure fwd_a and fwd_b default to 2'd0 (register file) at the start of each always_comb block.
  6. Implement the condition for MEM stage forwarding: check mem_we, ensure mem_rd is not x0, and match mem_rd with the source register.
  7. Implement the condition for WB stage forwarding: check wb_we, ensure wb_rd is not x0, and match wb_rd with the source register.
  8. Save the file and run Simulation from the sidebar.

Summary

You implemented the forwarding unit logic to resolve data hazards by selecting operands from the MEM or WB pipeline stages. The design prioritizes MEM stage results over WB stage results to ensure correct timing and data validity. You also ensured that register x0 is never forwarded to prevent incorrect zero propagation.

© 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

  1. Open the system lesson in the IDE. The RV32I core and the mini-SoC fabric simulate together.
  2. Run Verilator and trace the program through MMIO: address, load/store data, and the peripheral response.
  3. Interrupts and DMA belong on the waveform next to the instruction stream, not only in a pass/fail line.
  4. 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 Forwarding unit. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.