CS 61 C Great Ideas in Computer Architecture

  • Slides: 57
Download presentation
CS 61 C Great Ideas in Computer Architecture (a. k. a. Machine Structures) Lecture

CS 61 C Great Ideas in Computer Architecture (a. k. a. Machine Structures) Lecture 1: Course Introduction Instructors: Bernhard Boser Randy H. Katz http: //inst. eecs. berkeley. edu/~cs 61 c/

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You Need to Know About This Class Everything is a Number 11/9/2020 Fall 2016 - Lecture #1 2

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You Need to Know About This Class Everything is a Number 11/9/2020 Fall 2016 - Lecture #1 3

Most Popular Programming Languages • What do you think is the most “popular” programming

Most Popular Programming Languages • What do you think is the most “popular” programming language in use today? 11/9/2020 Fall 2016 - Lecture #1 4

Why You Need to Learn C! 11/9/2020 Fall 2016 - Lecture #1 5

Why You Need to Learn C! 11/9/2020 Fall 2016 - Lecture #1 5

CS 61 C is NOT really about C Programming • It is about the

CS 61 C is NOT really about C Programming • It is about the hardware-software interface – What does the programmer need to know to achieve the highest possible performance • C is close to the underlying hardware, unlike languages like Python and Java! – Allows us to talk about key hardware features in higher level terms – Allows programmer to explicitly harness underlying hardware parallelism for high performance 11/9/2020 Fall 2016 - Lecture #1 6

Old School CS 61 C 11/9/2020 Fall 2016 - Lecture #1 7

Old School CS 61 C 11/9/2020 Fall 2016 - Lecture #1 7

New School CS 61 C (1/2) Personal Mobile Devices 11/9/2020 Fall 2016 - Lecture

New School CS 61 C (1/2) Personal Mobile Devices 11/9/2020 Fall 2016 - Lecture #1 8 8

 New School CS 61 C (2/2) 11/9/2020 Fall 2016 - Lecture #1 9

New School CS 61 C (2/2) 11/9/2020 Fall 2016 - Lecture #1 9 9

New-School Machine Structures Software • Parallel Requests Assigned to computer e. g. , Search

New-School Machine Structures Software • Parallel Requests Assigned to computer e. g. , Search “cats” • Parallel Threads Assigned to core e. g. , Lookup, Ads Hardware Harness Parallelism & Achieve High Performance Smart Phone Warehouse -Scale Computer • Parallel Instructions >1 instruction @ one time e. g. , 5 pipelined instructions • Parallel Data >1 data item @ one time e. g. , Add of 4 pairs of words • Hardware descriptions All gates functioning in parallel at same time • 11/9/2020 … Core Memory Core (Cache) Input/Output Instruction Unit(s) Core Functional Unit(s) A 0+B 0 A 1+B 1 A 2+B 2 A 3+B 3 Main Memory Logic Gates Fall 2016 - Lecture #1 10

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You Need to Know About This Class Everything is a Number 11/9/2020 Fall 2016 - Lecture #1 12

Five Great Ideas in Computer Architecture 1. Abstraction (Layers of Representation/Interpretation) 2. Moore’s Law

Five Great Ideas in Computer Architecture 1. Abstraction (Layers of Representation/Interpretation) 2. Moore’s Law (Designing through trends) 3. Principle of Locality (Memory Hierarchy) 4. Parallelism 5. Dependability via Redundancy 11/9/2020 Fall 2016 - Lecture #1 13 13

Great Idea #1: Abstraction (Levels of Representation/Interpretation) High Level Language Program (e. g. ,

Great Idea #1: Abstraction (Levels of Representation/Interpretation) High Level Language Program (e. g. , C) Compiler Assembly Language Program (e. g. , MIPS) Assembler Machine Language Program (MIPS) temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw lw sw sw 0000 1010 1100 0101 $t 0, 0($2) $t 1, 4($2) $t 1, 0($2) $t 0, 4($2) 1001 1111 0110 1000 1100 0101 1010 0000 Anything can be represented as a number, i. e. , data or instructions 0110 1000 1111 1001 1010 0000 0101 1100 1111 1000 0110 0101 1100 0000 1010 1000 0110 1001 1111 Machine Interpretation Hardware Architecture Description (e. g. , block diagrams) Architecture Implementation Logic Circuit Description (Circuit Schematic Diagrams) 11/9/2020 Fall 2016 - Lecture #1 14 14

