Processor Datapath and Pipelining

See how a processor actually runs instructions. Build a single-cycle RISC-V datapath from registers, an ALU, memories and multiplexers, design the control signals that steer it, and trace real instructions through it with concrete values. Then pipeline it into five stages, calculate the speedup, and learn how forwarding, stalls, code scheduling and branch prediction keep the pipeline busy despite data and control hazards.

IntermediateLesson 4 of 6 in Computer Organization and Architecture Course

What you will learn

  1. Identify the hardware units a RISC-V processor needs, connect them so that arithmetic, memory and branch instructions each finish in one clock cycle, and trace real instructions through the result.
    • Name the building blocks of a datapath and how they are clocked
      Tell combinational elements from state elements, and describe what the program counter, memories, register file, ALU, immediate generator, adders and multiplexers each do.
    • Connect the datapath for arithmetic, memory and branch instructions
      Work out which units and connections each instruction class uses, and join the separate paths into one datapath with multiplexers where they meet.
    • Trace instructions through the single-cycle datapath
      Follow concrete instructions with real register and memory values through every unit, give the values on the key wires, and state what changes at the clock edge.
  2. Derive the control signals that make the datapath carry out each instruction, using a main control unit driven by the opcode and a small ALU control unit driven by the function fields.
    • Set the main control signals for each instruction
      Explain what each main control signal does, build the control table for R-type, load, store and branch instructions, and use don't-care values correctly.
    • Generate ALU control from ALUOp and the function fields
      Use two-level decoding to turn the 2-bit ALUOp and the instruction's funct7 and funct3 fields into the 4-bit code that selects the ALU operation.
  3. Explain how overlapping instructions raises throughput, describe the five-stage pipelined datapath with its pipeline registers and control, and trace instructions with pipeline diagrams.
    • Explain why pipelining speeds up a processor
      Find the clock period of a single-cycle design from its critical path, then calculate the throughput, latency and speedup of a pipelined version.
    • Describe the five-stage pipelined datapath and its pipeline registers
      Explain what the pipeline registers hold, how control signals travel with each instruction, and why every instruction passes through all five stages.
    • Trace instructions with pipeline diagrams
      Draw and read multiple-cycle pipeline diagrams, find which instruction is in each stage in a given cycle, and count total cycles with and without stalls.
  4. Recognize when instructions in the pipeline conflict, and resolve data hazards with forwarding, stalls and instruction scheduling.
    • Identify hazards and the data dependences that cause them
      Classify hazards as structural, data or control, find the dependences between instructions, and work out which ones cause stalls in a pipeline without forwarding.
    • Forward results to avoid stalls
      Explain forwarding paths and the forwarding unit's conditions, and decide where each ALU operand comes from in a given instruction sequence.
    • Stall for load-use hazards and schedule code to avoid them
      Detect load-use hazards, explain how the pipeline inserts a bubble, and reorder instructions to remove stalls without changing the program's result.
  5. Reduce the cost of branches with early resolution, flushing and static or dynamic branch prediction, and estimate how all hazards together affect pipeline performance.
    • Reduce the cost of branches in the pipeline
      Explain why branches cause control hazards, compare stalling, predicting not taken and resolving branches earlier, and treat exceptions as a related change in control flow.
    • Predict branches dynamically with history
      Trace 1-bit and 2-bit branch predictors, explain the branch history table and branch target buffer, and recognize where simple predictors fail.
    • Estimate pipeline performance with hazards
      Combine load-use stalls and branch penalties into an effective CPI, compute execution times, and compare branch-handling strategies and processor designs.

Processor Datapath and Pipelining study guide

5 chapters

1

Build a single-cycle datapath

A processor turns instruction bits into changes in registers, memory, and the next instruction address. Follow the parts that perform this work, then connect them into paths for arithmetic, loads, stores, and branches. Concrete traces show the values on the wires and the changes saved at each clock edge. The design uses RV64 registers and a small set of 4-byte RISC-V instructions, so each connection has a clear purpose.

1.1 Identify the hardware and the clock boundary

A datapath holds and transforms the values an instruction needs. The control unit steers those values and enables writes. Together they carry out instructions such as add, sub, and, or, ld, sd, and beq.

Follow values between clock edges

A state element remembers a value: the program counter, register file, and data memory are examples. A combinational element produces an output from its current inputs. Adders, multiplexers, the ALU, and the immediate generator do this work without storing an instruction's result between cycles.

At the active clock edge, state elements capture their next values. Between edges, their outputs feed combinational logic. The PC can therefore supply the current address throughout a cycle and capture the next address at its end. Reading a state element does not itself overwrite it.

Fetch and register access

The program counter (PC) holds the instruction address. Instruction memory returns the 32-bit instruction at that address. In this model it is read-only while the program runs and acts as an address-to-instruction lookup. A separate adder forms PC + 4 because the instructions in this subset occupy 4 bytes.

The register file contains x0–x31. Two read ports take the source numbers rs1 and rs2 and return their values. One write port takes destination rd, write data, and RegWrite. Reads are combinational; an enabled write is saved at the clock edge. Register x0 always reads as zero and discards writes. RV64 registers hold 64 bits. An RV32 version uses 32-bit registers and lw/sw, with the same basic connections.

Compute, select, and access memory

The arithmetic logic unit (ALU) adds, subtracts, or performs a bitwise operation. A 4-bit control code selects the operation. Its Zero output is 1 when the result is zero; subtraction can therefore test whether two values are equal.

The immediate generator, ImmGen, rebuilds an instruction's immediate and sign-extends it to 64 bits. Copying the sign bit preserves a negative value. The 12-bit pattern 1111 1111 1000 represents −8; zero extension would turn it into 4088 and send a memory operation to the wrong address.

A multiplexer, or mux, selects one input. Muxes choose the ALU's second operand, register write data, and next PC. A mux changes the route; a write enable decides whether a stored value changes.

Data memory has address and write-data inputs, a read-data output, and MemRead and MemWrite controls. A load needs instruction fetch and data access during the same single cycle. Separate instruction and data memories provide both accesses. Separate adders also let PC + 4 and the branch target be computed while the ALU does other work.

Unused outputs can still change during a cycle. Correct control means that only the selected outputs reach enabled state writes. A computed value on an unselected wire has no effect on the program.

Key Takeaways

  • The datapath processes values; control signals select routes and enable writes.
  • State elements retain values across clock edges; combinational elements transform current inputs.
  • The register file has two read ports and one write port, and x0 always reads as zero.
  • Sign extension preserves the signed value of an immediate.
  • Separate memories and adders support work needed simultaneously in a single cycle.

1.2 Connect the paths for each instruction class

Start with what each instruction must read and what it must change. The shared datapath combines these routes, with a multiplexer wherever alternative values meet one input.

Fetch and decode the fields

Fetch uses the PC to read instruction memory and computes PC + 4 in parallel. The opcode occupies bits 6–0. Where present, rd is in bits 11–7, funct3 in 14–12, rs1 in 19–15, and rs2 in 24–20; R-type funct7 occupies bits 31–25. Stable source-field positions allow register reads to begin while instruction control is being decoded. A store or branch has no rd field: bits 11–7 contribute to its immediate.

Compare the execution paths
InstructionALU inputs and actionData memorySaved result
add x5, x6, x7x6 + x7No accessSum to x5
ld x5, 16(x6)x6 + 16Read at effective addressMemory data to x5
sd x5, 24(x6)x6 + 24Write x5 at effective addressMemory changes
beq x8, x9, offsetx8 − x9No accessSelect next PC

For a load, the ALU result is an effective address, the address of the data to read. The memory output then returns to the register file. A store also forms an address with the ALU, but its second source value travels separately to the memory's write-data input. Selecting an immediate as the ALU operand must not discard that store value. ImmGen rebuilds the S-format offset from its two groups of bits.

A branch performs two operations in parallel. The ALU subtracts the compared register values; Zero tells whether they match. The branch adder adds the signed byte offset to the branch's own PC. The B-format encoding leaves out the always-zero low bit. ImmGen can reconstruct the complete byte offset, including that zero; a drawing that instead generates the offset in halfword units needs a left shift by one. The shift belongs in the path exactly once.

Merge the paths with muxes

ALUSrc selects either rs2's value or the immediate for the second ALU input. MemtoReg selects either the ALU result or the data-memory output for register write-back. PCSrc selects PC + 4 or the branch target. Two competing results need a selector, not a direct wire joining their outputs.

These paths explain why the load has the longest chain: fetch, register read, address calculation, memory read, and register write all contribute. Arithmetic bypasses data memory; a store bypasses register write-back.

Extend the existing routes

addi x5, x6, 3 reuses the immediate-input ALU path and the ALU-result write-back path. It needs suitable control, but no new datapath unit. jal has an additional requirement: it writes PC + 4 to rd while redirecting the PC without an equality test. Its write-back selector therefore needs a PC + 4 input, and its next-PC logic must support an unconditional jump.

Key Takeaways

  • A load writes memory data to rd; its ALU output is the address.
  • A store sends rs2 to memory while the ALU adds the base and offset.
  • A branch compares register values and computes PC + offset in parallel.
  • ALUSrc, MemtoReg, and PCSrc select shared routes.
  • B-format byte-offset reconstruction includes the implicit zero bit exactly once.
  • Immediate addition reuses existing hardware; jump-and-link also needs a PC + 4 write-back route.

1.3 Trace the values and the state changes

An instruction trace connects the assembly operation to actual wire values. Separate values computed during the cycle from values saved at the ending clock edge.

Use a consistent trace order
  1. Fetch from the current PC and identify the instruction fields.
  2. Read source registers and form the signed immediate.
  3. Select the ALU operands and calculate the result.
  4. Perform the requested data-memory access.
  5. Select register write data and the next PC.
  6. List the state writes at the clock edge.
Add two register values

At PC 400, add x5, x6, x7 has encoding 0x007302B3. Its fields are opcode 0110011, rd 5, funct3 000, rs1 6, rs2 7, and funct7 0000000. With x6 = 25 and x7 = −9, the read ports output 25 and −9. ALUSrc selects the second register value, and the ALU produces 16. MemtoReg selects 16 for write-back. At the edge, x5 becomes 16 and the PC becomes 404. MemRead and MemWrite are both zero.

Load, then store a doubleword

At PC 404, consider ld x5, 16(x6) with x6 = 1000 and memory at 1016 holding 42. ImmGen outputs 16. The ALU computes the address 1016, and data memory returns 42. MemtoReg selects that memory value, so x5 becomes 42 and the PC becomes 408 at the edge. Writing 1016 to x5 would confuse the address with the value stored there.

