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

Size: px
Start display at page:

## Transcription

1 Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS Lecture 13 Floating Point I (1) Fall 2005

2 Integer Multiplication (1/3) Paper and pencil example (unsigned): Multiplicand Multiplier x m digits x n digits = m + n digit product Lecture 13 Floating Point I (2) Fall 2005

3 Integer Multiplication (2/3) In MIPS, we multiply registers, so: 32-bit value x 32-bit value = 64-bit value Syntax of Multiplication (signed): mult register1, register2 Multiplies 32-bit values in those registers & puts 64-bit product in special result regs: - puts product upper half in hi, lower half in lo hi and lo are 2 registers separate from the 32 general purpose registers Use mfhi register & mflo register to move from hi, lo to another register Lecture 13 Floating Point I (3) Fall 2005

4 Integer Multiplication (3/3) Example: in C: a = b * c; in MIPS: - let b be \$s2; let c be \$s3; and let a be \$s0 and \$s1 (since it may be up to 64 bits) mult \$s2,\$s3 mfhi \$s0 mflo \$s1 # b*c # upper half of # product into \$s0 # lower half of # product into \$s1 Note: Often, we only care about the lower half of the product. Lecture 13 Floating Point I (4) Fall 2005

5 Integer Division (1/2) Paper and pencil example (unsigned): 1001 Quotient Divisor Dividend Remainder (or Modulo) Dividend = Quotient x Divisor + Remainder Lecture 13 Floating Point I (5) Fall 2005

6 Integer Division (2/2) Syntax of Division (signed): div register1, register2 Divides 32-bit register 1 by 32-bit register 2: puts remainder of division in hi, quotient in lo Implements C division (/) and modulo (%) Example in C: a = c / d; b = c % d; in MIPS: a \$s0;b \$s1;c \$s2;d \$s3 div \$s2,\$s3 mflo \$s0 mfhi \$s1 # lo=c/d, hi=c%d # get quotient # get remainder Lecture 13 Floating Point I (6) Fall 2005

7 Unsigned Instructions & Overflow MIPS also has versions of mult, div for unsigned operands: multu divu MIPS does not check overflow on ANY signed/unsigned multiply or divide instruction Up to the software to check hi Lecture 13 Floating Point I (7) Fall 2005

8 Two s complement limits What can we represent in N bits? Unsigned integers: 0 to 2 N -1 Signed Integers (Two s Complement) -2 (N-1) to 2 (N-1) -1 Lecture 13 Floating Point I (8) Fall 2005

9 Other Numbers What about other numbers? Very large numbers? (seconds/century) 3,155,760, ( x 10 9 ) Very small numbers? (atomic diameter) ( x 10-8 ) Rationals (repeating pattern) 2/3 ( ) Irrationals 2 1/2 ( ) Transcendentals e ( ), π ( ) All represented in scientific notation Lecture 13 Floating Point I (9) Fall 2005

10 Scientific Notation (in Decimal) mantissa exponent x decimal point radix (base) Normalized form: no leadings 0s (exactly one digit to left of decimal point) Alternatives to representing 1/1,000,000,000 Normalized: 1.0 x 10-9 Not normalized: 0.1 x 10-8,10.0 x Lecture 13 Floating Point I (10) Fall 2005

11 Scientific Notation (in Binary) mantissa exponent 1.0 two x 2-1 radix (base) binary point Computer arithmetic that supports it called floating point, because it represents numbers where binary point is not fixed, as it is for integers In C float Lecture 13 Floating Point I (11) Fall 2005

12 Floating Point Representation (1/2) Normal format: +1.xxxxxxxxxx 2 *2 yyyy 2 Multiple of Word Size (32 bits) S Exponent Significand 1 bit 8 bits 23 bits S represents Sign Exponent represents y s Significand represents x s Represent numbers as small as 2.0 x to as large as 2.0 x Lecture 13 Floating Point I (12) Fall 2005

