CO Computer Architecture and Programming Languages CAPL. Lecture 15

Similar documents
Written Homework 3. Floating-Point Example (1/2)

Divide: Paper & Pencil

CSCI 402: Computer Architectures. Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI.

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Floating Point Arithmetic

Floating Point Arithmetic

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Defining Performance. Performance. Which airplane has the best performance? Boeing 777. Boeing 777. Boeing 747. Boeing 747

CS3350B Computer Architecture CPU Performance and Profiling

Chapter 3 Arithmetic for Computers (Part 2)

Number Systems and Computer Arithmetic

Thomas Polzer Institut für Technische Informatik

Review: MIPS Organization

Defining Performance. Performance 1. Which airplane has the best performance? Computer Organization II Ribbens & McQuain.

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

Lecture 10: Floating Point, Digital Design

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

Arithmetic for Computers. Hwansoo Han

Lecture 10: Floating Point, Digital Design

Chapter 3. Arithmetic Text: P&H rev

CO Computer Architecture and Programming Languages CAPL. Lecture 18 & 19

ECE 154A Introduction to. Fall 2012

Floating Point Arithmetic

3.5 Floating Point: Overview

Computer Architecture. Chapter 3: Arithmetic for Computers

MEASURING COMPUTER TIME. A computer faster than another? Necessity of evaluation computer performance

COMPUTER ORGANIZATION AND DESIGN

Module 2: Computer Arithmetic

Floating Point Numbers

1.3 Data processing; data storage; data movement; and control.

M1 Computers and Data

Floating-point representations

Floating-point representations

Chapter 1. Instructor: Josep Torrellas CS433. Copyright Josep Torrellas 1999, 2001, 2002,

Performance, Power, Die Yield. CS301 Prof Szajda

Number Representations

Floating Point Numbers. Lecture 9 CAP

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

MIPS Integer ALU Requirements

MIPS ISA AND PIPELINING OVERVIEW Appendix A and C

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

IC220 Slide Set #5B: Performance (Chapter 1: 1.6, )

Response Time and Throughput

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Course web site: teaching/courses/car. Piazza discussion forum:

CS6303 Computer Architecture Regulation 2013 BE-Computer Science and Engineering III semester 2 MARKS

Designing for Performance. Patrick Happ Raul Feitosa

Performance COE 403. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

CMCS Mohamed Younis CMCS 611, Advanced Computer Architecture 1

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

CPE300: Digital System Architecture and Design

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Computer Organisation CS303

ECE260: Fundamentals of Computer Engineering

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Signed Multiplication Multiply the positives Negate result if signs of operand are different

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

Floating-Point Arithmetic

EE878 Special Topics in VLSI. Computer Arithmetic for Digital Signal Processing

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Digital Computer Arithmetic ECE 666

Floating Point Representation in Computers

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

Floating-Point Arithmetic

Computer and Information Sciences College / Computer Science Department CS 207 D. Computer Architecture

Lecture 2: Computer Performance. Assist.Prof.Dr. Gürhan Küçük Advanced Computer Architectures CSE 533

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING QUESTION BANK

4. What is the average CPI of a 1.4 GHz machine that executes 12.5 million instructions in 12 seconds?

Foundations of Computer Systems

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. 5 th. Edition. Chapter 1. Computer Abstractions and Technology

TDT4255 Computer Design. Lecture 4. Magnus Jahre

Lecture - 4. Measurement. Dr. Soner Onder CS 4431 Michigan Technological University 9/29/2009 1

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Chapter 4. Operations on Data

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

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

Arithmetic. Chapter 3 Computer Organization and Design

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Computer Architecture ECE 568

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

3/12/2014. Single Cycle (Review) CSE 2021: Computer Organization. Single Cycle with Jump. Multi-Cycle Implementation. Why Multi-Cycle?

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

IEEE Standard for Floating-Point Arithmetic: 754

CS61C : Machine Structures

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

IEEE Standard 754 for Binary Floating-Point Arithmetic.

Computer Performance. Reread Chapter Quiz on Friday. Study Session Wed Night FB 009, 5pm-6:30pm

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

CpE 442 Introduction to Computer Architecture. The Role of Performance

Chapter 3. Arithmetic for Computers

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Giving credit where credit is due

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

Instruction Pipelining Review

Giving credit where credit is due