At PC 408, sd x5, 24(x6) reads x5 = 42 and x6 = 1000. The ALU calculates 1024 while the rs2 path supplies 42 to memory. MemWrite enables the store; RegWrite is zero. At the edge, the doubleword at 1024 becomes 42 and the PC becomes 412. The memory address and store value travel on different wires.

The offsets are measured in bytes. Adjacent RV64 doublewords begin 8 bytes apart: after the doubleword at 1016, the next begins at 1024. Advancing by one byte would not reach the next doubleword.

Decide a branch

At PC 412, beq x8, x9, 12 compares x8 = 7 with x9 = 7. The ALU subtracts to obtain zero. Branch is 1, so Branch AND Zero is 1 and PCSrc selects the branch target. The branch adder produces 424 by adding 12 to 412. Only the PC changes.

If x9 is 8 instead, subtraction produces −1 and Zero is 0. The next PC is then 416. The encoded offset is in units of 2 bytes, so the stored signed quantity for this 12-byte displacement is 6; the complete displacement used by the adder is still 12.

Read the next instruction's state

Each single-cycle instruction completes its work between adjacent clock edges. The next instruction reads the state saved by the previous edge. Thus the store can read the load's new x5 value in the next cycle without pipeline forwarding. Each instruction takes one clock cycle, giving a single-cycle CPI of 1, regardless of how many hardware units its path uses.

Key Takeaways

  • A trace gives numeric wire values and separately identifies clock-edge state changes.
  • An arithmetic instruction writes an ALU result; a load writes the memory output.
  • A store changes memory and the PC, with no register-file write.
  • For beq, equality selects the target measured from the branch PC.
2

Design the control unit for the single-cycle processor

The same hardware can add two registers, calculate a memory address, or compare values for a branch. Control signals decide which action matters in each cycle. Derive those signals from the work an instruction must do, including the write enables that protect stored state. Then follow the two decoding levels that turn an opcode and function bits into a specific ALU operation, and extend the design to immediate addition.

2.1 Derive the main control table

The main control unit translates an opcode into steering signals and write permissions. It is a combinational truth table implemented with logic gates: hardwired control.

Give each signal a job

RegWrite enables a write to rd. ALUSrc selects the second ALU input: 0 for rs2, 1 for an immediate. MemRead and MemWrite request the corresponding data-memory access. MemtoReg selects register write data: 0 for the ALU result, 1 for memory data. Branch marks an equality branch. The 2-bit ALUOp tells the separate ALU control unit what operation class is needed.

PCSrc is different: it depends on the instruction and the compared values. The main control asserts Branch, and the ALU supplies Zero. Their AND forms PCSrc, so an ordinary arithmetic result of zero cannot by itself cause a branch.

Build the table from required actions
ClassALUSrcMemtoRegRegWriteMemReadMemWriteBranchALUOp
R-type00100010
ld11110000
sd1X001000
beq0X000101

For ld, the ALU needs an immediate offset, so ALUSrc is 1. The loaded data goes to rd, making MemtoReg and RegWrite both 1. Memory is read, not written, giving MemRead = 1 and MemWrite = 0. Branch is 0, and ALUOp = 00 requests address addition.

For sd, the ALU also adds an offset, but the destination is memory. Set MemWrite = 1 and RegWrite = 0. MemRead stays zero: using memory does not mean reading it. For beq, the ALU uses both register values and subtracts, while the only possible architectural update is the PC.

Use don't-cares only where results are ignored

X is a don't-care, meaning either select value gives the same behavior. MemtoReg may be X for a store or branch because RegWrite is zero. The register-file write-data input is ignored, so the designer may choose the select value that simplifies the circuit.

A state-write enable cannot be treated this way when a write is forbidden. An accidental MemWrite during arithmetic can corrupt memory, even though the arithmetic instruction does not otherwise need that memory output. RegWrite and MemWrite must therefore be explicitly zero for instructions that do not perform those writes.

Add an immediate-arithmetic row

addi x5, x6, 3 takes its second operand from ImmGen and writes the ALU sum. Its row is ALUSrc 1, MemtoReg 0, RegWrite 1, MemRead 0, MemWrite 0, Branch 0, ALUOp 00. Its opcode 0010011 differs from the R-type opcode 0110011, so the main control needs this extra row. Supporting andi and ori also requires decoding their funct3 values to select the operation.

Signal names depend on the design. RegWEn, BSel, and WBSel in other course diagrams describe related write-enable and input-selection jobs. Follow the definition of a signal and its mux inputs when reading a new diagram.

Key Takeaways

  • Main control derives route selections and write enables from the opcode.
  • PCSrc combines Branch with the ALU Zero flag.
  • A store enables MemWrite and disables RegWrite and MemRead.
  • A selector is a don't-care only when its selected value cannot affect behavior.
  • addi needs a new opcode row but reuses the existing immediate-add datapath.

2.2 Decode the ALU operation in two levels

The opcode alone cannot tell add from sub: both belong to the R-type class. Two-level control first identifies the class, then uses the function bits where they matter.

From ALUOp to operation

The main control supplies a 2-bit ALUOp among its other outputs. The ALU control combines it with funct3 and instruction bit 30, part of funct7, to produce four operation-control bits.

ALUOpAdditional informationALU controlOperation
00Function bits ignored0010Add
01Function bits ignored0110Subtract
10funct3 000, bit 30 = 00010Add
10funct3 000, bit 30 = 10110Subtract
10funct3 1110000AND
10funct3 1100001OR

These codes describe this ALU implementation, not RISC-V instruction encodings. Loads and stores use ALUOp 00 because they add a base and offset. Equality branches use ALUOp 01 because subtraction produces Zero when the operands match. R-type instructions use ALUOp 10 and need further decoding.

Trace an encoded subtraction

sub x5, x6, x7 has encoding 0x407302B3. The opcode 0110011 identifies R-type and selects ALUOp 10. Its funct3 is 000, which leaves addition and subtraction as possibilities. Bit 30 is 1, from funct7 0100000, so the ALU control outputs 0110 for subtraction.

Changing that function bit to zero yields the corresponding add encoding 0x007302B3, with funct7 0000000 and ALU control 0010. The main-control row stays the same because both instructions use two register inputs, write an ALU result, and do not access data memory.

Reuse the adder for subtraction

In the classic ALU, the control lines represent Ainvert, Bnegate, and a 2-bit operation selector. Subtraction uses the adder after inverting the second operand and supplying a carry-in of 1:

a−b=a+b‾+1

This two's-complement identity allows add and subtract to share hardware. The Bnegate difference accounts for the codes 0010 and 0110; it does not require a separate arithmetic path for every instruction.

Decode bits only in their proper format

For ALUOp 00 or 01, the function-field positions do not select the ALU operation. A load's funct3 011 describes a doubleword access. Store and branch upper bits include immediate bits. Treating those positions as R-type function fields would confuse address formation with arithmetic decoding.

For a quick R-type check, ALUOp 10 with funct3 110 selects 0001, the OR operation. Adding another operation under the same opcode can require only an ALU-control change if the ALU already supports it. A new instruction class can also require main-control changes, as immediate arithmetic does.

Key Takeaways

  • ALUOp selects an operation class; R-type function bits finish the decoding.
  • ALUOp 00 requests addition and 01 requests subtraction without function decoding.
  • In this design, 0010 selects add and 0110 selects subtract.
  • Bit 30 distinguishes add from sub when funct3 is 000.
  • Function-field meanings depend on the instruction format.
  • Two's-complement subtraction reuses addition with an inverted second operand and carry-in 1.
3

Pipeline the datapath

A long single-cycle clock must accommodate a load even when the current instruction needs less work. Pipelining divides that work into stages and overlaps instructions. Compare the resulting clock period, throughput, and latency, then track the data and control stored between stages. Pipeline diagrams make the overlap visible and give a direct way to count the fill, steady operation, and completion of a short instruction sequence.

3.1 Calculate clock period, latency, and throughput

A single-cycle processor must finish its slowest instruction before the next edge. Faster instructions still wait for the same fixed clock. Pipelining changes how much work each clock period must contain.

Find the single-cycle limit

Use these component delays, ignoring muxes and small adders: fetch 250 ps, register read 150 ps, ALU 200 ps, data memory 250 ps, and register write 150 ps.

InstructionPath delay
R-type250 + 150 + 200 + 150 = 750 ps
ld250 + 150 + 200 + 250 + 150 = 1000 ps
sd250 + 150 + 200 + 250 = 850 ps
beq250 + 150 + 200 = 600 ps

The load is the critical path, setting the period to 1000 ps, or 1 ns. That is a 1 GHz clock. A mix of 25% loads, 10% stores, 50% R-type, and 15% branches has a weighted path delay of 800 ps. Yet every instruction gets 1000 ps, which is 1.25 times that average. An average delay cannot set a clock that must also accommodate the longest instruction.

Overlap five stages

The pipeline divides execution into IF (fetch), ID (decode and register read), EX (execute or calculate an address), MEM (access data memory), and WB (write a register). Different instructions occupy different stages simultaneously.

Throughput counts completed instructions per unit time. Latency measures the time one instruction spends from entry to completion. An assembly line can finish one item per interval even when each item needs several intervals to travel through it. The same distinction applies here.

The slowest stage takes 250 ps. With 20 ps of pipeline-register overhead, the clock period is 270 ps, about 3.70 GHz. One instruction travels through five periods, taking 1350 ps. This exceeds its single-cycle latency, but a full pipeline can complete an instruction every 270 ps.

Include fill and completion time

With no stalls, a k-stage pipeline executes n instructions in k + n − 1 cycles. For five stages this is n + 4. Four instructions need eight cycles, taking 2160 ps, compared with 4000 ps in the single-cycle processor. The speedup is about 1.85.

For 1,000,000 instructions, the pipeline needs 1,000,004 cycles, approximately 270.0 μs. The single-cycle design needs 1000 μs. The speedup approaches the ratio 1000/270, about 3.70, as the fixed fill-and-drain cost becomes small.

Perfect fivefold speedup would require five equally slow 200 ps stages with no register overhead or hazard delays. Unequal stages leave faster stages waiting for the slowest. More stages also add overhead and can increase hazard costs.

Fixed 32-bit instructions in this subset simplify fetch. Stable register fields help ID, and restricting data-memory access to loads and stores fits EX address calculation followed by MEM. These ISA properties make the stage boundaries practical.

Key Takeaways

  • The slowest complete instruction sets the single-cycle clock period.
  • The slowest stage plus register overhead sets the pipelined period.
  • Pipelining raises throughput; one instruction's latency can increase.
  • A hazard-free five-stage sequence of n instructions takes n + 4 cycles.
  • Unequal stages, register overhead, short sequences, and hazards reduce speedup.

3.2 Carry each instruction through pipeline registers

Several instructions share the datapath at once, so each stage needs its own instruction's values. Pipeline registers preserve those values and their control signals at each clock edge.