13 Floating Point Representation (2/2) What if result too large? (> 2.0x10 38 ) Overflow! Overflow Exponent larger than represented in 8-bit Exponent field What if result too small? (>0, < 2.0x10-38 ) Underflow! Underflow Negative exponent larger than represented in 8-bit Exponent field How to reduce chances of overflow or underflow? Lecture 13 Floating Point I (13) Fall 2005

14 Double Precision Fl. Pt. Representation Next Multiple of Word Size (64 bits) S Exponent Significand 1 bit 11 bits 20 bits Significand (cont d) 32 bits Double Precision (vs. Single Precision) C variable declared as double Represent numbers almost as small as 2.0 x to almost as large as 2.0 x But primary advantage is greater accuracy due to larger significand 0 Lecture 13 Floating Point I (14) Fall 2005

15 QUAD Precision Fl. Pt. Representation Next Multiple of Word Size (128 bits) Unbelievable range of numbers Unbelievable precision (accuracy) This is currently being worked on Lecture 13 Floating Point I (15) Fall 2005

16 Father of the Floating point standard IEEE Standard 754 for Binary Floating-Point Arithmetic ACM Turing Award Winner! Prof. Kahan /ieee754status/754story.html Lecture 13 Floating Point I (16) Fall 2005

17 IEEE 754 Floating Point Standard (1/4) Sign bit: Significand: 1 means negative 0 means positive To pack more bits, leading 1 implicit for normalized numbers bits single, bits double always true: Significand < 1 (for normalized numbers) Note: 0 has no leading 1, so reserve exponent value 0 just for number 0 Lecture 13 Floating Point I (17) Fall 2005

18 IEEE 754 Floating Point Standard (2/4) Kahan wanted FP numbers to be used even if no FP hardware; e.g., sort records with FP numbers using integer compares Could break FP number into 3 parts: compare signs, then compare exponents, then compare significands Wanted it to be faster, single compare if possible, especially if positive numbers Then want order: Highest order bit is sign ( negative < positive) Exponent next, so big exponent => bigger # Significand last: exponents same => bigger # Lecture 13 Floating Point I (18) Fall 2005

19 1/2 2 IEEE 754 Floating Point Standard (3/4) Negative Exponent? 2 s comp? 1.0 x 2-1 v. 1.0 x2 +1 (1/2 v. 2) This notation using integer compare of 1/2 v. 2 makes 1/2 > 2! Instead, pick notation is most negative, and is most positive 1/ x 2-1 v. 1.0 x2 +1 (1/2 v. 2) Lecture 13 Floating Point I (19) Fall 2005

20 IEEE 754 Floating Point Standard (4/4) Called Biased Notation, where bias is number subtract to get real number IEEE 754 uses bias of 127 for single prec. Subtract 127 from Exponent field to get actual value for exponent 1023 is bias for double precision Summary (single precision): S Exponent Significand 1 bit 8 bits 23 bits (-1) S x (1 + Significand) x 2 (Exponent-127) Double precision identical, except with exponent bias of 1023 Lecture 13 Floating Point I (20) Fall

21 Understanding the Significand (1/2) Method 1 (Fractions): In decimal: => / => / In binary: => / = 6 10 /8 10 => 11 2 /100 2 = 3 10 /4 10 Advantage: less purely numerical, more thought oriented; this method usually helps people understand the meaning of the significand better Lecture 13 Floating Point I (21) Fall 2005

22 Understanding the Significand (2/2) Method 2 (Place Values): Convert from scientific notation In decimal: = (1x10 0 ) + (6x10-1 ) + (7x10-2 ) + (3x10-3 ) + (2x10-4 ) In binary: = (1x2 0 ) + (1x2-1 ) + (0x2-2 ) + (0x2-3 ) + (1x2-4 ) Interpretation of value in each position extends beyond the decimal/binary point Advantage: good for quickly calculating significand value; use this method for translating FP numbers Lecture 13 Floating Point I (22) Fall 2005

23 Example: Converting Binary FP to Decimal Sign: 0 => positive Exponent: two = 104 ten Bias adjustment: = -23 Significand: 1 + 1x x x x x = = 1.0 ten ten Represents: ten *2-23 ~ 1.986*10-7 (about 2/10,000,000) Lecture 13 Floating Point I (23) Fall 2005

