Computer Science 61C Spring Friedland and Weaver. The MIPS Datapath

Similar documents
CS 61C: Great Ideas in Computer Architecture Datapath. Instructors: John Wawrzynek & Vladimir Stojanovic

CS3350B Computer Architecture Winter 2015

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 18 CPU Design: The Single-Cycle I ! Nasty new windows vulnerability!

Review. N-bit adder-subtractor done using N 1- bit adders with XOR gates on input. Lecture #19 Designing a Single-Cycle CPU

CS61C : Machine Structures

CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture. MIPS CPU Datapath, Control Introduction

EECS150 - Digital Design Lecture 10- CPU Microarchitecture. Processor Microarchitecture Introduction

UC Berkeley CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Single- Cycle CPU Datapath Control Part 1

Clever Signed Adder/Subtractor. Five Components of a Computer. The CPU. Stages of the Datapath (1/5) Stages of the Datapath : Overview

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Lecture 27: Single- Cycle CPU Datapath Design

EECS150 - Digital Design Lecture 9- CPU Microarchitecture. Watson: Jeopardy-playing Computer

CS61C : Machine Structures

Outline. EEL-4713 Computer Architecture Designing a Single Cycle Datapath

CS61C : Machine Structures

361 datapath.1. Computer Architecture EECS 361 Lecture 8: Designing a Single Cycle Datapath

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Lecture 28: Single- Cycle CPU Datapath Control Part 1

Ch 5: Designing a Single Cycle Datapath

EECS 151/251A Fall 2017 Digital Design and Integrated Circuits. Instructor: John Wawrzynek and Nicholas Weaver. Lecture 13 EE141

The Big Picture: Where are We Now? EEM 486: Computer Architecture. Lecture 3. Designing a Single Cycle Datapath

COMP303 - Computer Architecture Lecture 8. Designing a Single Cycle Datapath

Truth Table! Review! Use this table and techniques we learned to transform from 1 to another! ! Gate Diagram! Today!

ECE468 Computer Organization and Architecture. Designing a Single Cycle Datapath

CpE242 Computer Architecture and Engineering Designing a Single Cycle Datapath

CPU Organization (Design)

CS 110 Computer Architecture Single-Cycle CPU Datapath & Control

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

Chapter 4. The Processor

CS3350B Computer Architecture Winter Lecture 5.7: Single-Cycle CPU: Datapath Control (Part 2)

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

CS3350B Computer Architecture Quiz 3 March 15, 2018

Chapter 4. The Processor

The Processor: Datapath & Control

ECE170 Computer Architecture. Single Cycle Control. Review: 3b: Add & Subtract. Review: 3e: Store Operations. Review: 3d: Load Operations

Processor (I) - datapath & control. Hwansoo Han

CS 61c: Great Ideas in Computer Architecture

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CENG 3420 Lecture 06: Datapath

CS Computer Architecture Spring Week 10: Chapter

Chapter 4. The Processor. Computer Architecture and IC Design Lab

The MIPS Processor Datapath

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

ECE260: Fundamentals of Computer Engineering

Instructor: Randy H. Katz hcp://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #18. Warehouse Scale Computer

Adding Support for jal to Single Cycle Datapath (For More Practice Exercise 5.20)


Chapter 4. The Processor Designing the datapath

Computer and Information Sciences College / Computer Science Department The Processor: Datapath and Control

CS 61C: Great Ideas in Computer Architecture. Lecture 11: Datapath. Bernhard Boser & Randy Katz

Chapter 4. The Processor

Review: Abstract Implementation View

University of California College of Engineering Computer Science Division -EECS. CS 152 Midterm I

Working on the Pipeline

CS 61C: Great Ideas in Computer Architecture Lecture 12: Single- Cycle CPU, Datapath & Control Part 2

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

EN2910A: Advanced Computer Architecture Topic 02: Review of classical concepts

Full Datapath. CSCI 402: Computer Architectures. The Processor (2) 3/21/19. Fengguang Song Department of Computer & Information Science IUPUI

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

Chapter 4. Instruction Execution. Introduction. CPU Overview. Multiplexers. Chapter 4 The Processor 1. The Processor.

Lecture #17: CPU Design II Control

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 19 CPU Design: The Single-Cycle II & Control !

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

CS222: Processor Design

COMPUTER ORGANIZATION AND DESIGN. The Hardware/Software Interface. Chapter 4. The Processor: A Based on P&H

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 351 Exam 2 Mon. 11/2/2015