Match contents to later work
RegisterInformation carried forward
IF/IDInstruction and its PC
ID/EXSource values, immediate, PC, rs1, rs2, rd, function bits, EX/MEM/WB controls
EX/MEMALU result, Zero, branch target, store value, rd, MEM/WB controls
MEM/WBMemory data, ALU result, rd, WB controls

Each register is named for its adjoining stages. It captures the outputs of the first stage for use in the second. There is no extra pipeline register after WB; WB writes architectural state. The PC supplies the state at the front of fetch.

The EX/MEM contents above support a design that acts on the branch information in MEM. A design that resolves branches in EX returns that information to fetch sooner. The resolving stage determines the control-hazard penalty.

Keep destination and data together

A load is decoded in ID but writes rd three cycles later in WB. At that time IF/ID contains a younger instruction. If the write port used that younger instruction's rd, the loaded value would go to the wrong register. The load's destination number must therefore travel through ID/EX, EX/MEM, and MEM/WB beside its result.

A store similarly carries its rs2 value through ID/EX and EX/MEM. Its address and data must describe the same store when they reach data memory. Pipeline registers preserve an instruction's identity through these paired values even though several other instructions are active nearby.

Move control with the instruction

Control is generated in ID. EX consumes ALUSrc and ALUOp; MEM consumes Branch, MemRead, and MemWrite; WB consumes MemtoReg and RegWrite. Each stage passes the controls needed later along with the data.

If ALU control is decoded in EX, ID/EX must carry bit 30 and funct3 as well as ALUOp. R-type operations share ALUOp 10, so that value alone cannot distinguish add, sub, AND, and OR. Another valid design decodes the complete 4-bit operation in ID and carries that code instead.

Keep the stage schedule regular

An R-type instruction passes through MEM without using data memory. A store passes through WB without writing a register. Keeping all instructions in the same five-stage schedule preserves the order of register writes. If an R-type instruction skipped MEM, it could reach the single register write port in the same cycle as the load just ahead of it.

The register file serves WB and ID in one cycle by writing in the first half and reading in the second. ID can then see a value written by an older instruction that cycle. Separate instruction and data memories let IF and MEM operate simultaneously.

Most information moves forward through the pipeline. Write-back returns a result to the register file, and branch control returns a next-PC decision to fetch. These long return paths explain why later instructions may need help before an older instruction has finished.

Key Takeaways

  • Pipeline registers preserve each instruction's data and pending controls.
  • rd travels to WB alongside the result that belongs in it.
  • EX needs the function bits or an already decoded ALU control code.
  • All instructions retain the five-stage schedule even when a stage does no work.
  • First-half write and second-half read let WB supply ID in the same cycle.
  • Separate memories permit simultaneous instruction fetch and data access.

3.3 Read pipeline diagrams and count cycles

A pipeline diagram makes overlap explicit. Rows show instructions in program order, and columns show clock cycles. Each cell names the stage occupied by that instruction during that cycle.

Build a staircase

For five independent instructions, enter IF for I1 in cycle 1, then ID, EX, MEM, and WB in cycles 2–5. Start I2 one cycle later and repeat. The stage names form a diagonal staircase.

Instruction123456789
I1IFIDEXMEMWB
I2IFIDEXMEMWB
I3IFIDEXMEMWB
I4IFIDEXMEMWB
I5IFIDEXMEMWB

At cycle 5, I1 is in WB, I2 in MEM, I3 in EX, I4 in ID, and I5 in IF. Reading down a column gives a single-cycle snapshot. Following a row gives the history of one instruction.

Number the stages IF = 1 through WB = 5. Without stalls, instruction i reaches stage s in cycle i + s − 1. I3 therefore reaches MEM in cycle 6. The final WB cell gives the completion cycle: five instructions finish in cycle 9.

Put values into a snapshot

Let I1 be ld x5, 16(x6), with x6 = 1000 and memory at 1016 holding 42. Let I2 be an independent add, I3 an independent subtract, and I4 an independent OR. In cycle 4, the load reads memory at 1016, I2 uses the ALU, I3 reads registers, and I4 is fetched. In cycle 5 the load writes 42 into x5. A column contains work from several instructions, not several stages of the load.

Show a stall without stopping older work

Now use ld x10, 0(x20) followed by add x11, x10, x12, then an independent instruction. With forwarding, the immediate consumer still needs one stall:

  • The load occupies IF 1, ID 2, EX 3, MEM 4, WB 5.
  • The add occupies IF 2, ID 3, ID 4 again, EX 5, MEM 6, WB 7.
  • The third instruction occupies IF 3, IF 4 again, ID 5, EX 6, MEM 7, WB 8.

The add waits in ID while a bubble moves through EX. The load continues normally; freezing it would postpone the very value the add needs. Every younger instruction is delayed with the add.

Count the sequence once

A five-stage pipeline needs n + 4 cycles without stalls. Each inserted stall adds one more cycle, giving n + 4 + stalls when there are no other losses. The three-instruction example finishes in cycle 8: three instructions, four extra stage intervals, and one stall.

The first four cycles fill the pipeline, and the last four drain it. These are views of the same n + 4 schedule, not two separate four-cycle charges. For a long sequence their fixed contribution is small; for a short sequence it can dominate the speedup.

Key Takeaways

  • Rows follow one instruction; columns show simultaneous work.
  • Without stalls, instruction i occupies stage s in cycle i + s − 1.
  • A stall repeats ID and holds younger fetch while older instructions advance.
  • Total cycles are n + 4 + stalls for the five-stage schedule with no other losses.
4

Detect and resolve data hazards

Overlapping instructions can expose a value before its producer has written it to the register file. Identify the actual producer for each source operand, then follow the forwarding paths that deliver new results to later instructions. Loads reveal the timing limit of forwarding: their data arrives too late for an immediate consumer. Trace the required stall and see how moving independent work can remove the delay while preserving the program's result.

4.1 Find the dependences that can delay execution

A hazard prevents the next instruction from executing in its planned cycle. To diagnose one, identify the resource or value needed, the cycle it is needed, and the cycle it becomes available.

Distinguish three hazard types
TypeConflictExample
StructuralSimultaneous demand for one resourceIF and MEM need one single-port memory
DataA needed value is not readyA subtract needs the preceding add's result
ControlThe correct next address is unresolvedFetch continues before a branch is decided

Separate instruction and data memories remove the IF/MEM structural conflict. Writing the register file in the first half of a cycle and reading it in the second also allows WB and ID to share it. These arrangements leave no structural hazard in this five-stage model.

Identify the actual producer

A read-after-write (RAW) dependence exists when a later instruction reads a value written by an earlier one. In add x1, x2, x3 followed by sub x4, x1, x5, the add produces x1 and the subtract consumes it. Without help, the subtract reads x1 in ID during cycle 3, before the add writes it in WB during cycle 5.

A write-after-read (WAR) dependence reuses a register after an older instruction has read it. A write-after-write (WAW) dependence gives two instructions the same destination. These name dependences do not cause hazards in the in-order five-stage design: reads occur in ID and writes occur in WB in program order. They matter when deciding whether software may reorder instructions.

Follow a sequence with repeated destinations

Consider:

ld  x5, 0(x10)
add x6, x5, x7
sub x5, x8, x9
or  x9, x6, x5

The RAW links are load → add through x5, add → OR through x6, and subtract → OR through x5. The OR needs the subtract's new x5, not the older loaded value. Looking only for equal register names can miss this change of producer.

The subtract writes x5 after the add reads x5, a WAR dependence. The load and subtract also have a WAW dependence on x5. The OR writes x9 after the subtract reads it, another WAR dependence. None of these creates a WAR or WAW hardware hazard in this ordered pipeline.

Count waits without forwarding

With only the write-then-read register file, an immediate consumer needs two stall cycles. It must delay its ID read from cycle 3 to cycle 5. One independent instruction between producer and consumer reduces this to one stall. Two independent instructions let the consumer reach ID in the producer's WB cycle, requiring none.

A dependence is a property of the program; whether it creates a stall depends on timing and the available paths. A distant RAW dependence may require no action. Register x0 never supplies a pending result because it always reads zero and ignores writes.

Software can insert nop instructions or move independent work into waiting intervals. Hardware can forward results or insert stalls automatically. Both approaches must keep each consumer connected to the value its program-order producer writes.

Key Takeaways

  • Structural, data, and control hazards involve different kinds of conflict.
  • RAW identifies a producer whose value a later instruction reads.
  • Only RAW dependences create data hazards in this in-order five-stage design.
  • The nearest earlier writer of a source register supplies its required value.
  • Without forwarding, an adjacent consumer waits two cycles; one gap reduces the wait to one.
  • WAR and WAW still constrain valid software reordering.

4.2 Select the newest available value with forwarding

An ALU result exists before it reaches register write-back. Forwarding, also called bypassing, routes that result directly to a later instruction's input, avoiding a wait for the register file.

Select the source for each operand

Two muxes feed the execution paths. ForwardA serves rs1 and ForwardB serves rs2. Each operand is checked independently.

Select codeValue source
00Register value carried in ID/EX
10ALU result carried in EX/MEM
01Write-back value carried in MEM/WB

The EX/MEM path reaches the immediately following instruction. The MEM/WB path reaches an instruction two places behind and can carry either an ALU result or loaded data. ForwardB also supplies the store-data path before ALUSrc chooses between that value and an immediate.

Check permission, destination, and match

For ForwardA = 10, the instruction in EX/MEM must have RegWrite = 1, a nonzero rd, and rd equal to ID/EX.rs1. Replace rs1 with rs2 for the ForwardB test. A store or branch must not be treated as a producer just because its instruction bits happen to resemble a destination number. Writes to x0 must not become forwarded values either.

For ForwardA = 01, perform the corresponding RegWrite, nonzero-rd, and register-match checks on MEM/WB. Use this older result only when EX/MEM does not already provide the required operand. ForwardB follows the same priority rule independently.

Follow one result across later consumers

Start with add x1, x2, x3, where x2 = 10 and x3 = 5. It produces 15 at the end of EX in cycle 3.

  • The next instruction, sub x4, x1, x5, reaches EX in cycle 4. With x5 = 3, ForwardA = 10 supplies 15 and the subtraction gives 12.
  • and x6, x7, x1 reaches EX in cycle 5. ForwardB = 01 takes x1 from MEM/WB.
  • or x8, x1, x9 reads registers in ID during cycle 5, after the add's first-half write. It needs no forwarding in EX.

No stall is needed for these ALU-result dependences. The consumer receives the value when it uses the ALU, even if its earlier ID read obtained a stale value.

Resolve two matching writers

