Restoring division. 2. Run the algorithm Let s do 0111/0010 (7/2) unsigned. 3. Find remainder here. 4. Find quotient here.

Similar documents
Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

Numerical Matrix Analysis

Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML. By Prashanth Tilleti

Computer Science 281 Binary and Hexadecimal Review

Lecture 8: Binary Multiplication & Division

Attention: This material is copyright Chris Hecker. All rights reserved.

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

CS321. Introduction to Numerical Methods

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

What Every Computer Scientist Should Know About Floating-Point Arithmetic

CHAPTER 5 Round-off errors

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

The string of digits in the binary number system represents the quantity

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Lecture 2. Binary and Hexadecimal Numbers

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Some Functions Computable with a Fused-mac

Floating point package user s guide By David Bishop (dbishop@vhdl.org)

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Precision & Performance: Floating Point and IEEE 754 Compliance for NVIDIA GPUs

A new binary floating-point division algorithm and its software implementation on the ST231 processor

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

Monday January 19th 2015 Title: "Transmathematics - a survey of recent results on division by zero" Facilitator: TheNumberNullity / James Anderson, UK

Useful Number Systems

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Systems I: Computer Organization and Architecture

Numerical Analysis I

Binary Numbering Systems

Paramedic Program Pre-Admission Mathematics Test Study Guide

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

DNA Data and Program Representation. Alexandre David

