Docsity

Computer Systems: Chapter 4 - Processor Architecture - Prof. Thomas Way, Exams of Operating Systems

Toggle sidebar
bg1
1
CSC 8400
Computer Systems
Chapter 4
Processor Architecture
2
Chapter 3
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
3
Chapter 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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

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
  1. Register Add R4, R3 R4 <- R4 + R
  2. Immediate Add R4, #3 R4 <- R4 + 3
  3. Displacement Add R4, 100(R1) R4 <- R4 + M[100 + R1]
  4. Register indirect Add R4, (R1) R4 <- R4 + M[R1]
  5. Indexed Add R4, (R1 + R2) R4 <- R4 + M[R1 + R2]
  6. Direct or absolute Add R4, (1000) R4 <- R4 + M[1000]
  7. Memory Indirect Add R4, @(R3) R4 <- R4 + M[M[R3]]
  8. Autoincrement Add R4, (R2)+ R4 <- R4 + M[R2] R2 <- R2 + d
  9. Autodecrement Add R4, (R2)- R4 <- R4 + M[R2] R2 <- R2 - d
  10. 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

  1. AND combinations that yield a "1" in the truth table.
  2. 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