In three consecutive instructions add x1, x1, x2, add x1, x1, x3, and add x1, x1, x4, both EX/MEM and MEM/WB match the third instruction's rs1. EX/MEM holds the second add's result, the newest x1. MEM/WB holds the first add's result and must lose priority.

The same paths let add x5, x6, x7 feed sd x5, 0(x8) without a stall. The forwarded x5 reaches memory's write-data path while the store's ALU uses the immediate offset.

Forwarding cannot supply data before it exists. EX/MEM for a load contains its address, not the loaded value. The immediate consumer must wait until the load finishes MEM; forwarding the address would silently compute with the wrong quantity.

Key Takeaways

  • Forwarding delivers a result directly to a later instruction before register write-back.
  • 00 selects ID/EX, 10 selects EX/MEM, and 01 selects MEM/WB.
  • Each forwarding match requires RegWrite, a nonzero rd, and a matching source number.
  • EX/MEM has priority over MEM/WB for the same operand.
  • ForwardB can supply store data as well as an ALU register operand.
  • An immediate load consumer still needs a stall because the data is not yet ready.

4.3 Insert one bubble or fill the gap with useful work

A load produces data at the end of MEM. The immediately following instruction would need that data at the beginning of EX in the same cycle. One stall moves the consumer's EX stage to the next cycle, when MEM/WB can supply the value.

Detect the missing value in ID

The hazard detection unit examines the instruction in EX and the instruction being decoded. The basic test is ID/EX.MemRead = 1 and a match between ID/EX.rd and either source-number field in IF/ID. A refined test excludes rd = x0 and checks which source fields the decoded instruction actually reads.

This last check avoids a false stall on an I-type instruction whose immediate bits occupy the usual rs2 position. Comparing raw field positions is safe but can delay an instruction that does not really read the register.

Hold younger work and advance the load

The stall performs three coordinated actions:

  1. Set the controls entering ID/EX to zero, inserting a bubble.
  2. Set PCWrite = 0 to keep the fetch address unchanged.
  3. Set IF/IDWrite = 0 to retain the instruction waiting in ID.

The load and older instructions keep moving. The bubble passes through later stages without writing registers or memory. Freezing ID/EX with the load still in it would repeat the load instead of inserting an empty operation.

For ld x10, 0(x20) followed by add x11, x10, x12, the load is in EX and the add in ID during cycle 3. In cycle 4, the load is in MEM, the bubble in EX, and the add still in ID. In cycle 5, the load is in WB and the add reaches EX with ForwardA = 01.

Schedule independent instructions

Consider:

ld  x10, 0(x20)
ld  x11, 8(x20)
add x12, x10, x11
sd  x12, 24(x20)
ld  x13, 16(x20)
add x14, x10, x13
sd  x14, 32(x20)

The uses of x11 and x13 immediately follow their loads. With forwarding, these cause two stalls, giving 7 + 4 + 2 = 13 cycles. Move ld x13, 16(x20) to third place, before the first add. It separates the x11 load from its consumer and places x13 far enough ahead of its consumer. The sequence now takes 7 + 4 = 11 cycles.

The move is valid because the load reads x20, which the crossed instructions do not change. Its destination x13 does not affect those instructions. Its address x20 + 16 is distinct from the crossed store's x20 + 24. A load cannot move across a store that might write the bytes it reads. Reordering must preserve RAW, WAR, WAW, and memory dependences.

Combine stalls and forwarding

For ld x5, 0(x10), add x6, x5, x7, sub x5, x8, x9, and or x9, x6, x5, only the immediate load-use pair stalls. When OR reaches EX, ForwardA = 01 supplies the add's x6 and ForwardB = 10 supplies the subtract's x5. The total is 4 + 4 + 1 = 9 cycles.

Key Takeaways

  • A load-use pair needs one stall with forwarding.
  • A stall zeros the incoming ID/EX controls and freezes PC and IF/ID.
  • The load continues through MEM while the consumer waits in ID.
  • Scheduling independent work can separate loads from their consumers.
  • Valid reordering preserves register and memory dependences.
  • After a stall, select each forwarded operand from its own actual producer.
  • Cycles equal instructions + 4 + stalls for these five-stage sequences.
5

Handle control hazards and predict branches

A branch makes the next instruction address depend on work still in the pipeline. Follow what happens when fetch waits, guesses the next address, or recovers from a wrong guess. Trace history-based predictors and distinguish their direction guesses from stored branch targets. Finally, combine load-use delays and branch penalties with the clock period to compare execution times, including the tradeoffs introduced by deeper pipelines.

5.1 Recover from branches and exceptions

Fetch needs a new address every cycle. A conditional branch provides the correct choice only after its comparison and target calculation. This gap creates a control hazard.

Relate resolution stage to penalty

In a five-stage pipeline with redirection after the resolving stage, an outcome known at the end of ID loses one fetch slot on a wrong guess. Resolution at the end of EX loses two; at the end of MEM it loses three. Younger instructions have already entered during those slots.

One strategy stalls fetch until every branch is decided. It is simple, but taken and not-taken branches both pay the full wait. Predict not taken instead continues at PC + 4. A correct guess needs no recovery. A taken branch redirects fetch and discards the younger instructions from the sequential path.

Trace a taken branch

Fetch beq x1, x2, 16 at address 100 in cycle 1 and resolve it at the end of EX in cycle 3. Predict-not-taken fetches addresses 104 and 108 in cycles 2 and 3. If the branch is taken, both are wrong-path instructions. Fetch begins at 116 in cycle 4, after a two-cycle penalty.

A flush makes those younger entries unable to change architectural state or raise exceptions. The implementation can invalidate entries or suppress their controls and exception effects. A wrong-path store must never reach an effective memory write.

A bubble is not the same as an all-zero RISC-V instruction. The all-zero encoding is illegal. If a real instruction encoding is inserted, the canonical nop is addi x0, x0, 0, encoded as 0x00000013. A killed pipeline entry instead represents no executed instruction.

Resolve earlier, but get operands earlier

Moving the comparator and branch-target adder to ID reduces the redirection penalty to one cycle. The comparison now needs source values in ID, so the usual EX forwarding alone is insufficient. With suitable ID forwarding, a branch immediately after its producing ALU instruction waits one cycle. Immediately after a producing load, it waits two. Earlier resolution trades fewer lost fetch slots for more demanding operand delivery.

Static prediction fixes a rule in advance. Common rules are always not taken, always taken, and backward taken/forward not taken. A backward branch at a loop's bottom often repeats the loop, making that direction a useful clue.

RISC-V has no branch delay slot. If a branch is taken, its sequential successor is not executed merely because it was fetched. Some older MIPS designs made that successor execute as a defined delay-slot instruction; that is a different ISA rule.

Preserve a precise exception boundary

An illegal instruction or ecall transfers control to a handler. Older instructions finish; the faulting instruction and younger instructions do not commit their normal effects. The processor records the faulting PC and cause, using registers such as sepc/scause in supervisor mode or mepc/mcause in machine mode, then fetches from the handler. This precise exception presents the state as a boundary between completed older instructions and uncompleted later work.

Key Takeaways

  • Later branch resolution leaves more younger instructions to discard.
  • Predict-not-taken pays a recovery penalty only when its guess is wrong.
  • A flush suppresses wrong-path state changes and exceptions.
  • All-zero instruction bits are illegal; the canonical nop is 0x00000013.
  • Early ID resolution also requires earlier operands and suitable forwarding.
  • RISC-V has no architectural branch delay slot.
  • Precise exceptions preserve completed older work and discard faulting and younger effects.

5.2 Trace history-based branch predictions

Dynamic prediction learns from outcomes observed while a program runs. A branch history table (BHT) stores small state entries selected using bits from a branch address. Predict first, compare with the real outcome later, then update the entry.

See why one bit loses twice on a loop

A 1-bit predictor stores the previous outcome. If the last branch was taken, it predicts taken next time; otherwise it predicts not taken. For a repeatedly invoked loop whose branch is taken nine times and then not taken once, the exit leaves the bit at not taken.

On the next invocation, the first taken branch is mispredicted. The intervening taken branches train the bit to taken, so the final not-taken exit is also mispredicted. In steady state that is two errors in ten outcomes, or 80% accuracy.

Add a second bit for persistence

A 2-bit saturating counter has states 0 through 3. States 0 and 1 predict not taken; 2 and 3 predict taken. A taken outcome increments the counter, and a not-taken outcome decrements it. Values stop at 0 and 3.

StateNamePrediction
0Strongly not takenNot taken
1Weakly not takenNot taken
2Weakly takenTaken
3Strongly takenTaken

From state 3, one not-taken exit moves the state to 2, which still predicts taken. The next loop entry is therefore predicted correctly. The same ten-outcome loop has one error per invocation in steady state, or 90% accuracy. Two consecutive contrary outcomes are needed to reverse a prediction starting from a strong state.

Trace before updating

Start in state 1 and observe taken, taken, not taken, taken:

  1. State 1 predicts not taken: wrong. Increment to 2.
  2. State 2 predicts taken: correct. Increment to 3.
  3. State 3 predicts taken: wrong. Decrement to 2.
  4. State 2 predicts taken: correct. Increment to 3.

There are two errors and the final state is 3. Updating before predicting would incorrectly give the predictor access to the outcome it is supposed to guess.

Distinguish direction, target, and interference

Two branch addresses can index the same BHT entry. This aliasing lets their outcomes interfere. A wrong guess costs cycles, but recovery checks the real outcome and preserves correctness.

A branch target buffer (BTB) supplies an address, not just a direction bit. Looked up by PC during IF, it can provide the predicted taken target for the next fetch cycle before decode. The direction prediction decides whether to use that target.

Simple history has limits. For a strictly alternating taken/not-taken pattern, a 1-bit predictor stays wrong after it follows the pattern. A 2-bit counter is at most half correct; starting in state 1 before a taken outcome makes it wrong every time. Correlating predictors add recent branch history, tournament predictors select between predictors, and a return address stack predicts procedure-return targets. Deeper pipelines make recovery more expensive because more younger work accumulates before resolution.

Key Takeaways

  • A 1-bit predictor repeats the last outcome.
  • A 2-bit counter predicts taken in states 2 and 3 and saturates at 0 and 3.
  • Prediction uses the old state; update follows the actual outcome.
  • Two bits avoid the loop-entry error caused by a single exit.
  • BHT aliasing allows different branches to disturb one history entry.
  • A BTB supplies a predicted target; direction prediction chooses whether to use it.

5.3 Turn hazard rates into execution time

Pipeline speed depends on both the clock period and the cycles spent waiting or recovering. Effective CPI measures those extra cycles averaged across the instruction stream.

Weight each cost by the affected instructions

For a long single-issue sequence, start with ideal CPI 1. Add each distinct, nonoverlapping source of lost cycles as an affected-instruction fraction times cycles lost per event. A conditional rate needs its parent fraction too.