24 Converting Decimal to FP (1/3) Simple Case: If denominator is an exponent of 2 (2, 4, 8, 16, etc.), then it s easy. Show MIPS representation of = -3/4-11 two /100 two = two Normalized to -1.1 two x 2-1 (-1) S x (1 + Significand) x 2 (Exponent-127) (-1) 1 x ( ) x 2 ( ) Lecture 13 Floating Point I (24) Fall 2005

25 Converting Decimal to FP (2/3) Not So Simple Case: If denominator is not an exponent of 2. Then we can t represent number precisely, but that s why we have so many bits in significand: for precision Once we have significand, normalizing a number to get the exponent is easy. So how do we get the significand of a neverending number? Lecture 13 Floating Point I (25) Fall 2005

26 Converting Decimal to FP (3/3) Fact: All rational numbers have a repeating pattern when written out in decimal. Fact: This still applies in binary. To finish conversion: Write out binary number with repeating pattern. Cut it off after correct number of bits (different for single v. double precision). Derive Sign, Exponent and Significand fields. Lecture 13 Floating Point I (26) Fall 2005

27 Peer Instruction What is the decimal equivalent of the floating pt # above? 1: : : : -7 5: : -15 7: -7 * 2^129 8: -129 * 2^7 Lecture 13 Floating Point I (27) Fall 2005

28 Peer Instruction Answer What is the decimal equivalent of: S Exponent Significand (-1) S x (1 + Significand) x 2 (Exponent-127) (-1) 1 x ( ) x 2 ( ) -1 x (1.111) x 2 (2) : : : : -7 5: : -15 7: -7 * 2^129 8: -129 * 2^7 Lecture 13 Floating Point I (28) Fall 2005

29 Example: Representing 1/3 in MIPS 1/3 = = = 1/4 + 1/16 + 1/64 + 1/256 + = = * 2 0 = * 2-2 Sign: 0 Exponent = = 125 = Significand = Lecture 13 Floating Point I (29) Fall 2005

30 Representation for ± In FP, divide by 0 should produce ±, not overflow. Why? OK to do further computations with E.g., X/0 > Y may be a valid comparison Ask math majors IEEE 754 represents ± Most positive exponent reserved for Significands all zeroes Lecture 13 Floating Point I (30) Fall 2005

31 Representation for 0 Represent 0? exponent all zeroes significand all zeroes too What about sign? +0: : Why two zeroes? Helps in some limit comparisons Ask math majors Lecture 13 Floating Point I (31) Fall 2005

32 Special Numbers What have we defined so far? (Single Precision) Exponent Significand Object nonzero??? anything +/- fl. pt. # /- 255 nonzero??? Lecture 13 Floating Point I (32) Fall 2005

33 Representation for Not a Number What is sqrt(-4.0)or 0/0? If not an error, these shouldn t be either. Called Not a Number (NaN) Exponent = 255, Significand nonzero Why is this useful? Hope NaNs help with debugging? They contaminate: op(nan, X) = NaN Lecture 13 Floating Point I (33) Fall 2005

34 Representation for Denorms (1/2) Problem: There s a gap among representable FP numbers around 0 Smallest representable pos num: a = * = Second smallest representable pos num: b = * = a - 0 = b - a = Gaps! b 0 a Normalization and implicit 1 is to blame! + RQ answer! Lecture 13 Floating Point I (34) Fall 2005

35 Representation for Denorms (2/2) Solution: We still haven t used Exponent = 0, Significand nonzero Denormalized number: no leading 1, implicit exponent = Smallest representable pos num: a = Second smallest representable pos num: b = Lecture 13 Floating Point I (35) Fall 2005

36 Rounding Math on real numbers we worry about rounding to fit result in the significant field. RQ answer! FP hardware carries 2 extra bits of precision, and rounds for proper value Rounding occurs when converting double to single precision floating point # to an integer Lecture 13 Floating Point I (36) Fall 2005

