CS/COE 0447 (term 2181) Jarrett Billingsley

Slides:



Advertisements
Similar presentations
Fixed Point Numbers The binary integer arithmetic you are used to is known by the more general term of Fixed Point arithmetic. Fixed Point means that we.
Advertisements

Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Floating Point Numbers
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Booth’s Algorithm.
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
1 Lecture 4: Arithmetic for Computers (Part 5) CS 447 Jason Bakos.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
CPSC 321 Computer Architecture ALU Design – Integer Addition, Multiplication & Division Copyright 2002 David H. Albonesi and the University of Rochester.
ECEN 248 Integer Multiplication, Number Format Adopted from Copyright 2002 David H. Albonesi and the University of Rochester.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Number Systems II Prepared by Dr P Marais (Modified by D Burford)
Computing Systems Basic arithmetic for computers.
Floating Point (a brief look) We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large numbers,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Lecture 9: Floating Point
CSC 221 Computer Organization and Assembly Language
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Floating Point Representations
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Integer Multiplication and Division
Integer Division.
Floating Point Math & Representation
Lecture 9: Floating Point
Topics IEEE Floating Point Standard Rounding Floating Point Operations
CS 232: Computer Architecture II
CS/COE0447 Computer Organization & Assembly Language
Morgan Kaufmann Publishers
CS 367 Floating Point Topics (Ch 2.4) IEEE Floating Point Standard
William Stallings Computer Organization and Architecture 7th Edition
Chapter 6 Floating Point
Topic 3d Representation of Real Numbers
CSCE 350 Computer Architecture
Number Representations
CS/COE 0447 Jarrett Billingsley
How to represent real numbers
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
Computer Architecture
Multiplication and Division
Chapter 8 Computer Arithmetic
Morgan Kaufmann Publishers Arithmetic for Computers
Number Representation
Number Representations
Presentation transcript:

CS/COE 0447 (term 2181) Jarrett Billingsley Division and Floats CS/COE 0447 (term 2181) Jarrett Billingsley

Class announcements I finished Stranger Things 2 :O 11/2/2017 CS/COE 0447 term 2181

Division Like multiplication, but not 11/2/2017 CS/COE 0447 term 2181

If multiplication is repeated addition… …is division repeated subtraction? Yes. Yes, it is. In A ÷ B, the quotient (answer) is "how many times can you subtract B from A until you get a number less than B?" 20 ÷ 3 = 6 R 2 1 2 3 What about these lil guys? 4 5 6 Now, how many subtractions would it take to calculate 1,000,000,000 ÷ 2? 11/2/2017 CS/COE 0447 term 2181

That's not what you learned in school, was it You learned something a tiiiiiny bit more complicated. 5 4 R51 4÷77? 4209 77 42÷77? -385 =77×5 9 420÷77! Oh, that's like 77×4 35 Uhh…how many times? Like, 5-ish? Guess and check -308 =77×4 51 What the fuck? 11/2/2017 CS/COE 0447 term 2181

What's going on? Division is multiplication backwards. It's like parallel parking. 77 ×54 308 3850 4158 We're finding the partial products that add up to a total product. Division goes left-to-right because we find the partial products from biggest to smallest. And to make it even more interesting, there might be a remainder. +R51=4209 Division is hard. Like, mathematically proven hard. 11/2/2017 CS/COE 0447 term 2181

Thanks, tiny multiplication table. Thable. At least multiplication in binary is easy, which simplifies the task. 1 1 R1 1100≤1? 1100≤10? 1100≤100? 1001001 1100 1100≤1001? -1100 1 1100≤10010! 110 1100≤1100! -1100 In binary, each step becomes a yes-no choice: does the divisor fit into the remainder? 1100≤1? 11/2/2017 CS/COE 0447 term 2181

Divisor? Dividend? Remainder? (animated) The divisor divides the dividend. The dividend is the number that is being divided. 1001001 1100 1001001 Remainder Original dividend The remainder is the smaller number that we're trying to fit the divisor into. 1001001 1001001 1001001 It's actually being shifted left. 1001001 11/2/2017 CS/COE 0447 term 2181

Another way of thinking about it (animated) We're starting with the divisor shifted all the way left, and sliding it right. 1 1 R1 1100 1 11001 1001001 1100000000 Shifting the divisor right is the same as shifting the remainder/dividend left. 11/2/2017 CS/COE 0447 term 2181