Suppose 25% of instructions are loads and 40% of those loads have an immediate consumer. Each such pair stalls once, so the load-use contribution is 0.25 × 0.40 × 1 = 0.10 cycles per instruction. Suppose 15% are branches, 10% of those are mispredicted, and recovery costs two cycles. The branch contribution is 0.15 × 0.10 × 2 = 0.03.

Adding the independent costs gives CPI = 1 + 0.10 + 0.03 = 1.13. Charging one stall to every load would produce 0.25 instead of 0.10. Applying the 10% branch-error rate to every instruction would similarly overcount.

Include clock period and instruction count

Execution time equals instruction count × CPI × clock period. A 4 GHz clock has a period of 0.25 ns. For 10⁹ instructions at CPI 1.13, execution takes 10⁹ × 1.13 × 0.25 ns = 0.2825 s. The average time per instruction is 0.2825 ns.

For a short sequence, count fill, drain, and hazard cycles explicitly. The ideal base CPI of 1 describes steady throughput; a five-stage pipeline executing only a few instructions also has its four-cycle fill-and-completion contribution.

Compare branch strategies on equal terms

Keep the load-use cost of 0.10, branch fraction of 0.15, and two-cycle penalty:

Branch strategyBranch costEffective CPI
Wait on every branch0.15 × 2 = 0.301.40
Predict not taken, 60% taken0.15 × 0.60 × 2 = 0.181.28
Dynamic, 90% accurate0.15 × 0.10 × 2 = 0.031.13

At the same clock period and instruction count, dynamic prediction is about 1.24 times as fast as waiting, because 1.40/1.13 ≈ 1.24.

Across different processors, compare CPI × period. A single-cycle design at 1000 ps takes 1000 ps per instruction. A pipeline at 270 ps and CPI 1.13 takes 305.1 ps per instruction, a speedup of about 3.28. Comparing CPI alone would favor the single-cycle CPI of 1 and reach the wrong conclusion.

Understand the next design tradeoff

More pipeline stages can shorten the combinational work per cycle. They also introduce register overhead and can increase load-use and misprediction penalties. Clock frequency alone cannot decide whether the deeper design wins.

Multiple issue starts several instructions per cycle, allowing CPI below 1 and instructions per cycle (IPC) above 1. Static issue groups are chosen by the compiler; dynamic issue, or superscalar execution, is chosen by hardware and often uses speculation and out-of-order execution. Data dependences and branch prediction still limit the useful overlap.

Key Takeaways

  • Average each hazard cost over all instructions, including the parent fraction for conditional rates.
  • Add distinct lost-cycle contributions to ideal CPI 1 for long single-issue streams.
  • Execution time is instruction count × CPI × clock period.
  • Compare different processors using CPI × period, not CPI alone.
  • Deeper pipelines trade shorter stages for more overhead and hazard cost.
  • Multiple issue can achieve IPC above 1 and CPI below 1.

Processor Datapath and Pipelining examples

5 Walkthroughs

1

Follow an instruction from fetch to saved result

14 steps
Build the shared single-cycle paths and trace arithmetic, a load, a store, and a branch with concrete values.
  1. 1
    IntroductionTurn instruction bits into saved values

    An instruction names work, such as adding register values or loading data. The processor needs hardware that does that work and control signals that select the right routes.

    Follow the single-cycle datapath from its storage elements to its outputs. Then trace a short sequence and identify exactly what changes at each ending clock edge. Each instruction in this subset occupies 4 bytes.

  2. 2
    ExplanationBegin with the stored instruction address

    The PC holds the current instruction address. Instruction memory returns the instruction at that address, and a separate adder calculates PC + 4 at the same time.

    The PC is a state element: it keeps its value during the cycle. The adder is combinational: its output follows the inputs. At the ending clock edge, the PC captures whichever next address its input mux selects.

  3. 3
    ExplanationRead the operands and form the immediate

    The register file reads rs1 and rs2 through two ports. Its write port changes rd only when RegWrite enables the clock-edge write; x0 always reads zero.

    ImmGen rebuilds an immediate and sign-extends it to 64 bits. Copying the sign bit keeps a negative offset negative. For the 12-bit value 1111 1111 1000, the result is −8, not the zero-extended value 4088.

  4. 4
    Key InsightSeparate a computed result from a stored result

    The ALU adds, subtracts, ANDs, or ORs according to its control input. Its Zero flag reports whether the result is zero. Muxes select among candidate inputs, and write enables determine which selected values become stored state.

    A unit can calculate an unused output without changing the program. A memory write enable is different: asserting it can save a value even when that write was never intended.

  5. 5
    ChallengeWhich part remembers?

    A branch-target adder computes 740 while the PC still holds 720. Before the active edge, which unit retains the current instruction address, and does the computed target itself change that address?

    ---reveal---

    The PC retains 720. The adder only computes a candidate target. The PC changes when the selected next value is captured at the edge; a candidate on an unselected input does not overwrite it.

  6. 6
    ExplanationRoute arithmetic and memory operations

    An R-type operation reads two register values, sends them through the ALU, and returns the result to rd. A load instead needs a base-plus-offset address and then the memory value at that address.

    A store calculates an address the same way, but rs2 supplies the data to write. The data path to memory must remain available even while ALUSrc selects an immediate for the ALU's second input.

  7. 7
    ExplanationChoose the shared connections

    Three selectors merge the paths:

    • ALUSrc chooses rs2 or the immediate for the ALU.
    • MemtoReg chooses the ALU result or memory data for rd.
    • PCSrc chooses PC + 4 or the branch target.

    A load sets ALUSrc to 1 and MemtoReg to 1. A store uses the immediate-address path too, but disables register write-back and enables memory write.

  8. 8
    TipCalculate a branch target once

    For beq, subtraction tests equality while a separate adder forms branch PC + signed byte offset. These calculations can proceed in parallel.

    B-format encoding omits the offset's low zero bit. ImmGen can reconstruct the complete byte offset, or an external shift can supply that bit. Once the complete byte offset exists, shifting it again would double the displacement.

  9. 9
    ChallengeSeparate store address from store data

    For sd x11, 32(x18), x18 holds 2400 and x11 holds 55. What are the ALU result and the memory write data?

    ---reveal---

    The ALU computes the address 2432 from 2400 + 32. Memory write data is 55, supplied by x11. Sending 55 to the ALU in place of the offset would calculate an unrelated address; selecting the immediate must leave the store-data route intact.

  10. 10
    ExampleTrace an add at the clock edge

    At PC 400, add x5, x6, x7 reads x6 = 25 and x7 = −9. ALUSrc selects the second register value, the ALU adds, and MemtoReg selects the resulting 16.

    At the edge, RegWrite saves 16 in x5, and the PC becomes 404. Data memory is neither read nor written.

  11. 11
    ExampleFollow a load, then a store

    At PC 404, ld x5, 16(x6) uses x6 = 1000 and reads address 1016, whose doubleword holds 42. The ALU outputs 1016; memory outputs 42, which MemtoReg selects for x5. The PC advances to 408.

    The next sd x5, 24(x6) computes address 1024 and writes the updated x5 value, 42. It advances the PC to 412 without writing any register.

  12. 12
    ExampleDecide the next instruction address

    At PC 412, beq x8, x9, 12 reads two values of 7. Subtraction gives zero and the target adder gives 424. Branch AND Zero selects 424 as the next PC.

    If x9 were 8, subtraction would give −1 and the PC would advance to 416. Neither case writes a general-purpose register or data memory. The comparison controls which candidate address is saved.

  13. 13
    ChallengeDiagnose the wrong destination value

    A correct ld x10, 8(x20) with x20 = 3200 reads the doubleword 91 at 3208. A faulty write-back mux instead leaves x10 = 3208. What did the mux select, and what should it select?

    ---reveal---

    It selected the ALU result, the address 3208. It should select the data-memory output, 91. Address calculation can be correct while the final state is wrong because write-back chose the wrong source.

  14. 14
    RecapMatch every state write to its route

    For a complete single-cycle trace, distinguish the arithmetic result, the effective address, the memory data, and the next PC. Loads and arithmetic write rd through different mux inputs; stores use a separate data path; branches select only the next instruction address.

    All use the same edge boundary: combinational work produces candidates during the cycle, and enabled state writes capture the selected values at its end.

2

Derive control from the work an instruction needs

11 steps
Build a load control row, justify don't-cares, and decode R-type arithmetic with ALUOp and function bits.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionMake the shared datapath obey the instruction
  2. 2
    ExampleDerive a load row from its data route
  3. 3
    ExplanationProtect state with definite write enables
  4. 4
    Key InsightLet data finish the branch decision
  5. 5
    ChallengeChoose the harmless unspecified setting
  6. 6
    ExplanationUse ALUOp to select an operation class
  7. 7
    ExampleTrace the subtraction function bits
  8. 8
    ConnectionReuse the adder for subtraction
  9. 9
    ChallengeKeep a load's bits in their proper role
  10. 10
    ChallengeExtend control without adding an address path
  11. 11
    RecapConnect permissions with decoding
3

Watch independent instructions overlap

15 steps
Calculate a pipeline clock, follow values through stage registers, and read completion times from the five-stage schedule.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionSeparate one instruction from the instruction stream
  2. 2
    ExampleFind the slowest complete instruction
  3. 3
    ExampleSet the pipeline clock by the slowest stage
  4. 4
    AnalogyCompare throughput and latency
  5. 5
    ChallengeCalculate a short sequence
  6. 6
    ExplanationCarry the instruction, not just its result
  7. 7
    ExampleKeep the destination beside a load
  8. 8
    ExplanationCarry the controls until their stage uses them
  9. 9
    ChallengeWhy keep the unused MEM slot?
  10. 10
    ExampleBuild a staircase of stages
  11. 11
    TipLocate a stage without drawing every cell
  12. 12
    ExampleInsert a wait without repeating older work
  13. 13
    ChallengeRead the delayed finish
  14. 14
    ChallengeCombine storage with a cycle snapshot
  15. 15
    RecapRead performance from the schedule
4

Follow the newest value through a stalled pipeline

17 steps
Identify producers, select forwarding sources, insert a load-use bubble, and check a scheduling move.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionFind where the needed value exists
  2. 2
    ExplanationSeparate conflicts by their cause
  3. 3
    ExampleIdentify the producer for each read
  4. 4
    ChallengeDoes register reuse create a hardware hazard?
  5. 5
    ExplanationDeliver an ALU result before write-back
  6. 6
    TipQualify each forwarding match
  7. 7
    ExampleResolve two matching writers
  8. 8
    ChallengeForward two operands independently
  9. 9
    ConnectionPreserve the separate store-data route
  10. 10
    ExplanationSee the timing limit of forwarding
  11. 11
    ExplanationHold the consumer and insert a bubble
  12. 12
    ExampleTrace the wait across three cycles
  13. 13
    TipMake the detector read actual sources
  14. 14
    ExampleMove useful work into the gap
  15. 15
    ChallengeCheck the move before counting the gain
  16. 16
    ChallengeCombine the bubble with later forwarding
  17. 17
    RecapChoose help according to production time
