ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 3: Arithmetic Instructions Partially adapted from Computer Organization and Design, 4.

Slides:



Advertisements
Similar presentations
Instruction Set-Intro
Advertisements

COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Chapter 2.
Power calculation for transistor operation What will cause power consumption to increase? CS2710 Computer Organization1.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 2: Overview of Computer Organization Partially adapted from Computer Organization and.
CS 61C L07 MIPS Intro (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Fall 2011 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Chapter 1 CSF 2009 Computer Performance. Defining Performance Which airplane has the best performance? Chapter 1 — Computer Abstractions and Technology.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
Lec 2 Aug 31 review of lec 1 continue Ch 1 course overview performance measures Ch 1 exercises quiz 1.
CSCE 212 Chapter 4: Assessing and Understanding Performance Instructor: Jason D. Bakos.
CS 61C L06 MIPS Intro (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
CIS 314: Introduction to MIPS Assembly Language: Arithmetic Fall 2005 I´ve been getting this a lot lately So, what are you teaching this term? Computer.
CS/ECE 3330 Computer Architecture Chapter 1 Performance / Power.
CS61C L08 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Chapter 1 Computer Abstractions and Technology. Chapter 1 — Computer Abstractions and Technology — 2 The Computer Revolution Progress in computer technology.
EET 4250: Chapter 1 Performance Measurement, Instruction Count & CPI Acknowledgements: Some slides and lecture notes for this course adapted from Prof.
CS1104 Assembly Language: Part 1
CIS 314 : Computer Organization Lecture 1 – Introduction.
CS 61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61C L06 More Memory Management, Intro to MIPS (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
Lecture 3: Computer Performance
From C to Assembly Language Jen-Chang Liu, Spring 2006 Adapted from
Lecture 7: Instruction Set Architecture CSE 30: Computer Organization and Systems Programming Winter 2014 Diba Mirza Dept. of Computer Science and Engineering.
Chapter 1 Section 1.4 Dr. Iyad F. Jafar Evaluating Performance.
CS 61C L2.1.2 MM and MIPS (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Garbage Collection & Intro to MIPS Kurt Meinz.
Chapter 1 Computer Abstractions and Technology Part II.
Chapter 1 - The Computer Revolution Chapter 1 — Computer Abstractions and Technology — 1  Progress in computer technology  Underpinned by Moore’s Law.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 1 Computer Abstractions and Technology Sections 1.5 – 1.11.
Reformatting a Machine 125 Million Miles Away! Mars rover “Opportunity” got its flash drive reformatted 9/8/14, reason: rover keeps rebooting. Happy news:
Chapter 1 — Computer Abstractions and Technology — 1 Understanding Performance Algorithm Determines number of operations executed Programming language,
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Chapter 2 Instructions: Language of the Computer Part I.
Performance Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Chapter 1 Technology Trends and Performance. Chapter 1 — Computer Abstractions and Technology — 2 Technology Trends Electronics technology continues to.
ECE 15B Computer Organization Spring 2011 Dmitri Strukov Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy,
CSE2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 2: Measuring Performance Topics: 1. Performance:
1 Lecture 2: Performance, MIPS ISA Today’s topics:  Performance equations  MIPS instructions Reminder: canvas and class webpage:
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /03/2013 Lecture 3: Computer Performance Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Performance Computer Organization II 1 Computer Science Dept Va Tech January 2009 © McQuain & Ribbens Defining Performance Which airplane has.
CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro 1 Instructors: Vladimir Stojanovic & Nicholas Weaver
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Chapter 1 Computer Abstractions and Technology. Chapter 1 — Computer Abstractions and Technology — 2 The Computer Revolution Progress in computer technology.
Chapter 1 Performance & Technology Trends. Outline What is computer architecture? Performance What is performance: latency (response time), throughput.
Chapter 1 Computer Abstractions and Technology. Chapter 1 — Computer Abstractions and Technology — 2 The Computer Revolution Progress in computer technology.
Lecture 3. Performance Prof. Taeweon Suh Computer Science & Engineering Korea University COSE222, COMP212, CYDF210 Computer Architecture.
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2014 © UCB TA/Guest Lecturer: Shreyas Chand inst.eecs.berkeley.edu/~cs61c.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 4, EE 334.
Computer Architecture & Operations I
Computer Architecture & Operations I
IT 251 Computer Organization and Architecture
CS161 – Design and Architecture of Computer Systems
Lecturer PSOE Dan Garcia
Lecture 3: MIPS Instruction Set
Performance Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
Instruction Set Architecture
Morgan Kaufmann Publishers
COSC 3406: Computer Organization
IT 251 Computer Organization and Architecture
CSCE 212 Chapter 4: Assessing and Understanding Performance
Instructions - Type and Format
Hello to Jessy VanDivner listening from Ohio!
Instructions in Machine Language
COMS 361 Computer Organization
March 2006 Saeid Nooshabadi
Presentation transcript:

ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 3: Arithmetic Instructions Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy, and classes taught by Patterson at Berkeley, Ryan Kastner at UCSB and Mary Jane Irwin at Penn State

Announcement TA office hours for Vivek were moved to Tuesday 11:00 am – 12:00 am Basics of logic design is in Appendix C (P+H) SPIM and reading status ECE 15B Spring 2010

Agenda Key concepts from last lecture & several new ones C operators and operands Variables in Assembly: Registers Addition and Subtraction in Assembly ECE 15B Spring 2010

Key Concepts from Last Lecture Synchronous circuits Clocking & Pipelining & Timing Diagram CPU simplified diagram ECE 15B Spring 2010

CPU Clocking Operation of digital hardware governed by a constant-rate clock Clock (cycles) Data transfer and computation Update state Clock period Clock period: duration of a clock cycle e.g., 250ps = 0.25ns = 250×10 –12 s Clock frequency (rate): cycles per second e.g., 4.0GHz = 4000MHz = 4.0×10 9 Hz ECE 15B Spring 2010

CPU Overview ECE 15B Spring 2010

… with muxes Can’t just join wires together Use multiplexers ECE 15B Spring 2010

… with muxes ECE 15B Spring 2010

Below the Program lw $t0, 0($2) lw $t1, 4($2) sw $t1, 0($2) sw $t0, 4($2) High Level Language Program (e.g., C) Assembly Language Program (e.g.,MIPS) Machine Language Program (MIPS) Hardware Architecture Description (e.g., block diagrams) Compiler Assembler Machine Interpretation temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; Logic Circuit Description (Circuit Schematic Diagrams) Architecture Implementation ECE 15B Spring 2010

Assembly Language ECE 15B Spring 2010 Basic job of a CPU: execute lots of instructions Instructions are the primitive operations that the CPU may execute Different CPUs implement different sets of instructions Instruction Set Architecture (ISA) is a set of instructions a particular CPU implements Examples: Intel 80x86 (Pentium 4), IBM/Motorola Power PC (Macintosh), MIPS, Intel IA64, ARM

Instruction Set Architectures ECE 15B Spring 2010 Early trend was to add more and more instructions to new CPU to do elaborate operations VAX architecture had an instruction to multiply polynomials RISC philosophy (Cocke IBM, Patterson, Hennessy, 1980s) RISC = Reduced Instruction Set Computing Keep the instruction set small and simple which makes it easier to build fast hardware Let software (compiler) do complicated operations by composing simpler ones

How to Access Performance of Instruction Set Architecture? ECE 15B Spring 2010

SPEC CPU Benchmark Programs used to measure performance – Supposedly typical of actual workload Standard Performance Evaluation Corp (SPEC) – Develops benchmarks for CPU, I/O, Web, … SPEC CPU2006 – Elapsed time to execute a selection of programs Negligible I/O, so focuses on CPU performance – Normalize relative to reference machine – Summarize as geometric mean of performance ratios CINT2006 (integer) and CFP2006 (floating-point)

CINT2006 for Opteron X ECE 15B Spring 2010 NameDescriptionIC×10 9 CPITc (ns)Exec timeRef timeSPECratio perlInterpreted string processing2, , bzip2Block-sorting compression2, , gccGNU C Compiler1, , mcfCombinatorial optimization ,3459, goGo game (AI)1, , hmmerSearch gene sequence2, , sjengChess game (AI)2, , libquantumQuantum computer simulation1, ,04720, h264avcVideo compression3, , omnetppDiscrete event simulation , astarGames/path finding1, , xalancbmkXML parsing1, ,1436, Geometric mean11.7

Review: Technology Trends Uniprocessor Performance (SPECint) VAX : 1.25x/year 1978 to 1986 RISC + x86: 1.52x/year 1986 to 2002 RISC + x86: 1.20x/year 2002 to present 1.25x/year 1.52x/year 1.20x/year Performance (vs. VAX-11/780) 3X “Sea change” in chip design: multiple “cores” or processors per chip ECE 15B Spring 2010

MIPS Architecture MIPS – Semiconductor company that built one of the first commercial RISC architectures We will study the MIPS architecture in detail in this class Why MIPS instead of Intel 80x86 – MIPS is simple and elegant. Don’t want to get bogged down in gritty details – MIPS is widely used in embedded apps – There are more embedded computers than PCs ECE 15B Spring 2010

Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep hardware simple Assembly Operands are registers – Limited number of special locations built directly into the hardware – Operations can only be performed on these – Benefit: Since registers file is small, it is very fast ECE 15B Spring 2010

Assembly Variables: Registers Drawback: – Registers are in a hardware, there are a predetermined number of them Solution: – MIPS code must be very carefully put together to efficiently use registers 32 registers in MIPS – Smaller is faster Each MIPS register is 32 bits wide – Groups of 32 bits called a word in MIPS ECE 15B Spring 2010

Assembly Variables Registers are numbered from 0 to 31 Each Register can be referred to by number or name Number references – $0, $1, $2, …., $30, $31 ECE 15B Spring 2010

Assembly Variables: Registers By convention, each register also has a name to make it easier to code For now: $16 - $23  $s0 - $s7 (correspond to C variables) $8 - $15  $t0 - $t7 (correspond to temporary variables) Will explain other 16 register names later In general, use names to make your code more readable ECE 15B Spring 2010

C, Java Variables vs. Registers In C (and most High Level Languages) variables declared first and given a type – Example: int fahr, celcius; char a, b, c, d, e; – Each variable can only represent a value of the type it was declared as (cannot mic and match int and char variables) In assembly Language the registers have no type – Operation determines how register contents are treated ECE 15B Spring 2010

Comments in Assembly Another way to make your code more readable: comments Hash (#) is used for MIPS comments – Anything from hash mark to end of line is a comment and will be ignored – Note: different from C, comments have format /* comment */, so they can span many lines ECE 15B Spring 2010

Assembly Instructions In assembly language, each statement (called an instruction), executes exactly one of a short list of simple commands Unlike in C (and most other high level languages), each line of assembly code contains at most one instruction Instructions are related to operations (=,+,-, *,/) in C or Java ECE 15B Spring 2010

MIPS Syntax Instruction Syntax: [Label:] Op-code [oper. 1], [oper. 2], [oper.3], [#comment] (0) (1) (2) (3) (4) (5) – Where 1) operation name 2,3,4) operands 5) comments 0) label field is optional, will discuss later – For arithmetic and logic instruction 2) operand getting result (“destination”) 3) 1 st operand for operation (“source 1”) 4) 2 nd operand for operation (source 2” Syntax is rigid – 1 operator, 3 operands – Why? Keep hardware simple via regularity ECE 15B Spring 2010

Addition and Subtraction of Integers Addition in assembly – Example: add $s0, $s1, $s2 (in MIPS) Equivalent to: a = b + c (in C) Where MIPS registers $s0, $s1, $s2 are associated with C variables a, b, c Subtraction in Assembly – Example Sub $s3, $s4, S5(in MIPS) Equivalent to: d = e - f (in C) Where MIPS registers $s3, $s4, $s5 are associated with C variables d, e, f ECE 15B Spring 2010

Addition and Subtraction of Integers The following C statement in MIPS? a= b + c+ d - a Break into multiple instructions add $t0, $s1, $s2#temp = b + c add $t0, $t0, $s3# temp = temp + d sub $s0, $t0, $s4# a = temp – e – Notes: A single line of C may break up into several lines of MIPS Everything after the hash mark on each line is ignored (i.e. comments) ECE 15B Spring 2010

Addition and Subtraction of Integers How do we do this? f = (g + h) – (i + j) Use intermediate temporary registers add $t0, $s1, $s2#temp = g + h add $t1, $s3, $s4#temp = I + j sub $s0, $t0, $t1#f = (g+h)-(i+j) ECE 15B Spring 2010

Immediates Immediates are numerical constants They appear often in code, so there are special instructions for them Add immediate: addi $s0, $s1, 10# f= g + 10 (in C) – Where MIPS registers $s0 and $s1 are associated with C variables f and g – Syntax similar to add instruction, except that last argument is a number instead of register ECE 15B Spring 2010

Immediates There is no Subtract Immediate in MIPS: Why? – Remove redundant operations, i.e. if operation can be decomposed to into simpler ones exclude it from the set of instructions addi …, -X is equivalent to subi …, X so no subi Example addi $so, $s1, -10# f = g – 10 – where MIPS registers $s0 and $s1 are associated with C variables f and g ECE 15B Spring 2010

Register Zero One particular immediate, the number zero (o) appears very often in code – So define register zero ($0 or $zero) to always have the value 0 Example add $s0, S1, $zero # f = g Where MIPS registers $s0 and $s1 are associated with C variables f, g, Defined in hardware, so an instruction addi $zero, $zero, 5 will not do anything! ECE 15B Spring 2010

Additional Notes: CPU Time Performance improved by – Reducing number of clock cycles – Increasing clock rate – Hardware designer must often trade off clock rate against cycle count ECE 15B Spring 2010

Additional Notes: CPU Time Example Computer A: 2GHz clock, 10s CPU time Designing Computer B – Aim for 6s CPU time – Can do faster clock, but causes 1.2 × clock cycles How fast must Computer B clock be? ECE 15B Spring 2010

Additional Notes: Instruction Count and CPI Instruction Count for a program – Determined by program, ISA and compiler Average cycles per instruction – Determined by CPU hardware – If different instructions have different CPI Average CPI affected by instruction mix ECE 15B Spring 2010

Additional Notes: CPI Example Computer A: Cycle Time = 250ps, CPI = 2.0 Computer B: Cycle Time = 500ps, CPI = 1.2 Same ISA Which is faster, and by how much? A is faster… …by this much ECE 15B Spring 2010

Additional Notes: CPI in More Detail If different instruction classes take different numbers of cycles Weighted average CPI Relative frequency ECE 15B Spring 2010

Additional Notes: Pipelining Analogy Pipelined laundry: overlapping execution – Parallelism improves performance Four loads: Speedup = 8/3.5 = 2.3 Non-stop: Speedup = 2n/0.5n ≈ 4 = number of stages ECE 15B Spring 2010

Additional Notes: Pipeline Performance Single-cycle (T c = 800ps) Pipelined (T c = 200ps) ECE 15B Spring 2010

Conclusions In MIPS assembly language – Register replace C variables – One instruction (simple operation) per line – Simpler is faster ECE 15B Spring 2010

Review Instructions so far: add, addi, sub Registers so far C variables: $s0 - $s7 Temporary variables: $t0 - $t9 Zero: $zero ECE 15B Spring 2010