π Lecture 18 β Pipelining
π Overview: This lecture covers the SRC exception processing mechanism, introducing how interrupts and exceptions are handled in the SRC architecture. It then introduces the fundamental concept of pipelining, explaining its stages, benefits, complications like data dependencies and branch delays, and the design requirements for implementing a pipelined processor.
ποΈ Topics Covered
The lecture begins by detailing the SRC exception processing mechanism, including the behavioral and structural RTL for interrupt handling and the additional instructions that support interrupts. It then provides a comprehensive introduction to pipelining, describing its five stages (instruction fetch, decode/operand fetch, ALU operation, memory access, register write) and the concepts of latency and throughput. The lecture concludes by discussing the complications related to pipelining such as data dependence, branch delay, and load delay, as well as the design requirements for a pipelined implementation.
π Lecture Summary
SRC Exception Processing Mechanism
The lecture explains how the SRC architecture handles exceptions, specifically interrupts, which are external events that require immediate processor attention. The mechanism modifies the normal instruction fetch cycle.
When an interrupt request (ireq) occurs and the interrupt enable (IE) flag is set, the processor performs the following actions:
- Saves the current PC (Program Counter) into the IPC (Interrupt PC) register.
- Loads the II (Interrupt Information) register with information from
Isrc_info. - Clears the
IEflag to disable further interrupts during the handler. - Loads the PC with the address from
Ivect(Interrupt Vector), which points to the interrupt service routine. - Sends an interrupt acknowledge signal (
iack).
The lecture also introduces new instructions to support interrupts:
π Definition β svi (Save Interrupt Vectors and Information): This instruction saves the contents of the II and IPC registers into general-purpose registers ra and rb, respectively.
π Example: svi r1, r2 β R[1]<15..0> β II<15..0>, R[2] β IPC
π Definition β ri (Restore Interrupt Vectors and Information): This instruction restores the II and IPC registers from general-purpose registers ra and rb, respectively.
π Example: ri r1, r2 β II<15..0> β R[1]<15..0>, IPC β R[2]
π Definition β een (Exception Enable): This instruction sets the IE flag to 1, enabling exception processing.
π Definition β edi (Exception Disable): This instruction clears the IE flag to 0, disabling exception processing.
π Definition β rfi (Return from Interrupt): This instruction restores the PC from the IPC register and re-enables interrupts by setting IE to 1, effectively returning to the interrupted program.
π‘ Why this matters: This mechanism allows the processor to respond to urgent external events, save the current state, execute a special handler, and then seamlessly return to the original program.
The lecture then combines the RTL for reset and exception into a single, unified Instruction_Fetch state. It includes:
- Normal Fetch:
Run & !Rst & !(ireq & IE) - Soft Reset:
Run & Rstβ Clears internal state, setsIEto 0, and resets PC to 0. - Hard Reset:
!Run & Strtβ SetsRunto 1, resets PC and all registers to 0. - Interrupt:
Run & !Rst & (ireq & IE)β Performs the interrupt handling sequence as described.
Introduction to Pipelining
Pipelining is a technique of overlapping the execution of multiple instructions in time. A pipelined processor issues a new instruction before the previous one completes, leading to a higher overall throughput (instructions per second). This results in more efficient use of the processor's functional units.
The lecture presents a five-stage pipeline as an example:
-
Instruction Fetch: The instruction is fetched from instruction memory and loaded into a temporary pipeline register.
-
Instruction Decode/Operand Fetch: The operands for the instruction are fetched from the register file. For example, for
add r1, r2, r3, the values inr2andr3are read. -
ALU Operation: The fetched operands are processed by the ALU (Arithmetic Logic Unit), also known as the ALSU (Arithmetic Logic Shift Unit). The result is stored in a temporary register. For memory access instructions (load/store), the ALU calculates the effective memory address in this stage.
-
Memory Access: For a
loadinstruction, a memory read is performed. For astoreinstruction, a memory write is performed. If the instruction requires no memory access, this stage is bypassed. -
Register Write: The result is written back to the destination register.
π Definition β Latency: The time required to process a single instruction from start to finish. π Definition β Throughput: The number of instructions processed per second. π Definition β (Key Insight): Pipelining does NOT lower the latency of a single instruction, but it significantly increases the throughput of the processor. A key limitation is that the performance gain in a pipeline is limited by the slowest stage in the pipeline.
Complications Related to Pipelining
Several complications arise from overlapping instruction execution.
Data dependence occurs when an instruction in one pipeline stage uses the result of an instruction in a previous stage. For example:
S1: add r3, r2, r1
S2: sub r4, r5, r3
Here, S2 needs the value of r3 that S1 is calculating. Executing S2 before S1 completes would use an incorrect value. Two methods resolve this:
-
Pipeline Stalls: Special
nop(no operation) instructions are inserted to block subsequent instructions from entering the pipeline until the dependent instruction has completed. For the example, stalls are inserted betweenS1andS2. -
Data Forwarding: Special hardware is added to the processor to transfer the result of a pipeline stage directly to another stage that needs it, without waiting for the result to be written to the register file. In the example, the result from
S1's execute stage can be forwarded directly toS2's decode stage.
Branch delay is a complication where the processor cannot easily predict whether a branch will be taken before the branch condition is evaluated. If a branch is treated like a normal instruction, subsequent instructions are loaded into the pipeline. If the branch is taken, these instructions must be flushed from the pipeline and their effects undone. An alternative is to introduce stalls after the branch instruction.
Load delay is a problem that arises when a value is loaded from memory and then immediately used in the next instruction. For example:
S1: load r2, 34(r1)
S2: add r5, r2, r3
The correct value of r2 is only available after S1's memory access stage. Even with data forwarding, a stall must be placed between S1 and S2 to give the data time to arrive from memory.
Pipeline Design Requirements
For a pipelined design to work correctly, several requirements must be met:
- The program must produce the same results as on a non-pipelined machine.
- Instruction and data memories should be separate to allow instruction fetch while data is being read/written.
- There should be a single data path to maintain program execution order.
- A three-port register file is needed to read two operands and write a result in parallel.
- Data must be latched between pipeline stages using temporary registers.
- ALU operations must be quick to avoid lengthening the clock cycle for the entire pipeline.
The lecture outlines three steps for designing a pipelined implementation:
-
Adapting the instructions to pipelined execution: The instruction set must have clear, definite phases. A register-register architecture is often adopted to avoid complex instructions that mix memory and register operands, which are difficult to pipeline.
-
Designing the pipelined data path: The data path specifies the sequence of steps (like instruction fetch, register read, execute) for each instruction. It is defined in terms of registers placed between the stages and becomes more complex with forwarding mechanisms.
-
Generating control signals: Digital logic is needed to generate the control signals that regulate the flow of data through the data path.
β Key Takeaways
From this lecture, a student must understand the behavioral RTL for interrupt handling in the SRC, including the role of IPC, II, IE, and the special instructions svi, ri, een, edi, and rfi. The core concept of pipelining as an overlapping technique that increases throughput without reducing latency must be grasped. The five standard pipeline stages are critical for analysis. Students must be able to identify and explain complications like data dependence (and its solutions: stalls and forwarding), branch delay, and load delay. Finally, the fundamental design requirements for a pipelineβsuch as separate memories, a three-port register file, and latching between stagesβare essential for exam comprehension.
π§ Quick Revision Questions
- What are the two key events that can cause a deviation from the normal SRC instruction fetch cycle, and what are their respective behavioral RTL sequences?
- Explain the difference between latency and throughput in the context of a pipelined processor. Does pipelining reduce latency?
- Name the five stages of the example pipeline discussed in the lecture and describe the primary operation performed in each stage.
- What is a data dependency? Describe the two primary methods for resolving a data dependency in a pipelined processor.
- Why is a three-port register file a design requirement for a pipelined processor? What feature does it enable?
π Lecture 19 β Pipelined SRC
π Overview: This lecture introduces a five-stage pipelined version of the Simple RISC Computer (SRC). It explains how different categories of SRC instructions (ALU, Load/Store, and Branch) are adapted for pipelined execution and defines the control signals needed to manage the pipeline stages.
ποΈ Topics Covered
This lecture covers the five-stage pipeline structure of the SRC (Instruction Fetch, Instruction Decode/Operand Fetch, ALU Operation, Memory Access, Register Write), the adaptation of ALU, Load/Store, and Branch instructions for pipeline execution, the inter-stage pipeline registers (IR2-IR5, PC2, X3, Y3, Z4-Z5, MD3), and the control signals (alu, load, store, rl, dsp, branch, cond) used to manage multiplexers across different pipeline stages.
π Lecture Summary
Pipelined Version of the SRC
The SRC uses a five-stage pipeline composed of: 1) Instruction Fetch, 2) Instruction Decode/Operand Fetch, 3) ALU Operation, 4) Memory Access, and 5) Register Write. Between each stage, several pipeline registers hold intermediate values. After instruction fetch, the instruction is stored in IR2 and the incremented program counter in PC2. After register reads, the first operand goes to X3, the second to Y3, and the opcode and ra are held in IR3. For store instructions, MD3 holds the value to be stored. After ALU execution, the result is stored in Z4 and the opcode/ra in IR4. During write-back, Z5 holds the value for register storage, while opcode and ra pass to IR5.
Adapting SRC Instructions for Pipelined Execution
1. ALU Instructions
ALU instructions take the form op-code ra, rb, rc or op-code ra, rb, constant. Temporary registers X3 and Y3 hold operand values between pipeline stages. X3 receives the operand value from the register file. Y3 receives either a register value or a constant from the instruction. The ALU function is determined by decoding the op-code bits. The ALU result is stored in Z4, then written to the destination register during the register write-back stage. There is no activity in the memory access stage for ALU instructions.
2. Load/Store Instructions
Load/Store instructions take the form op-code ra, constant(rb). The instruction is loaded into IR2 and the incremented PC into PC2. In the next stage, X3 receives either the value from PC2 (for relative addressing) or the value from rb (for displacement addressing). Y3 receives either C1 (relative) or c2 (displacement). For store instructions, execution completes after memory access and writing to memory. For load instructions, execution completes when the loaded value is transferred back to the register file.
3. Branch Instructions Branch instructions involve calculating the target address and evaluating a condition. The condition is evaluated based on the c2 field of the IR and the value in R[rc]. If the condition is true, the PC is loaded with the value in R[rb]; otherwise, the PC is incremented by 4 as usual.
Control Signals for the Pipelined SRC
Control signals are defined by grouping similar op-codes: alu, load, store, rl (relative load), dsp (displacement), branch, and cond. In most cases, these signals are used in the same stage where they are generated. If not, a number after the signal indicates the stage of generation.
Control Signals for Different Pipeline Stages
The Mp1 signal controls the input to the PC. If branch and cond are not activated, the PC is incremented by 4. If both are activated, the value of R1 is copied into the PC.
The Mp2 multiplexer decides which registers are read from the register file. If the store signal is activated, R[rb] from the instruction bits is read (for memory storage). Otherwise, R[rc] is read.
The Mp3 multiplexer decides which registers are read for operand 1 (X3). If either rl or branch is activated, the updated value of PC2 is transferred to X3. If dsp or alu is activated, the value of R[ra] is transferred to X3.
The Mp4 multiplexer selects an input for Y3.
The MP5 multiplexer decides which value is written back to the register file. If the load signal is activated, data from memory is transferred to Z5. If load is not activated, data from Z4 (the ALU result) is transferred to Z5, which is then written back to the register file.
β Key Takeaways
The SRC pipeline has five distinct stages with dedicated inter-stage registers (IR2-IR5, PC2, X3, Y3, Z4-Z5, MD3) that hold values as instructions progress. ALU instructions are the simplest, requiring no memory access stage activity. Load/Store instructions use either relative or displacement addressing modes, with X3 and Y3 receiving different inputs accordingly. Branch instructions compute the target address and evaluate the condition using R[rc] to decide whether to load a new PC value or increment by 4. The control signals (alu, load, store, rl, dsp, branch, cond) drive the multiplexers Mp1 through Mp5 to manage data flow through the pipeline, with the signal name often indicating the stage where it is generated.
π§ Quick Revision Questions
- What are the five stages of the SRC pipeline?
- For a Load instruction, how are X3 and Y3 loaded differently for relative vs. displacement addressing modes?
- What determines whether the PC is loaded with R[rb] or incremented by 4 during a Branch instruction?
- What is the role of the Mp5 multiplexer, and what two sources can it select for writing back to the register file?
- When a number is appended to a control signal name (e.g., signal3), what does that number indicate?
π Lecture 20 β Hazards in Pipelining
π Overview: This lecture examines the fundamental challenges that arise when executing instructions in parallel within a pipelined processor. It covers the three main categories of pipeline hazards (branch, structural, and data hazards), explains how data dependence distances affect instruction scheduling, and presents both hardware and compiler-based solutions for hazard detection and correction, including data forwarding and pipeline stalls.
ποΈ Topics Covered
The lecture provides structural RTL for all pipeline stages (fetch, decode, ALU, memory access, write back), explains instruction propagation through the pipeline with a specific code example, classifies pipeline hazards into three categories, introduces the concept of data dependence distance, discusses compiler solutions to hazards, and presents SRC hazard detection and correction mechanisms including pipeline stalls, data forwarding, and their corresponding RTL expressions.
π Lecture Summary
Structural RTL for Pipeline Stages
The Register Transfer Language (RTL) for each pipeline phase is defined precisely. In Instruction Fetch, the instruction is loaded from memory and the program counter is incremented: IR2 β M[PC]; PC2 β PC+4. During Instruction Decode & Operand Fetch, multiple operations occur simultaneously including loading operands into X3 and Y3, setting the MD3 register for store operations, and calculating the next PC value for branches. The ALU operation stage computes results in Z4 based on the instruction type (I-s, brl, or Alu). During Memory access, data is read from or written to memory based on the instruction type (load, store, branch, or ALU). Finally, in Write back, the result in Z5 is written to the register file: regwrite5: (R[ra] β Z5).
Instruction Propagation Through the Pipeline
π Pipeline Propagation: The process by which instructions move through successive pipeline stages (fetch, decode, execute, memory access, write back) each clock cycle.
π Example: Consider the following SRC code executing through the pipeline:
200: add r1, r2, r3
204: ld r5, [4(r7)]
208: br r6
212: str r4, 56
- Clock Cycle 1: Add enters fetch stage. PC increments from 200 to 204.
- Clock Cycle 2: Add moves to decode; operands fetched to X3 and Y3.
ldenters fetch. PC becomes 208. - Clock Cycle 3: Add executes; result written to Z4.
lddecodes; displacement address calculated.brenters fetch. PC becomes 212. - Clock Cycle 4: Add result passes through memory stage to Z5.
ldexecutes; address calculated in Z4.brin decode; since branch is always true, PC is modified.strenters fetch. PC becomes 216. - Clock Cycle 5: Add completes; result written to r1.
ldaccesses data memory; result stored in Z5.brpropagates through execute.strdecodes; operands fetched. Instruction at address 400 enters fetch. PC becomes 404.
π‘ Why this matters: Understanding instruction propagation helps visualize how instructions overlap in time and reveals where dependencies create hazards.
Pipeline Hazards
A hazard occurs when an instruction depends on the result of a previous instruction that is not yet complete. There are three categories:
π Branch Hazard: The instruction following a branch is always executed whether or not the branch is takenβthis is called the branch delay slot. Compilers may insert a nop instruction in this slot. Branch delays cannot be avoided by forwarding schemes.
π Structural Hazard: Occurs when attempting to access the same resource in different ways simultaneously. This happens when the hardware is insufficient to implement pipelining properly, e.g., when the machine does not support separate data and instruction memories.
π Data Hazard: Occurs when an instruction attempts to access data that has not yet been updated by a previous instruction. The most common type is RAW (Read After Write) .
π Example of RAW data hazard:
200: add r2, r3, r4 ; writes r2 in clock cycle 5
204: sub r7, r2, r6 ; reads r2 - cannot proceed beyond stage 2 until add completes
Register r2 is written in clock cycle 5, so the sub instruction cannot proceed beyond stage 2 until the add instruction leaves the pipeline.
Data Dependence Distance
Data Dependence Distance is the minimum spacing required between two data-dependent instructions to avoid hazard. Without forwarding, this minimum distance is four. The load instruction has a minimum distance of two from all other instructions except branch. Branch delays cannot be removed even with forwarding.
Compiler Solution to Hazards
The compiler can detect hazards by analyzing instruction sequences and dependencies. It can insert bubbles (nop instructions) between two instructions that form a hazard, or it can reorder instructions to put sufficient distance between dependent instructions. However, this compiler solution is complex, expensive, and less efficient compared to hardware solutions.
SRC Hazard Detection and Correction
The SRC uses a hazard detection unit that resolves hazards using either pipeline stalls or data forwarding.
Pipeline Stalls: When using pipeline stalls, nop instructions are placed between dependent instructions. The logic: if opcode in stage 2 and 3 are both ALU, and if ra in stage 3 equals rb or rc in stage 2, then a pause signal is issued to insert a bubble between stage 3 and 2. Similar logic applies for hazards between stage 2 and 4, and stage 4 and 5.
Data Forwarding: By adding data forwarding hardware, stalls can be completely eliminated for ALU instructions. The testing and forwarding circuits employ wider IRs to store data needed in later stages. The logic: if the ALU is activated for both stages 3 and 5 and ra in stage 5 equals rb in stage 3, then Z5 (the currently loaded or calculated result) is directly forwarded to X3. Similarly, if both are ALU operations and the instruction in stage 3 does not employ immediate operands, then Z5 is transferred to Y3.
RTL for Hazard Detection and Pipeline Stall
π Data hazard detection RTL for detecting hazards between stage 2 and 3:
alu3 & alu2 & ((ra3=rb2) ~ ((ra3=rc2) & !imm2)): (pause2, pause1, op3β0)
Meaning: If opcode in stage 2 and 3 are both ALU, and if ra in stage 3 is the same as rb or rc in stage 2, issue a pause signal to insert a bubble between stage 3 and 2.
Complete RTL for detecting hazards among ALU instructions:
- Stage 2 and 3:
alu3 & alu2 & ((ra3=rb2) ~ ((ra3=rc2) & !imm2)): (pause2, pause1, op3β0) - Stage 2 and 4:
alu4 & alu2 & ((ra4=rb2) ~ ((ra4=rc2) & !imm2)): (pause2, pause1, op3β0) - Stage 2 and 5:
alu5 & alu2 & ((ra5=rb2) ~ ((ra5=rc2) & !imm2)): (pause2, pause1, op3β0)
β Key Takeaways
Students must remember that pipeline hazards arise from instruction dependencies and are classified into three types: branch (caused by the branch delay slot), structural (caused by insufficient hardware resources), and data (caused by RAW dependencies). Data dependence distance is criticalβwithout forwarding, the minimum spacing between dependent instructions is four, and branch delays cannot be eliminated even with forwarding. The two hardware solutions are pipeline stalls (inserting bubbles) and data forwarding (directing results from later stages back to earlier ones), with the SRC employing both through explicit RTL expressions that detect register matches between pipeline stages. The compiler solution, while possible through instruction reordering or nop insertion, is less efficient than hardware-based approaches.
π§ Quick Revision Questions
- What are the three categories of pipeline hazards, and what causes each type?
- How does the instruction propagation through a 5-stage pipeline work for a sequence containing add, load, branch, and store instructions?
- What is data dependence distance, and why is the load instruction's distance different from other instructions?
- In the SRC hazard detection RTL, what does the expression
alu3 & alu2 & ((ra3=rb2) ~ ((ra3=rc2) & !imm2))mean in plain language? - How does data forwarding eliminate stalls for ALU instructions, and what are the specific forwarding paths described in the lecture?
π Lecture 21 β Instruction Level Parallelism
π Overview: This lecture explores two primary methods for increasing a processor's throughput: increasing clock speed and increasing parallel instruction execution. It introduces instruction-level parallelism (ILP) through superscalar and VLIW architectures, contrasting them with standard pipelining and detailing the hardware and design philosophies behind each approach.
ποΈ Topics Covered
The lecture begins with data forwarding hardware and its RTL representation for ALU instructions. It then introduces instruction-level parallelism and the two main approaches to achieve it: superscalar architecture and VLIW architecture. The differences between pipelining and instruction-level parallelism are outlined, followed by detailed explanations of superscalar architecture, superscalar design, and VLIW architecture, including examples of superscalar processors.
π Lecture Summary
Data Forwarding Hardware
The concept of data forwarding was introduced in the previous lecture. This hardware resolves data hazards by forwarding results from a later pipeline stage directly to an earlier stage that needs the data, rather than waiting for the write-back stage. The lecture provides RTL (Register Transfer Language) for data forwarding specifically for ALU instructions.
π Definition β Data Forwarding: A hardware technique that resolves data hazards by passing the result of an instruction from a later pipeline stage directly to an earlier stage that requires it as an operand, bypassing the register file.
π Formula: Dependence RTL for Stage 3-5: alu5&alu3:((ra5=rb3):XβZ5, (ra5=rc3)&!imm3: Y β Z5); β This means when the ALU stage 5 result is ready and stage 3 needs a register, if the register address from stage 5 (ra5) matches the B register address from stage 3 (rb3), forward the Z5 result to the X input. Similarly, if ra5 matches rc3 and the instruction is not immediate, forward Z5 to the Y input.
π Example: For Stage 3-4 forwarding: alu4&alu3:((ra4=rb3):XβZ4, (ra4=rc3)&!imm3: Y β Z4); β This checks if instructions in ALU stage 4 and stage 3 have a register dependency. If the destination register of the instruction in stage 4 (ra4) equals the source register of the instruction in stage 3 (rb3), the result from stage 4 (Z4) is forwarded to the ALU input X of stage 3.
Instruction-Level Parallelism
Instruction-Level Parallelism (ILP) refers to the degree to which the instructions of a program can be executed in parallel. There are two ways to increase the number of instructions executed in a given time by a processor: by increasing the clock speed, and by increasing the number of instructions that can execute in parallel.
Increasing the clock speed is an IC design issue and depends on advancements in chip technology, which the computer architect or logic designer cannot manipulate. However, the architect can increase the number of instructions processed per unit time. In pipelining, instructions are executed in a staggered fashion. Taking this concept further, multiple data paths allow multiple pipelines to execute simultaneously. The two main categories of these parallel instruction processors are superscalar and VLIW (Very Long Instruction Word).
π Definition β Superscalar Architecture: A scalar processor that can issue multiple instructions simultaneously is said to be superscalar.
π Definition β VLIW Architecture: A VLIW processor is based on a very long instruction word. VLIW relies on instruction scheduling by the compiler, which forms instruction packets that can run in parallel without dependencies.
Difference between Pipelining and Instruction-Level Parallelism
| Pipelining | Instruction-Level Parallelism |
|---|---|
| Single functional unit | Multiple functional units |
| Instructions are issued sequentially | Instructions are issued in parallel |
| Throughput increased by overlapping the instruction execution | Instructions are not overlapped but executed in parallel in multiple functional units |
| Very little extra hardware required to implement pipelining | Multiple functional units within the CPU are required |
Superscalar Architecture
A superscalar machine has one or more IUs (Integer Units), FPUs (Floating Point Units), and BPUs (Branch Prediction Units). It divides instructions into three classes: Integer, Floating point, and Branch prediction. The general operation involves fetching multiple instructions, decoding some of their portion to determine the class, and dispatching them to the corresponding functional unit. The superscalar design uses multiple pipelines to implement instruction level parallelism.
The Branch Prediction Unit (BPU) calculates the branch target address ahead of time to save CPU cycles. Branch instructions are routed from the queue to the BPU where the target address is calculated and supplied when required without any stalls. The BPU also starts executing branch instructions by speculating and discards the results if the prediction turns out to be wrong.
Superscalar Design
The philosophy behind a superscalar design is to prefetch and decode as many instructions as possible before execution, start several branch instruction streams speculatively on the basis of this decoding, and finally discard all but the correct stream of execution. This architecture uses multiple instruction issues and techniques such as branch prediction and speculative instruction execution, where it speculates on whether a particular branch will be taken and then continues to execute it and the following instructions. The results are not written back to the registers until the branch decision is confirmed. Most superscalar architectures contain a reorder buffer, which acts like an intermediary between the processor and the register file. All results are written onto the reorder buffer, and when the speculated course of action is confirmed, the reorder buffer is committed to the register file.
π‘ Why this matters: The reorder buffer is a critical hardware structure that allows superscalar processors to execute instructions out-of-order (for efficiency) while still committing their results in the original program order, ensuring correct program execution despite speculative execution.
Examples of superscalar processors include the PowerPC 601, Intel P6, and DEC Alpha 21164.
VLIW Architecture
VLIW stands for "Very Long Instruction Word," typically 64 or 128 bits wide. The longer instruction word carries information to route data to register files and execution units. The execution-order decisions are made at compile time, unlike the superscalar design where decisions are made at run time. Branch instructions are not handled very efficiently in this architecture. The VLIW compiler makes use of techniques such as loop unrolling and code reordering to minimize dependencies and the occurrence of branch instructions.
β Key Takeaways
Instruction-level parallelism is the ability to execute multiple instructions simultaneously, distinct from pipelining which overlaps sequential instruction stages. Two primary architectural approaches achieve ILP: superscalar (hardware-intensive, run-time decision making) and VLIW (compiler-intensive, compile-time decision making). Superscalar processors rely on complex hardware like reorder buffers for speculative execution and branch prediction units to manage branch hazards, whereas VLIW architectures shift the complexity to the compiler for static scheduling. Understanding the trade-off between hardware and compiler involvement is central to modern processor design.
π§ Quick Revision Questions
- What are the two main ways to increase a processor's throughput?
- How does instruction-level parallelism differ from standard pipelining?
- What is the key difference between how a superscalar and a VLIW processor handle instruction scheduling?
- What is the role of a reorder buffer in a superscalar processor?
- Why does the VLIW architecture rely heavily on the compiler?
π Lecture 22 β Microprogramming
π Overview: This lecture introduces microprogramming as an alternative method for designing the control unit in a computer processor. It explains the structure and working of a microcoded controller, compares it with hardwired control, and covers concepts like microprogram memory, horizontal and vertical microcode schemes, and the microcoded 1-bus SRC design.
ποΈ Topics Covered
The lecture covers the concept of microprogramming and microcoded control units, the working of a general microcoded controller including its components like micro-PC and microprogram memory, and the generation of microcode for sample instructions. It also discusses the layout of microprogram memory, branching and looping in microcode, and compares horizontal and vertical microcode schemes. Finally, it presents the microcoded 1-bus SRC design and the SRC microprogram controller.
π Lecture Summary
Microprogramming
Microprogramming (or microcoding) is an alternative way to design the control unit. In a microprogrammed control unit, all the control signals needed at a certain time are stored together in a control word, which is called a microinstruction. A collection of microinstructions is called a microprogram. These microprograms generate the sequence of necessary control signals required to process an instruction and are stored in a memory called the control store. The microcoded control unit is itself a small stored program computer consisting of a Micro-PC, a Microprogram memory, and a Microinstruction word.
Working of a general microcoded controller
A microcoded controller works like a small general-purpose computer. Its operation is a cycle of three steps:
- Fetch a micro-instruction and increment the micro-PC.
- Execute the instruction present in the micro-IR (Micro-Instruction Register).
- Fetch the next instruction and so on.
The micro-PC is controlled by the microprogram controller. The value of the micro-PC depends on a 4-to-1 MUX. The source may be the incremented micro-PC value, a calculated branch value, or a value derived by decoding an opcode for an instruction. The microprogram memory writes the control word at the chosen address into the microinstruction register.
Fields in the micro instruction A control word has three main fields:
- C Bits: These form the control signal field.
- M Bits: These form the branch address field.
- B Bits: These form the branch control field.
Loading the micro-PC The micro-PC can be loaded from one of four possible sources:
- Simple increment: Steps sequentially from microinstruction to microinstruction.
- Lookup table: A lookup table maps the opcode field to the starting address of the microcode routine that generates control signals.
- External source: Initializes micro-PC to begin an operation, e.g., interrupt service, reset.
- Branch addresses: Jumps anywhere in the microprogram memory on the basis of conditional or unconditional branch.
Microprogram Memory
This is a small, fast memory that contains micro routines for all the instructions in the ISA. The micro-PC supplies the address, and the microprogram memory returns the control word stored at that address. It is much faster and smaller than a typical main memory.
Generating Microcode for Some Sample Instructions
The control word for an instruction is used to generate the equivalent microcode sequence. Each step in RTL (Register Transfer Language) corresponds to a microinstruction executed to generate the control signals. Each bit in the control words in the microprogram memory represents a control signal, and its value (0 or 1) decides whether the signal is to be activated.
π Definition β RTL: A register transfer language is used to describe the sequence of micro-operations (register transfers) that occur in a computer system.
Example: Control Signals for the sub Instruction
For the SRC processor, the first three addresses (e.g., 100 to 102) represent microcode for instruction fetch. The last three addresses (e.g., 203 to 205) represent microcode for the sub instruction.
- At address 100, the control signals
PCout,LMAR,LC, andINC4are activated. This corresponds to the structural RTL description of theT0clock during the instruction fetch phase. - The content of address 101 corresponds to
T1, and the content of address 102 corresponds toT2.
Microprogram Controller functions: Branching and looping The microprogram controller controls the sequence of the flow of microinstructions. Its inputs are from the branch control fields specified in the microcode word. Its output controls the 4-to-1 multiplexer inside the microcoded control unit. It implements conditional execution and both conditional and unconditional branches. If a branch instruction is encountered within the microprogram, hardwired logic selects the branch address as the source of the micro-PC using the 4-to-1 MUX.
4-1 Multiplexer The multiplexer supplies one of four possible values to the micro-PC:
- The incremented value of the micro-PC (used for the normal sequential flow).
- The opcode from the instruction (used to set the micro-PC when a microroutine is initially loaded).
- An external address (used to reset the microprogram controller).
- A branch address (set when a branch microinstruction is encountered).
How to form a branch A branch can be implemented by choosing one alternative from a list of conditions and one from a list of address sources. This scheme provides flexibility, as any combination of conditions and addresses can be formed.
π Formula: Branch Condition β Next Address
- Condition: Unconditional, Branch if Zero, Branch if Negative, Branch if Overflow.
- Address: Opcode, Next Sequential, Branch Address from Microinstruction.
Similarity between microcode and high level programs
Any high-level construct, such as if-else, while, or repeat, can be implemented using microcode. A variety of microcode compilers are available that allow easier programming in microcode. This similarity simplifies the task of controller design.
Horizontal and vertical microcode schemes
In horizontal microcode schemes, there are no intermediate decoders. The control word bits are directly connected to their destination. Each bit in the control word is directly connected to some control signal, and the total number of bits in the control word equals the total number of control signals in the CPU.
Vertical microcode schemes employ an extra level of decoding to reduce the control word width. From an n-bit control word, we may have 2^n bit signal values. However, a completely vertical scheme is not feasible because of the high degree of fan-out.
π‘ Why this matters: Horizontal microcode is very fast but requires a wide control word, while vertical microcode reduces the width at the cost of speed due to the extra decoding delay.
Microcoded 1-bus SRC design
In the SRC (Simple RISC Computer), the bits from the opcode in the instruction register are decoded to fetch the address of the suitable microroutine from the microprogram memory. The microprogram controller for the SRC microcoded control unit employs the logic for handling exceptions and the reset process. Since the SRC does not have any condition codes, it uses the CON and n signals instead of the N and Z flags to control branches for instructions like "branch if equal to zero" or "branch if less than".
Microcode for some SRC instructions
Assume the first control word for an instruction fetch is at address 300. The RTL for this step is MAR <- PC; C <- PC+4. To facilitate these actions, the PCout signal bit and the LMAR signal bit are set to one, so the value of the PC may be written to the internal processor bus and written onto the MAR. The instructions at addresses 300, 301, and 302 form the microcode for the instruction fetch. In this sequence, the value of PC is incremented, the old value of PC is sent to memory, and the instruction from that address is loaded into the MBR (Memory Buffer Register). Then, the opcode of the fetched instruction is used to invoke the appropriate microroutine.
π Definition β CON and n signals: Control signals used in the SRC microcontroller to handle conditional branches, replacing traditional N and Z condition code flags.
Alternative approaches to microcoding Several other approaches exist in microcoding:
- Bit ORing
- Nanocoding
- Writable Microprogram Memory
- Subroutines in Microprogramming
β Key Takeaways
The most critical concepts from this lecture are that microprogramming implements the control unit as a small stored-program computer using a control store of microinstructions, with each microinstruction generating control signals for one clock cycle. The micro-PC sequencing is managed by a 4-to-1 multiplexer with options for incremental, opcode-based, external, or branch address loading. Horizontal microcode is wide and fast with no decoding, while vertical microcode is narrower and slower due to extra decoding. The SRC processor uses a microcoded controller with the CON signal for branching instead of condition code flags, and the instruction fetch phase is a multi-step microcode routine that loads the MBR and invokes the correct microroutine.
π§ Quick Revision Questions
- What are the three main components of a microcoded control unit?
- What are the three fields (C, M, B bits) in a microinstruction word, and what is the purpose of each?
- How does the 4-to-1 multiplexer in the microcoded controller select the next value for the micro-PC?
- What is the key difference between horizontal and vertical microcode schemes in terms of control word structure and decoding?
- In the SRC microprogrammed controller, why are the
CONandnsignals used instead ofNandZflags?