5

Recover the instruction stream and measure the cost

19 steps
Trace a taken branch, compare prediction states, and combine hazard rates with clock period to estimate execution time.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionKeep useful work on the correct path
  2. 2
    ExplanationCount the younger fetch slots
  3. 3
    ExampleFollow a taken branch under predict-not-taken
  4. 4
    TipDiscard work without executing an illegal instruction
  5. 5
    ExplanationTrade earlier resolution for earlier operands
  6. 6
    ChallengeProtect the state after a wrong guess
  7. 7
    ConnectionPreserve the exception boundary
  8. 8
    ExplanationUse history to guess direction
  9. 9
    ExplanationLet two bits retain confidence
  10. 10
    ExampleTrace the prediction before the update
  11. 11
    ChallengeTest a contrary pair
  12. 12
    ExplanationSeparate direction from target
  13. 13
    Key InsightRecognize interference and pattern limits
  14. 14
    ExampleConvert conditional rates to instruction-wide cost
  15. 15
    ExampleInclude the duration of a cycle
  16. 16
    ExampleCompare prediction strategies
  17. 17
    ChallengeRecover the missing branch fraction
  18. 18
    ChallengeJudge a deeper pipeline
  19. 19
    RecapMeasure useful overlap after recovery costs

Processor Datapath and Pipelining practice questions

50 Practice Questions in 5 sets

Set 1: Follow values and control signals10 Practice Questions

Question 1 of 10

Which circuit retains the instruction address between clock cycles?
  1. The immediate generator
  2. The branch-target adder
  3. The program counter
  4. The ALU multiplexer
Show answerHide answer
Answer: C
The program counter is a state element, so it retains the instruction address across cycles. A branch-target adder can calculate a candidate next address, but it does not store that address. The PC captures the selected next value at the active clock edge.

Question 2 of 10

For sd x14, 40(x9), where does the value written to memory come from?
  1. The value in x14
  2. The value in x9
  3. The immediate 40
  4. The ALU address output
Show answerHide answer
Answer: A
The store writes the value read from rs2, which is x14. Register x9 provides the base for address calculation, and 40 is the byte offset. The ALU adds the base and offset to locate the destination; that address is separate from the value sent to memory.

Question 3 of 10

At PC 640, ld x12, -16(x8) runs with x8 = 2080 and a doubleword value of −6 at address 2064. What are x12 and the PC after completion?
  1. x12 = 2064; PC = 644
  2. x12 = −6; PC = 624
  3. x12 = 2080; PC = 644
  4. x12 = −6; PC = 644
Show answerHide answer
Answer: D
The ALU forms address 2064 by adding −16 to 2080. The load writes the memory value, −6, into x12 and advances the instruction PC by 4 to 644. Writing 2064 into x12 would confuse the calculated address with the data returned from that address.

Question 4 of 10

A beq x16, x17, -24 at address 880 compares two registers both holding 11. What address is fetched next?
  1. 860
  2. 856
  3. 884
  4. 904
Show answerHide answer
Answer: B
The register values match, so the branch is taken. Add the signed byte displacement to the branch PC: 880 − 24 gives 856. Starting from PC + 4 instead would give 860, but the branch displacement is measured from the branch instruction itself.

Question 5 of 10

Why can MemtoReg be a don't-care for beq?
  1. MemRead is 0, so every control value is ignored.
  2. RegWrite is 0, so its selected value is ignored.
  3. Branch is 1, so the register file is overwritten.
  4. Zero is 1, so both write-back inputs are identical.
Show answerHide answer
Answer: B
MemtoReg only selects register write data, and RegWrite = 0 prevents a branch from writing a register. Its selection therefore has no effect. MemRead = 0 does not make all controls irrelevant: an erroneous write enable could still change stored state.

Question 6 of 10

An instruction has the R-type opcode, funct3 000, and bit 30 = 1. What ALUOp and ALU control does this design produce?
  1. ALUOp 01; ALU control 0110
  2. ALUOp 10; ALU control 0010
  3. ALUOp 00; ALU control 0010
  4. ALUOp 10; ALU control 0110
Show answerHide answer
Answer: D
The R-type opcode first gives ALUOp 10. Function decoding then uses funct3 000 and bit 30 = 1 to select subtraction, code 0110. ALUOp 01 also requests subtraction, but it is the branch-class setting and is not generated by this R-type opcode.

Question 7 of 10

A 12-bit immediate contains 1111 1111 0000. What signed value must ImmGen supply to the 64-bit datapath?
  1. −16
  2. 4080
  3. −15
  4. 240
Show answerHide answer
Answer: A
The leading sign bit is 1, so this is a negative two's-complement immediate. Its 12-bit unsigned value is 4080; subtracting 4096 gives −16, which sign extension preserves. Zero extension would incorrectly preserve the unsigned value 4080 instead.

Question 8 of 10

A single-cycle ld x15, 32(x18) has x18 = 3000 and memory at 3032 holding 77. A control fault changes only MemtoReg from 1 to 0. The next instruction is sd x15, 48(x18). What value does that store write, and where?
  1. 77 at address 3048
  2. 3032 at address 3032
  3. 3032 at address 3048
  4. 77 at address 3080
Show answerHide answer
Answer: C
The faulty load selects its ALU address, 3032, as write-back data, so x15 becomes 3032. The following store computes its own address as 3000 + 48 = 3048 and writes that x15 value there. Storing 77 would require the load's correct memory-data selection.

Question 9 of 10

A branch at PC 1200 compares equal registers. Its reconstructed signed byte offset is −32, but a faulty branch path shifts that complete offset left once more before adding. What next PC results, and what should it have been?
  1. 1168 instead of 1136
  2. 1136 instead of 1168
  3. 1140 instead of 1172
  4. 1264 instead of 1232
Show answerHide answer
Answer: B
The reconstructed offset already includes the implicit low zero bit. The extra shift incorrectly doubles −32 to −64, producing 1136; the correct target is 1200 − 32 = 1168. Adding from PC + 4 would introduce a separate error that this stem does not describe.

Question 10 of 10

A designer adds a supported R-type bitwise operation under the existing R-type opcode. Its data routes and state writes match other R-type operations, and the ALU already implements it. What decoding change is needed?
  1. Extend ALU function decoding.
  2. Add a new opcode control row.
  3. Reuse the load control row.
  4. Set MemtoReg to select memory.
Show answerHide answer
Answer: A
The new operation shares the existing R-type main-control row, since it still reads registers and writes an ALU result. Its function bits need a decoding entry that selects the existing ALU operation. A new opcode row would be needed for a new instruction class, which this extension does not introduce.
Set 2: Read the five-stage schedule10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What performance quantity counts completed instructions per unit time?
  1. Instruction latency
  2. Throughput
  3. Clock-cycle latency
  4. Pipeline depth
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Why must a load's rd field be carried to MEM/WB?
  1. WB must decode the next branch's immediate.
  2. MEM must reread that load's base register.
  3. IF must select that load's source operand.
  4. WB must identify that load's destination.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

In a hazard-free five-stage pipeline, instruction I6 begins IF in cycle 6. In which cycle does it reach MEM?
  1. 9
  2. 8
  3. 10
  4. 11
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Stage logic delays are 180, 120, 210, 160, and 130 ps. Pipeline-register overhead is 15 ps. What clock period is required?
  1. 800 ps
  2. 210 ps
  3. 225 ps
  4. 175 ps
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

The instruction in EX is an R-type operation with ALUOp 10. ID/EX carries neither its function bits nor a predecoded operation code. What information is missing?
  1. The identity of the specific R-type ALU operation.
  2. The fact that its instruction class is R-type.
  3. The number of pipeline stages in the design.
  4. The address of the next sequential instruction.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A five-stage pipeline runs eight instructions with three inserted stall cycles and no branch losses. At the end of which cycle does the last instruction finish WB?
  1. 11
  2. 15
  3. 12
  4. 19
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A five-stage pipeline has no forwarding and writes the register file before reading it each cycle. Run add x13, x2, x3; or x20, x4, x5; sub x14, x13, x6. The middle instruction is independent. How many stalls and total cycles are needed?
  1. 2 stalls; 9 cycles
  2. 0 stalls; 7 cycles
  3. 1 stall; 9 cycles
  4. 1 stall; 8 cycles
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A single-cycle processor takes 900 ps per instruction. A five-stage version has logic delays 180, 120, 210, 160, 130 ps and 15 ps register overhead. Both execute six independent instructions. What is the pipeline speedup?
  1. 4.00 times
  2. 2.57 times
  3. 2.40 times
  4. 5.00 times
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A load enters IF one cycle before an R-type instruction. If only the R-type instruction skipped MEM and entered WB directly from EX, what conflict would occur?
  1. Both would need data memory in the same cycle.
  2. The load would reach EX after the R-type instruction.
  3. The R-type would read registers before decode.
  4. Both instructions would use WB in the same cycle.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

With full EX forwarding, run ld x21, 0(x25); add x22, x21, x3; or x24, x6, x7; sub x23, x22, x4. The OR is independent, and branch and structural hazards are absent. In which cycle does the final subtract enter EX?
  1. 6
  2. 7
  3. 8
  4. 9
Show answerHide answer

Save this lesson to see this answer.

Set 3: Choose operands and schedule around loads10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What dependence connects sub x11, x2, x3 to the later instruction and x12, x11, x4?
  1. WAR through x11
  2. WAW through x11
  3. RAW through x12
  4. RAW through x11
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

Both EX/MEM and MEM/WB contain ready register-writing results for the same nonzero source register. Which result must the forwarding unit select?
  1. MEM/WB
  2. EX/MEM
  3. The old ID/EX value
  4. The immediate-generator value
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A load in EX produces x19 and the instruction in ID reads x19. What actions implement the needed load-use stall?
  1. Hold PC and IF/ID; zero incoming ID/EX controls.
  2. Hold ID/EX and EX/MEM; advance PC and IF/ID.
  3. Clear IF/ID and hold every older pipeline register.
  4. Advance PC; duplicate the load controls into ID/EX.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

An instruction would write x0 and is immediately followed by add x18, x0, x7. The earlier ALU result is nonzero. What value should the add use for its first operand?
  1. ALU result
  2. The number 18
  3. Zero from x0
  4. Old x18 data
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

