Download Computer Systems: Chapter 4 - Processor Architecture - Prof. Thomas Way and more Exams Operating Systems in PDF only on Docsity!
CSC 8400
Computer Systems
Chapter 4
Processor Architecture
Chapter 3^2
Today in class (9/30)
ļ¬ 6:15 Chapter 4 (4.1,4.2) quiz, recap, Q&A
ļ¬ 6:30 Chapter 4 lecture
ļ¬ 7:30 Break
ļ¬ 7:40 Chapter 4 (contād)
ļ¬ 8:40 Test 1 study guide
ļ¬ 9:00 Wrap
Chapter 3^3
Today in class (10/07)
ļ¬ 6:15 Test 1 (no quiz)
ļ¬ 7:30 Break
ļ¬ 7:40 Chapter 4 (contād)
ļ¬ 7:55 Workshop 3 handout
ļ¬ 8:00 Video āMachine That Changed the Worldā Part 2
ļ¬ 9:00 Wrap
Chapter 3^4
Today in class (10/21)
ļ¬ 6:15 Chapter 4 (4.3,4.4) quiz, recap, Q&A
ļ¬ 6:30 Chapter 4 lecture (contād)
ļ¬ 7:30 Break
ļ¬ 7:40 Chapter 4 lecture (finish)
ļ¬ 8:00 Test 1 return & discussion
ļ¬ 8:30 Workshop 3 lab time
ļ¬ 9:00 Wrap
Chapter 4^5
So far this semester
ļ¬ Systems are HW & SW, compiler, assembly lang, Von
Neumann model is universal, information=bits+context
ļ¬ Mooreās Law, Base 2, word, memory is bytes, pointer is
address, endian, machine instructions are data, 2s
complement, ASCII, converting between hex-binary-
decimal, sign extension, limits of machine, IEEE floating
point
ļ¬ Assembly, dissasemble, machine instructions, condition
codes, stack, call chain, memory layout, buffer overflow
ļ¬ RAM, read, write, disk, platters, sectors, tracks, Memory
Gap, locality, memory hierarchy, caches
Instruction Set Architecture
Chapter 4^10 Instruction Set Architectures Basic ISA Classes Stack Accumulator Register (Register-memory) Register (load-store) Push A Load A Load R1, A Load R1, A Push B Add B Add R1, B Load R2, B Add Store C Store C, R1 Add R3, R1, R Pop C Store C, R The results of different address classes is easiest to see with the examples here, all of which implement the sequences for C = A + B. Registers are the class that won out. The more registers on the CPU, the better. Chapter 4^11 Comparison of ISA Classifications
Accumulator (before 1960):
1 address add A acc acc + mem[A]
Stack (1960s to 1970s):
0 address add tos tos + next
Memory-Memory (1970s to 1980s):
2 address add A, B mem[A] mem[A] + mem[B] 3 address add A, B, C mem[A] mem[B] + mem[C]
Register-Memory (1970s to present):
2 address add R1, A R1 R1 + mem[A] load R1, A R1 mem[A]
Register-Register (Load/Store) (1960s to present):
3 address add R1, R2, R3 R1 R2 + R load R1, R2 R1 mem[R2] store R1, R2 mem[R1] R Chapter 4^12
Accumulator Architectures
- Instruction set: add A, sub A, mult A, div A,... load A, store A
- Example: AB - (A+CB)** load B mul C add A store D load A mul B sub D B BC A+BC** (^) A+BC A AB result**
Chapter 4^13
Accumulators: Pros and Cons
- Pros
- Very low hardware requirements
- Easy to design and understand
- Cons
- Accumulator becomes the bottleneck
- Little ability for parallelism or pipelining
- High memory traffic Chapter 4^14
Stack Architectures
ļ¬ Instruction set:
add, sub, mult, div,... push A, pop A
ļ¬ Example: AB - (A+CB)
push A push B mul push A push C push B mul add sub A B A AB* (^) AB AB AB A A C AB A AB A C B BC A+BC result* Chapter 4^15
Stacks: Pros and Cons
ļ¬ Pros
- Good code density (implicit top of stack)
- Low hardware requirements
- Easy to write a simpler compiler for stack architectures
ļ¬ Cons
- Stack becomes the bottleneck
- Little ability for parallelism or pipelining
- Data is not always at the top of stack when need, so additional instructions like TOP and SWAP are needed
- Difficult to write an optimizing compiler for stack architectures
Chapter 4^19
Register-Memory: Pros and Cons
- Pros
- Some data can be accessed without loading first
- Instruction format easy to encode
- Good code density
- Cons
- Operands are not equivalent (poor orthogonal)
- Variable number of clocks per instruction
- May limit number of registers Chapter 4^20
Load-Store Architectures
- Instruction set: add R1, R2, R3 sub R1, R2, R3 mul R1, R2, R load R1, &A store R1, &A move R1, R
- Example: AB - (A+CB)** load R1, &A load R2, &B load R3, &C mul R7, R3, R2 / CB /* add R8, R7, R1 / A + CB /* mul R9, R1, R2 / AB /* sub R10, R9, R8 / AB - (A+CB) / Chapter 4^21
Load-Store: Pros and Cons
- Pros
- Simple, fixed length instruction encodings
- Instructions take similar number of cycles
- Relatively easy to pipeline and make superscalar
- Cons
- Higher instruction count
- Not all instructions need three operands
- Dependent on good compiler
Chapter 4^22 Registers: Advantages and Disadvantages
- Advantages
- Faster than cache or main memory (no addressing mode or tags)
- Deterministic (no misses)
- Can replicate (multiple read ports)
- Short identifier (typically 3 to 8 bits)
- Reduce memory traffic
- Disadvantages
- Need to save and restore on procedure calls and context switch
- Canāt take the address of a register (for pointers)
- Fixed size (canāt store strings or structures efficiently)
- Compiler must manage
- Limited number Chapter 4^23 Types of Addressing Modes (Ch. 6) Addressing Mode Example Action
- Register Add R4, R3 R4 <- R4 + R
- Immediate Add R4, #3 R4 <- R4 + 3
- Displacement Add R4, 100(R1) R4 <- R4 + M[100 + R1]
- Register indirect Add R4, (R1) R4 <- R4 + M[R1]
- Indexed Add R4, (R1 + R2) R4 <- R4 + M[R1 + R2]
- Direct or absolute Add R4, (1000) R4 <- R4 + M[1000]
- Memory Indirect Add R4, @(R3) R4 <- R4 + M[M[R3]]
- Autoincrement Add R4, (R2)+ R4 <- R4 + M[R2] R2 <- R2 + d
- Autodecrement Add R4, (R2)- R4 <- R4 + M[R2] R2 <- R2 - d
- Scaled Add R4, 100(R2)[R3] R4 <- R4 + M[100 + R2 + R3*d] ļ¬ Modes 1-4 account for 93% of all operands Chapter 4^24
Types of Operations
ļ¬ Arithmetic and Logic: AND, ADD
ļ¬ Data Transfer: MOVE, LOAD, STORE
ļ¬ Control BRANCH, JUMP, CALL
ļ¬ System OS CALL, VM
ļ¬ Floating Point ADDF, MULF, DIVF
ļ¬ Decimal ADDD, CONVERT
ļ¬ String MOVE, COMPARE
ļ¬ Graphics (DE)COMPRESS
Chapter 4^28
Role of Compilers
ļ¬ What does the compiler do?
- Translate HLL to machine lang, optimize, check for errors
ļ¬ Optimizations
- Generic high-level: common subexpression, strength reduction, āmachine independentā
- Local: within a straight-line code fragment (a āblockā)
- Global: cross branches, transform loops
- Register allocation: associate registers with operands
- Machine-dependent: tune to the specific architecture (or ISA) Chapter 4^29
Role of Compilers (contād)
ļ¬ Impact of optimization on performance
- Goal is to improve
- Sometimes makes worse, or not better
ļ¬ How to make the compiler writerās life easier
- Make frequent case fast, rare case correct
- Make things uniform
- Reduce trade-offs, have one ābestā way of doing each thing
- Allow for constant values Chapter 4^30
CISC Instruction Sets
- Complex Instruction Set Computer
- Dominant style through mid-80ās
ļ¬ Stack-oriented instruction set
- Use stack to pass arguments, save program counter
- Explicit push and pop instructions
ļ¬ Arithmetic instructions can access memory
- addl %eax, 12(%ebx,%ecx,4) ļ¬ requires memory read and write ļ¬ Complex address calculation
ļ¬ Condition codes
- Set as side effect of arithmetic and logical instructions
ļ¬ Philosophy
- Add instructions to perform ātypicalā programming tasks
Chapter 4^31
RISC Instruction Sets
- Reduced Instruction Set Computer
- Internal project at IBM, later popularized by Hennessy (Stanford) and Patterson (Berkeley)
ļ¬ Fewer, simpler instructions
- Might take more to get given task done
- Can execute them with small and fast hardware
ļ¬ Register-oriented instruction set
- Many more (typically 32) registers
- Use for arguments, return pointer, temporaries
ļ¬ Only load and store instructions can access memory
- Similar to Y86 mrmovl and rmmovl
ļ¬ No Condition codes
- Test instructions return 0/1 in register Chapter 4^32 Example RISC Instruction Formats Op 31 26 25 2120 1615 0 rs1 rd immediate Op 31 26 25 0 Op 31 26 25 2120 1615 0 rs1 rs offset added to PC rd Register-Register (R-type) ADD R1, R2, R 1110 65 Register-Immediate (I-type) SUB R1, R2, # Jump / Call (J-type) JUMP end func (ALU imm. operations, loads and stores, conditional branch, jump (and link) (jump, jump and link, trap and return from exception) (ALI reg. operations, read/write special registers and moves) Chapter 4^33
CISC vs. RISC
ļ¬ Original Debate
- Strong opinions!
- CISC proponents---easy for compiler, fewer code bytes
- RISC proponents---better for optimizing compilers, can make run fast with simple chip design
ļ¬ Current Status
- For desktop processors, choice of ISA not a technical issue ļ¬ With enough hardware, can make anything run fast ļ¬ Code compatibility more important
- For embedded processors, RISC makes sense ļ¬ Smaller, cheaper, less power
Chapter 4^37
Computing with Logic Gates
- Outputs are Boolean functions of inputs
- Respond continuously to changes in inputs ļ¬ With some, small delay
a
b out^
a
b out^ a^ out
out = a && b out = a || b out = !a
And Or Not
Voltage Time a b Rising Delay (^) a && b Falling Delay Chapter 4^38
Combinational Circuits
ļ¬ Acyclic Network of Logic Gates
- Continuously responds to changes on primary inputs
- Primary outputs become (after some delay) Boolean functions of primary inputs Acyclic Network Primary Inputs Primary Outputs Chapter 4^39
Bit Equality
- Generate 1 if a and b are equal
ļ¬ Hardware Control Language (HCL)
- Very simple hardware description language ļ¬ Boolean operations have syntax similar to C logical operations
- Weāll use it to describe control logic for processors a^ Bit equal b eq bool eq = (a&&b)||(!a&&!b) HCL Expression
Chapter 4^40
Word Equality
- 32 - bit word size
- HCL representation ļ¬ Equality operation ļ¬ Generates Boolean value b 31 Bit equal a 31 eq 31 b (^30) Bit equal a 30 eq 30 b 1 Bit equal a 1 eq 1 b (^0) Bit equal a 0 eq 0 Eq
B
A
Eq Word-Level Representation bool Eq = (A == B) HCL Representation Chapter 4^41
1 - Bit Latch
D Latch Q+ Qā
R
S
D
C
Data Clock Latching 1 Q+ Qā R S D C Q+ Qā R S D C d !d !d !d d d d !d^0 Storing Q+ Qā R S D C Q+ Qā R S D C d !d (^) q !q !q 0 q 0 Chapter 4^42
Registers
- Stores word of data ļ¬ Different from program registers seen in assembly code
- Collection of edge-triggered latches
- Loads input on rising edge of clock
I O
Clock D C Q+ D C Q+ D C Q+ D C Q+ D C Q+ D C Q+ D C Q+ D C Q+ i 7 i 6 i 5 i 4 i 3 i 2 i 1 i 0 o 7 o 6 o 5 o 4 o 3 o 2 o 1 o 0 Clock Structure
Chapter 4^46
Logical Completeness
ļ¬ Can implement ANY truth table with AND, OR, NOT.
A B C D
- AND combinations that yield a "1" in the truth table.
- OR the results of the AND gates. Chapter 4^47
Practice
ļ¬ Implement the following truth table.
A B C
Chapter 4^48
DeMorgan's Law
ļ¬ Converting AND to OR (with some help from NOT)
ļ¬ Consider the following gate:
A B
A B AB AB
To convert AND to OR (or vice versa), invert inputs and output.
Chapter 4^49
Decoder
ļ¬ n inputs, 2 n^ outputs
- exactly one output is 1 for each possible input pattern 2 - bit decoder Chapter 4^50
Hands-on Exercise - Intro
ļ¬ Half-Adder
- Logic circuit that adds two single bits
- Inputs are bits A and B
- Outputs are S (sum) and C (carry)
ļ¬ Steps
- Write truth table
- For S (sum), AND together only lines that are TRUE (1) in table, using NOT when needed
- OR together the outputs of AND
- Repeat for C (carry)
- Redraw if needed to clean up Chapter 4^51
Hands-on Exercise
ļ¬ Full-Adder
- Logic circuit that adds two single bits
- Inputs are bits A and B and Cin (carry in)
- Outputs are S (sum) and Cout (carry out)
ļ¬ Use Half-Adder as starting point
ļ¬ Design a one-bit Full-Adder
Chapter 4^55 Phases Memory Access Write Back Instruction Fetch Instr. Decode Reg. Fetch Execute Addr. Calc IR L M D
Instruction Fetch (IF):
Send out the PC and fetch the instruction from memory into the instruction register (IR); increment the PC by 4 to address the next sequential instruction. IR holds the instruction that will be used in the next stage. NPC holds the value of the next PC. Passed To Next Stage IR <- Mem[PC] NPC <- PC + 4 Instruction Cycle Chapter 4^56 Phases Instruction Fetch Instr. Decode Reg. Fetch Execute Addr. Memory Access Write Back Calc IR L M D
Instruction Decode / Register Fetch (ID):
Decode the instruction and access the register file to read the registers. The outputs of the general purpose registers are read into two temporary registers (A & B) for use in later clock cycles. We extend the sign of the lower 16 bits of the Instruction Register. Passed To Next Stage A <- Regs[IR6..IR10]; B <- Regs[IR10..IR15]; Imm <- ((IR16) ##IR16- 31 Instruction Cycle Chapter 4^57
Instruction Decoding
ļ¬ Instruction Format
- Instruction byte icode:ifun
- Optional register byte rA:rB
- Optional constant word valC 5 0 rA rB D icode ifun rA rB valC Optional (^) Optional
Chapter 4^58 Phases Memory Access Write Back Instruction Fetch Instr. Decode Reg. Fetch Execute Addr. Calc IR L M D Passed To Next Stage A <- A func. B cond = 0;
Execute / Address Calculation (EX):
We perform an operation (for an ALU) or an address calculation (if itās a load or a Branch). If an ALU, actually do the operation. If an address calculation, figure out how to obtain the address and stash away the location of that address for the next cycle. Instruction Cycle Chapter 4^59 Phases Instruction Fetch Instr. Decode Reg. Fetch Execute Addr. Memory Access Write Back Calc IR L M D Passed To Next Stage A = Mem[prev. B] or Mem[prev. B] = A
Memory Access (MEM):
If this is an ALU, do nothing. If a load or store, then access memory. Instruction Cycle Chapter 4^60 Phases Instruction Fetch Instr. Decode Reg. Fetch Execute Addr. Memory Access Write Back Calc IR L M D Passed To Next Stage Regs <- A, B;
Write Back (WB):
Update the registers from either the ALU or from the data loaded. Instruction Cycle