CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

Similar documents
COMP2611: Computer Organization. Data Representation

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

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

CS 61c: Great Ideas in Computer Architecture

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

CENG3420 Lecture 03 Review

Name: Login: cs61c- Decimal Ternary 5 12 three three

Chapter 2A Instructions: Language of the Computer

Lecture 5: Procedure Calls

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Lecture 4: MIPS Instruction Set

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

EC 413 Computer Organization

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

ECE331: Hardware Organization and Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Assembler. Lecture 8 CS301

COMPUTER ORGANIZATION AND DESIGN

Unsigned Binary Integers

Unsigned Binary Integers

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Course Administration

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

MIPS Functions and Instruction Formats

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Lecture 4: Instruction Set Architecture

CO212 Lecture 10: Arithmetic & Logical Unit

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Levels of Programming. Registers

Operations, Operands, and Instructions

CS367 Test 1 Review Guide

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Thomas Polzer Institut für Technische Informatik

M1 Computers and Data

CS 61c: Great Ideas in Computer Architecture

Computer Organization MIPS ISA

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Chapter 2. Instructions: Language of the Computer

CS 61C: Great Ideas in Computer Architecture. Multilevel Caches, Cache Questions

Computer Architecture. The Language of the Machine

Floating Point Arithmetic

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

CSEE 3827: Fundamentals of Computer Systems

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Outline. What is Performance? Restating Performance Equation Time = Seconds. CPU Performance Factors

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

Control Instructions

Inf2C - Computer Systems Lecture 2 Data Representation

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Instructions: Language of the Computer

Instructions: Language of the Computer

Department of Electrical Engineering and Computer Sciences Spring 2007 Instructor: Dr. Dan Garcia

CS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

ECE 486/586. Computer Architecture. Lecture # 7

Computer Architecture I Midterm I

CS3350B Computer Architecture MIPS Instruction Representation

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CS 110 Computer Architecture MIPS Instruction Formats

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Computer Architecture

ECE232: Hardware Organization and Design

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

CS61C Summer 2013 Midterm

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

3. Address Translation (25 pts)

15213 Recitation 2: Floating Point

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

CPS 104 Computer Organization and Programming

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches, Set Associative Caches, Cache Performance

Floating-point representations

Floating-point representations

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

Run time environment of a MIPS program

CS3350B Computer Architecture MIPS Introduction

MIPS Instruction Set Architecture (2)

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

Transcription:

CS 61C: Great Ideas in Computer Architecture (Brief) Review Lecture Instructor: Justin Hsia 7/16/2013 Summer 2013 Lecture #13 1

Topic List So Far (1/2) Number Representation Signed/unsigned, Floating Point Powers of 2 (IEC) C Topics Pointers, Arrays, Strings, Structs Bitwise operators and bit masking Memory Management Memory Layout Memory Allocation Strategies 7/16/2013 Summer 2013 Lecture #13 2

Topic List So Far (2/2) MIPS Topics Instruction Formats Labels, Branches, and Jumps Relative vs. Absolute Addressing Function/Register Conventions C.A.L.L. Performance Caches 7/16/2013 Summer 2013 Lecture #13 3

Number Representation (1/5) Anything can be represented as a number! Different interpretations of the same numeral n digits in base B can represent at most B n things Bases: binary (2), decimal (10), hex (16) Bit sizes: nibble (4), byte (8), word (32) Overflow: result of operation can t be properly represented Signed vs. Unsigned 7/16/2013 Summer 2013 Lecture #13 4

Number Representation (2/5) Integers Unsigned vs. Signed: sign & magnitude, 1 s complement, 2 s complement, biased Negation procedures vs. representation names Sign Extension vs. Zero Extension Characters Smallest unit of data (1 byte) ASCII standard maps characters to small numbers (e.g. 0 = 48, a = 97) 7/16/2013 Summer 2013 Lecture #13 5

Number Representation (3/5) Floating Point Binary point encoded in scientific notation 31 30 23 22 0 S Exponent (8) Mantissa (23) ( 1) S x (1. Mantissa) x 2 (Exponent 127) Exponent uses biased notation (bias of 2 7 1 = 127) Can only save 23 bits past binary point in Mantissa (rest gets rounded off) Double precision uses 1 11 52 split 7/16/2013 Summer 2013 Lecture #13 6