37 IEEE Four Rounding Modes Round towards + ALWAYS round up : 2.1 3, Round towards - ALWAYS round down : 1.9 1, Truncate Just drop the last bits (round towards 0) Round to (nearest) even (default) Normal rounding, almost: 2.5 2, Like you learned in grade school Insures fairness on calculation Half the time we round up, other half down Lecture 13 Floating Point I (37) Fall 2005

38 FP Addition & Subtraction Much more difficult than with integers (can t just add significands) How do we do it? De-normalize to match larger exponent Add significands to get resulting one Normalize (& check for under/overflow) Round if needed (may need to renormalize) If signs, do a subtract. (Subtract similar) If signs for add (or = for sub), what s ans sign? Question: How do we integrate this into the integer arithmetic unit? [Answer: We don t!] Lecture 13 Floating Point I (38) Fall 2005

39 MIPS Floating Point Architecture (1/4) Separate floating point instructions: Single Precision: add.s, sub.s, mul.s, div.s Double Precision: add.d, sub.d, mul.d, div.d These are far more complicated than their integer counterparts Can take much longer to execute Lecture 13 Floating Point I (39) Fall 2005

40 MIPS Floating Point Architecture (2/4) Problems: Inefficient to have different instructions take vastly differing amounts of time. Generally, a particular piece of data will not change FP int within a program. - Only 1 type of instruction will be used on it. Some programs do no FP calculations It takes lots of hardware relative to integers to do FP fast Lecture 13 Floating Point I (40) Fall 2005

41 MIPS Floating Point Architecture (3/4) 1990 Solution: Make a completely separate chip that handles only FP. Coprocessor 1: FP chip contains bit registers: \$f0, \$f1, most of the registers specified in.s and.d instruction refer to this set separate load and store: lwc1 and swc1 ( load word coprocessor 1, store ) Double Precision: by convention, even/odd pair contain one DP FP number: \$f0/\$f1, \$f2/\$f3,, \$f30/\$f31 - Even register is the name Lecture 13 Floating Point I (41) Fall 2005

42 MIPS Floating Point Architecture (4/4) 1990 Computer actually contains multiple separate chips: Processor: handles all the normal stuff Coprocessor 1: handles FP and only FP; more coprocessors? Yes, later Today, FP coprocessor integrated with CPU, or cheap chips may leave out FP HW Instructions to move data between main processor and coprocessors: mfc0, mtc0, mfc1, mtc1, etc. Appendix contains many more FP ops Lecture 13 Floating Point I (42) Fall 2005

43 Peer Instruction 1. Converting float -> int -> float produces same float number 2. Converting int -> float -> int produces same int number 3. FP add is associative: (x+y)+z = x+(y+z) ABC 1: FFF 2: FFT 3: FTF 4: FTT 5: TFF 6: TFT 7: TTF 8: TTT Lecture 13 Floating Point I (43) Fall 2005

44 Peer Instruction Answer F A L S E 1. Converting a float -> int -> float produces same float number 2. Converting F A L a int S -> E float -> int produces same int number FP add is associative (x+y)+z = x+(y+z) F A L S E > 3 -> bits for signed int, but 24 for FP mantissa? 3. x = biggest pos #, y = -x, z = 1 (x!= inf) ABC 1: FFF 2: FFT 3: FTF 4: FTT 5: TFF 6: TFT 7: TTF 8: TTT Lecture 13 Floating Point I (44) Fall 2005

45 And in conclusion Reserve exponents, significands: Exponent Significand Object nonzero Denorm anything +/- fl. pt. # /- 255 nonzero NaN Integer mult, div uses hi, lo regs mfhi and mflo copies out. Four rounding modes (to even default) MIPS FL ops complicated, expensive Lecture 13 Floating Point I (45) Fall 2005

