π Lecture 5 β Instruction Set Principles (Encoding instructions and MIPS Instruction format)
π Overview: This lecture explores the principles of instruction set encoding, including different instruction word lengths and formats. It details the essential elements of computer instructions, compares variable, fixed, and hybrid length formats, and introduces the MIPS instruction set architecture with its specific formats (R-type, I-type, J-type) and operations.
ποΈ Topics Covered
The lecture begins with a recap of instruction set taxonomy from Lecture 4, then covers instruction set encoding, including essential elements like op-code, operand locations, and next instruction address. It classifies instruction word types as variable, fixed, or hybrid length, and explores the hybrid length taxonomy (4-address through 0-address). A detailed comparison of these formats is provided using code size and memory access parameters. Finally, the MIPS ISA is introduced, covering its characteristics and the R-type, I-type, and J-type instruction word formats with examples.
π Lecture Summary
Recap: Lecture 4
The lecture begins with a quick review. The three pillars of Computer Architecture are Hardware, Software, and Instruction Set. The Instruction Set acts as an interface between hardware and software. The taxonomy includes Stack, Accumulator, and General Purpose Register architectures. Operand types include Integer, FP, and Character, with sizes like Half word, word, and double word. Operations are classified as arithmetic, data transfer, control, and support. Addressing modes include immediate, register, direct (absolute), and indirect, with special modes like auto-increment, auto-decrement, and scaled. Control instruction addressing covers branch, jump, and procedure call/return.
Instruction set Encoding
The essential elements of computer instructions are four-fold. First, the type of operation is encoded in the operation code, or op-code, field (e.g., add, mov). Second, the place to find the source operand(s) can be CPU registers, memory cells, I/O locations, or part of the instruction itself. Third, the place to store the result is similarly in CPU registers, memory cells, or I/O locations. Fourth, the place to find the next instruction is either the address of the next instruction in sequence (default) or the address of the instruction at the branch target location.
Instruction Word Types are categorized into three main formats. Variable Length format specifies the operation in one field (op-code) and can support any number of operands. It generally generates the smallest code representation as unused fields need not be included. Typical examples are VAX and Intel 80x86.
The Fixed Length Format always has the same number of operands, and addressing modes are specified in the op-code. It generally generates the largest code size. Typical examples are Alpha, MIPS, PowerPC, and SPARC.
The Third Alternative: Hybrid Length specifies multiple formats by the op-code, with one or two fields for addressing mode. It generally generates the optimum code size. Typical examples include IBM 360/370, MIPS16, and TI-TMS320c54x.
Hybrid Length Taxonomy
This taxonomy is based on the number of address fields. 4-address instructions specify the two source operands, the destination operand, and the address of the next instruction. 3-address instructions specify addresses for both operands as well as the result. 2-address instructions overwrite one operand with the result, so one field serves two purposes. 1-address instructions use a dedicated CPU register, the accumulator, to hold one operand and the result, while the address of the other operand is specified. 0-address instructions use a stack to hold both operands and the result; operations are performed between the value on the top of the stack (TOS) and the second value on the stack (SOS), with the result stored on the TOS.
π Definition β TOS: Top of Stack π Definition β SOS: Second value on the stack
π Example: Evaluate the expression: F = (B + C)*D β E, using 0-address through 3-address format.
| 0-Address | 1-Address | 2-Address | 3-Address |
|---|---|---|---|
| PUSH B | LDA B | LOAD F, B | ADD F, B, C |
| PUSH C | ADD C | ADD F, C | MUL F, F, D |
| ADD | MUL D | MUL F, D | SUB F, F, E |
| PUSH D | SUB E | SUB F, E | |
| MUL | STA F | ||
| PUSH E | |||
| SUB | |||
| POP F | |||
| Number of Instructions: 8 | 5 | 4 | 3 |
π Example: Using different instruction formats, write pseudo-code to evaluate the following expression: Z = 4(A+B) β 16(C+58). Your code should not change the source operands.
| 3-Address | 2-Address | 1-Address | 0-Address |
|---|---|---|---|
| ADD x, A, B | LOAD y, B | LDA C | PUSH C |
| MUL y, x, 4 | MUL y, 4 | ADDA 58 | PUSH 58 |
| ADD r, C, 58 | LOAD s, C | MULA 16 | ADD |
| MUL s, r, 16 | ADD s, 58 | STA S | PUSH 16 |
| SUB Z, y, s | MUL s, 16 | LDA A | MUL |
| SUB y, s | ADDA B | PUSH A | |
| STORE Z, y | MULA 4 | PUSH B | |
| SUBA s | ADD | ||
| STA Z | PUSH 4 | ||
| MUL | |||
| SUB | |||
| POP Z |
Comparison of instruction formats
A comparison is made assuming: a single byte for the op code, a 16 Mbyte memory address space, a single addressable memory unit of a byte, operands of 24 bits, and an 8-bit data bus. The parameters compared are code size and number of memory accesses.
The 4-address instruction has a code size of 1(op) + 3(src1) + 3(src2) + 3(dest) + 3(next) = 13 bytes. The number of bytes accessed from memory is 13 (fetch) + 6 (source operands) + 3 (store destination) = 22 bytes.
The 3-address instruction has a code size of 1 + 3 + 3 + 3 = 10 bytes. The number of bytes accessed from memory is 10 + 6 + 3 = 19 bytes.
The 2-address instruction has a code size of 1 + 3 + 3 = 7 bytes. The number of bytes accessed from memory is 7 + 6 + 3 = 16 bytes.
The 1-address instruction has a code size of 1 + 3 = 4 bytes. The number of bytes accessed from memory is 4 + 3 (source operand fetch) + 0 (destination operand) = 7 bytes.
The 0-address instruction has a code size of 1 byte. The number of bytes accessed from memory is 1 + 6 (source operands) + 3 (store destination) = 10 bytes.
Result Summary:
| Instruction Format | Code size | Number of memory bytes |
|---|---|---|
| 4-address instruction | 13 | 22 |
| 3-address instruction | 10 | 19 |
| 2-address instruction | 7 | 16 |
| 1-address instruction | 4 | 7 |
| 0-address instruction | 1 | 10 |
RISC and MIPS ISA
RISC and MIPS is a fixed length, 64-bit LOAD/STORE Architecture. It contains 32 GPR (General Purpose Registers), each of 32-bit. It supports 3-address, reg-reg arithmetic instructions; displacement instructions with address offset 12-16 bits; immediate data 8-bit and 16-bit; register indirect addressing; data size 8-, 16-, 32-, and 64-bit integer; and 64-bit IEEE 754 floating point. Instructions include data transfer (load, store, register-register move), simple arithmetic (add, subtract, shift), compare (equal, not-equal, less), and branch (PC-relative, jump, call/return). It is designed for pipelining efficiency.
π‘ Why this matters: The trade-offs between code size and memory accesses in instruction formats directly impact program size and execution speed, and understanding the fixed-length format of MIPS is crucial for appreciating its pipelining advantages.
MIPS Instruction Word format
Recap: MIPS types and size of operands: Operand types are Integer, Single-precision floating point, and Character. Sizes are Character (8-bit), Half word (16-bit), Single precision FP or Word (32-bit), Double precision FP or double word (64-bit).
Register-Register (R-Type) format has an op-code of 000000. Rs and Rt are source operand registers, Rd is the result carrying register, Sht is the number of bit-shift, and Func is the ALU function to encode the data path operation. Execution: Rd <- Rs func Rt.
π Definition β R-Type: A MIPS instruction format where all operands are in registers. π Format: Op-code (6), Rs (5), Rt (5), Rd (5), Sht (5), Func (6) -> total 32 bits.
π Example Encoding MIPS64 Arithmetic Instruction: DADD R1, R2, R3 (Add word signed) means Reg[R1] β Reg[R2] + Reg[R3].
π Example Shift Instruction: DSLL R1, R2, # 30 (Shift Left Logical) means Reg[R1] β Reg[R2] << 30.
Register-Immediate (I-Type) format uses Rt as the destination field for immediate data instructions (Rt <- Rs op immediate). This same format is used for Load/Store instructions: for Load (Rt <- Mem[immediate + [Rs]]), for Store (Mem[immediate + [Rs]] <- Rt).
π Definition β I-Type: A MIPS instruction format used for operations with an immediate operand or for load/store instructions. π Format: Op-code (6), Rs (5), Rt (5), Immediate (16) -> total 32 bits.
π Example Immediate Arithmetic Instruction: DADDIU R1, R2, # 30 (Add unsigned Immediate) means Reg[R1] β Reg[R2] + Reg[R3].
π Example Load/Store Instruction: LW R1, 30(R2) (Load word) means Reg[R1] β Mem[30+Reg[R2]]. SW R1, 30(R2) (Store word) means Mem[30+Reg[R2]] β Reg[R1].
Branch/Jump Register format is used for conditional branch instructions (e.g., BEQZ tests Rs for zero; BNE compares Rs and Rt) and for jump register instructions (JR and JALR).
π Example Branch/Jump Register Instruction: BEQZ R4, name (Branch equal zero) means If Reg[R4] = 0 then PC β name. BNE R4, R3, name means If Reg[R4]!=Reg[R3] then PC <- name. JR R4 (jump register) means PC β Reg[R4]. JALR R4 (Jump and Link Register) means Reg[R31] β PC+4; PC β Reg[R4].
Jump / Call format uses a 26-bit offset that is shifted 2 bits and then replaces the lower 28 bits of the PC. Jump and Link (JAL) places the return address in R31 for use in returning from a procedure.
π Definition β J-Type: A MIPS instruction format used for jump and jump-and-link instructions. π Format: Op-code (6), Address offset (26) -> total 32 bits.
π Example Jump/Call Instruction: J name (Jump) means PC[36..63] β name. JAL R4 (Jump and Link) means Reg[R31] β PC+4; PC[36..63] β name.
β Key Takeaways
A student must understand that instruction set encoding determines the trade-off between code size and number of memory accesses, with 1-address (accumulator) format requiring the fewest memory bytes per instruction. The three main instruction word types are variable, fixed, and hybrid length, with MIPS being a prime example of a fixed-length, 64-bit LOAD/STORE architecture. The MIPS ISA uses three primary formats: R-type (register-register), I-type (immediate and load/store), and J-type (jump/call), each with a specific bit layout. For R-type, op-code 000000 requires the Func field to specify the operation, while I-type uses the immediate field for data or address offset. Finally, the ability to hand-translate arithmetic expressions into MIPS assembly instructions (e.g., DADD, DADDIU, LW, SW) for different address formats is a core skill.
π§ Quick Revision Questions
- What are the four essential elements that must be encoded in a machine language instruction?
- Compare and contrast variable-length and fixed-length instruction formats, giving one advantage of each.
- For a given expression, why does a 0-address (stack) format require more instructions than a 3-address format?
- In the MIPS R-type instruction format, what is the purpose of the
funcfield, and why is it necessary when the op-code is000000? - Describe the three MIPS instruction formats (R-type, I-type, J-type) and provide the specific purpose of the
Rtfield in each.
π Lecture 6 β Instruction Set Principles (ISA Performance Analysis, Fallacies and Pitfalls)
π Overview: This lecture concludes the discussion on Instruction Set Architecture by examining ISA performance, the role of compilers, and media/signal processing operations. It covers DSP multimedia operations, compiler optimization techniques, and the historical evolution of architectures, while also addressing key fallacies and pitfalls in ISA design.
ποΈ Topics Covered
The lecture begins with a recap of Lecture 5 covering instruction encoding, word length, and MIPS format. It then explores media and signal processing operands including 3D data types, SIMD operations, and DSP issues like saturating add/subtract, result rounding, and multiply-accumulate operations. The role of compilers in ISA performance is examined through optimization classifications and data allocation areas. Finally, the lecture presents a historical perspective on architecture evolution and concludes with a comprehensive summary of ISA principles.
π Lecture Summary
Recap: Lecture 5
The recap covers essential elements of computer instruction words including operand types, source/destination locations, and next instruction placement. Instruction word length categories include variable length, fixed length, and hybrid formats. The hybrid length taxonomy uses 4, 3, 2, 1, and 0 address formats. In comparison, the minimum number of memory bytes is required in the 1-address (accumulator) format, while the maximum is required for the 4-address format. The MIPS Instruction word format is a RISC fixed-length, 64-bit LOAD/STORE architecture supporting 8-, 16-, 32-, and 64-bit operands, with R-type, I-type, and J-type formats for arithmetic/logic, data transfer, and control flow operations.
π Definition β Hybrid Format: A combination of variable and fixed length instruction encoding that uses different numbers of address fields (from 0 to 4) to balance code density and instruction complexity.
π Formula: Memory bytes required: 1-address format (minimum) < 4-address format (maximum)
Media and Signal Processing Operands
Graphic applications deal with 2D and 3D images. The 3D data type is called a vertex, which has a 4-component structure: x-coordinate, y-coordinate, z-coordinate, and w-coordinate. Three vertices specify a graphic primitive like a triangle, and the fourth (w) helps with color and hidden surfaces. Vertex values are usually 32-bit floating-point values. DSP adds fixed point to the data types, with the binary point placed just to the right of the sign bit.
A triangle is visible when depicted as filled with pixels. Pixels are typically 32-bits, usually consisting of four 8-bit channels: R (red), G (green), B (blue), and A (transparency).
π‘ Why this matters: Understanding 3D data types is critical for graphics processing because modern multimedia applications rely heavily on vertex and pixel manipulation.
π Definition β Vertex: A 4-component data structure (x, y, z, w) used in 3D graphics to specify points in space, with the fourth component aiding color and hidden surface calculations.
Media and Signal Processing Operations
Data for multimedia operations is usually much narrower than the 64-bit data word of modern processors. Thus, 64-bit may be partitioned into four 16-bit data values so that the 64-bit ALU can perform four 16-bit operations (like add) in a single clock cycle. Extra hardware is added to prevent the 'CARRY' between the four 16-bit partitions of the 64-bit ALU. These operations are called Single-Instruction Multiple-Data (SIMD) or vector operations.
Most graphic multimedia applications use 32-bit floating-point operations, allowing a single instruction to launch two 32-bit operations on operands found side-by-side in double precision registers. All SIMD instructions are fixed-width operations performing multiple narrow operations on either 64-bit or 128-bit ALUs. The narrow operations are shown as B (byte), H (half word), W (word), and 8B (double word).
π Definition β SIMD: Single-Instruction Multiple-Data operations where a single instruction performs the same operation on multiple data elements simultaneously by partitioning a wider ALU.
Digital Signal Processing Issues
Three main DSP issues are identified:
- Saturating Add/Subtract: When the result is too large and overflow occurs
- Result Rounding: Choosing from IEEE 754 mode algorithms
- Multiply Accumulate (MAC): Vector and matrix dot product operations
Saturating Add/Sub: DSP cannot ignore overflow results as it may miss an event, so it uses saturating arithmetic. If the result is too large to be represented, it is set to the largest representable number based on the sign of the number. Result Rounding: IEEE 754 has several algorithms to round the wider accumulator into a narrower one; DSPs select the appropriate mode. Multiply-Accumulate (MAC): MAC operations are key to dot product operations of vector and matrix multiply, which need to accumulate a series of products.
π Definition β Saturating Arithmetic: An arithmetic mode where overflow results are clamped to the maximum or minimum representable value instead of wrapping around, commonly used in DSP to prevent missed events.
π Example: In saturating addition for an 8-bit signed number (range -128 to 127), if adding 100 + 40 = 140 (overflow), the result is clamped to 127 instead of wrapping to -116.
ISA Performance β Role of Compiler
The interaction of compiler and high-level languages significantly affects how a program uses an ISA. Optimizations performed by compilers are classified as:
- High-level optimization: Often done on the source with output fed to later optimization passes
- Local Optimization: Done within a straight-line code fragment (basic block)
- Global Optimization: Extends optimization across branches
- Register Allocation: Associates registers with operands
- Processor-dependent optimization: Uses specific architecture features
Two important questions regarding compiler technology impact are:
- How are variables allocated?
- How many registers are needed to allocate variables appropriately?
These questions are addressed using three areas where high-level language allocates data:
- Local Variable area β Stack: Used to allocate local variables; grows or shrinks on procedure call/return. Objects are primarily scalar (single variables) addressed by stack-pointer. Register allocation is much more effective for stack-allocated objects.
- Global Data Area: Used to allocate statically declared objects like global variables and constants. Objects are mostly arrays and other aggregate data structures. Register allocation is relatively less effective for global variables. Global variables are aliased (multiple ways to address them), making it illegal to put them in registers.
- Dynamic Object Allocation: Heap: Used to allocate objects that do not adhere to stack. Objects are accessed with pointers but are not scalars. Most heap variables are aliased, so register allocation is almost impossible.
ISA Performance β MIPS Floating-point Operations
The instructions manipulate floating-point registers and indicate whether the operation is single or double precision:
- MOV.S: Copies a single precision register to another of the same type
- MOV.D: Copies a double precision register to another of the same type
To get greater performance for graphic routines, MIPS64 offers Paired-Single Instructions. These instructions perform two 32-bit floating-point operations on each half of the 64-bit floating-point register. Examples include ADD.PS, SUB.PS, MUL.PS, and DIV.PS.
π Definition β Paired-Single Instructions: MIPS64 instructions that perform two simultaneous 32-bit floating-point operations on a 64-bit register, doubling throughput for graphics applications.
Putting it All Together
The historical evolution of architectures is traced:
- Earliest architectures: Limited instruction sets by hardware technology of that time
- 1960s: Stack architecture became popular, viewed as a good match for high-level languages
- 1970s: Main concern was reducing software cost, producing high-level architectures like VAX
- 1980s: Return to simpler architecture due to sophisticated compiler technology
- 1990s: New architectures introduced with:
- Address size doubling (32-bit to 64-bit)
- Optimization of conditional branches via conditional execution (e.g., conditional move)
- Optimization of cache performance via pre-fetch
- Multimedia support
- Faster floating-point instructions
- Long Instruction Word
Concluding the Instruction Set Principles
The three pillars of computer architecture are Hardware, Software, and Instruction Set. The instruction set is the interface between hardware and software.
The taxonomy of instruction sets includes Stack, Accumulator, and General Purpose Register. Types and sizes of operands include types like Integer, FP, and Character, with sizes of Half word, Word, and Double word.
Operations are classified as Arithmetic, Data transfer, Control, and Support. Operand addressing modes include Immediate, Register, Direct (Absolute), and Indirect. Classification of indirect addressing includes Register, Indexed, Relative (with displacement), and Memory. Special addressing modes include Auto-increment, Auto-decrement, and Scaled. Control instruction addressing modes include Branch, Jump, and Procedure call/return.
During the 1950s-1960s, computer architecture focused on computer arithmetic. From 1970s to mid-1980s, the focus was instruction set design. In the 1990s, focus became multi-dimensional, emphasizing CPU design, memory system, I/O system, and multi-processor systems based on quantitative principles.
β Key Takeaways
The instruction set architecture serves as the critical interface between hardware and software, and its design fundamentally impacts computer performance. For modern multimedia applications, SIMD operations and DSP-specific features like saturating arithmetic and MAC operations are essential for efficient processing. Compiler technology plays a pivotal role in ISA performance through various optimization levels and data allocation strategies (stack, global, heap). The historical evolution shows a cycle from simple to complex architectures and back to simplicity, driven by compiler capabilities. Understanding instruction encoding formats, addressing modes, and the relationship between instruction count and CPI is crucial for evaluating and comparing different ISA designs.
π§ Quick Revision Questions
- What are the three areas of data allocation in high-level languages, and which one is most suitable for register allocation?
- Explain the difference between saturating arithmetic and standard overflow handling in DSP operations.
- How does a paired-single instruction in MIPS64 achieve higher performance for graphics routines?
- What are the five classifications of compiler optimizations, and where is each applied?
- Which instruction format (0, 1, 2, 3, or 4 address) requires the minimum number of memory bytes, and why?
π Lecture 7 β Computer Hardware Design (Single Cycle Data path and Control Design)
π Overview: This lecture reviews the fundamental hardware design of a computer, focusing on the sub-systems of the CPU (datapath and control). It introduces the concept of a Single Cycle Datapath, where each instruction is executed in one clock cycle, and details the RTL micro-operations for different datapath implementations (Unibus, 2-bus, 3-bus). Understanding these concepts is crucial for designing a functional processor, as the datapath and control directly impact performance metrics like CPI and clock cycle time.
ποΈ Topics Covered
The lecture begins with a recap of instruction set principles, including encoding, multimedia/ DSP operations, and ISA performance. It then reviews the basic building blocks of a computer and the sub-systems of the CPU (datapath and control). The core of the lecture covers the processor design steps, followed by a detailed explanation of datapath implementations (Unibus, 2-bus, 3-bus) and their RTL micro-operations. It concludes with an introduction to Single Cycle Datapath design, its timing, and the control signals required for executing instructions like Add.
π Lecture Summary
Recap: Instruction Set Principles
The lecture starts by revisiting the three pillars of computer architecture. It covers instruction encoding, which can be fixed, variable, or hybrid in word length, using the MIPS format as an example. It also reviews Multimedia and Digital Signal Processor (DSP) operations, such as saturating add/subtract, result rounding, and the multiply accumulate operation. Finally, it discusses Instruction Set Performance, emphasizing the role of the compiler and how it affects the use of the ISA by a program, specifically in allocating variables to the stack (local variables), global data area, and heap (dynamic objects).
Basics of Hardware Design
The computer's basic building blocks are the Central Processing Unit (CPU), Memory, Input/Output (Peripherals), and Buses. The CPU itself has two main sub-systems: the Datapath, which facilitates the transfer of information, and the Control, which generates signals to control the sequence of steps and direct data flow. Design is a creative process involving top-down decomposition of complex functions into primitive ones and bottom-up composition of primitive building blocks into complex assemblies.
Processor Design Steps
The design process follows these steps: 1) Design the Instruction Set Architecture (ISA). 2) Use RTL (Register Transfer Language) to describe the processor's static and dynamic behavior. 3) Select a suitable datapath implementation. 4) Map the behavioral RTL of each instruction to structural RTL, based on the chosen implementation and synchronous clocking signals. 5) Prepare a list of control signals for each structural RTL statement. 6) Develop logic circuits for the control signals. 7) Tie the datapath and control together. Key goals are to minimize the amount of control hardware and development time. Each instruction is performed in two phases: Instruction Fetch and Instruction Execute, which are divided into micro-operations completed in fixed time intervals.
Datapath Implementations
The datapath is the arithmetic organ of the stored-program computer. It consists of registers, internal buses, arithmetic units, and shifters, and can be implemented as a Unibus, 2-bus, or 3-bus structure.
π Definition β Datapath: The arithmetic organ of the Von-Neumannβs stored-program organization that facilitates the transfer of information from one part (register/memory/IO) to the other.
Unibus Datapath Structure: Has a single internal bus connecting a register file (32 registers of 32-bit each), an arithmetic and shifter unit, and other registers (PC, IR, MAR, MBR, A, C). Each register has a load control line and tri-state buffers for bus access.
RTL micro-operations of Unibus structure:
- Instruction Fetch: T0 MAR β PC, C β PC + 4 T1 MBR β M[MAR], PC β C T2 IR β MBR
- R-type Arithmetic/Logical (Add/Sub/And/OR ra, rb, rc): T3 A β R[rb] T4 C β A op R[rc] T5 R[ra] β C
- Load/Store (ld/st ra, c2(rb)): T3 A β ((rb = 0): 0, (rb β 0): R[rb]) T4 C β A + (sign extended and shifted c2) T5 MAR β C T6 MBR β M[MAR] (load); MBR β R[ra] (store) T7 R[ra] β MBR (load); M[MAR] β MBR (store)
2-bus Datapath Structure: Contains two internal buses (in-bus and out-bus). The ALU output connects directly to the in-bus, speeding up execution.
- R-type Arithmetic/Logical (Add/Sub/And/OR ra, rb, rc): T3 A β R[rb] T4 R[ra] β A op R[rc] (Completed in 2 steps, instead of 3)
3-bus Datapath Structure: Contains three internal buses (A-bus, B-bus, C-bus). The register file has two read ports (to A and B buses) and one write port (from C bus). This allows an R-type instruction to be completed in a single execute step.
- Example for
sub ra, rb, rc: R[ra] β R[rb] - R[rc] is done in one step.
π Formula: Execution time (ET) = IC x CPI X T β The total time to run a program is the number of instructions (IC) multiplied by the clock cycles per instruction (CPI) multiplied by the clock cycle time (T). The datapath implementation directly affects CPI and T.
Single Cycle Datapath
In a Single Cycle Datapath, an instruction's fetch and execute phases are completed in a single clock cycle. The cycle length is constant, but the number of internal micro-operations may vary. The timing step generator returns to T0 on cycle completion.
π Definition β Single Cycle Datapath: A datapath where an instruction is fetched and executed in one clock cycle, so CPI = 1.
Worst Case Timing (Load): The load instruction uses the most time resources. The clock cycle must be long enough to accommodate all the delays in this path:
- Clock-to-Q time for the PC.
- Instruction Memory access time.
- Control Logic delay (generating signals like ALUctr), Register File access (to put Rs on busA), and Sign Extension (for immediate). We assume register file access takes longer than sign extension.
- ALU delay for address calculation.
- Data Memory access time.
- Setup time for writing result (busW) into the register file at the next clock tick.
Single Cycle Memory Structure: Since the instruction and data memory addresses are available simultaneously, a structural hazard occurs. To solve this, the memory unit is partitioned into Instruction Memory and Data Memory.
Single Cycle Datapath during Add: For an Add instruction, the Rs and Rt fields are used to read registers onto busA and busB. The ALUctr signals are set to "Add". With MemtoReg set to 0, the ALU output is placed on busW. RegWr is set to 1 to write the result to the register file. ALUSrc is 0 (using busB), so ExtOp is a "don't care". MemWr is set to 0.
Instruction Fetch Unit at the End of Add: For instructions other than Branch and Jump, the Branch and Jump control signals are set to 0. This causes the output of the first adder (PC + 4) to be selected via the multiplexers and placed into the PC, which is updated at the next clock tick. The PC does not have a Write Enable signal as it is updated every cycle.
β Key Takeaways
A student must understand the fundamental CPU subsystems: the datapath (for data transfer and computation) and the control unit (which generates signals to orchestrate operations). The processor design process starts with the ISA and uses RTL to formally describe instruction behavior. The choice of datapath (Unibus, 2-bus, 3-bus) directly impacts the number of micro-operations and, consequently, the CPI. The Single Cycle datapath achieves a CPI of 1 but has a long clock cycle, determined by the worst-case path (the Load instruction). Finally, the control signals (e.g., RegWr, ALUSrc, MemtoReg, MemWr) are the key to routing data and controlling functional units.
π§ Quick Revision Questions
- What are the two main sub-systems of a CPU, and what is the primary function of each?
- Describe the key difference between a Unibus and a 3-bus datapath in terms of how many clock cycles are needed for an R-type instruction.
- Why is the memory unit partitioned into "Instruction Memory" and "Data Memory" in a single-cycle datapath?
- Explain why the Load instruction determines the minimum clock cycle time for a single-cycle processor.
- For an R-type
Addinstruction, what must be the values of the control signalsRegWr,ALUSrc, andMemtoReg?
π Lecture 8 β Computer Hardware Design (Multi Cycle Datapath and Control Design)
π Overview: This lecture critically reviews the single-cycle datapath design, demonstrating how control signals are set for various instruction types (R-type, I-type, J-type). It then introduces the motivation for multi-cycle design, showing how hardware utilization can be improved by reusing components across multiple clock cycles instead of requiring a single long cycle.
ποΈ Topics Covered
This lecture begins with a recap of the single-cycle datapath and its control signals, using detailed examples for the Add, Or Immediate, Load, Store, and Branch instructions. It then analyzes hardware utilization inefficiencies, introduces the concept of local decoding for the ALU control, presents the multi-cycle datapath architecture, discusses controller FSM specification and sequencer-based control, and concludes with an introduction to exceptions including interrupts, traps, and precise interrupts.
π Lecture Summary
Recap: Single cycle datapath and control signals
The lecture begins by reviewing the 3-bus based single-cycle MIPS datapath, where every instruction completes in one clock cycle. The key micro-operations of the fetch phase are: MBR β M[PC]; PC β PC+4; IR β MBR. The execute phase involves: ID (instruction decode), operand read, execution, memory access, and writeback. Control signals are generated by a main controller that decodes the instruction's op field. The lecture then examines how control signals are set for different instruction types, starting with R-type instructions like Add and Subtract.
Example of Single Cycle Design
Control Signals for Add rd, rs, rt (R[rd] β R[rs] + R[rt])
During execution of an Add instruction, the Rs and Rt fields are fed to the Ra and Rb address ports of the register file, placing register contents on busA and busB. The ALUctr signals are set to Add, and MemtoReg is set to 0 so the ALU output goes onto busW. RegWr is set to 1 to write the result to the register file. ExtOp is a donβt care because ALUSrc is 0 (using busB). MemWr must be 0, and Branch and Jump must be 0.
π Definition β Control Signal: A binary signal generated by the control unit that selects the operation of a datapath component (e.g., MUX selection, ALU operation, register write enable).
For the Instruction Fetch Unit at the end of Add, PC is updated to PC+4. Both Branch and Jump signals are 0, so the output of the first adder (PC+4) is selected through the two 2-to-1 MUXes and placed into the Program Counter register. The PC updates every cycle (no Write Enable signal).
The Single Cycle Datapath during Or Immediate (R[rt] β R[rs] OR ZeroExt[imm16])
The OR Immediate instruction ORs the content of Rs with the Zero Extended immediate field and writes the result to Rt. The Rs field goes to Ra. ExtOp is set to 0 for Zero Extend. ALUSrc is set to 1 to select the immediate field over busB. ALUctr is set to OR. The key difference from R-type: RegDst must be 0 because the destination is specified by the Rt field (not Rd). RegWr is 1.
π Example: For instruction ORI $t0, $s1, 100:
- Op field = ORI, Rs = $s1, Rt = $t0, Imm16 = 100
- ExtOp = 0 (zero extend 100 to 0x00000064)
- Rs ($s1) value placed on busA
- ALUSrc = 1, so ALU input B = 0x00000064
- ALUctr = OR β output = R[$s1] OR 0x00000064
- RegDst = 0, so write address is Rt ($t0)
- MemtoReg = 0, so result from ALU goes to busW
- RegWr = 1 β R[$t0] = result
The Single Cycle Datapath during Load (R[rt] β Data Memory[R[rs] + SignExt[imm16]])
The Load instruction reads the contents of Rs and adds it to the Sign Extended immediate field to form the data memory address. ExtOp is set to 1 (SignExtend). ALUSrc = 1, ALUctr = Add. The effective address is sent to Data Memory, and the read data goes to busW via MemtoReg = 1. RegDst = 0 (destination is Rt). RegWr = 1. MemWr = 0.
The Single Cycle Datapath during Store
Store is the inverse of Load. It reads Rs for the base address and Rt for the data to be stored. ExtOp = 1 (SignExtend), ALUSrc = 1, ALUctr = Add (for address calculation). The Rt field is fed to the Rb port of the register file to place the store data on busB. MemWr = 1 to write to Data Memory. Store does not update the register file, so RegWr = 0, making RegDst and MemtoReg donβt cares.
The Single Cycle Datapath during Branch (if R[rs] == R[rt] then PC = PC + 4 + SignExt[imm16]*4)
The Branch instruction subtracts Rs from Rt to set the Zero condition. Rs goes to Ra, Rt goes to Rb. ALUSrc = 0 (using busB). ALUctr = Subtract. Zero bit is set to 1 if the difference is 0 (branch taken). RegWr = 0, MemWr = 0. Branch signal is set to 1. In the Instruction Fetch Unit, when Branch = 1 and Zero = 1, the output of the second adder (PC+4 + SignExt[imm16]*4) is selected and written to PC. If Zero = 0, PC+4 is selected (boring case).
A Summary of the Control Signals
A table summarizes control signals for seven instructions: Add, Subtract, Ori, Lw, Sw, Branch on Equal, and Jump. The first two (Add, Sub) are R-type instructions, requiring both the op field and func field to be identified. Ori, Lw, Sw, and Branch are I-type, and Jump is J-type β these are identified by the op field alone. Note that Add and Sub have identical control signals except the last row (ALUctr), which motivates the concept of local decoding.
Local Decoding Concept
Instead of the Main Control generating ALUctr signals directly, it generates a set of signals called ALUop. For I-type and J-type instructions, ALUop directly tells the ALU what to do. For R-type instructions, the Main Control signals "I don't know what the ALU has to do but I know it is R-type," and a separate ALU Control block (local decoder) uses the func field to generate the correct ALUctr. This saves columns in the control table and allows the same ALUop encoding to work for ALL R-type instructions, not just Add/Subtract.
π Formula: ALUctr = f(ALUop, func_field) β The ALU control generates the exact ALU operation code using ALUop from Main Control and the instruction's func field.
Multi Cycle Design - Datapath
How Effectively are we utilizing our hardware? In the single-cycle design, hardware is used inefficiently. For example, memory is used twice at different times (instruction fetch and data access). The average memory access per instruction = 1 + F_lw + F_sw β 1.3. If CPI were 4.8 (hypothetical), instruction memory utilization = 1/4.8 and data memory utilization = 0.3/4.8 β very low. We could reduce hardware without hurting performance by using an alternative datapath: Multiple Cycle Datapath that immunizes hardware β using 1 memory unit and 1 adder shared across multiple cycles.
π‘ Why this matters: Multi-cycle design allows each clock cycle to be shorter (just the time for one functional unit operation) and reuses expensive components like memory and ALU, reducing hardware cost while still maintaining correct execution.
Controller FSM Spec and Sequencer-based control unit are introduced as the method to manage the multi-cycle datapath. The control unit is implemented as a Finite State Machine that sequences through states corresponding to different cycles of instruction execution (fetch, decode, execute, memory, writeback).
Two Types of Exceptions
- Interrupts: Caused by external events, asynchronous to program execution, may be handled between instructions. Simply suspend and resume the user program.
- Traps: Caused by internal events (exceptional conditions like overflow, errors like parity, faults like non-resident page). Synchronous to program execution. The condition must be remedied by the handler. The instruction may be retried, simulated, and program continued, or the program may be aborted.
Precise Interrupts: A precise interrupt preserves the state of the machine as if the program executed up to the offending instruction. This means the same system code will work on different implementations of the architecture. This position is clearly established by IBM and taken by MIPS. Precision is difficult in the presence of pipelining and out-of-order execution. Imprecise interrupts force system software to figure out what is where and put everything back together. Performance goals often lead designers to forsake precise interrupts, though developers and users usually wish they had not.
β Key Takeaways
The single-cycle datapath requires a unique set of control signals for each instruction type, with R-type instructions needing both the op and func fields decoded, while I-type and J-type are identified by the op field alone. The concept of local decoding separates ALU control generation into two stages: the Main Control produces ALUop, and a dedicated ALU Control uses the func field to generate ALUctr for R-type instructions, making the design scalable. Multi-cycle design improves hardware utilization by sharing components like memory and ALU across multiple shorter clock cycles, allowing a single memory unit and adder to serve all instruction phases. The transition to multi-cycle design requires a sequencer-based control unit or controller FSM to manage the sequence of micro-operations. Finally, exceptions are classified as interrupts (external, asynchronous) and traps (internal, synchronous), with precise interrupts being crucial for software portability across different implementations.
π§ Quick Revision Questions
- Compare the control signal settings for an R-type instruction (Add) and an I-type instruction (Or Immediate). Which control signals are the same, and which differ, and why?
- Explain the concept of "local decoding" for ALU control. What signals does the Main Control generate, and what does the ALU Control block use to produce the final ALUctr?
- How does the hardware utilization differ between single-cycle and multi-cycle datapath designs? Give a specific example using memory utilization.
- Describe how the Branch instruction affects the Instruction Fetch Unit. What signals are involved when the branch is taken versus not taken?
- What is the difference between a precise interrupt and an imprecise interrupt? Why is this distinction important for system software compatibility?