Number Representation (4/5) Floating Point Special Cases: Exponent Significand Meaning 0 0 ±0 0 non zero ± Denorm Num 1 254 anything ± Norm Num 255 0 ± 255 non zero NaN Exponent of 2 126 What numbers can we can represent? Watch out for exponent overflow and underflow Watch out for rounding (and loss of associativity) 7/16/2013 Summer 2013 Lecture #13 7

Number Representation (5/5) Powers of 2 (IEC Prefixes) Convert 2 XY : Y (Digit) Value 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 X (Digit) Value 0 1 Kibi(Ki) 2 Mebi(Mi) 3 Gibi(Gi) 4 Tebi(Ti) 5 Pebi (Pi) 6 Exbi(Ei) 7 Zebi(Zi) 8 Yobi(Yi) + Things 7/16/2013 Summer 2013 Lecture #13 8

C Topics (1/4) Pointer: data type that holds an address Visually can draw an arrow to another variable NULL (0x00000000) means pointer to nothing & (address of) and * (dereference) operators Pointer arithmetic moves correct number of bytes for data type (e.g. 1 for char, 4 for int) Trying to access invalid, un owned, or unaligned addresses causes errors Use pointers to pass by reference (C functions naturally pass by value) 7/16/2013 Summer 2013 Lecture #13 9

C Topics (2/4) Array: sequential collection of objects of the same data type Must be initialized with a size, cannot be changed type array[size]; or type array[] = {d 1,,d n }; Size implicit in initialization Bounds checking done manually (pass size) Access array: array[i] *(array + i) 7/16/2013 Summer 2013 Lecture #13 10

C Topics (3/4) Strings Array of characters; null terminated ( \0 =0) Don t need to pass length because can look for null terminator (strlen does not count it) For n characters, need space for n+1 bytes (sizeof(char)=1) 7/16/2013 Summer 2013 Lecture #13 11

C Topics (4/4) Structs Collection of variables (stored together in mem) Definition: struct name { fields }; Variable type is struct name (2 words) Access field (.) With pointers: x->field (*x).field Typedef Rename an existing variable type typedef name orig name new ; 7/16/2013 Summer 2013 Lecture #13 12

Memory Management (1/4) Program s address space contains 4 regions: ~ FFFF FFFF hex Stack: local variables, grows downward Heap: space requested for pointers via malloc(); resizes dynamically, grows upward Static Data: global and static variables, does not grow or shrink Code: loaded when program starts, does not change size ~ 0 hex stack heap static data code 7/16/2013 Summer 2013 Lecture #13 13

Memory Management (2/4) Stack grows in frames (1 per function) Hold local variables (these disappear) Bottom of Stack tracked by $sp LIFO action (pop/push) Stack holds what we can t fit in registers Spilling if more variables than registers Large local variables (arrays, structs) Old values we want to save (saved or volatile registers) 7/16/2013 Summer 2013 Lecture #13 14

Memory Management (3/4) Heap managed with malloc and free Pointers to chunks of memory of requested size (in bytes); use sizeof operator Check pointer; NULL if allocation failed Don t lose original address (need for free) With structs, free allocated fields before freeing struct itself Avoid memory leaks! 7/16/2013 Summer 2013 Lecture #13 15

Memory Management (4/4) Memory management Want fast with minimal memory overhead Avoid fragmentation Basic allocation strategies Best fit: Choose smallest block that fits request First fit: Choose first block that is large enough (always starts from beginning) Next fit: Like first fit, but resume search from where we last left off 7/16/2013 Summer 2013 Lecture #13 16

MIPS Topics (1/6) MIPS is a RISC ISA Smaller is faster and Keep is simple Goal is to produce faster hardware Pseudo instructions help programmer, but not actually part of ISA (MAL vs. TAL) 32 32 bit registers are extremely fast Only operands of instructions Need lw/sw/lb/sb for memory access Learn how to use your Green Card! It has soooooooooo much info on it 7/16/2013 Summer 2013 Lecture #13 17