#2: Moore’s Law Predicts: 2 X Transistors / chip every 2 years Gordon Moore

#2: Moore’s Law Predicts: 2 X Transistors / chip every 2 years Gordon Moore Intel Cofounder B. S. Cal 1950! 11/9/2020 Fall 2016 - Lecture #1 15

End of Moore’s Law? Cost per transistor is rising as transistor size continues to

End of Moore’s Law? Cost per transistor is rising as transistor size continues to shrink 11/9/2020 Fall 2016 - Lecture #1 16

Jim Gray’s Storage Latency Analogy: How Far Away is the Data? Andromeda 10 9

Jim Gray’s Storage Latency Analogy: How Far Away is the Data? Andromeda 10 9 10 100 Tape /Optical Robot 6 Disk Main Memory 10 On Board Cache 2 On Chip Cache 1 Registers 11/9/2020 (ns) 2, 000 Years Pluto Sacramento This Campus This Room My Head Fall 2016 -2016 - Lecture #1 2 Years Jim Gray 1. 5 hr Turing Award B. S. Cal 1966 10 min Ph. D. Cal 1969! 1 min 17

Great Idea #3: Principle of Locality/ Memory Hierarchy 11/9/2020 Fall 2016 - Lecture #1

Great Idea #3: Principle of Locality/ Memory Hierarchy 11/9/2020 Fall 2016 - Lecture #1 18 18

Great Idea #4: Parallelism 11/9/2020 Fall 2016 - Lecture #1 19

Great Idea #4: Parallelism 11/9/2020 Fall 2016 - Lecture #1 19

Great Idea #5: Dependability via Redundancy • Redundancy so that a failing piece doesn’t

Great Idea #5: Dependability via Redundancy • Redundancy so that a failing piece doesn’t make the whole system fail 1+1=2 2 of 3 agree 1+1=2 1+1=1 FAIL! Increasing transistor density reduces the cost of redundancy 11/9/2020 Fall 2016 - Lecture #1 23

Great Idea #5: Dependability via Redundancy • Applies to everything from datacenters to storage

Great Idea #5: Dependability via Redundancy • Applies to everything from datacenters to storage to memory to instructors – Redundant datacenters so that can lose 1 datacenter but Internet service stays online – Redundant disks so that can lose 1 disk but not lose data (Redundant Arrays of Independent Disks/RAID) – Redundant memory bits of so that can lose 1 bit but no data (Error Correcting Code/ECC Memory) 11/9/2020 Fall 2016 - Lecture #1 24

Your Turn • You have 8 disks, 1 TB each. – What is the

Your Turn • You have 8 disks, 1 TB each. – What is the minimum number of extra disks to insure that no information is lost if a single disk fails? 1 1 0 0 A) 8 0 0 1 1 1 B) log 28 = 3 0 0 1 1 0 0 C) 1 D) 2 Rule: Each bit row has an odd The missing bit E) 0 number of ones (odd parity) must be one! 11/9/2020 Fall 2016 - Lecture #1 25

Break! 11/9/2020 Fall 2016 - Lecture #1 26

Break! 11/9/2020 Fall 2016 - Lecture #1 26

Understanding Computer Architecture de. pinterest. com 11/9/2020 Fall 2016 - Lecture #1 27

Understanding Computer Architecture de. pinterest. com 11/9/2020 Fall 2016 - Lecture #1 27

Why is Architecture Exciting Today? CPU Speed Flat ear y / 15% + d

Why is Architecture Exciting Today? CPU Speed Flat ear y / 15% + d pee k S oc l C CPU 11/9/2020 Fall 2016 - Lecture #1 28

Code (C) Motivation: Example Execution time $ gcc array. c $. /a. out 1.

Code (C) Motivation: Example Execution time $ gcc array. c $. /a. out 1. 0 X time for inc 1 1. 0 X time for inc 3 2. 3 X time for inc 15485867 Consecutive is >2 x faster! Relevance: • E. g. Vector vs Hash. Map • Independent of programming language 11/9/2020 Why? Fall 2016 - Lecture #1 29

Complete Code, Page 1 11/9/2020 Fall 2016 - Lecture #1 30

Complete Code, Page 1 11/9/2020 Fall 2016 - Lecture #1 30

Complete Code, Page 2 11/9/2020 Fall 2016 - Lecture #1 31

Complete Code, Page 2 11/9/2020 Fall 2016 - Lecture #1 31

How to get an A in 61 C 11/9/2020 Fall 2016 - Lecture #1