noitacilpitluM Divisor 101 Remainder Dividend Quotient 1011 for(n bits in dividend) { quotient <<= 1 remainder << dividend << 1 if(divisor <= remainder) { quotient[0] = 1 remainder -= divisor } 1 0110 10 1100 101 1000 -101 |1 1000 1 1 0000 10 1 10 11/2/2017 CS/COE 0447 term 2181

Huh, another similarity The MIPS div instruction works like mult: div t0, a0 then HI = remainder and LO = quotient. Then we can use mfhi/mflo to get the answers. The div pseudo-op does a div followed by an mflo. The rem pseudo-op does a div followed by an mfhi. So, does this mean the multiplication and division hardware are linked somehow? 11/2/2017 CS/COE 0447 term 2181

- Well then FSM control unit 8 shift left shift left LSB 8 8 go! The divider circuitry is closely related to the multiplier. These are hooked together. 8 Remainder Dividend Quotient write enable shift left shift left LSB Divisor 8 8 FSM control unit go! - negative? 8 I'm done! 11/2/2017 CS/COE 0447 term 2181

÷ Rem A Quot B Signed division sign(A)⊕sign(B) abs neg abs It works just like signed multiplication. Absolute value the inputs, negate the output if the signs differ. Rem A abs ÷ Quot neg B abs sign(A)⊕sign(B) 11/2/2017 CS/COE 0447 term 2181

Floating-point number representation 11/2/2017 CS/COE 0447 term 2181

This could be a whole unit itself... Floating-point arithmetic is COMPLEX STUFF. But it's not super useful to know unless you're either: doing lots of high-precision numerical programming, or implementing floating-point arithmetic yourself. However... It's good to have an understanding of why limitations exist It's good to have an appreciation of how complex this is... and how much better things are now than they were in the 1970s and 1980s. 11/2/2017 CS/COE 0447 term 2181

This is called fixed-point representation. Fixing the point If we want to represent decimal places, one way of doing so is by assuming that the lowest n digits are the decimal places. $12.34 1234 This is called fixed-point representation. +$54.32 +5432 It's fast and easy, but limited. You trade off speed for accuracy and range. $66.66 6666 11/2/2017 CS/COE 0447 term 2181

IEEE 754 Est'd 1985, updated as recently as 2008 Standard for floating-point representation and arithmetic that virtually every CPU now uses Floating-point representation is based around scientific notation 1,348 = -0.0039 = 1,440,000 = +1.348 × 10+3 -3.9 × 10-3 +1.44 × 10+6 sign exponent significand 11/2/2017 CS/COE 0447 term 2181

Binary Scientific Notation Scientific notation works equally well in any other base! (below uses base-10 exponents for clarity) 1001 0101 = -0.001 010 = 1001 0000 0000 0000 = +1.001 0101 × 2+7 -1.010 × 2-3 +1.001 × 2+15 what do you notice about the digit before the binary point? 11/2/2017 CS/COE 0447 term 2181

IEEE 754 Single-precision Known as float in C/C++/Java etc., 32-bit float format 1 bit for sign, 8 bits for the exponent, 23 bits for the fraction Note that the fraction field only stores the digits after the binary point – the 1 before the binary point is implicit! In effect this gives us a 24-bit significand. The only number with a 0 before the binary point is 0! Floating-point numbers are actually in sign-magnitude! Do you remember the downsides? 11/2/2017 illustration from user Stannered on Wikimedia Commons CS/COE 0447 term 2181

The exponent field -127 => -10 => 34 => 117 161 Signed Biased The exponent field is 8 bits, and can hold positive or negative exponents, but... it doesn't use S-M, 1's, or 2's complement. It uses something called biased notation. Basically, you take the signed number and add a constant to get the biased representation. Single-precision floats use 127. -127 => -10 => 34 => 117 161 Signed Biased The exponent can range from -127 to 127 (0 to 254 biased) Why'd they do this? So you can kinda-sorta sort floating point numbers with integer comparisons. Or something. 11/2/2017 CS/COE 0447 term 2181

Special values Some mathematical operations can give infinity values (like n/0) or are undefined (like 0/0). An exponent of 255 (biased) is used to signal these values. If the fraction part is 0, it's positive or negative infinity If the fraction part is nonzero, it's "NaN" (not a number) To sum up... Exponent Fraction Value nonzero "denormalized" number 1..254 anything regular number 255 infinity NaN 11/2/2017 CS/COE 0447 term 2181

Other formats The most common other format is double-precision (C/C++/Java double), which uses an 11-bit exponent and 52-bit fraction. GPUs have driven the creation of a half-precision 16-bit floating-point format. Isn't it cute? 11/2/2017 both illustrations from user Codekaizen on Wikimedia Commons CS/COE 0447 term 2181