cs 251 fall 2019 cs 240 spring 2020 principles of
play

CS 251 Fall 2019 CS 240 Spring 2020 Principles of Programming - PowerPoint PPT Presentation

CS 251 Fall 2019 CS 240 Spring 2020 Principles of Programming Languages Foundations of Computer Systems Ben Wood Ben Wood A Simple Processor 1. A simple Instruction Set Architecture 2. A simple microarchitecture (implementation): Data


  1. λ CS 251 Fall 2019 CS 240 Spring 2020 Principles of Programming Languages Foundations of Computer Systems Ben Wood Ben Wood A Simple Processor 1. A simple Instruction Set Architecture 2. A simple microarchitecture (implementation): Data Path and Control Logic https://cs.wellesley.edu/~cs240/s20/ A Simple Processor 1

  2. Program, Application Software Programming Language Compiler/Interpreter Operating System Instruction Set Architecture Microarchitecture Hardware Digital Logic Devices (transistors, etc.) Solid-State Physics A Simple Processor 2

  3. Instruction Set Architecture (HW/SW Interface ) processor memory Instructions Instruction Encoded Names, Encodings • Logic Instructions Effects • Arguments, Results • Registers Data Local storage Names, Size • • How many Large storage Addresses, Locations • Computer A Simple Processor 3

  4. Computer Microarchitecture ( Implementation of ISA) Instruction ALU Registers Fetch and Memory Decode A Simple Processor 4

  5. HW ISA HW (HW = Hardware or Hogwarts?) An example made-up instruction set architecture Word size = 16 bits • Register size = 16 bits. • ALU computes on 16-bit values. Memory is byte-addressable , accesses full words (byte pairs). 16 registers: R0 - R15 Address Contents • R0 always holds hardcoded 0 0 First instruction, • R1 always holds hardcoded 1 low-order byte • R2 – R15: general purpose 1 First instruction, Instructions are 1 word in size. high-order byte 2 Second instruction, Separate instruction memory . low-order byte Program Counter (PC) register ... ... • holds address of next instruction to execute. A Simple Processor 5

  6. R: Register File M: Data Memory Reg Contents Reg Contents Address Contents R0 0x0000 R8 0x0 – 0x1 R1 0x0001 R9 0x2 – 0x3 R2 R10 0x4 – 0x5 R3 R11 0x6 – 0x7 R4 R12 0x8 – 0x9 R5 R13 0xA – 0xB R6 R14 0xC – 0xD R7 R15 … Program Counter IM: Instruction Memory PC Address Contents 0x0 – 0x1 1. ins ß IM[PC] Processor 0x2 – 0x3 2. PC ß PC + 2 Loop 0x4 – 0x5 3. Do ins 0x6 – 0x7 HW HW ISA Abstract 0x8 – 0x9 Machine … A Simple Processor 6

  7. HW HW ISA Instructions 16-bit Encoding LSB MSB Assembly Syntax Meaning Opcode Rs Rt Rd ADD R s, R t, R d R[ d ] ß R[ s ] + R[ t ] 0010 s t d SUB R s, R t, R d R[ d ] ß R[ s ] - R[ t ] 0011 s t d AND R s, R t, R d R[ d ] ß R[ s ] & R[ t ] 0100 s t d OR R s, R t, R d R[ d ] ß R[ s ] | R[ t ] 0101 s t d LW R t, offset (R s ) R[ t ] ß M[R[ s ] + offset ] 0000 s t offset SW R t, offset (R s ) M[R[ s ] + offset ] ß R[ t ] 0001 s t offset If R[ s ] == R[ t ] then BEQ R s, R t, offset 0111 s t offset PC ß PC + offset *2 JMP offset PC ß offset *2 1000 o f f s e t (R = register file, M = memory) A Simple Processor 7

  8. R: Register File M: Data Memory Reg Contents Reg Contents Address Contents R0 0x0000 R8 0x0 – 0x1 0x46 0x12 R1 0x0001 R9 0x2 – 0x3 0xA9 0x56 R2 R10 0x4 – 0x5 R3 R11 0x6 – 0x7 R4 R12 0x8 – 0x9 R5 R13 0xA – 0xB R6 R14 0xC – 0xD R7 R15 … Program Counter IM: Instruction Memory PC Address Contents 0x0 – 0x1 LW R3, 0(R0) 1. ins ß IM[PC] Processor 0x2 – 0x3 LW R4, 2(R0) 2. PC ß PC + 2 Loop 0x4 – 0x5 AND R3, R4, R5 3. Do ins 0x6 – 0x7 SW R5, 4(R0) HW HW ISA Abstract 0x8 – 0x9 Machine 0xA – 0xB A Simple Processor 8

  9. R: Register File M: Data Memory Reg Contents Reg Contents Address Contents R0 0x0000 R8 0x0 – 0x1 R1 0x0001 R9 2 0x2 – 0x3 R2 R10 3 0x4 – 0x5 R3 R11 0x6 – 0x7 R4 R12 0x8 – 0x9 R5 R13 0xA – 0xB R6 R14 0xC – 0xD R7 R15 … Program Counter IM: Instruction Memory PC Address Contents 0x0 – 0x1 SUB R8, R8, R8 1. ins ß IM[PC] Processor 0x2 – 0x3 BEQ R9, R0, 3 2. PC ß PC + 2 Loop 0x4 – 0x5 ADD R10, R8, R8 3. Do ins 0x6 – 0x7 SUB R9, R1, R9 HW HW ISA Abstract 0x8 – 0x9 JMP 1 Machine 0xA – 0xB HALT A Simple Processor 9

  10. arch microarchitecture HW HW arch 4 1 3 2 Instruction ALU Registers Memory Fetch and Decode One possible hardware implementation of the HW HW IS ISA A Simple Processor 11

  11. 1. ins ß IM[PC] Processor Instruction Fetch 2. PC ß PC + 2 Loop 3. Do ins Fetch instruction from memory. Increment program counter Add (PC) to point to the next 2 instruction. Instruction Memory Read PC Address Instruction 12 A Simple Processor

  12. Arithmetic Instructions Opcode Rs Rt Rd ADD R3, R6, R8 0010 0011 0110 1000 16-bit Encoding Instruction Meaning Opcode Rs Rt Rd ADD Rs, Rt, Rd R[d] ß R[s] + R[t] 0010 0-15 0-15 0-15 SUB Rs, Rt, Rd R[d] ß R[s] – R[t] 0011 0-15 0-15 0-15 AND Rs, Rt, Rd R[d] ß R[s] & R[t] 0100 0-15 0-15 0-15 OR Rs, Rt, Rd Rd ß R[s] | R[t] 0101 0-15 0-15 0-15 ... A Simple Processor 13

  13. Instruction Decode, Register Access, ALU Control 4 Opcode Unit Reg Write ALU Op Write Enable 4 Read Addr 1 16 Read Rs 16 Data 1 4 Read Addr 2 overflow Rt Register File ALU Instruction zero 4 Write Addr Rd 16 Read ALU result 16 Data 2 Write Data A Simple Processor 14

  14. Memory Instructions Opcode Rs Rt Rd SW R6, -8(R3) 0001 0011 0110 1000 Instruction Meaning Op Rs Rt Rd LW Rt, offset(Rs) R[t] ß Mem[R[s] + offset] 0000 0-15 0-15 offset SW Rt, offset(Rs) Mem[R[s] + offset] ß R[t] 0001 0-15 0-15 offset ... A Simple Processor 15

  15. How can we support arithmetic Memory access and memory instructions? What's shared? Control 4 Opcode Unit Reg Write ALU Op Write Enable 4 Mem Store Read Addr 1 16 Read Rs Write Enable Data 1 16 4 Address Read Addr 2 16 Rt ALU Register File Inst 32 Data Memory Write Addr 16 Read Rt Data 2 Read Write 16 Write Data Data Data 4 4 16 Sign Rd extend (offset) A Simple Processor 16

  16. Choose with MUXs Mem Control 4 Opcode Unit Reg Write ALU Op Write Enable 4 Mem Store Read Addr 1 16 Read Rs Write Enable Data 1 16 4 Address Read Addr 2 16 Rt ALU Register File Inst 32 Data Memory Rt 1 4 Write Addr 16 Read 0 0 Data 2 Rd Read Write 16 1 Write Data Data Data 4 16 Rd Sign (offset) extend 0 1 A Simple Processor 17

  17. Control-flow Instructions Op Rs Rt Rd BEQ R1, R2, -2 0111 0001 0010 1110 16-bit Encoding Instruction Meaning Op Rs Rt Rd BEQ Rs, Rt, offset If R[s] == R[t] then 0111 0-15 0-15 offset PC ß PC + offset*2 ... A Simple Processor 18

  18. Compute branch target + Shift left by 1 Control 4 ALU Op Unit w o Reg Write l + f r e o v r o e 2 z Write Enable 4 Read Addr 1 16 Read Instruction Memory Data 1 16 4 Read Addr 2 16 Read PC ALU Address Register File Inst 32 1 4 Write Addr 16 Read 0 0 Data 2 1 Write Data 4 Sign 16 extend A Simple Processor 19

  19. Make branch decision MUX + Shift left by 1 Branch? Mem Control 4 ALU Op Unit w o Reg Write l + f r e o v r o e 2 z Write Enable Mem Store 4 Read Addr 1 16 Read Instruction Write Enable Memory Data 1 16 4 Address Read Addr 2 16 Read PC ALU Address Register File Inst 32 Data Memory 1 4 Write Addr 16 Read 0 0 Data 2 Read Write 16 1 Write Data Data Data 4 Sign 16 extend 0 1 A Simple Processor 20

  20. arch : not the only implementation HW HW arch Single-cycle architecture Simple, "easily" fits on a slide (and in your head). • One instruction takes one clock cycle. • Slowest instruction determines minimum clock cycle. • Inefficient. • Could it be better? Performance, energy, debugging, security, reconfigurability, … • Pipelining • OoO: out-of-order execution • SIMD: single instruction multiple data • Caching • Microcode vs. direct hardware implementation • … enormous, interesting design space of Computer Architecture • A Simple Processor 21

Recommend


More recommend