46 And in conclusion Floating Point numbers approximate values that we want to use. IEEE 754 Floating Point Standard is most widely accepted attempt to standardize interpretation of such numbers Every desktop or server computer sold since ~1997 follows these conventions Summary (single precision): S Exponent Significand 1 bit 8 bits 23 bits (-1) S x (1 + Significand) x 2 (Exponent-127) Double precision identical, bias of 1023 Lecture 13 Floating Point I (46) Fall

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II Scott Beamer, Instructor Sony & Nintendo make E3 News 2007-7-12 CS61C L11 Floating Point II (1) www.nytimes.com Review

### IEEE Standard 754 for Binary Floating-Point Arithmetic.

CS61C L11 Floating Point II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II 2005-10-05 There is one handout today at the front and back of the room! Lecturer

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

CS61C L11 Floating Point II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II 2007-7-12 Scott Beamer, Instructor Sony & Nintendo make E3 News www.nytimes.com Review

### UC Berkeley CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 16 Floating Point II 2010-02-26 TA Michael Greenbaum www.cs.berkeley.edu/~cs61c-tf Research without Google would be like life

### Precision and Accuracy

inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 16 Floating Point II 2010-02-26 TA Michael Greenbaum www.cs.berkeley.edu/~cs61c-tf Research without Google would be like life

### 3.5 Floating Point: Overview

3.5 Floating Point: Overview Floating point (FP) numbers Scientific notation Decimal scientific notation Binary scientific notation IEEE 754 FP Standard Floating point representation inside a computer

### UC Berkeley CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures www.cs.berkeley.edu/~ddgarcia Google takes on Office! Google Apps: premium services (email, instant vs messaging, calendar, web creation,

### IEEE Standard 754 for Binary Floating-Point Arithmetic.

CS61C L14 MIPS Instruction Representation II (1) inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 16 Floating Point II 27-2-23 Lecturer SOE Dan Garcia As Pink Floyd crooned:

### 95% of the folks out there are completely clueless about floating-point.

CS61C L11 Floating Point (1) Instructor Paul Pearce inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Well, not quite yet. A UC Davis student (shown left) is attempting to standardize hella

### UCB CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Instructor Paul Pearce Lecture 11 Floating Point 2010-07-08 Well, not quite yet. A UC Davis student (shown left) is attempting to standardize

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 15 Floating Point!!Senior Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia! UNUM, Float replacement? Dr. John Gustafson, Senior Fellow

### Floating Point Numbers. Lecture 9 CAP

Floating Point Numbers Lecture 9 CAP 3103 06-16-2014 Review of Numbers Computers are made to deal with numbers What can we represent in N bits? 2 N things, and no more! They could be Unsigned integers:

### ecture 25 Floating Point Friedland and Weaver Computer Science 61C Spring 2017 March 17th, 2017

ecture 25 Computer Science 61C Spring 2017 March 17th, 2017 Floating Point 1 New-School Machine Structures (It s a bit more complicated!) Software Hardware Parallel Requests Assigned to computer e.g.,

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