With full forwarding, run add x9, x1, x2; add x9, x9, x3; sub x11, x9, x4 with x1 = 6, x2 = 7, x3 = 9, and x4 = 5. What value does the subtract produce, and which pipeline register supplies its x9?
  1. 8; x9 from MEM/WB
  2. 17; x9 from MEM/WB
  3. 17; x9 from EX/MEM
  4. 26; x9 from EX/MEM
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

An add x16, x5, x6 is immediately followed by sd x16, 56(x20). The pipeline forwards store data before ALUSrc selection. How does the store obtain its data?
  1. ForwardB supplies the add result; ALUSrc still selects 56.
  2. ALUSrc must select x16, so the address omits the offset.
  3. The store must wait until x16 has completed register write-back.
  4. ForwardA supplies x16 as the address base instead of x20.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

Consider ld x6, 0(x20); add x7, x6, x8; ld x9, 16(x20); sub x10, x9, x11. No other instruction changes x20, x8, or x11, and both reads are valid. What ordering removes both load-use stalls while preserving results?
  1. add x7; ld x6; ld x9; sub x10
  2. ld x6; ld x9; add x7; sub x10
  3. ld x6; add x7; sub x10; ld x9
  4. ld x9; sub x10; ld x6; add x7
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

The sequence is ld x5, 0(x20); add x6, x5, x7; sd x6, 8(x20); ld x8, 8(x20). Why is moving the final load to second place invalid even if it fills the load-use gap?
  1. It would create a hardware WAR hazard on x8.
  2. It would make both loads write the same register.
  3. It would change the byte offset of the first load.
  4. It would read memory before the store updates it.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

In add x5, x6, x7; sub x6, x8, x9, what register dependence constrains swapping the instructions?
  1. WAR through x6
  2. RAW through x6
  3. WAW through x5
  4. RAW through x8
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

With full forwarding, execute ld x12, 0(x26); add x13, x12, x2; ld x14, 8(x26); sub x15, x14, x13; sd x15, 24(x26). Store data is forwarded before ALUSrc, and there are no other hazards. How many cycles are needed through the final WB slot?
  1. 9
  2. 10
  3. 11
  4. 12
Show answerHide answer

Save this lesson to see this answer.

Set 4: Recover fetch and trace branch history10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

Why does an all-zero RISC-V instruction fail as a replacement nop?
  1. It is an illegal instruction encoding.
  2. It is the encoding of a taken branch.
  3. It is the encoding of a store to address zero.
  4. It is a legal instruction that writes x0 nonzero.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A 2-bit saturating branch counter is in state 0. What state follows another not-taken outcome?
  1. 1
  2. 2
  3. 0
  4. 3
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A taken branch at PC 960 has byte offset −40. It is fetched in cycle 1 and resolved at the end of EX, with predict-not-taken. Which addresses are discarded before the target fetch?
  1. 920 and 924
  2. 964 and 968
  3. 960 and 964
  4. 968 and 972
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A 2-bit saturating counter starts in state 2 and sees outcomes not taken, not taken, taken, taken, not taken. How many predictions are wrong, and what is the final state?
  1. 3 wrong; final state 1
  2. 4 wrong; final state 2
  3. 2 wrong; final state 0
  4. 4 wrong; final state 1
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Fetch predicts a branch taken, but no target address is available until decode. What additional structure can supply a previously seen target during IF?
  1. A direction-history bit
  2. A hazard detection unit
  3. A branch target buffer
  4. A write-back multiplexer
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

With suitable ID forwarding, ld x18, 0(x22) is immediately followed by a branch comparing x18. The branch resolves in ID. Relative to no operand wait, how many cycles must the comparison wait, and why?
  1. 1 cycle; ordinary EX forwarding reaches the comparison in time.
  2. 2 cycles; loaded data must reach the earlier ID comparison.
  3. 0 cycles; reading registers in ID bypasses the memory access.
  4. 3 cycles; a load must finish a separate cycle after WB.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A repeatedly invoked loop branch has five taken outcomes followed by one not-taken exit per invocation. With no aliasing and steady-state training, how do the one-bit and two-bit predictor accuracies compare?
  1. One bit: 4/6; two bits: 5/6
  2. One bit: 5/6; two bits: 5/6
  3. One bit: 4/6; two bits: 4/6
  4. One bit: 5/6; two bits: 6/6
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

An illegal instruction is followed by a younger store while two older arithmetic instructions are still completing. What state must a precise exception present to the handler?
  1. Neither older result present; younger store absent.
  2. Both older results present; younger store present.
  3. Only the younger store present; older results absent.
  4. Both older results present; younger store absent.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A 2-bit counter starts at state 1 before a strictly alternating taken, not-taken pattern. What prediction accuracy does it achieve over the first six outcomes?
  1. 50%
  2. 0%
  3. 67%
  4. 100%
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Two branches share a 2-bit counter initially at state 3. Branch A is taken, B is not taken, A is taken, and B is not taken. How many misses occur, and which branch causes them?
  1. 2 misses, both on B
  2. 1 miss, only on B
  3. 2 misses, one on each
  4. 3 misses, two on B
Show answerHide answer

Save this lesson to see this answer.

Set 5: Combine pipeline timing and hazard costs10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

For the same instruction count, what quantity compares execution time per instruction across processors with different clocks?
  1. CPI ÷ clock period
  2. CPI × clock period
  3. Clock frequency × CPI
  4. Instruction count ÷ CPI
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

In a long instruction stream, 30% are loads and 20% of those have an immediate consumer needing one stall. What is the load-use contribution to CPI?
  1. 0.06
  2. 0.20
  3. 0.30
  4. 0.50
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A long stream has 30% loads, with immediate consumers after 20% of loads, and 20% branches, with 15% mispredicted. Each load-use event costs one cycle and each miss costs three. Costs do not overlap. At 2 GHz, how long do 400 million instructions take?
  1. 0.212 s
  2. 0.290 s
  3. 0.460 s
  4. 0.230 s
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

Two processors run the same long program. A has a 300 ps period, load-use cost 0.08 cycles/instruction, branch fraction 0.20, 10% branch errors, and two-cycle recovery. B has a 240 ps period, the same load-use cost and branch fraction, 20% branch errors, and four-cycle recovery. Costs do not overlap. Which is faster, and by about how much?
  1. A, about 1.13 times
  2. B, about 1.25 times
  3. B, about 1.13 times
  4. A, about 1.11 times
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A single-cycle design uses 800 ps per instruction. A five-stage version uses 200 ps per cycle and executes a short sequence with two stalls and no branch losses. What is the smallest positive instruction count for which the pipeline is strictly faster?
  1. 3 instructions
  2. 2 instructions
  3. 4 instructions
  4. 6 instructions
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A long stream has 25% branches and an unrelated stall cost of 0.05 cycles/instruction. A new predictor raises branch accuracy from 80% to 92%, with the same three-cycle recovery and clock period. What is the execution speedup?
  1. 1.120 times
  2. 1.136 times
  3. 1.081 times
  4. 1.250 times
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A valid scheduling change removes two load-use stalls from a six-instruction five-stage sequence with no other losses. How does total time change at a 250 ps period?
  1. 2000 ps becomes 1500 ps
  2. 2500 ps becomes 2000 ps
  3. 3500 ps becomes 3000 ps
  4. 3000 ps becomes 2500 ps
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

Two designs run a branch-heavy long stream with 30% branches and no other hazards. Predict-not-taken is 60% accurate. X resolves at the end of EX with a 200 ps period; Y resolves at the end of ID with a 220 ps period and no operand stalls. Which has lower time per instruction?
  1. X at 248 ps
  2. Y at 246.4 ps
  3. X at 224 ps
  4. Y at 272.8 ps
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A multiple-issue processor sustains IPC 2. What average CPI corresponds to that rate?
  1. 1
  2. 2
  3. 0.5
  4. 4
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A five-stage processor has baseline load-use cost 0.09 cycles/instruction and 18% branches. Its measured long-run CPI is 1.18. All remaining lost cycles are branch misses with three-cycle recovery. What branch prediction accuracy is implied?
  1. About 95.0%
  2. About 66.7%
  3. About 50.0%
  4. About 83.3%
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

72 Key Terms, each with its definition

A

Aliasing
Aliasing occurs when different branch addresses select the same prediction-table entry and their updates interfere.
A mostly taken branch can disturb the shared entry used by a mostly not-taken branch.
ALU control
ALU control is the four-bit code selecting the specific arithmetic or bitwise operation performed by the ALU in this implementation.
The code 0110 selects subtraction, whereas the related code 0010 selects addition.
ALUOp
ALUOp is a two-bit instruction-class signal that tells ALU control to add, subtract, or decode the R-type function fields.
ALUOp 00 selects address addition even though a load's funct3 describes its memory access size.
ALUSrc
ALUSrc is the control signal selecting the second ALU operand, choosing a register value at 0 or an immediate at 1 in this design.
A store sets ALUSrc to 1 while its rs2 value travels separately toward memory.

B

Branch history table
A branch history table stores small prediction-state entries selected by branch-address bits, allowing recent behavior to guide fetch.
Two branch addresses can select one entry, so the stored state need not belong to one branch alone.
Branch penalty
A branch penalty is the lost-cycle cost of waiting for or recovering from a branch, determined by when correct fetch can resume.
In a five-stage pipeline, end-of-EX resolution loses two fetch slots on a wrong prediction.
Branch target
A branch target is the instruction address reached when a branch is taken, calculated from the branch PC and signed byte offset.
A taken branch at address 600 with offset −20 transfers instruction fetch to address 580.
Branch target buffer
A branch target buffer stores target addresses and supplies a predicted target during fetch before the branch is decoded.
A taken direction guess can use a BTB hit to fetch from the predicted target next cycle.
Bubble
A bubble is an inactive pipeline slot that advances without performing an instruction's state-changing work.
A load-use stall places a bubble in EX while the load proceeds through MEM.

C

Clock edge
A clock edge is the active clock transition at which an edge-triggered state element captures an enabled next value.
At the final edge of an add, rd receives the sum and the PC receives its next address.
Code scheduling
Code scheduling reorders instructions while preserving program results, placing independent work in intervals that would otherwise stall.
Moving an independent load between another load and its consumer can remove a load-use delay.
Combinational element
A combinational element is a circuit whose output depends on its current inputs without retaining a value between clock cycles.
An adder recomputes its output when an input changes, before a register captures the sum.
Control hazard
A control hazard arises when fetch needs the next instruction address before a branch or other control transfer has resolved it.
Predict-not-taken continues sequential fetch while a branch comparison is still in a later stage.
Correlating predictor
A correlating predictor uses recent branch outcomes beyond one branch's local history to help predict a direction.
A decision can become easier to predict when an earlier branch outcome reveals which path was taken.
Critical path
A critical path is the longest required combinational path between state boundaries, limiting how short the clock period can be.
In a single-cycle design, the load path sets the clock even when a shorter add executes.