MIPS Topics (2/6) Stored Program Concept Instructions are data, too! Memory is byte addressed Most data (including instructions) in words and word aligned, so all word addresses are multiples of 4 (end in 0b00) Endianness: 3 2 1 0 little endian msb lsb big endian 0 1 2 3 7/16/2013 Summer 2013 Lecture #13 18

Instruction Formats R: I: J: opcode MIPS Topics (3/6) rs rt rd shamt opcode rs rt immediate opcode target address funct Determine format/instr using opcode/funct (6) Register fields (5): rs/rt/rd Shift amount (5): shamt Constants/addresses: immediate (16), target address (26) 7/16/2013 Summer 2013 Lecture #13 19

MIPS Topics (4/6) Relative addressing: signed Branch instructions relative to PC PC = (PC+4) + (immediate*4) Can count by instruction for immediate Max forward: 2 15 instr = 2 17 bytes Max backwards: 2 15 +1 instr = 2 17 +4 bytes Do not need to be relocated Relative to current instruction 7/16/2013 Summer 2013 Lecture #13 20

MIPS Topics (5/6) Pseudo absolute addressing: Jump instructions try to specify exact address j/jal: PC = { (PC+4)[31..28], target address, 00 } jr: PC = R[rs] Target address field is desired byte address/4 j/jal can specify 2 26 instr = 2 28 bytes jr can specify 2 32 bytes = 2 30 instr Always need to be relocated 7/16/2013 Summer 2013 Lecture #13 21

MIPS Topics (6/6) MIPS functions jal invokes function, jr $ra returns $a0-$a3 for args, $v0-$v1 for return vals Saved registers: Volatile registers: $s0-$s7, $sp, $ra $t0-$t9, $v0-$v1, $a0-$a3 CalleR saves volatile registers it is using before making a procedure call CalleE saves saved registers it intends to use This is the confusing one 7/16/2013 Summer 2013 Lecture #13 22

C.A.L.L. Compiler converts a single HLL file into a single assembly file.c.s Assembler removes pseudo instructions, converts what it can to machine language, and creates symbol and relocation tables.s.o Resolves addresses by making 2 passes (for internal forward references) Linker combines several object files and resolves absolute addresses.o.out Enable separate compilation and use of libraries Loader loads executable into memory and begins execution 7/16/2013 Summer 2013 Lecture #13 23

Performance Performance measured in latency or bandwidth Latency measurement: Affected by different components of the computer 7/16/2013 Summer 2013 Lecture #13 24

Caches (1/4) Why cache? Take advantage of temporal/spatial locality to improve memory performance Cache Terminology Block: unit of data transfer between $ and Mem Slot: place to hold block of data in $ Set: set of slots an address can map into Hit, Miss, Replacement Hit Rate, Miss Rate, Hit:Miss Ratio 7/16/2013 Summer 2013 Lecture #13 25

Request is an address: Caches (2/4) Search by Index, check Valid & Tag(s) for match Cache Parameters T I O XX XX XX Block address Address space 2 A bytes A address bits Block size K bytes O = log 2 (K) offset bits Associativity N N slots/set Cache size C bytes C/K/N sets I = log 2 (C/K/N) index bits 2 T blocks map to set T = A I O 7/16/2013 Summer 2013 Lecture #13 26 A

Caches (3/4) Policies Write hit: write back / write through Write miss: write allocate / no write allocate Replacement: random / LRU Implementation Valid bit Dirty bit (if write back) Tag (identifier) Block data (8*K bits) LRU management bits per slot per set 7/16/2013 Summer 2013 Lecture #13 27

Caches (4/4) 3 C s of Cache Misses Compulsory, Capacity, Conflict Performance AMAT = HT + MR MP AMAT = HT 1 + MR 1 (HT 2 + MR 2 MP 2 ) Accesses Instr Accesses Instr CPI stall = CPI base + MR MP CPI stall = CPI base + (MR 1 MP 1 + MR 1 MR 2 MP 2 ) Extra terms if L1$ split among I$ and D$ MR global = product of all MR i 7/16/2013 Summer 2013 Lecture #13 28

Get To Know Your Staff Category: Food 7/16/2013 Summer 2013 Lecture #13 29