Floating Point : Introduction to Computer Systems 4 th Lecture, May 25, Instructor: Brian Railing. Carnegie Mellon

System Programming CISC 360. Floating Point September 16, 2008

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 1. Computer Abstractions and Technology

The Role of Performance

Transcription:

CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 15 Dr. Kinga Lipskoch Fall 2017

How to Compute a Binary Float Decimal fraction: 8.703125 Integral part: 8 1000 Fraction part: 0.703125 Bits: 0 bit: 0.7031250 x 2 = 1.4062500 1 1 bit: 0.4062500 x 2 = 0.8125000 0 2 bit: 0.8125000 x 2 = 1.6250000 1 3 bit: 0.6250000 x 2 = 1.2500000 1 4 bit: 0.2500000 x 2 = 0.5000000 0 5 bit: 0.5000000 x 2 = 1.0000000 1 1000.101101000000000000000000000 x 2 0 1.000101101000000000000000000000 x 2 3 Number now needs to be normalized and exponent needs to be determined (127 + 3) Result: 0 10000010 00010110100000000000000 Split number in integral and fractional part Compute bit pattern for integral part For the fractional part multiply by 2 If result has bit set left of decimal point (>= 1.0) generate set bit, otherwise generate zero bit Continue with rest until result does not have rest CAPL Fall 2017 2 / 39

Floating Point Addition 0.5 ten = 1/2 ten = 1/2 1 ten = 0.1 two = 0.1 two 2 0 = 1.000 two 2 1 0.4375 ten = 7/16 ten = 7/2 4 ten = 0.0111 two = 0.0111 two 2 0 = 1.110 two 2 2 Lesser exponent shifted right until exponent matches larger number 1.110 two 2 2 = 0.111 two 2 1 Add significands 1.000 two 2 1 + ( 0.111 two 2 1 ) = 0.001 two 2 1 Normalize the sum 0.001 two 2 1 = 1.000 two 2 4 Round the sum (already fits into 4 bits) 1.000 two 2 4 = 0.0001 two = 1/2 4 ten = 0.0625 CAPL Fall 2017 3 / 39

Floating Point Addition Addition (and subtraction) (±F 1 2 E1 ) + (±F 2 2 E2 ) = ±F 3 2 E3 Step 1: Restore the hidden bit in F 1 and in F 2 Step 2: Align fractions by right shifting F 2 by E1 E2 positions (assuming E1 E2) keeping track of (three of) the bits shifted out in a round bit, a guard bit, and a sticky bit Step 3: Add the resulting F 2 to F 1 to form F 3 Step 4: Normalize F 3 (so it is in the form 1.XXXXX... ) If F 1 and F 2 have the same sign F 3 [1, 4) 1 bit right shift F 3 and increment E3 If F 1 and F 2 have different signs F 3 may require many left shifts each time decrementing E 3 Step 5: Round F 3 and possibly normalize F 3 again Step 6: Rehide the most significant bit of F 3 before storing the result CAPL Fall 2017 4 / 39

Start 1. Compare the exponents of the two numbers Shift the smaller number to the right until its exponent would match the larger exponent 2. Add the significands 3. Normalize the sum, either shifting right and incrementing the exponent or shifting left and decrementing the exponent Overflow or Underflow? Yes No 4. Round the significand to the appropriate number of bits Exception No Still normalized? Yes Done CAPL Fall 2017 5 / 39

MIPS Floating Point Instructions MIPS has a separate Floating Point Register File ($f0, $f1,..., $f31) (whose registers are used in pairs for double precision values) with special instructions to load to and store from them lwc1 $f1,54($s2) # $f1 = Memory[$s2+54] swc1 $f1,58($s4) # Memory[$s4+58] = $f1 And supports IEEE 754 single add.s $f2,$f4,$f6 # $f2 = $f4 + $f6 and double precision operations add.d $f2,$f4,$f6 # $f2 $f3 = $f4 $f5 + $f6 $f7 similarly for sub.s, sub.d, mul.s, mul.d, div.s, div.d CAPL Fall 2017 6 / 39

Summary Computer arithmetic is constrained by limited precision Bit patterns have no inherent meaning but standards do exist two s complement IEEE 754 floating point Computer instructions determine meaning of the bit patterns Performance and accuracy are important so there are many complexities in real machines Algorithm choice is important and may lead to hardware optimizations for both space and time (e.g., multiplication) CAPL Fall 2017 7 / 39