D

Data hazard
A data hazard occurs when an instruction reaches a point that needs a value before an earlier instruction has made it available.
Without forwarding, a consumer in ID can read a stale value before its producer reaches WB.
Datapath
A datapath is the hardware that holds and transforms values during instruction fetch, register access, computation, and memory access.
An arithmetic instruction sends two register values through the datapath and returns an ALU result.
Don't-care
A don't-care is a control-table value that can be either 0 or 1 because the selected setting cannot affect the instruction's behavior.
MemtoReg can be a don't-care for beq because no register write takes place.
Doubleword
A doubleword is a 64-bit data quantity, occupying 8 bytes and transferred by the RV64 instructions ld and sd.
Doublewords at consecutive aligned addresses might start at 2048, 2056, and 2064.
Dynamic branch prediction
Dynamic branch prediction uses branch outcomes observed during execution to update the state used for future direction guesses.
A loop's repeated taken outcomes train the predictor before the unusual not-taken exit.

E

Effective address
An effective address is the memory address calculated for a load or store by adding the base register value and signed byte offset.
For ld x4, 24(x8) with x8 = 2000, the effective address is 2024.
Effective CPI
Effective CPI is the average cycles per instruction including the additional cycles lost to hazards and branch recovery.
A long single-issue stream with 0.12 lost cycles per instruction has effective CPI 1.12.
EX/MEM
EX/MEM is the pipeline register carrying the execution result, store data, destination number, and pending memory and write-back controls.
An arithmetic result in EX/MEM can be forwarded to the next instruction's EX inputs.
Execution time
Execution time is the elapsed program time calculated from instruction count, average CPI, and the clock period for the processor.
The same instruction count can finish faster at higher CPI if the clock period is sufficiently shorter.

F

Flush
A flush invalidates pipeline work so wrong-path or otherwise discarded instructions cannot change architectural state or raise exceptions.
A flushed store cannot perform its memory write after a taken branch redirects fetch.
ForwardA
ForwardA controls the rs1 forwarding mux: 00 chooses ID/EX, 10 chooses EX/MEM, and 01 chooses MEM/WB in this design.
A recent update to a load's base register can be forwarded into its address calculation.
ForwardB
ForwardB controls the rs2 forwarding mux, supplying a register operand and the store-data path before ALUSrc selection.
A store can forward its data even while ALUSrc selects an immediate for address calculation.
Forwarding
Forwarding routes a produced value from a pipeline register directly to a later instruction's input before architectural write-back.
An adjacent subtract can receive an add's new result from EX/MEM without stalling.
Forwarding unit
A forwarding unit compares source and destination numbers and checks write permission to select the correct ready operand source.
It excludes rd = x0 because a computed result cannot change that register's zero value.
Function field
A function field supplies instruction bits that distinguish operations sharing an opcode, such as funct3 and funct7 for R-type instructions.
For add and sub with funct3 000, instruction bit 30 selects which arithmetic operation runs.

H

Hardwired control
Hardwired control is a combinational logic implementation that translates instruction bits into datapath selections and write enables.
The load opcode produces a control row that selects an immediate and enables memory read and register write.
Hazard detection unit
A hazard detection unit identifies cases that need a stall, including a load in EX whose destination is read by the instruction in ID.
A precise source-use check avoids treating I-type immediate bits as a second source register.

I

ID/EX
ID/EX is the register carrying decoded operands, register numbers, immediate, function information, and controls into execute.
EX combines the carried ALUOp with the carried function bits to select an R-type operation.
IF/ID
IF/ID is the pipeline register between instruction fetch and decode, retaining the fetched instruction and its associated PC.
During a load-use stall, holding IF/ID lets the waiting consumer be decoded again.
Immediate generator
An immediate generator reconstructs the immediate bits for an instruction format and extends the signed value to the register width.
For a store, ImmGen combines bits from two parts of the instruction to recover its offset.
IPC
IPC, or instructions per cycle, measures average instruction completion per clock cycle and is the reciprocal of average CPI.
Multiple issue can complete enough independent work to achieve IPC greater than one.

L

Latency
Latency is the elapsed time for one instruction to pass from entry to completion, including all the stages it traverses.
Five 270 ps stage intervals give one instruction 1350 ps of pipeline latency.
Load-use hazard
A load-use hazard occurs when an instruction immediately after a load needs its result before the load finishes reading data memory.
The consumer waits one cycle with EX forwarding, then takes the data from MEM/WB.

M

MEM/WB
MEM/WB is the pipeline register holding memory data, the ALU result, destination number, and controls needed for register write-back.
A stalled load consumer can take its operand from the loaded value held in MEM/WB.
Memory dependence
A memory dependence links accesses whose order matters because they can access overlapping bytes and at least one access writes them.
A load cannot move before a store that may supply the bytes it is supposed to read.
MemRead
MemRead is the control signal that requests data-memory read access, allowing a load to retrieve data from its effective address.
The instruction memory fetch is separate from the MemRead-controlled access to data memory.
MemtoReg
MemtoReg selects the value sent to register write-back: the ALU result at 0 or data-memory output at 1 in this design.
A load with MemtoReg mistakenly set to 0 would write its address instead of the loaded data.
MemWrite
MemWrite is the control signal enabling a data-memory write, so the store value is saved at the effective address at the clock edge.
An arithmetic instruction must keep MemWrite at 0 to prevent unintended memory changes.
Multiple issue
Multiple issue starts more than one instruction in a clock cycle, using compiler or hardware choices to find work that can overlap.
Static multiple issue relies on compiler groups; dynamic issue lets hardware select instructions.
Multiple-cycle pipeline diagram
A multiple-cycle pipeline diagram shows instructions as rows and cycles as columns, marking each instruction's stage over time.
Reading down cycle 5 can show one instruction in each of the five pipeline stages.
Multiplexer
A multiplexer is a circuit that forwards one of several data inputs to one output according to a selection signal.
The write-back multiplexer selects memory data for a load and the ALU result for arithmetic.

P

PCSrc
PCSrc selects the next PC; for the single-cycle equality-branch design it is the logical AND of Branch and the ALU Zero flag.
An add producing zero still takes the sequential path because its Branch signal is 0.
Pipeline drain
Pipeline drain is the final interval in which previously fetched instructions finish after the sequence's last instruction enters.
The last instruction still needs ID, EX, MEM, and WB after its fetch cycle.
Pipeline fill
Pipeline fill is the initial interval during which successive instructions enter and not all stages yet contain useful work.
The first instruction reaches WB in cycle 5, after the initial stages have filled.
Pipeline register
A pipeline register captures the data and control an instruction needs after a stage, keeping them available during the following cycle.
ID/EX retains a decoded instruction's operands while IF/ID receives a younger instruction.
Pipeline-register overhead
Pipeline-register overhead is the timing cost of storing and delivering stage values, added to the slowest stage's logic delay.
A 250 ps limiting stage with 20 ps register overhead requires a 270 ps period.
Pipelining
Pipelining overlaps instructions by dividing their execution into stages, allowing different instructions to occupy different stages at once.
While one instruction accesses data memory, a younger instruction can calculate in the ALU.
Precise exception
A precise exception leaves all older instructions complete and excludes the faulting instruction's normal effects and all younger effects.
The handler receives a saved faulting PC and cause alongside the program-order state boundary.
Program counter
The program counter is a state register that holds the address used to fetch the current instruction from instruction memory.
After an ordinary 4-byte instruction at address 720, the program counter advances to 724.

R

Read-after-write dependence
A read-after-write dependence links a later register read to an earlier write that produces the value required by that read.
In an add followed by a subtract reading its result, the subtract depends on the add.
Register file
A register file is the collection of architectural registers, with read and write ports that access registers by their numbers.
The two read ports can supply the values of x6 and x7 to one arithmetic instruction.
RegWrite
RegWrite is the enable signal that permits an instruction's selected result to be stored in the register file at the clock edge.
A store keeps RegWrite at 0, even though it reads register values for its address and data.
Return address stack
A return address stack tracks procedure-return addresses so fetch can predict a return's target before normal execution resolves it.
Nested calls naturally pair return targets with the reverse order of the calls.

S

Saturating counter
A saturating counter changes toward its upper or lower limit without wrapping around, providing persistent prediction confidence.
A taken outcome leaves a 2-bit counter at 3 when it is already strongly taken.
Sign extension
Sign extension widens a signed binary value by copying its sign bit into the added high-order positions, preserving its value.
A negative 12-bit load offset remains negative after ImmGen extends it to the RV64 register width.
Stall
A stall delays selected pipeline work for a cycle so an instruction can wait for an operand or other required condition.
During a load-use stall, younger work waits while the load advances toward producing the value.
State element
A state element is a hardware component that retains a value across cycles and updates it through a controlled write.
The PC keeps the current instruction address while the next address is being calculated.
Static prediction
Static prediction guesses branch direction using a fixed rule that does not learn from outcomes during program execution.
Backward-taken, forward-not-taken uses the direction of the branch displacement as its clue.
Structural hazard
A structural hazard occurs when instructions need the same limited hardware resource during the same clock cycle.
A single-port memory cannot serve a load's MEM access and another instruction's fetch simultaneously.
Superscalar processor
A superscalar processor uses hardware to select and issue multiple instructions in a cycle, subject to available resources and dependences.
Branch misses and chains of dependent values limit how much parallel instruction work remains useful.

T

Throughput
Throughput is the number of instructions completed per unit of time, which rises when useful instruction work overlaps.
A full hazard-free pipeline can complete an instruction each cycle after its initial fill.
Tournament predictor
A tournament predictor chooses between prediction mechanisms, using their observed success to decide which to trust for a branch.
One predictor can suit one branch pattern while another performs better for a different pattern.
Two-level decoding
Two-level decoding separates main instruction-class control from the smaller decoder that selects the specific ALU operation.
The main control gives add and sub ALUOp 10; function-bit decoding then distinguishes them.

W

Write-after-read dependence
A write-after-read dependence occurs when a later instruction writes a register that an earlier instruction must first read.
Moving the later writer above that reader can change the program even though the pipeline is in order.
Write-after-write dependence
A write-after-write dependence occurs when two instructions write the same register, making their program-order write sequence significant.
Exchanging two writes to x12 can change the value that subsequent instructions observe.
Write-back
Write-back is the transfer of an instruction's selected result into its destination register when the register write is enabled.
A load writes back the memory value, while an add writes back its ALU result.

Z

Zero flag
The Zero flag is an ALU output that equals 1 when the calculated result is zero, allowing subtraction to test register equality.
Equal operands make a branch subtraction produce Zero = 1, so Branch can select the target.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started