How to get an A in 61 C 11/9/2020 Fall 2016 - Lecture #1 32

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You Need to Know About This Class Everything is a Number 11/9/2020 Fall 2016 - Lecture #1 33

Course Information • Course Web: http: //inst. eecs. Berkeley. edu/~cs 61 c/ • Instructors:

Course Information • Course Web: http: //inst. eecs. Berkeley. edu/~cs 61 c/ • Instructors: Bernhard Boser and Randy H. Katz • Teaching Staff: – Co-Head TAs: Derek Ahmed and Stephan Liu – Lead TAs: Manu Goyal, Rebecca Herman, Alex Khodaverdian, Jason Zhang – 20 TAs + 10 Tutors (see webpage) • Textbooks: Average 15 pages of reading/week (can rent!) – Patterson & Hennessey, Computer Organization and Design, 5/e – Kernighan & Ritchie, The C Programming Language, 2 nd Edition – Barroso & Holzle, The Datacenter as a Computer, 2 nd Edition • Piazza: – Every announcement, discussion, clarification happens there! 11/9/2020 Fall 2016 - Lecture #1 34

CS 61 c House Rules in a Nutshell • Please don’t disturb the instructors

CS 61 c House Rules in a Nutshell • Please don’t disturb the instructors setting up or tearing down just before/after lecture • Webcast? Yes! • Labs and discussion after NEXT Tuesday’s lecture • Wait listed? Enroll in any available section/lab, swap later • Excused Absences: Let us know by second week • Midterms are in class 9/27 and 11/1; Final is 12/16 at 7 -10 PM • Labs are partnered and Projects are solo (5) – Discussion is Good, but Co-Developing/Sharing/Borrowing Project Code or Circuits is Bad – No Public Repos Please: Don’t Look, Don’t Publish • Join Piazza for more details … see http: //inst. eecs. berkeley. edu/~cs 61 c/fa 16/ 11/9/2020 Fall 2016 - Lecture #1 35

EPA! • Effort – Attending prof and TA office hours, completing all assignments, turning

EPA! • Effort – Attending prof and TA office hours, completing all assignments, turning in HW, doing reading quizzes • Participation – Attending lecture and voting using the clickers – Asking great questions in discussion and lecture and making it more interactive • Altruism – Helping others in lab or on Piazza • EPA! points have the potential to bump students up to the next grade level! (but actual EPA! scores are internal) 11/9/2020 Fall 2016 - Lecture #1 37

Peer Instruction • Increase real-time learning in lecture, test understanding of concepts vs. details

Peer Instruction • Increase real-time learning in lecture, test understanding of concepts vs. details • As complete a “segment” ask multiple-choice question 1 -2 minutes to decide yourself 2 minutes in pairs/triples to reach consensus. Teach others! 2 minute discussion of answers, questions, clarifications • You can get transmitters from the ASUC bookstore – – – We’ll start this next week – No web-based clickers, sorry! 11/9/2020 Fall 2016 - Lecture #1 38 38

Laptops and Phones in Lecture? • What do you think the policy should be?

Laptops and Phones in Lecture? • What do you think the policy should be? 11/9/2020 Fall 2016 - Lecture #1 40

Architecture of a typical Lecture Full Attention 10 Clickers “And in Clickers Administrivia Fun/News

Architecture of a typical Lecture Full Attention 10 Clickers “And in Clickers Administrivia Fun/News conclusion…” 35 60 78 90 Time (minutes) 11/9/2020 Fall 2016 - Lecture #1 44

Break! 11/9/2020 Fall 2016 - Lecture #1 45

Break! 11/9/2020 Fall 2016 - Lecture #1 45

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You

Agenda • • Thinking about Machine Structures Great Ideas in Computer Architecture What You Need to Know About This Class Everything is a Number 11/9/2020 Fall 2016 - Lecture #1 46

11/9/2020 http: //www. ruthmalan. com 47

11/9/2020 http: //www. ruthmalan. com 47

Computer Data • Computers represent data as binary values • Unit element: bit –

Computer Data • Computers represent data as binary values • Unit element: bit – Just two possible values, 0 or 1 – Can be efficiently stored/communicated/manipulated in hardware • Use many bits to store more complex information, e. g. – – – 11/9/2020 Byte: 8 bits, can represent 28 = 256 different values Word, e. g. 4 bytes (32 bits) to represent 232 different values 64 -bit floating point numbers Text files, databases, … (many bytes) Computer program Fall 2016 - Lecture #1 48