( 214 (represen ed by flipping) (magnitude = -42) = = -42 (flip the bits and add 1)

FLOATING-POINT ARITHMETIC IN AMD PROCESSORS MICHAEL SCHULTE AMD RESEARCH JUNE 2015

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Solution for Homework 2

Number Representation

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

CS201: Architecture and Assembly Language

Fast Arithmetic Coding (FastAC) Implementations

Floating Point Fused Add-Subtract and Fused Dot-Product Units

INTRODUCTION TO FRACTIONS

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

Numbering Systems. InThisAppendix...

Q-Format number representation. Lecture 5 Fixed Point vs Floating Point. How to store Q30 number to 16-bit memory? Q-format notation.

Intel 64 and IA-32 Architectures Software Developer s Manual

NUMBER SYSTEMS. William Stallings

Number Systems and Radix Conversion

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Floating-point control in the Intel compiler and libraries or Why doesn t my application always give the expected answer?

MATH-0910 Review Concepts (Haugen)

Binary Representation

A NEW REPRESENTATION OF THE RATIONAL NUMBERS FOR FAST EASY ARITHMETIC. E. C. R. HEHNER and R. N. S. HORSPOOL

CPEN Digital Logic Design Binary Systems

The Euclidean Algorithm

EE361: Digital Computer Organization Course Syllabus

IA-32 Intel Architecture Software Developer s Manual

1. The Fly In The Ointment

NUMBER SYSTEMS. 1.1 Introduction

ADDITION. Children should extend the carrying method to numbers with at least four digits.

THE EXACT DOT PRODUCT AS BASIC TOOL FOR LONG INTERVAL ARITHMETIC

Dr Brian Beaudrie pg. 1

Decimals Adding and Subtracting

Intel Architecture Software Developer s Manual

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

ASCII Characters. 146 CHAPTER 3 Information Representation. The sign bit is 1, so the number is negative. Converting to decimal gives

COMPSCI 210. Binary Fractions. Agenda & Reading

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Fast Logarithms on a Floating-Point Device

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Chapter 2. Binary Values and Number Systems

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Some facts about polynomials modulo m (Full proof of the Fingerprinting Theorem)

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

Floating Point Arithmetic Chapter 14

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

PAYCHEX, INC. BASIC BUSINESS MATH TRAINING MODULE

CSI 333 Lecture 1 Number Systems

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

High-Precision C++ Arithmetic

The pitfalls of verifying floating-point computations

Math Workshop October 2010 Fractions and Repeating Decimals

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

2000: 3100 pages ( Source: Volkswagen AG ) This chapter will start with a brief comparison between the two types of processor.

Positional Numbering System

Multiplying and Dividing Signed Numbers. Finding the Product of Two Signed Numbers. (a) (3)( 4) ( 4) ( 4) ( 4) 12 (b) (4)( 5) ( 5) ( 5) ( 5) ( 5) 20

UNIVERSIDADE DE SANTIAGO DE COMPOSTELA DEPARTAMENTO DE ELECTRONICA E COMPUTACION

Transcription:

Binary division Dividend = divisor q quotient + remainder CS/COE447: Computer Organization and Assembly Language Given dividend and divisor, we want to obtain quotient (Q) and remainder (R) Chapter 3 We will start from our p paper p &p pencil method Sangyeun Cho Dept. of Computer Science 2 Hardware design 1 64-bit ALU Hardware design 2 32-bit 32 bit ALU 64 bit 64-bit 32-bit 32-bit 64-bit 64 bit 3 4

Hardware design 3 Example 2. Run the algorithm Let s do 111/1 (7/2) unsigned 3. Find remainder here 1. Place dividend here first 4. Find quotient here Iteration Divisor 1 1 1 2 1 3 1 4 1 Hardware design 3 initial iti values 111 shift remainder left by 1 111 remainder = remainder divisor 111 111 (remainder<) +divisor; shift left; r= 1 11 remainder = remainder divisor 1111 11 (remainder<) +divisor; shift left; r= 11 1 remainder = remainder divisor 1 1 (remainder>) shift left; r=1 11 1 remainder = remainder divisor 1 1 (remainder>) shift left; r=1 1 11 done 1 shift left half of remainder right by 1 1 11 5 6 Exercise sheet Restoring division Iteration Divisor Hardware design 3 initial iti values shift remainder left by 1 The three hardware designs we saw are based on the notion of restoring division At first, attempt to subtract divisor from dividend If the result of subtraction is negative it rolls back by adding divisor This step is called restoring 1 It s a trial-and-error and error approach; can we do better? 2 3 4 done shift left half of remainder right by 1 7 8

Non-restoring division Example, non-restoring division Let s revisit the restoring division designs Given remainder R (R<) after subtraction By adding divisor D back, we have (R+D) After shifting the result, we have 2 (R+D)=2 R+2 D If we subtract the divisor in the next step, we have 2 R+2 D D =2 R+D This is equivalent to Left-shifting R by 1 bit and then adding D! Let s again do 111/1 (7/2) unsigned Iteration Divisor 1 1 1 2 1 3 1 Hardware design 3, non-restoring initial iti values 111 shift remainder left by 1 111 remainder = remainder divisor 111 111 (remainder<) shift left; r= 111 11 remainder = remainder + divisor 1111 11 (remainder<) shift left; r= 1111 1 remainder = remainder + divisor 1 1 (remainder>) shift left; r=1 11 1 remainder = remainder divisor 1 1 4 1 (remainder>) shift left; r=1 1 11 done 1 shift left half of remainder right by 1 1 11 9 1 Exercise sheet Floating-point (FP) numbers Iteration Divisor Hardware design 3, non-restoring Computers need to deal with real numbers Fractional numbers (e.g., 3.1416) Very small numbers (e.g.,.1) Very larger numbers (e.g., 2.7596 1 9 ) 1 2 initial iti values shift remainder left by 1 Components in an FP number (-1) sign significand (a.k.a. mantisa) 2 exponent More bits in significand gives higher accuracy More bits in exponent gives wider range 3 4 done shift left half of remainder right by 1 A case for FP representation standard Portability issues Improved implementations IEEE-754 11 12

Format choice issues Example floating-point numbers (base-1) 1.4 1-2 -2. = -2. 1 1 What components do we have? Sign Significandifi Exponent Representing sign is easy. Significand is unsigned. Exponent is a signed integer. What method do we use? IEEE 754 A standard for representing FP numbers in computers Single precision (32 bits): 8-bit exponent, 23-bit significand Double precision (64 bits): 11-bit exponent, 52-bit significand N-1 N-2 M Leading 1 in significand ifi is implicit it (why?) Exponent is a signed number M-1 sign exponent significand (or mantisa) Biased format for easier sorting of FP numbers All s is the smallest, all 1 s is the largest Bias of 127 for SP and 123 for DP Hence, to obtain the actual value of a representation (-1) sign (1#. #significand) 2 # i ifi 2 exponent : here # is concatenation ti 13 14 Biased representation IEEE 754 example Yet another binary number representation Signed number allowed -.75 ten Same as -3/4 or -3/2 2 is the smallest number 111 111 is the largest number To get the real value, subtract a pre-determined bias from the unsigned evaluation of the bit pattern In other words, representation = value + bias Bias for the exponent field in IEEE 754 127 (SP) 123 (DP) In binary, -11 two /2 2 ten or -.11 two In a normalized form, it s -1.1 two 2-1, two In IEEE 754 Sign bit is 1 number is negative! Significand is.1 the leading 1 is implicit! Exponent is -1 or 126 in biased representation 31 3 23 22 1 1 1 1 1 1 1 1 sign 8-bit exponent 23-bit significand (or mantissa) 15 16

IEEE 754 summary Denormal number Single Precision Double Precision Represented Object Exponent Fraction Exponent Fraction non-zero non-zero +/- denormalized number 1~254 anything 1~246 anything +/- floating-point numbers 255 247 +/- infinity Smallest normal: 1. 2 Emin Below, use denormal:.f 2 Emin e = E min 1, f!= ######################## 255 non-zero 247 non-zero NaN (Not a Number) 17 18 NaN Values represented with IEEE 754 Not a Number Result of illegal computation /, infinity/infinity, infinity infinity, Any computation involving a NaN e = E max +1, f!= #11111111####################### Many NaN s 19 2

FP arithmetic operations Overflow and underflow We want to support four arithmetic functions (+,,, ) Overflow The exponent is too large to fit in the exponent field (+, ): Must equalize exponents first. Why? ( ): Multiply/divide significand (, significand, add/subtract exponents exponents. Underflow The exponent is too small to fit in the exponent field Use rounding when result is not accurate Exception conditions E.g., Overflow, underflow (what is underflow?) Error conditions E.g., divide-by-zero 21 FP addition 22 FP multiplication 1 Align binary points 1. 1 Compute exponents 1. 2. Add significands 2. Multiply significands 3. Normalize result 3. Normalize result (Example) (E l ).5ten.4375ten =1.two 2-1 1.11two 2-2 4. Set sign (Example) (1. (1 two 2-11) (-1.11 ) ( 1 11two 2-22) 23 24

Accuracy and rounding Guard bit examples Goal IEEE 754 guarantees that the maximum error is ±½ u.l.p. compared with infinite precision u.l.p. = Units in the Last Place = distance to the next floating-point value larger in magnitude Assume 5-bit significand Add 1. 2 + 1.1111 2-2 Rounding using extra bits Alignment step in the addition algorithm can cause data to be discarded (shifted out on right) Multiplication step IEEE 754 defines three types of extra bits: G (guard), R (round), S (sticky) Multiply 1. 2 1.11 2-2 25 26 Rounding modes Pentium processor divide flaw IEEE 754 has four rounding modes Round to nearest even (default) Round towards plus infinity Round towards minus infinity Round towards Round bit is calculated to the right of Guard bit Sticky bit is used to determine whether there are any 1 bit truncated below Guard and Round bits It can be shown that Round to nearest even minimizes the mean error introduced by rounding Pentium FP divider algorithm generates multiple bits per step FPU uses MSBs of divisor and dividend/remainder to guess next 2 bits of quotient Guess is taken from a lookup table: -2, -1,, +1, +2 Guess is multiplied by divisor and subtracted from remainder to generate a new remainder SRT division (Sweeny, Robertson, and Tocher): Used in most CPUs Pentium processor table = 7 bits remainder + 4 bits divisor = 11 bits, 2 11 entries 5 entries of divisors omitted: 1.1, 1.1, 1.111, 1.11, 1.111 from the table Fix is just add 5 entries back into the table Eventually, it cost Intel $3M 27 28