Floating Point Issues Integers can represent every number between smallest and largest number Floating point numbers only represent an approximation, for numbers they cannot really represent gap between 0 and smallest positive number Infinite number of real numbers between 0 and 1, but no more than 2 53 numbers can be represented in double precision format IEEE 754 keeps two extra bits during intermediate results guard and round sticky bit four rounding modes CAPL Fall 2017 8 / 39

Guard and Round Add 2.56 ten 10 0 to 2.34 ten 10 2 Assume we have only three significant digits Additionally guard and round shift smaller number right to align exponents able to represent the two least significant digits when we align exponents 2.3400 ten + 0.0256 ten = 2.3656 ten Rounding up yields 2.37 ten 10 2 Without guard drop two digits from calculation, result would be 2.36 ten 10 2 CAPL Fall 2017 9 / 39

Round, Guard and Sticky Bit Example above may only need one bit, multiply can need two binary product may have leading 0 bit normalization must shift product left, round bit is being used to round Rounding modes includes nearest even What to do with 0.50? half the time up, half the time down standard says if least significant bit retained in such case is odd round up, otherwise truncate Sticky bit is set whenever nonzero bits to the right of round bit allows to see difference between 0.50...00ten and 0.50...01 ten CAPL Fall 2017 10 / 39

Sign Exponent Fraction Sign Exponent Fraction Small ALU Exponent difference 0 1 0 1 0 1 Control Shift right Big ALU 0 1 0 1 Increment or decrement Shift left or right Floating point adder: Exponent of one operand is subtracted from the other to determine which is larger and by how much Difference controls three multiplexers: from left to right Select larger exponent Significand of smaller number Significand of larger number Smaller significand is shifted right, then significands are added using Big ALU Normalization step shifts sum left or right and increments or decrements the exponent Rounding creates final result Rounding hardware May require normalizing again Sign Exponent Fraction CAPL Fall 2017 11 / 39

Performance What is performance? Measuring performance Performance metrics Performance evaluation Why does some hardware perform better with different programs? What performance factors are related to hardware? CAPL Fall 2017 12 / 39

Performance Metrics Purchasing perspective given a collection of machines, which has the best performance? least cost? best cost/performance rate? Design perspective faced with design options, which has the best performance improvement? least cost? best cost/performance rate? Both require basis for comparison metric for evaluation Goal is to understand what factors in the architecture contribute to the overall system performance and the relative importance (and cost) of these factors CAPL Fall 2017 13 / 39

Speed Performance Definition Normally interested in reducing Response time (a.k.a. execution time) the time between the start and the completion of a task Important to individual users Thus, to maximize performance, need to minimize execution time performance X = 1 / execution_time X If X is n times faster than Y, then performance X performance Y execution_time Y = = n execution_time X CAPL Fall 2017 14 / 39

Very Simple Example How much faster is A than B? If ratio Performance A / Performance B = n Execution time B / Execution time A = n 25/20 = 1.25 then A is by a factor of 1.25 faster than B CAPL Fall 2017 15 / 39

Computer Performance Response Time (latency) How long does it take for my job to run? How long does it take to execute a job? How long must I wait for the database query? Throughput How many jobs can the machine run at once? What is the average execution rate? How much work is getting done? Decreasing response time almost always improves throughput CAPL Fall 2017 16 / 39

What is Meant by Time Time is the measure of computer performance The computer that performs the same amount of work in the least time is the fastest Elapsed Time counts everything (disk and memory accesses, I/O, etc.) a useful number, but often not good for comparison purposes CPU time does not count I/O or time spent running other programs can be broken up into system time and user time Our focus: user CPU time time spent executing the lines of code that are in our program CAPL Fall 2017 17 / 39

Performance Factors Want to distinguish elapsed time and the time spent on our task CPU execution time (CPU time) time the CPU spends working on a task Does not include time waiting for I/O or running other programs CPU execution time for a program = CPU clock cycles for a program x Clock cycle time CPU execution time for a program = CPU clock cycles for a program Clock rate Can improve performance by reducing either the length of the clock cycle or the number of clock cycles required for a program CAPL Fall 2017 18 / 39