The MIPS Instruction Set Architecture

Chapter 4. The Processor

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Single- Cycle CPU Datapath & Control Part 2

Systems Architecture

Major CPU Design Steps

Single Cycle CPU Design. Mehran Rezaei

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Single Cycle Datapath

CS 61C: Great Ideas in Computer Architecture Control and Pipelining

COMP303 Computer Architecture Lecture 9. Single Cycle Control

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

361 control.1. EECS 361 Computer Architecture Lecture 9: Designing Single Cycle Control

The Processor. Z. Jerry Shi Department of Computer Science and Engineering University of Connecticut. CSE3666: Introduction to Computer Architecture

CSE140: Components and Design Techniques for Digital Systems

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

CSCI 402: Computer Architectures. Fengguang Song Department of Computer & Information Science IUPUI. Today s Content

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

CPE 335 Computer Organization. Basic MIPS Architecture Part I

CSE 141 Computer Architecture Summer Session Lecture 3 ALU Part 2 Single Cycle CPU Part 1. Pramod V. Argade

Processor Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Lecture 10: Simple Data Path

Chapter 5: The Processor: Datapath and Control

Lecture Topics. Announcements. Today: Single-Cycle Processors (P&H ) Next: continued. Milestone #3 (due 2/9) Milestone #4 (due 2/23)

Mark Redekopp and Gandhi Puvvada, All rights reserved. EE 357 Unit 15. Single-Cycle CPU Datapath and Control

Single Cycle Datapath

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

are Softw Instruction Set Architecture Microarchitecture are rdw

Chapter 4 The Processor 1. Chapter 4A. The Processor

Midterm I October 6, 1999 CS152 Computer Architecture and Engineering

Midterm I March 3, 1999 CS152 Computer Architecture and Engineering

Processor Architecture

Transcription:

The MIPS Datapath 1

The Critical Path and Circuit Timing The critical path is the slowest path through the circuit For a synchronous circuit, the clock cycle must be longer than the critical path otherwise we will have timing problems Its the combination of the CLK->Q time for the flip flop, the combinational delay, and the setup time CLK->Q: Time it takes from when the clock edge comes to the flip-flop output changes Combinational delay: The slowest/longest path in the combinational logic Setup time: Time that the flip-flop requires the the input be stable before the clock comes 2

And Hold Time... Flip-flops are delicate little circuits... They don't like their input changing before the clock comes (setup time) And they don't like their input changing just after the clock edge (hold time) Hold time violations occur when there exists a path through the circuit that is very short CLK->Q + shortest combinational delay < hold time Fix by deliberately adding in delays 3

How A D-type Flip-Flop Works A Flip-Flop is two transparent D-type latches A latch passes D->Q when C is high A latch holds Q when C is low D LATCH D Q LATCH D Q Q Latch Truth Table D CLK Q X 0 NC 0 1 0 1 1 1 CLK CLK CLK This is why we need: Setup time Hold Time CLQ->Q time 4

Arithmetic and Logic Unit Most processors contain a special logic block called the Arithmetic and Logic Unit (ALU) We ll show you an easy one that does ADD, SUB, bitwise AND, bitwise OR 5

Our simple ALU 6

Extremely Clever Subtractor Computer Science 61C Fall 2016 x y XOR(x,y) 0 0 0 0 1 1 1 0 1 1 1 0 + + + XOR serves as conditional inverter! 7

Clickers How was the midterm? Emotion Spectrum A E 8

Clicker Question Convert the truth table to a boolean expression (no need to simplify): A: F = xy + x(~y) x y F(x,y) B: F = xy + (~x)y + (~x)(~y) C: F = (~x)y + x(~y) D: F = xy + (~x)y 0 0 0 0 1 1 1 0 0 1 1 1 E: F = (x+y)(~x+~y) 9

Components of a Computer Processor Control Enable? Read/Write Memory Input Datapath PC Address Program Bytes Registers Write Data Arithmetic & Logic Unit (ALU) Read Data Data Output Processor-Memory Interface I/O-Memory Interfaces 10

The CPU Processor (CPU): the active part of the computer that does all the work (data manipulation and decision-making) Datapath: portion of the processor that contains hardware necessary to perform operations required by the processor (the brawn) Control: portion of the processor (also in hardware) that tells the datapath what needs to be done (the brain) 11

