Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Chapter 8 Computer Arithmetic
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Chapter Outline Unsigned notationsUnsigned notations Signed notationsSigned notations Binary Coded DecimalBinary Coded Decimal Specialized arithmetic hardwareSpecialized arithmetic hardware Floating point numbersFloating point numbers IEEE 754 floating point standardIEEE 754 floating point standard
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Unsigned Notations Unsigned non-negativeUnsigned non-negative Unsigned two’s-complementUnsigned two’s-complement
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Unsigned Notations Unsigned non-negativeUnsigned non-negative Unsigned two’s-complementUnsigned two’s-complement
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Addition: X X + Y
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Overflow
Subtraction: X X - Y
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Overflow
Multiplication A non-optimal methodA non-optimal method z = 0 FOR i = 1 TO y DO { z = z + x }
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication A more typical methodA more typical method
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication Calculating running totalsCalculating running totals
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication Shifting partial results to align sumsShifting partial results to align sums
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Shift-add Multiplication Algorithm C = 0, U = 0;
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: UV X Y (X = 1101, Y = 1001) C = 0, U = 0 0
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code C 0, U 0, i n
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: UV X Y (X = 1101, Y = 1001) C 0, U 0, i 4 0
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Optimizing the RTL Code UV X VUV X V Register Y not neededRegister Y not needed One operand is lostOne operand is lost
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Optimizing the RTL Code C 0, U 0
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example C 0, U 0, i 4 0
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Booth’s Algorithm Multiplying unsigned 2’s-complement numbersMultiplying unsigned 2’s-complement numbers
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example UV X Y, X = -3 (1101), Y = -5 (1011)UV X Y, X = -3 (1101), Y = -5 (1011)
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example UV X Y, X = -3 (1101), Y = -5 (1011)UV X Y, X = -3 (1101), Y = -5 (1011)
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Optimized RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Division A non-optimal methodA non-optimal method
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Division A more typical methodA more typical method
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Division Shifting results to align remaindersShifting results to align remainders
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Shift-subtract Division Algorithm
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: UV X (UV = , X = 1101)
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Restoring Division Algorithm
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Overflow Comparison
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Signed Notations Signed-magnitudeSigned-magnitude
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Signed Notations Signed-magnitudeSigned-magnitude Signed-2’s complementSigned-2’s complement
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Signed Notations Signed-magnitudeSigned-magnitude Signed-2’s complementSigned-2’s complement Value Signed-magnitude Signed-2’s complement
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Addition and Subtraction
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Examples
Examples
Examples
Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication
Example
Binary Coded Decimal (BCD) Every 4 bits = 1 decimal digitEvery 4 bits = 1 decimal digit 1 bit sign1 bit sign Example: +27 = Example: +27 =
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 BCD Adder
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Nine’s Complement Equivalent of 1’s complement in binaryEquivalent of 1’s complement in binary
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Nine’s Complement Equivalent of 1’s complement in binaryEquivalent of 1’s complement in binary
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Examples
Examples
Examples
Hardware Implementation
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication dshr: decimal shift rightdshr: decimal shift right
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication dshr: decimal shift rightdshr: decimal shift right
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Arithmetic Pipelines Increase throughputIncrease throughput
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Arithmetic Pipelines Increase throughputIncrease throughput Speedup:Speedup:
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Example
Example
Steady State Speedup
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Steady State Speedup
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Speedup with Latch Delays
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Speedup with Latch Delays
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Lookup Tables
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Wallace Trees Carry Save AdderCarry Save Adder
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Wallace Trees Carry Save AdderCarry Save Adder
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Wallace Trees Partial productsPartial products
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Wallace Trees Partial productsPartial products
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Example
4 4 Wallace Tree
Images courtesy of Addison Wesley Longman, Inc. Copyright © 8 Wallace Tree
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Floating Point Numbers Sign, Significand, ExponentSign, Significand, Exponent Normalized:Normalized: = = 10 4 NaNNaN BiasingBiasing
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Floating Point Numbers PrecisionPrecision GapGap RangeRange Round, Guard, Sticky bitsRound, Guard, Sticky bits
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Rounding Round toward nearestRound toward nearest Round toward 0Round toward 0 Round toward + Round toward + Round toward - Round toward -
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example
Addition and Subtraction
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Addition and Subtraction
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: (.1101 2 3 ) + (.1110 2 2 )
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: (.1101 2 3 ) - (.1110 2 2 )
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Multiplication Check for special valuesCheck for special values Add exponentsAdd exponents Multiply significandsMultiply significands Normalize resultNormalize result
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 RTL Code
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Example: (.1101 2 3 ) (.1110 2 2 )
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 IEEE 754 Floating Point Standard 1 significand < 21 significand < 2 Single of double precisionSingle of double precision
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 IEEE 754 Floating Point Standard IEEE 754 Floating Point Standard
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 IEEE 754 Floating Point Standard
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Denormalized Values Used to express smaller numbers than possible with normalized notationUsed to express smaller numbers than possible with normalized notation Smallest normalized value: (single precision)Smallest normalized value: (single precision) Smallest denormalized value: (single precision)Smallest denormalized value: (single precision)
Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Summary Unsigned notationsUnsigned notations Signed notationsSigned notations Binary Coded DecimalBinary Coded Decimal Specialized arithmetic hardwareSpecialized arithmetic hardware Floating point numbersFloating point numbers IEEE 754 floating point standardIEEE 754 floating point standard