Binary Number Conversion Binary Decimal Binary 1001010 two = ? ten 74 ten =

Binary Number Conversion Binary Decimal Binary 1001010 two = ? ten 74 ten = ? two Binary Digit Decimal Value Decimal Binary (odd? ) 0 0 x 20 = 0 74 0 1 1 x 21 = 2 /2 = 37 1 0 0 x 22 = 0 /2 = 18 0 1 0 x 23 = 8 /2 = 9 1 0 0 x 24 = 0 /2 = 4 0 0 0 x 25 = 0 /2 = 2 0 1 1 x 26 = 64 /2 = 1 1 S = 74 ten Collect 1001010 two 11/9/2020 Fall 2016 - Lecture #1 49

Hexadecimal • Problem: many digits – e. g. 7643 ten = 111011011 two •

Hexadecimal • Problem: many digits – e. g. 7643 ten = 111011011 two • Solutions: – Grouping: 1 1101 1011 two – Hexadecimal: 1 DDBhex – Octal: 1 110 111 011 two 16733 oct 11/9/2020 Fall 2016 - Lecture #1 Binary Hex 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F 50

The Computer Knows it, too Output 11/9/2020 Decimal: 1234 Hex: 4 d 2 Octal:

The Computer Knows it, too Output 11/9/2020 Decimal: 1234 Hex: 4 d 2 Octal: 2322 Literals (not supported by all compilers): 0 x 4 d 2 = 1234 (hex) 0 b 10011010010 = 1234 (binary) 02322 = 1234 (octal, prefix 0 - zero) Fall 2016 - Lecture #1 51

Large Numbers Decimal Binary (IEC) Suffix Multiplier Value K 103 1000 Ki 210 1024

Large Numbers Decimal Binary (IEC) Suffix Multiplier Value K 103 1000 Ki 210 1024 M 106 1000, 000 Mi 220 1048, 576 G 109 1000, 000 Gi 230 1073, 741, 824 T 1012 1000, 000 Ti 240 1099, 511, 627, 776 E. g. 1 Gi. Byte disk versus 1 GByte disk Marketing exploits this: 1 TB disk 100 GB less than 1 Ti. B https: //en. wikipedia. org/wiki/Byte 11/9/2020 Fall 2016 - Lecture #1 52