CS 61C: Great Ideas in Computer Architecture Floating Point Arithmetic Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ New-School Machine Structures (It s a bit

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point I 2008-7-9 Upcoming Programming Contests! http://www.icfpcontest.org/ 7/11-7/14 QuickTime and a TIFF (Uncompressed) decompressor

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures #16 Cal rolls over OSU Behind the arm of Nate Longshore s 341 yds passing & 4 TDs, the Bears roll 41-13. Recall they stopped our winning streak

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

Another Improvement Save on space: Put multiplier in product saves on speed: only single shift needed Figure: Improved hardware for multiplication Signed Multiplication Multiply the positives Negate result

### Chapter 3 Arithmetic for Computers

Chapter 3 Arithmetic for Computers 1 Outline Signed and unsigned numbers (Sec. 3.2) Addition and subtraction (Sec. 3.3) Multiplication (Sec. 3.4) Division (Sec. 3.5) Floating point (Sec. 3.6) 2 Representation

### Arithmetic for Computers. Hwansoo Han

Arithmetic for Computers Hwansoo Han Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #10 Instruction Representation II, Floating Point I 2005-10-03 Lecturer PSOE, new dad Dan Garcia www.cs.berkeley.edu/~ddgarcia #9 bears

### CS61C Floating Point Operations & Multiply/Divide. Lecture 9. February 17, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

CS61C Floating Point Operations & Multiply/Divide Lecture 9 February 17, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html cs 61C L9 FP.1 Review 1/2

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 15 Floating Point I 2008-02-27 TA Ordinaire Dave Jacobs www.ocf.berkeley.edu/~djacobs Doomsday Seed Vault Opens The seed bank on a remote

### 95% of the folks out there are completely clueless about floating-point.

CS61C L15 Floating Point I (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 15 Floating Point I 28-2-27 TA Ordinaire Dave Jacobs www.ocf.berkeley.edu/~djacobs Doomsday Seed Vault Opens

### Review 1/2 Big Idea: Instructions determine meaning of data; nothing inherent inside the data Characters: ASCII takes one byte

CS61C Floating Point Operations & Multiply/Divide Lecture 9 February 17, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html Review 1/2 Big Idea: Instructions

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 15 Floating Point 2010-02-24! Hello to Robb Neuschwander listening from Louisville, KY!!!Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia

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

CS61C L1 MIPS Instruction Representation II, Floating Point I (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #1 Instruction Representation II, Floating Point I 25-1-3 There is one

### Thomas Polzer Institut für Technische Informatik

Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers VO

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

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic Instructors: Bernhard Boser & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/ 10/25/16 Fall 2016 -- Lecture #17

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

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic Instructors: Krste Asanović & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 Outline Defining Performance

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

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic Instructors: Krste Asanović & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 10/24/17 Fall 2017-- Lecture

### Divide: Paper & Pencil

Divide: Paper & Pencil 1001 Quotient Divisor 1000 1001010 Dividend -1000 10 101 1010 1000 10 Remainder See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or

### Chapter 3 Arithmetic for Computers (Part 2)

Department of Electr rical Eng ineering, Chapter 3 Arithmetic for Computers (Part 2) 王振傑 (Chen-Chieh Wang) ccwang@mail.ee.ncku.edu.tw ncku edu Depar rtment of Electr rical Eng ineering, Feng-Chia Unive

### Chapter 3. Arithmetic Text: P&H rev

Chapter 3 Arithmetic Text: P&H rev3.29.16 Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

### Arithmetic. Chapter 3 Computer Organization and Design

Arithmetic Chapter 3 Computer Organization and Design Addition Addition is similar to decimals 0000 0111 + 0000 0101 = 0000 1100 Subtraction (negate) 0000 0111 + 1111 1011 = 0000 0010 Over(under)flow For

### September, Saeid Nooshabadi. Overview IEEE 754 Standard COMP Microprocessors and Embedded Systems

COMP3221 lec20-fp-ii.1 COMP 3221 Microprocessors and Embedded Systems Lectures 20 : Floating Point Number Representation II http://www.cse.unsw.edu.au/~cs3221 September, 2003 Saeid@unsw.edu.au Overview

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

Written Homework 3 Assigned on Tuesday, Feb 19 Due Time: 11:59pm, Feb 26 on Tuesday Problems: 3.22, 3.23, 3.24, 3.41, 3.43 Note: You have 1 week to work on homework 3. 3 Floating-Point Example (1/2) Q:

### COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers Arithmetic for Computers Operations on integers Addition and subtraction Multiplication

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

Floating Point COE 38 Computer Architecture Prof. Muhamed Mudawar Computer Engineering Department King Fahd University of Petroleum and Minerals Presentation Outline Floating-Point Numbers IEEE 754 Floating-Point

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

Chapter 3 Part 2 Arithmetic for Computers Floating Point Floating Point Representation for non integral numbers Including very small and very large numbers 4,600,000,000 or 4.6 x 10 9 0.0000000000000000000000000166

### Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

Computer Architecture Chapter 3 Fall 2005 Department of Computer Science Kent State University Objectives Signed and Unsigned Numbers Addition and Subtraction Multiplication and Division Floating Point

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

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic Instructors: Nick Weaver & John Wawrzynek http://inst.eecs.berkeley.edu/~cs61c/sp18 3/16/18 Spring 2018 Lecture #17

### COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

### Floating Point Arithmetic

Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678

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

Floating Point Arithmetic Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Floating Point (1) Representation for non-integral numbers Including very

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

Computer Organization and Structure Bing-Yu Chen National Taiwan University Arithmetic for Computers Addition and Subtraction Gate Logic and K-Map Method Constructing a Basic ALU Arithmetic Logic Unit

### MIPS Integer ALU Requirements

MIPS Integer ALU Requirements Add, AddU, Sub, SubU, AddI, AddIU: 2 s complement adder/sub with overflow detection. And, Or, Andi, Ori, Xor, Xori, Nor: Logical AND, logical OR, XOR, nor. SLTI, SLTIU (set

### Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Instructor: Nicole Hynes nicole.hynes@rutgers.edu 1 Fixed Point Numbers Fixed point number: integer part

### Chapter Three. Arithmetic

Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing

### Floating Point Arithmetic

Floating Point Arithmetic Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

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

1 Floating Point The World is Not Just Integers Programming languages support numbers with fraction Called floating-point numbers Examples: 3.14159265 (π) 2.71828 (e) 0.000000001 or 1.0 10 9 (seconds in

### Module 2: Computer Arithmetic

Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N

### EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

1 EE 109 Unit 19 IEEE 754 Floating Point Representation Floating Point Arithmetic 2 Floating Point Used to represent very small numbers (fractions) and very large numbers Avogadro s Number: +6.0247 * 10

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

Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating

### TDT4255 Computer Design. Lecture 4. Magnus Jahre

1 TDT4255 Computer Design Lecture 4 Magnus Jahre 2 Chapter 3 Computer Arithmetic ti Acknowledgement: Slides are adapted from Morgan Kaufmann companion material 3 Arithmetic for Computers Operations on

### ECE331: Hardware Organization and Design

ECE331: Hardware Organization and Design Lecture 10: Multiplication & Floating Point Representation Adapted from Computer Organization and Design, Patterson & Hennessy, UCB MIPS Division Two 32-bit registers

### Number Systems and Computer Arithmetic

Number Systems and Computer Arithmetic Counting to four billion two fingers at a time What do all those bits mean now? bits (011011011100010...01) instruction R-format I-format... integer data number text

### Lecture 8: Addition, Multiplication & Division

Lecture 8: Addition, Multiplication & Division Today s topics: Signed/Unsigned Addition Multiplication Division 1 Signed / Unsigned The hardware recognizes two formats: unsigned (corresponding to the C

### Review: MIPS Organization

1 MIPS Arithmetic Review: MIPS Organization Processor Memory src1 addr 5 src2 addr 5 dst addr 5 write data Register File registers (\$zero - \$ra) bits src1 data src2 data read/write addr 1 1100 2 30 words

### UCB CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 18 Running a Program I (Compiling, Assembling, Linking, Loading) Lecturer SOE Dan Garcia 2008-03-04 Researchers at the University of

### Chapter 3. Arithmetic for Computers

Chapter 3 Arithmetic for Computers Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

### Chapter 3. Arithmetic for Computers

Chapter 3 Arithmetic for Computers Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

### Chapter 3. Arithmetic for Computers

Chapter 3 Arithmetic for Computers Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

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

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner Topic 3: Arithmetic These slides are mostly taken verbatim, or with minor changes, from those

### ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design Lecture 11: Floating Point & Floating Point Addition Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Last time: Single Precision Format

### Computer Architecture. Chapter 3: Arithmetic for Computers

182.092 Computer Architecture Chapter 3: Arithmetic for Computers Adapted from Computer Organization and Design, 4 th Edition, Patterson & Hennessy, 2008, Morgan Kaufmann Publishers and Mary Jane Irwin

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

Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

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

Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

### Floating Point Numbers

Floating Point Numbers Summer 8 Fractional numbers Fractional numbers fixed point Floating point numbers the IEEE 7 floating point standard Floating point operations Rounding modes CMPE Summer 8 Slides

### Floating Point Arithmetic

Floating Point Arithmetic ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted from

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

Chapter 2 Float Point Arithmetic Topics IEEE Floating Point Standard Fractional Binary Numbers Rounding Floating Point Operations Mathematical properties Real Numbers in Decimal Notation Representation

### Floating Point January 24, 2008

15-213 The course that gives CMU its Zip! Floating Point January 24, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties class04.ppt 15-213, S 08 Floating

### System Programming CISC 360. Floating Point September 16, 2008

System Programming CISC 360 Floating Point September 16, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Powerpoint Lecture Notes for Computer Systems:

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

CSCI 402: Computer Architectures Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI Homework 4 Assigned on Feb 22, Thursday Due Time: 11:59pm, March 5 on Monday

### Foundations of Computer Systems

18-600 Foundations of Computer Systems Lecture 4: Floating Point Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments for This Week: Lab 1 18-600

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

EE 260: Introduction to Digital Design Arithmetic II Yao Zheng Department of Electrical Engineering University of Hawaiʻi at Mānoa Overview n Integer multiplication n Booth s algorithm n Integer division

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

Floating Point 15-213: Introduction to Computer Systems 4 th Lecture, May 25, 2018 Instructor: Brian Railing Today: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition

### ECE260: Fundamentals of Computer Engineering

Arithmetic for Computers James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy Arithmetic for

### Data Representation Floating Point

Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

### Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Integer Arithmetic Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

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

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science) Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties

### Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/899/

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

Carnegie Mellon Floating Point 15-213/18-213/14-513/15-513: Introduction to Computer Systems 4 th Lecture, Sept. 6, 2018 Today: Floating Point Background: Fractional binary numbers IEEE floating point

### Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/571/

### Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Systems I Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for

### Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan Administrivia Lab

CS61C L18 Running a Program I (1) inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 18 Running a Program I aka Compiling, Assembling, Linking, Loading 2006-10-09 Lecturer SOE

### Data Representation Floating Point

Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

### Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

### Floating-Point Arithmetic

Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } L11 Floating Point 1 What is the problem? Many numeric applications require numbers over a VERY large range. (e.g. nanoseconds to centuries)

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

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers Boolean Algebra Boolean algebra is the basic math used in digital circuits and computers.

### Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum

### Organisasi Sistem Komputer

LOGO Organisasi Sistem Komputer OSK 8 Aritmatika Komputer 1 1 PT. Elektronika FT UNY Does the calculations Arithmetic & Logic Unit Everything else in the computer is there to service this unit Handles

### Floating-Point Arithmetic

Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } Reading: Study Chapter 4. L12 Multiplication 1 Why Floating Point? Aren t Integers enough? Many applications require numbers with a VERY

### UC Berkeley CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 18 Running a Program I aka Compiling, Assembling, Linking, Loading Berkeley beat-down #10 Cal bears ate the OU ducks 45-24.

### EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

1 EE 109 Unit 20 IEEE 754 Floating Point Representation Floating Point Arithmetic 2 Floating Point Used to represent very small numbers (fractions) and very large numbers Avogadro s Number: +6.0247 * 10

### Floating-point representations

Lecture 10 Floating-point representations Methods of representing real numbers (1) 1. Fixed-point number system limited range and/or limited precision results must be scaled 100101010 1111010 100101010.1111010

### Floating-point representations

Lecture 10 Floating-point representations Methods of representing real numbers (1) 1. Fixed-point number system limited range and/or limited precision results must be scaled 100101010 1111010 100101010.1111010

### CO212 Lecture 10: Arithmetic & Logical Unit

CO212 Lecture 10: Arithmetic & Logical Unit Shobhanjana Kalita, Dept. of CSE, Tezpur University Slides courtesy: Computer Architecture and Organization, 9 th Ed, W. Stallings Integer Representation For

### IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

IT 1204 Section 2.0 Data Representation and Arithmetic 2009, University of Colombo School of Computing 1 What is Analog and Digital The interpretation of an analog signal would correspond to a signal whose

### Giving credit where credit is due

CSCE 230J Computer Organization Floating Point Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this lecture are based