line Register Modules Documentation
General Structure
Each pipeline-stage register module implements:
- A synchronous register bank (built from multiple
registerXinstances). - Independent clock/reset buffering for synthesis across multiple fanouts.
- Write-enable control where needed (IF/ID stage uses
IFID_we; others use constant write-enable). - Clean separation of stage-specific architectural data: operands, opcode, destination register, control flags, and PC.
These modules do not perform computation; their responsibility is to latch values between pipeline stages and maintain precise in-order semantics.
The following sections document each register stage.
1. IFID Stage Register
Purpose
The IFID module forms the boundary between the Instruction Fetch (IF) and Instruction Decode (ID) stages. It captures:
- The fetched instruction (
IFID_instr__in) - The program counter of that instruction (
IFID_pc__in)
Inputs / Outputs
| Signal | Width | Direction | Meaning |
|---|---|---|---|
clk |
1 | in | System clock |
reset |
1 | in | Synchronous reset for pipeline |
IFID_we |
1 | in | Write-enable; used for pipeline stall control |
IFID_instr__in |
16 | in | Instruction word from IF stage |
IFID_pc__in |
16 | in | PC associated with instruction |
IFID_instr__out |
16 | out | Latched instruction delivered to ID stage |
IFID_pc__out |
16 | out | Latched PC delivered to ID stage |
Operation
- If
resetis asserted: outputs clear to zero (NOP equivalent). - If
IFID_we = 1: new instruction and PC propagate into ID. - If
IFID_we = 0: stage holds previous values (stall behavior).
Architectural Role
This module determines whether the pipeline:
- Accepts new instructions from IF,
- Stalls (e.g., load-use interlock),
- Flushes (by injecting a NOP into the inputs in the top module).
Pseudocode Representation
if reset:
instr_out = 0
pc_out = 0
else if IFID_we:
instr_out = instr_in
pc_out = pc_in
else:
hold previous values
2. IDEX Stage Register
Purpose
The IDEX module forms the boundary between the Instruction Decode (ID) and Execute (EX) stages.
It captures decoded-data signals:
- Two register operand values (
op0,op1) - Immediate or extended operand (
op2) - ALU operation code (
op) - Destination register index (
rT) - Control bit
x(pipeline-dependent; usually indicates whether this instruction writes a result or has special semantics) - Program counter (for branch target calculation or JALR)
Inputs / Outputs
| Signal | Width | Direction | Meaning |
|---|---|---|---|
IDEX_op0__in |
16 | in | Operand A |
IDEX_op1__in |
16 | in | Operand B |
IDEX_op2__in |
16 | in | Immediate/extended operand |
IDEX_op__in |
3 | in | Operation code for ALU |
IDEX_rT__in |
3 | in | Destination register |
IDEX_x__in |
1 | in | Control flag |
IDEX_pc__in |
16 | in | PC from IF stage |
Corresponding __out signals |
match widths | out | Latched values to EX stage |
Write enable is permanently 1, meaning the ID→EX stage always advances (ID stalls are handled earlier in the top module).
Operation
- Always latches inputs every cycle unless reset is asserted.
- No stall input; upstream logic must ensure correctness before driving into this module.
Pseudocode
if reset:
op0 = op1 = op2 = 0
op = 0
rT = 0
x = 0
pc = 0
else:
op0 = op0_in
op1 = op1_in
op2 = op2_in
op = op_in
rT = rT_in
x = x_in
pc = pc_in
Architectural Role
- Preserves operand and control information exactly one pipeline stage before ALU execution.
- No hazard resolution occurs here; this stage simply conveys data.
3. EXMEM Stage Register
Purpose
The EXMEM module forms the boundary between the Execute (EX) and Memory (MEM) stages.
It captures:
- ALU result (
EXMEM_ALUout__in) - Store-data operand (
EXMEM_stdata__in) - Operation code (
EXMEM_op__in) - Destination register index
- Control flag
x - PC (for branch or JALR tracking)
Inputs / Outputs Table
| Signal | Width | Direction | Description |
|---|---|---|---|
EXMEM_stdata__in |
16 | in | Value to store to memory |
EXMEM_ALUout__in |
16 | in | Result of ALU computation |
EXMEM_op__in |
3 | in | Operation type |
EXMEM_rT__in |
3 | in | Dest register |
EXMEM_x__in |
1 | in | Control bit |
EXMEM_pc__in |
16 | in | Program counter |
| Output signals mirror the above |
Operation
- Always latches on the rising edge.
- Reset initializes to zero.
- No stall logic here; stall handling is done before entering EX.
Pseudocode
if reset:
ALUout = 0
stdata = 0
op = 0
rT = 0
x = 0
pc = 0
else:
ALUout = ALUout_in
stdata = stdata_in
op = op_in
rT = rT_in
x = x_in
pc = pc_in
Architectural Role
This stage passes:
- Load/store addresses
- Store data
- ALU results
- Register targets
into the memory stage.
Because forwarding uses the EXMEM outputs, this register is a key participant in the forwarding network.
4. MEMWB Stage Register
Purpose
The MEMWB module forms the boundary between Memory (MEM) and Writeback (WB) stages.
It captures:
- The final result to be written to the register file (
MEMWB_rfdata__in) - The destination register index
- Control flag
x - PC value (for JALR writeback)
Inputs / Outputs Table
| Signal | Width | Direction | Meaning |
|---|---|---|---|
MEMWB_rfdata__in |
16 | in | Data returned from MEM (load result or ALU result) |
MEMWB_rT__in |
3 | in | Destination register |
MEMWB_x__in |
1 | in | Control bit |
MEMWB_pc__in |
16 | in | PC forwarded for JALR or tracing |
| Outputs mirror the inputs |
Operation
- Latches new data every cycle.
- Reset clears the stage to zero.
- No stall logic; always advances.
Pseudocode
if reset:
rfdata = 0
rT = 0
x = 0
pc = 0
else:
rfdata = rfdata_in
rT = rT_in
x = x_in
pc = pc_in
Architectural Role
This register forms the final stage before register-file commit. It also supplies critical data to the forwarding network (MEM→EX forwarding).
Pipeline Register Summary Table
| Module | Stage Boundary | Primary Latched Information |
|---|---|---|
| IFID | IF → ID | Instruction word, PC |
| IDEX | ID → EX | Operand values, ALU operation, immediate, rT, control flag, PC |
| EXMEM | EX → MEM | ALU result, store data, rT, op, control flag, PC |
| MEMWB | MEM → WB | Final RF data, rT, control flag, PC |
Functional Role in the Superscalar Pipeline
The combined pipeline-register set ensures:
-
Precise in-order execution semantics Each register stage ensures only one cycle’s worth of architectural data is forwarded at a time.
-
Dual-lane independence These modules are instantiated once per lane, maintaining separation of slot 0 and slot 1 flows.
-
Hazard-interaction points Forwarding network uses IDEX, EXMEM, and MEMWB outputs. Stall logic primarily interacts with IFID through its write-enable.
-
Flush insertion points Squash logic in the top module forces NOPs into IFID or IDEX to flush mispredicted or invalid instructions.