Datapath and Control Datapath designed to support data transfers required by instructions Controller causes correct transfers to happen PC instruction memory rd rs rt registers ALU Data memory +4 imm opcode, funct Controller 12

Five Stages of Instruction Execution Stage 1: Instruction Fetch Stage 2: Instruction Decode Stage 3: ALU (Arithmetic-Logic Unit) Stage 4: Memory Access Stage 5: Register Write Later on we will add pipeline registers: So when one instruction is in stage 3, the next instruction is in stage 2 and the one after that in stage 1 13

Stages of Execution on Datapath PC instruction memory rd rs rt registers ALU Data memory +4 imm 1. Instruction Fetch 2. Decode/ Register Read 3. Execute 4. Memory 5. Register Write 14

Stages of Execution (1/5) There is a wide variety of MIPS instructions: so what general steps do they have in common? Stage 1: Instruction Fetch no matter what the instruction, the 32-bit instruction word must first be fetched from memory (the cache-memory hierarchy) also, this is where we Increment PC (that is, PC = PC + 4, to point to the next instruction: byte addressing so + 4) Which is why the branches are all relative to PC + 4, not PC 15

Stages of Execution (2/5) Stage 2: Instruction Decode upon fetching the instruction, we next gather data from the fields (decode all necessary instruction data) first, read the opcode to determine instruction type and field lengths second, read in data from all necessary registers for add, read two registers for addi, read one register for jal, no reads necessary 16

Stages of Execution (3/5) Stage 3: ALU (Arithmetic-Logic Unit) the real work of most instructions is done here: arithmetic (+, -, *, /), shifting, logic (&, ), comparisons (slt) what about loads and stores? lw $t0, 40($t1) the address we are accessing in memory = the value in $t1 PLUS the value 40 so we do this addition in this stage 17

Stages of Execution (4/5) Stage 4: Memory Access actually only the load and store instructions do anything during this stage; the others remain idle during this stage or skip it all together since these instructions have a unique step, we need this extra stage to account for them as a result of the cache system, this stage is expected to be fast But if the cache fails to hit (more later in the class), this can "stall" 18

Stages of Execution (5/5) Stage 5: Register Write most instructions write the result of some computation into a register examples: arithmetic, logical, shifts, loads, slt what about stores, branches, jumps? don t write anything into a register at the end these remain idle during this fifth stage or skip it all together 19

Stages of Execution on Datapath PC instruction memory rd rs rt registers ALU Data memory +4 imm 1. Instruction Fetch 2. Decode/ Register Read 3. Execute 4. Memory 5. Register Write 20

Datapath Walkthroughs (1/3) add $r3,$r1,$r2 # r3 = r1+r2 Stage 1: fetch this instruction, increment PC Stage 2: decode to determine it is an add, then read registers $r1 and $r2 Stage 3: add the two values retrieved in Stage 2 Stage 4: idle (nothing to write to memory) Stage 5: write result of Stage 3 into register $r3 21

Example: add Instruction PC add r3, r1, r2 instruction memory 3 1 2 registers reg[1] reg[2] reg[1] + reg[2] ALU Data memory +4 imm 22

Datapath Walkthroughs (2/3) slti $r3,$r1,17 # if (r1 <17 ) r3 = 1 else r3 = 0 Stage 1: fetch this instruction, increment PC Stage 2: decode to determine it is an slti, then read register $r1 We will also likely fetch $r3 but value is ignored: Simplifies decoding logic on deciding which registers to fetch Stage 3: compare value retrieved in Stage 2 with the integer 17 Stage 4: idle Stage 5: write the result of Stage 3 (1 if reg source was less than signed immediate, 0 otherwise) into register $r3 23

Example: slti Instruction PC slti r3, r1, 17 instruction memory x 1 3 registers reg[1] reg[1] < 17? ALU Data memory +4 imm 17 24

Datapath Walkthroughs (3/3) sw $r3,16($r1) # Mem[r1+16]=r3 Stage 1: fetch this instruction, increment PC Stage 2: decode to determine it is a sw, then read registers $r1 and $r3 Stage 3: add 16 to value in register $r1 (retrieved in Stage 2) to compute address Stage 4: write value in register $r3 (retrieved in Stage 2) into memory address computed in Stage 3 Stage 5: idle (nothing to write into a register) 25

Example: sw Instruction PC sw r3, 16(r1) instruction memory x 1 3 registers reg[1] reg[3] reg[1] + 16 ALU Data memory +4 imm 16 MEM[r1+17] = r3 26