Signed Integer Representation Sign & magnitude (8 -bit example): sign 7 -bit magnitude (0

Signed Integer Representation Sign & magnitude (8 -bit example): sign 7 -bit magnitude (0 … 127) Rules for addition, a + b: • • If (a>0 and b>0): add, sign 0 If (a>0 and b<0): subtract, sign … … +0, -0 are they equal? comparator must handle special case! Cumbersome • ”Complicated” hardware: reduced speed / increased power • Is there a better way? 11/9/2020 Fall 2016 - Lecture #1 53

4 -bit Example Decimal 7 + Binary 7 7 -3 + 4 -3 +

4 -bit Example Decimal 7 + Binary 7 7 -3 + 4 -3 + 16 4 + 16 + 0111 13 + 4 + 16 1101 1 0100 + 1 0000 • Map negative positive numbers § Example for N=4 -bit: -3 24 – 3 = 13 § “Two’s complement” § No special rules for adding positive and negative numbers -8 11/9/2020 -7 … -1 0 1 … 7 + 24 = 16 8 9 … 15 54

Two’s Complement (8 -bit example) Signed Decimal Unsigned Decimal Binary Two’s Complement -128 1000

Two’s Complement (8 -bit example) Signed Decimal Unsigned Decimal Binary Two’s Complement -128 1000 0000 -127 129 1000 0001 … … -2 254 1111 1110 -1 255 1111 0 0 0000 1 0000 0001 … … . . . 127 0111 1111 … 1 Note: 11/9/2020 +256 +0 Most significant bit (MSB) equals sign Fall 2016 - Lecture #1 55

Unary Negation (Two’s Complement) 4 -bit Example (-8 ten … +7 ten) Brute Force

Unary Negation (Two’s Complement) 4 -bit Example (-8 ten … +7 ten) Brute Force & Tedious Clever & Elegant ”largest” 4 -bit number + 1 16 ten - 3 ten 10000 two - 0011 two 15 ten - 3 ten 01111 two - 0011 two 13 ten 1101 two 16 ten - 13 ten 10000 two - 1101 two 12 ten + 1 ten 1100 two + 0001 two 13 ten 1101 two 3 ten 0011 two 11/9/2020 Fall 2016 - Lecture #1 invert 56

Your Turn • What is the decimal value of the following binary 8 -bit

Your Turn • What is the decimal value of the following binary 8 -bit 2’s complement number? 1110 0001 two Answer A B C D E 11/9/2020 Value 33 ten -31 ten 225 ten -33 ten None of the above Fall 2016 - Lecture #1 57

Addition 4 -bit Example Unsigned Signed (Two’s Complement) 3 ten 4 ten 0011 two

Addition 4 -bit Example Unsigned Signed (Two’s Complement) 3 ten 4 ten 0011 two + 0100 two 0111 two 7 ten 0111 two 3 ten + 11 ten 0011 two + 1011 two 3 ten + -5 ten 0011 two + 1011 two 14 ten 1110 two -2 ten 1110 two + 3 ten 4 ten 0011 two + 0100 two 7 ten + No special rules for two’s complement signed addition 11/9/2020 Fall 2016 - Lecture #1 58

Overflow 4 -bit Example Unsigned + Signed (Two’s Complement) 13 ten 14 ten 1101

Overflow 4 -bit Example Unsigned + Signed (Two’s Complement) 13 ten 14 ten 1101 two + 1110 two 27 ten 1 1011 two + -3 ten -2 ten 1101 two + 1110 two -5 ten 1 1011 two carry-out and overflow carry-out but no overflow 7 ten + 1 ten 0111 two + 0001 two 8 ten 0 1000 two -8 ten 0 1000 two no carry-out but overflow no carry-out and no overflow Carry-out Overflow 11/9/2020 Carry-out Overflow Fall 2016 - Lecture #1 59

Overflow Detection 4 -bit Example Unsigned Signed (Two’s Complement) • Carry-out indicates overflow •

Overflow Detection 4 -bit Example Unsigned Signed (Two’s Complement) • Carry-out indicates overflow • Overflow if – Signs of operands are equal AND – Sign of result differs from sign of operands • No overflow when signs of operands differ Overflow rules depend on operands (signed vs unsigned) 11/9/2020 Fall 2016 - Lecture #1 60

Sign Extension Decimal Binary 4 -bit 8 -bit 32 -bit 3 ten 0011 two

Sign Extension Decimal Binary 4 -bit 8 -bit 32 -bit 3 ten 0011 two 0000 0011 two -3 ten 1101 two 1111 1101 two • Why is this relevant? • Assignment differs for signed (above) and unsigned numbers • Compiler knows (from type declaration) • Different assembly instructions for copying signed/unsigned data 11/9/2020 Fall 2016 - Lecture #1 61

Your Turn • Which range of decimals can be expressed with a 6 -bit

Your Turn • Which range of decimals can be expressed with a 6 -bit two’s complement number? 11/9/2020 Answer A B C Range -32 … 32 -64 … 63 -31 … 32 D E -16 … 15 -32 … 31 Fall 2016 - Lecture #1 62

Answer • Which range of decimals can be expressed with a 6 -bit two’s

Answer • Which range of decimals can be expressed with a 6 -bit two’s complement number? 11/9/2020 Answer A B C Range -32 … 32 -64 … 63 -31 … 32 D E -16 … 15 -32 … 31 Fall 2016 - Lecture #1 63

And In Conclusion … (1/2) • CS 61 C: – High performance by leveraging

And In Conclusion … (1/2) • CS 61 C: – High performance by leveraging computer architecture: • Strength and weaknesses (e. g. cache) • Performance features (e. g. parallel instructions) – Learn C and assembly facilitate access to machine features • Basis: five great ideas in computer architecture 1. 2. 3. 4. 5. Abstraction: Layers of Representation/Interpretation Moore’s Law Principle of Locality/Memory Hierarchy Parallelism Dependability via Redundancy • Performance Measurement and Improvement 11/9/2020 Fall 2016 - Lecture #1 64

And In Conclusion … (2/2) • Everything is a Number! – Collections of bits

And In Conclusion … (2/2) • Everything is a Number! – Collections of bits can store and communicate arbitrary digital data – Even programs are represented by bits • Two’s complement representation avoids special rules for addition of negative numbers 11/9/2020 Fall 2016 - Lecture #1 65 65

And in Conclusion: Everything is a Number https: //www. cartoonstock. com 11/9/2020 Fall 2016

And in Conclusion: Everything is a Number https: //www. cartoonstock. com 11/9/2020 Fall 2016 - Lecture #1 66