Download presentation
Presentation is loading. Please wait.
Published byJoel Dawson Modified over 6 years ago
1
6/16/2018 CIS-550 Advanced Computer Architecture Lecture 4: ISA Tradeoffs (Continued) and MIPS ISA Dr. Muhammad Abid DCIS, PIEAS Spring 2017 1 1
2
Upcoming Readings Next week (Microarchitecture):
6/16/2018 Upcoming Readings Next week (Microarchitecture): P&H, Chapter 4, Sections P&P, revised Appendix C – LC3b datapath and microprogrammed operation 2
3
Last Lecture Recap Instruction processing style Elements of an ISA
6/16/2018 Last Lecture Recap Instruction processing style 0, 1, 2, 3 address machines Elements of an ISA Instructions, data types, memory organizations, registers, etc Addressing modes Complex (CISC) vs. simple (RISC) instructions Semantic gap ISA translation 3 3
4
ISA-level Tradeoffs: Instruction Length
6/16/2018 ISA-level Tradeoffs: Instruction Length Fixed length: Length of all instructions the same + Easier to decode single instruction in hardware + Easier to decode multiple instructions concurrently -- Wasted bits in instructions (Why is this bad?) -- Harder-to-extend ISA (how to add new instructions?) Variable length: Length of instructions different (determined by opcode and sub-opcode) + Compact encoding (Why is this good?) -- More logic to decode a single instruction -- Harder to decode multiple instructions concurrently Tradeoffs Code size (memory space, bandwidth, latency) vs. hardware complexity ISA extensibility and expressiveness vs. hardware complexity Performance? Energy? Smaller code vs. ease of decode 4 4
5
ISA-level Tradeoffs: Uniform Decode
6/16/2018 ISA-level Tradeoffs: Uniform Decode Uniform decode: Same bits in each instruction correspond to the same meaning Opcode is always in the same location Ditto operand specifiers, immediate values, … Many “RISC” ISAs: Alpha, MIPS, SPARC + Easier decode, simpler hardware + Enables parallelism: generate target address before knowing the instruction is a branch -- Restricts instruction format (fewer instructions?) or wastes space Non-uniform decode E.g., opcode can be the 1 to 7 byte in x86 + More compact and powerful instruction format -- More complex decode logic 5 5
6
x86 vs. Alpha Instruction Formats
6/16/2018 x86 vs. Alpha Instruction Formats x86: Alpha: 6 6
7
MIPS Instruction Format
6/16/2018 MIPS Instruction Format R-type, 3 register operands I-type, 2 register operands and 16-bit immediate operand J-type, 26-bit immediate operand Simple Decoding 4 bytes per instruction, regardless of format must be 4-byte aligned (2 lsb of PC must be 2b’00) format and fields easy to extract in hardware R-type 6-bit rs 5-bit rt rd shamt funct opcode 6-bit rs 5-bit rt immediate 16-bit I-type opcode 6-bit immediate 26-bit J-type Quickly. 7 7
8
A Note on Length and Uniformity
6/16/2018 A Note on Length and Uniformity Uniform decode usually goes with fixed length In a variable length ISA, uniform decode can be a property of instructions of the same length It is hard to think of it as a property of instructions of different lengths 8
9
A Note on RISC vs. CISC Usually, … RISC CISC Simple instructions
6/16/2018 A Note on RISC vs. CISC Usually, … RISC Simple instructions Fixed length Uniform decode Few addressing modes CISC Complex instructions Variable length Non-uniform decode Many addressing modes 9 9
10
x86 vs. Alpha Instruction Formats
6/16/2018 x86 vs. Alpha Instruction Formats x86: Alpha: 10 10
11
x86 Memory Register register indirect absolute SIB + displacement
6/16/2018 x86 register indirect Memory absolute SIB + displacement register + displacement register Register 11 11
12
6/16/2018 x86 indexed (base + index) scaled (base + index*4) 12 12
13
X86 SIB-D Addressing Mode
6/16/2018 X86 SIB-D Addressing Mode x86 Manual Vol. 1, page see course resources on website Also, see Section and 3.7.5 13 13
14
X86 Manual: Suggested Uses of Addressing Modes
6/16/2018 X86 Manual: Suggested Uses of Addressing Modes Static address Dynamic storage Arrays Records x86 Manual Vol. 1, page see course resources on website Also, see Section and 3.7.5 14 14
15
X86 Manual: Suggested Uses of Addressing Modes
6/16/2018 X86 Manual: Suggested Uses of Addressing Modes Static arrays w/ fixed-size elements 2D arrays 2D arrays x86 Manual Vol. 1, page see course resources on website Also, see Section and 3.7.5 15 15
16
Other Example ISA-level Tradeoffs
6/16/2018 Other Example ISA-level Tradeoffs Condition codes vs. not VLIW vs. single instruction Precise vs. imprecise exceptions Virtual memory vs. not Unaligned access vs. not Hardware interlocks vs. software-guaranteed interlocking Software vs. hardware managed page fault handling Cache coherence (hardware vs. software) … 16 16
17
Back to Programmer vs. (Micro)architect
6/16/2018 Back to Programmer vs. (Micro)architect Many ISA features designed to aid programmers But, complicate the hardware designer’s job Virtual memory vs. overlay programming Should the programmer be concerned about the size of code blocks fitting physical memory? Addressing modes Unaligned memory access Compiler/programmer needs to align data Instruction dependence 17 17
18
6/16/2018 CIS-550 MIPS ISA 18
19
MIPS R2000 Program Visible State
6/16/2018 MIPS R2000 Program Visible State Program Counter 32-bit memory address of the current instruction **Note** r0=0 r1 r2 General Purpose Register File 32 32-bit words named r0...r31 M[0] M[1] M[2] M[3] M[4] Memory 232 by 8-bit locations (4 Giga Bytes) 32-bit address (there is some magic going on) M[N-1] 19
20
Data Format signed and unsigned integers: Floating-point numbers
6/16/2018 Data Format signed and unsigned integers: 8-bit, 16-bit, and 32-bit integers Load/ Store instructions ALU operations supported Floating-point numbers IEEE standard 754 Single precision: 32-bit = 1-bit sign, 8-bit exponent, 23-bit significand Double precision: 64-bit = 1-bit sign, 11-bit exponent, 52-bit significand MIPS supports both Big and little endian 20
21
Instruction Formats R-type I-type J-type 3 simple formats
6/16/2018 Instruction Formats 3 simple formats R-type, 3 register operands I-type, 2 register operands and 16-bit immediate operand J-type, 26-bit immediate operand Simple Decoding 4 bytes per instruction, regardless of format must be 4-byte aligned (2 lsb of PC must be 2b’00) format and fields readily extractable R-type 6-bit rs 5-bit rt rd shamt funct opcode 6-bit rs 5-bit rt immediate 16-bit I-type opcode 6-bit immediate 26-bit J-type 21
22
ALU Instructions R-type
6/16/2018 ALU Instructions Assembly (e.g., register-register signed addition) ADD rdreg rsreg rtreg Machine encoding Semantics GPR[rd] GPR[rs] + GPR[rt] PC PC + 4 Exception on “overflow” Variations Arithmetic: {signed, unsigned} x {ADD, SUB} Logical: {AND, OR, XOR, NOR} Shift: {Left, Right-Logical, Right-Arithmetic} R-type 6-bit rs 5-bit rt 5-bit rd 5-bit 5-bit ADD 6-bit 22
23
Reg-Reg Instruction Encoding
6/16/2018 Reg-Reg Instruction Encoding [MIPS R4000 Microprocessor User’s Manual] What patterns do you see? Why are they there? 23
24
ALU Instructions I-type
6/16/2018 ALU Instructions Assembly (e.g., regi-immediate signed additions) ADDI rtreg rsreg immediate16 Machine encoding Semantics GPR[rt] GPR[rs] + sign-extend (immediate) PC PC + 4 Exception on “overflow” Variations Arithmetic: {signed, unsigned} x {ADD, SUB} Logical: {AND, OR, XOR, LUI} I-type ADDI 6-bit rs 5-bit rt 5-bit immediate 16-bit 24
25
Reg-Immed Instruction Encoding
6/16/2018 Reg-Immed Instruction Encoding [MIPS R4000 Microprocessor User’s Manual] 25
26
6/16/2018 Assembly Programming 101 Break down high-level program constructs into a sequence of elemental operations E.g. High-level Code f = ( g + h ) – ( i + j ) Assembly Code suppose f, g, h, i, j are in rf, rg, rh, ri, rj suppose rtemp is a free register add rtemp rg rh # rtemp = g+h add rf ri rj # rf = i+j sub rf rtemp rf # f = rtemp – rf 26
27
Load Instructions I-type Assembly (e.g., load 4-byte word)
6/16/2018 Load Instructions Assembly (e.g., load 4-byte word) LW rtreg offset16 (basereg) Machine encoding Semantics effective_address = sign-extend(offset) + GPR[base] GPR[rt] MEM[ translate(effective_address) ] PC PC + 4 Exceptions address must be “word-aligned” What if you want to load an unaligned word? MMU exceptions I-type LW 6-bit base 5-bit rt 5-bit offset 16-bit 27
28
Store Instructions I-type Assembly (e.g., store 4-byte word)
6/16/2018 Store Instructions Assembly (e.g., store 4-byte word) SW rtreg offset16 (basereg) Machine encoding Semantics effective_address = sign-extend(offset) + GPR[base] MEM[ translate(effective_address) ] GPR[rt] PC PC + 4 Exceptions address must be “word-aligned” MMU exceptions I-type SW 6-bit base 5-bit rt 5-bit offset 16-bit 28
29
Assembly Programming 201 E.g. High-level Code Assembly Code
6/16/2018 Assembly Programming 201 E.g. High-level Code A[ 8 ] = h + A[ 0 ] where A is an array of integers (4–byte each) Assembly Code suppose &A, h are in rA, rh suppose rtemp is a free register LW rtemp 0(rA) # rtemp = A[0] add rtemp rh rtemp # rtemp = h + A[0] SW rtemp 32(rA) # A[8] = rtemp # note A[8] is 32 bytes # from A[0] 29
30
Control Flow Instructions
6/16/2018 Control Flow Instructions Assembly Code (linearized) Control Flow Graph C-Code { code A } if X==Y then { code B } else { code C } { code D } code A if X==Y code A if X==Y goto True False code C goto code B code C these things are called basic blocks code B code D code D 30
31
(Conditional) Branch Instructions
6/16/2018 (Conditional) Branch Instructions Assembly (e.g., branch if equal) BEQ rsreg rtreg immediate16 Machine encoding Semantics target = PC + sign-extend(immediate) x 4 if GPR[rs]==GPR[rt] then PC target else PC PC + 4 How far can you jump? Variations BEQ, BNE, BLEZ, BGTZ I-type BEQ 6-bit rs 5-bit rt 5-bit immediate 16-bit PC + 4 w/ branch delay slot Why isn’t there a BLE or BGT instruction? 31
32
Jump Instructions J-type Assembly J immediate26 Machine encoding
6/16/2018 Jump Instructions Assembly J immediate26 Machine encoding Semantics target = PC[31:28] || immediate x 4 PC target How far can you jump? Variations Jump and Link Jump Registers J-type J 6-bit immediate 26-bit PC + 4 w/ branch delay slot 32
33
Assembly Programming 301 E.g. High-level Code Assembly Code
6/16/2018 Assembly Programming 301 E.g. High-level Code if (i == j) then e = g else e = h f = e Assembly Code suppose e, f, g, h, i, j are in re, rf, rg, rh, ri, rj bne ri rj L1 # L1 and L2 are addr labels # assembler computes offset add re rg r0 # e = g j L2 L1: add re rh r0 # e = h L2: add rf re r0 # f = e 33
34
Function Call and Return
6/16/2018 Function Call and Return Jump and Link: JAL offset26 return address = PC + 8 target = PC[31:28] || immediate x 4 PC target GPR[r31] return address On a function call, the callee needs to know where to go back to afterwards Jump Indirect: JR rsreg target = GPR [rs] PC-offset jumps and branches always jump to the same target every time the same instruction is executed Jump Indirect allows the same instruction to jump to any location specified by rs (usually r31) 34
35
6/16/2018 Assembly Programming 401 Callee _myfxn: ... code B ... JR r31 Caller ... code A ... JAL _myfxn ... code C ... JAL _myfxn ... code D ... A call B return C call B return D ..... How do you pass argument between caller and callee? If A set r10 to 1, what is the value of r10 when B returns to C? What registers can B use? What happens to r31 if B calls another function 35
36
Caller and Callee Saved Registers
6/16/2018 Caller and Callee Saved Registers Callee-Saved Registers Caller says to callee, “The values of these registers should not change when you return to me.” Callee says, “If I need to use these registers, I promise to save the old values to memory first and restore them before I return to you.” Caller-Saved Registers Caller says to callee, “If there is anything I care about in these registers, I already saved it myself.” Callee says to caller, “Don’t count on them staying the same values after I am done.
37
R2000 Register Usage Convention
6/16/2018 R2000 Register Usage Convention
38
R2000 Memory Usage Convention
6/16/2018 R2000 Memory Usage Convention high address free space stack space dynamic data grow down grow up stack pointer GPR[r29] e.g. malloc() Size determined at compile time static data text binary executable reserved low address
39
6/16/2018 Calling Convention Put parameters in a place where the procedure can access them. Transfer control to the procedure. Acquire the storage resources needed for the procedure. Perform the desired task. Put the result value in a place where the calling program can access it. Return control to the point of origin, since a procedure can be called from several points in a program.
40
To Summarize: MIPS RISC
6/16/2018 To Summarize: MIPS RISC Simple operations 2-input, 1-output arithmetic and logical operations few alternatives for accomplishing the same thing Simple data movements ALU ops are register-to-register (need a large register file) “Load-store” architecture Simple branches limited varieties of branch conditions and targets Simple instruction encoding all instructions encoded in the same number of bits only a few formats Loosely speaking, an ISA intended for compilers rather than assembly programmers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.