Machine Clock Rate Clock rate (CR) (unit: MHz, GHz) is inverse of clock cycle (CC) time (clock period) CC = 1/CR one clock period 10 nsec clock cycle 100 MHz clock rate 5 nsec clock cycle 200 MHz clock rate 2 nsec clock cycle 500 MHz clock rate 1 nsec clock cycle 1 GHz clock rate 500 psec clock cycle 2 GHz clock rate 250 psec clock cycle 4 GHz clock rate 200 psec clock cycle 5 GHz clock rate CAPL Fall 2017 19 / 39

Clock Cycles Per Instruction Not all instructions take the same amount of time to execute One way to think about execution time is that it equals the number of instructions executed multiplied by the average time per instruction # CPU clock cycles for a program = Instructions for a program x Average clock cycles per instruction Clock cycles per instruction (CPI) the average number of clock cycles each instruction takes to execute A way to compare two different implementations of the same ISA CAPL Fall 2017 20 / 39

Comparing Code Segments Compiler designer needs to decide between two code sequences for particular computer Knows that: CPI Code seq. Sequence 1: 2 + 1 + 2 = 5 instructions Sequence 2: 4 + 1 + 1 = 6 instructions CPU clock cycles = n CPI i IC i i=1 Is Sequence 1 faster? CPI varies by instruction mix instruction count & CPI needs to be compared 1 2 CPI for this instruction class A B C 1 2 3 Instr. counts for instr. class A B C 2 1 2 4 1 1 CAPL Fall 2017 21 / 39

Effective CPI Computing the overall effective CPI is done by looking at the different types of instructions and their individual cycle counts and averaging Overall effective CPI = n CPI i IC i IC total i=1 where n is the number of instruction classes CPI i is the (average) number of clock cycles per instruction for that instruction class IC i is the overall number of instructions of class i and IC total is the total number of instructions weight of instructions of class i The overall effective CPI varies by instruction mix a measure of the dynamic frequency of instructions across one or many programs CAPL Fall 2017 22 / 39

Performance Equation Our basic performance equation is then CPU time = Instruction count * CPI * Clock cycle time CPU time = Instruction count * CPI Clock rate These equations contain the three key factors that affect performance Can measure the CPU execution time by running the program The clock rate is usually given Can measure overall instruction count by using profilers/simulators without knowing all of the implementation details CPI varies by instruction type and ISA implementation for which we must know the implementation details CAPL Fall 2017 23 / 39

Evaluating Performance CPU time = Instruction count x CPI x Clock cycle Algorithm might also effect CPI, by using floating-point rather than integer arithmetic Language also affects CPI, for example Java allows more data abstraction more indirect calls higher CPI CAPL Fall 2017 24 / 39

A Simple Example (1) Op Frequency CPI i Freq * CPI ALU 50% 1 Load 20% 5 Store 10% 3 Branch 20% 2 = How much faster would the machine be if a better data cache reduced the average load time to 2 cycles? How does this compare with using branch prediction to shave a cycle off the branch time? What if two ALU instructions could be executed at once? CAPL Fall 2017 25 / 39

A Simple Example (2) Op Frequency CPI i Freq * CPI ALU 50% 1 0.5 0.5 Load 20% 5 1.0 0.4 Store 10% 3 0.3 0.3 Branch 20% 2 0.4 0.4 = 2.2 = 1.6 How much faster would the machine be if a better data cache reduced the average load time to 2 cycles? CPU time new = 1.6 x IC x CC so 2.2/1.6 means 37.5% faster How does this compare with using branch prediction to shave a cycle off the branch time? What if two ALU instructions could be executed at once? CAPL Fall 2017 26 / 39

A Simple Example (3) Op Frequency CPI i Freq * CPI ALU 50% 1 0.5 0.5 0.5 Load 20% 5 1.0 0.4 1.0 Store 10% 3 0.3 0.3 0.3 Branch 20% 2 0.4 0.4 0.2 = 2.2 = 1.6 = 2.0 How much faster would the machine be if a better data cache reduced the average load time to 2 cycles? CPU time new = 1.6 x IC x CC so 2.2/1.6 means 37.5% faster How does this compare with using branch prediction to shave a cycle off the branch time? CPU time new = 2.0 x IC x CC so 2.2/2.0 means 10% faster What if two ALU instructions could be executed at once? CAPL Fall 2017 27 / 39

