Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Chapter 8 Computer Arithmetic

Preview:

Citation preview

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Chapter 8Chapter 8Computer ArithmeticComputer Arithmetic

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Chapter OutlineChapter 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 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Unsigned NotationsUnsigned Notations

• Unsigned non-negativeUnsigned non-negative

• Unsigned twoUnsigned two’’s-complements-complement

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Unsigned NotationsUnsigned Notations

• Unsigned non-negativeUnsigned non-negative

• Unsigned twoUnsigned two’’s-complements-complement

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Addition: X Addition: X X + Y X + Y

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

OverflowOverflow

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Subtraction: X Subtraction: X X - Y X - Y

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

OverflowOverflow

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• A non-optimal methodA non-optimal method

z = 0 z = 0

FOR i = 1 TO y DO { z = z + x }FOR i = 1 TO y DO { z = z + x }

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• A more typical methodA more typical method

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• Calculating running totalsCalculating running totals

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• Shifting partial results to align sumsShifting partial results to align sums

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Shift-add Multiplication Shift-add Multiplication AlgorithmAlgorithm

C = 0, U = 0;

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: UV Example: UV X X Y Y(X = 1101, Y = 1001)(X = 1101, Y = 1001)

C = 0, U = 0 0

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

C 0, U 0, i n

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: UV Example: UV X X Y Y(X = 1101, Y = 1001)(X = 1101, Y = 1001)

C 0, U 0, i 4 0

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Optimizing the RTL CodeOptimizing the RTL Code

• UV UV X X V V

• Register Y not neededRegister Y not needed

• One operand is lostOne operand is lost

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Optimizing the RTL CodeOptimizing the RTL Code

C 0, U 0

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

C 0, U 0, i 4 0

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

BoothBooth’’s Algorithms Algorithm• Multiplying unsigned 2Multiplying unsigned 2’’s-complement s-complement

numbersnumbers

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample• UV UV X X Y, X = -3 (1101), Y = -5 Y, X = -3 (1101), Y = -5

(1011)(1011)

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample• UV UV X X Y, X = -3 (1101), Y = -5 Y, X = -3 (1101), Y = -5

(1011)(1011)

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Optimized RTL CodeOptimized RTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

DivisionDivision

• A non-optimal methodA non-optimal method

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

DivisionDivision• A more typical methodA more typical method

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

DivisionDivision• Shifting results to align remaindersShifting results to align remainders

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Shift-subtract Division AlgorithmShift-subtract Division Algorithm

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: UV Example: UV X X(UV = 1001 0011, X = 1101)(UV = 1001 0011, X = 1101)

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Restoring Division AlgorithmRestoring Division Algorithm

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Overflow ComparisonOverflow Comparison

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Signed NotationsSigned Notations

• Signed-magnitudeSigned-magnitude

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Signed NotationsSigned Notations

• Signed-magnitudeSigned-magnitude

• Signed-2Signed-2’’s complements complement

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Signed NotationsSigned Notations

• Signed-magnitudeSigned-magnitude

• Signed-2Signed-2’’s complements complementValue Signed-magnitude Signed-2Value Signed-magnitude Signed-2’’s complements complement

+3 0 0011 0 0011+3 0 0011 0 0011

-3 1 0011 1 1101-3 1 0011 1 1101

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Addition and SubtractionAddition and Subtraction

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Binary Coded Decimal (BCD)Binary Coded Decimal (BCD)

• Every 4 bits = 1 decimal digitEvery 4 bits = 1 decimal digit

• 1 bit sign1 bit sign

• Example: +27 = 0 0010 0111Example: +27 = 0 0010 0111

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

BCD AdderBCD Adder

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

NineNine’’s Complements Complement• Equivalent of 1Equivalent of 1’’s complement in binarys complement in binary

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

NineNine’’s Complements Complement• Equivalent of 1Equivalent of 1’’s complement in binarys complement in binary

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExamplesExamples

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Hardware ImplementationHardware Implementation

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• dshr: decimal shift rightdshr: decimal shift right

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• dshr: decimal shift rightdshr: decimal shift right

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Arithmetic PipelinesArithmetic Pipelines

• Increase throughputIncrease throughput

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Arithmetic PipelinesArithmetic Pipelines

• Increase throughputIncrease throughput

• Speedup:Speedup:

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Steady State SpeedupSteady State Speedup

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Steady State SpeedupSteady State Speedup

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Speedup with Latch DelaysSpeedup with Latch Delays

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Speedup with Latch DelaysSpeedup with Latch Delays

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Lookup TablesLookup Tables

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Wallace TreesWallace Trees

• Carry Save AdderCarry Save Adder

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Wallace TreesWallace Trees

• Carry Save AdderCarry Save Adder

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Wallace TreesWallace Trees• Partial productsPartial products

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Wallace TreesWallace Trees

• Partial productsPartial products

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

4 4 4 Wallace Tree 4 Wallace Tree

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

8 8 8 Wallace Tree 8 Wallace Tree

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Floating Point NumbersFloating Point Numbers

• Sign, Significand, ExponentSign, Significand, Exponent

• Normalized:Normalized: -1234.5678 = -.12345678 -1234.5678 = -.12345678 10 1044

• NaNNaN

• BiasingBiasing

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Floating Point NumbersFloating Point Numbers

• PrecisionPrecision

• GapGap

• RangeRange

• Round, Guard, Sticky bitsRound, Guard, Sticky bits

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RoundingRounding

• 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 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

ExampleExample

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Addition and SubtractionAddition and Subtraction

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Addition and SubtractionAddition and Subtraction

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: (.1101 Example: (.1101 2 233) + (.1110 ) + (.1110 2222))

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: (.1101 Example: (.1101 2 233) - (.1110 ) - (.1110 2222))

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

MultiplicationMultiplication

• 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 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

RTL CodeRTL Code

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Example: (.1101 Example: (.1101 2 233) ) (.1110 (.1110 2222))

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

IEEE 754 Floating Point IEEE 754 Floating Point StandardStandard

• 11 significand < 2 significand < 2

• Single of double precisionSingle of double precision

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

IEEE 754 Floating Point StandardIEEE 754 Floating Point Standard

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

IEEE 754 Floating Point StandardIEEE 754 Floating Point Standard

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

Denormalized ValuesDenormalized Values

• Used to express smaller numbers than Used to express smaller numbers than possible with normalized notationpossible with normalized notation

• Smallest normalized value: 2Smallest normalized value: 2-126-126 (single (single precision)precision)

• Smallest denormalized value: 2Smallest denormalized value: 2-149-149 (single precision)(single precision)

Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001 Images courtesy of Addison Wesley Longman, Inc. Copyright © 2001

SummarySummary

• 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

Recommended