Why Five Stages? (1/2) Could we have a different number of stages? Yes, other ISAs have different natural number of stages And these days, pipelining can be much more aggressive than the "natural" 5 stages MIPS uses Why does MIPS have five if instructions tend to idle for at least one stage? Five stages are the union of all the operations needed by all the instructions. One instruction uses all five stages: the load 27

Why Five Stages? (2/2) lw $r3,16($r1) # r3=mem[r1+16] Stage 1: fetch this instruction, increment PC Stage 2: decode to determine it is a lw, then read register $r1 Stage 3: add 16 to value in register $r1 (retrieved in Stage 2) Stage 4: read value from memory address computed in Stage 3 Stage 5: write value read in Stage 4 into register $r3 28

Example: lw Instruction PC lw r3, 17(r1) instruction memory x 1 3 registers reg[1] reg[1] + 16 ALU Data memory +4 imm 16 MEM[r1+16] 29

Processor Design: 5 steps Step 1: Analyze instruction set to determine datapath requirements Meaning of each instruction is given by register transfers Datapath must include storage element for ISA registers Datapath must support each register transfer Step 2: Select set of datapath components & establish clock methodology Step 3: Assemble datapath components that meet the requirements Step 4: Analyze implementation of each instruction to determine setting of control points that realizes the register transfer Step 5: Assemble the control logic 30

The MIPS Instruction Formats All MIPS instructions are 32 bits long. 3 formats: R-type I-type J-type 31 31 31 26 21 16 11 6 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 26 21 16 op rs rt address/immediate 6 bits 5 bits 5 bits 16 bits 26 op target address 6 bits 26 bits The different fields are: op: operation ( opcode ) of the instruction rs, rt, rd: the source and destination register specifiers shamt: shift amount funct: selects the variant of the operation in the op field address / immediate: address offset or immediate value target address: target address of jump instruction 0 0 0 31

The MIPS-lite Subset ADDU and SUBU addu rd,rs,rt subu rd,rs,rt OR Immediate: ori rt,rs,imm16 LOAD and STORE Word lw rt,rs,imm16 sw rt,rs,imm16 BRANCH: beq rs,rt,imm16 31 31 31 31 26 21 16 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 26 21 16 op rs rt immediate 6 bits 5 bits 5 bits 16 bits 26 21 op rs rt immediate 6 bits 5 bits 5 bits 16 bits 26 21 op rs rt immediate 6 bits 5 bits 5 bits 16 bits 16 16 11 6 0 0 0 0 32

Register Transfer Level (RTL) Colloquially called Register Transfer Language RTL gives the meaning of the instructions All start by fetching the instruction itself {op, rs, rt, rd, shamt, funct} MEM[ PC ] {op, rs, rt, Imm16} MEM[ PC ] Inst Register Transfers ADDU R[rd] R[rs] + R[rt]; PC PC + 4 SUBU R[rd] R[rs] R[rt]; PC PC + 4 ORI R[rt] R[rs] zero_ext(imm16); PC PC + 4 LOAD R[rt] MEM[ R[rs] + sign_ext(imm16)]; PC PC + 4 STORE MEM[ R[rs] + sign_ext(imm16) ] R[rt]; PC PC + 4 BEQ if ( R[rs] == R[rt] ) PC PC + 4 + {sign_ext(imm16), 2 b00} else PC PC + 4 33

In Conclusion Divide and Conquer to build complex logic blocks from smaller simpler pieces (adder) Five stages of MIPS instruction execution Mapping instructions to datapath components Single long clock cycle per instruction 34

If There is Time Left: CloudBleed... How many got "change your password" emails from various services? What happened: C out-of-bounds read! if(ptr == end)... Unfortunately, ptr got incremented 1 past end when it couldn't parse HTML right Result was that Cloudflare would, under some conditions, read out memory This memory contained other requests to different cloudflare sites And it would get picked up by search engines and stored in their caches! 35

Lessons Learned... Without detailed audibility, its impossible to know what was lost Which is why some sites went "oh, change your password", even though the odds of your password being compromised are slim 36

Lessons Already Forgotten... Don't Use C/C++! This is "yet another massively disruptive bug caused because programmers don't use safe languages!" And if you do, don't use pointer arithmetic Array logic, eg if (index >= end)... rather less likely to screw up Use Valgrind or similar Valgrind would have trapped this as an "out of bounds read" 37