A Simple Example (4) Op Frequency CPI i Freq * CPI ALU 50% 1 0.5 0.5 0.5 0.25 Load 20% 5 1.0 0.4 1.0 1.0 Store 10% 3 0.3 0.3 0.3 0.3 Branch 20% 2 0.4 0.4 0.2 0.4 = 2.2 = 1.6 = 2.0 = 1.95 How much faster would the machine be if a better data cache reduced the average load time to 2 cycles? CPU time new = 1.6 x IC x CC so 2.2/1.6 means 37.5% faster How does this compare with using branch prediction to shave a cycle off the branch time? CPU time new = 2.0 x IC x CC so 2.2/2.0 means 10% faster What if two ALU instructions could be executed at once? CPU time new = 1.95 x IC x CC so 2.2/1.95 means 12.8% faster CAPL Fall 2017 28 / 39

Summary: Evaluating ISA (1) Design-time metrics: Can it be implemented, in how long, at what cost? Can it be programmed? Ease of compilation? Static Metrics: How many bytes does the program occupy in memory? Dynamic Metrics: How many instructions are executed? How many bytes does the processor fetch to execute the program? How many clocks cycles are required per instruction? Best Metric: Time to execute the program CAPL Fall 2017 29 / 39

Summary: Evaluating ISA (2) Depends on the instructions set, the processor organization, and compilation techniques CPI Instruction Count Cycle Time CAPL Fall 2017 30 / 39

MIPS as a Performance Measure MIPS = Million Instructions Per Second MIPS = instruction count execution time * 10 6 = instruction count CPU clocks * cycle time * 10 6 = instruction count * clock rate = instruction count * CPI * 10 6 clock rate CPI * 10 6 A faster machine has a higher MIPS rate execution time = instruction count MIPS * 10 6 CAPL Fall 2017 31 / 39

MIPS Metric Not Adequate MIPS does not take into account the instruction set (capabilities or complexity of instructions) different ISAs not comparable The MIPS rate depends on the program and its instruction mix MIPS are not constant, even on a single machine MIPS can vary inversely with performance CAPL Fall 2017 32 / 39

MIPS Metric not Adequate: Example Three instruction classes and given CPI Two compilers Cycles CPI Code from Compiler 1 Compiler 2 CPI for this instruction class A B C 1 2 3 Instr. counts (in billions) for instruction class A 5 10 B 1 1 C 1 1 CPU clock cycles = CPIi IC i Compiler 1: 7 billion instructions, 10 billion cycles Compiler 2: 12 billion instructions, 15 billion cycles CAPL Fall 2017 33 / 39

Execution Time CPU execution time for a program = CPU clock cycles for a program Clock rate 10 * 10 9 Execution time = 1 4 * 10 9 = 2.50 seconds 15 * 10 9 Execution time = 2 4 * 10 9 = 3.75 seconds Compiler 1 generates a faster program CAPL Fall 2017 34 / 39

MIPS Rate (1) MIPS = Instruction count Execution time * 10 6 (5 + 1 + 1) * 10 9 MIPS = 1 2.5 * 10 6 = (10 + 1 + 1) * 10 9 MIPS = 2 3.75 * 10 6 = CAPL Fall 2017 35 / 39

MIPS Rate (2) MIPS = Instruction count Execution time * 10 6 (5 + 1 + 1) * 10 9 MIPS = 1 2.5 * 10 6 = 2800 (10 + 1 + 1) * 10 9 MIPS = 2 3.75 * 10 6 = 3200 Compiler 2 has a higher MIPS rating, but the code from Compiler 1 runs faster CAPL Fall 2017 36 / 39

Summary A given program will require Some number of instructions (machine) Some number of cycles Some number of seconds Vocabulary Cycle time (seconds per cycle) Clock rate (cycles per second) CPI (cycles per instruction) MIPS (millions of instructions per second) CAPL Fall 2017 37 / 39

Amdahl s Law (1967) General law concerning the speedup Version 1 speedup = = performance after improvement performance before improvement execution time before improvement execution time after improvement Version 2 execution time after improvement = execution time affected by improvement amount of improvement + execution time unaffected CAPL Fall 2017 38 / 39

Example Program runs 100 sec, of which multiplication operations run 80 sec How much do I have to improve speed of multiplication to run the program 5 times as fast? 80 sec / n + (100 sec - 80 sec) 20 sec = (80 sec / n) + 20 sec Not possible Performance enhancement is limited by the amount that the improved feature is used CAPL Fall 2017 39 / 39