Chapter 8
Computer Arithmetic
Chapter Outline
• Unsigned notations
• Signed notations
• Binary Coded Decimal
• Specialized arithmetic hardware
• Floating point numbers
• IEEE 754 floating point standard
Unsigned Notations
• Unsigned non-negative
• Unsigned two’s-complement
Unsigned Notations
Unsigned Notations
• Unsigned non-negative
Unsigned non-negative
• Unsigned two
Unsigned two’
’s-complement
s-complement
Addition: X  X + Y
Overflow
Subtraction: X  X- Y
Overflow
Multiplication
• A non-optimal method
z = 0
FOR i = 1 TO y DO { z = z + x }
Multiplication
• A more typical method
Multiplication
• Calculating running totals
Multiplication
• Shifting partial results to align sums
Shift-add Multiplication Algorithm
C = 0, U = 0;
Example: UV  X  Y
(X = 1101, Y = 1001)
C = 0, U = 0 0
RTL Code
C  0, U  0, i  n
Example: UV  X  Y
(X = 1101, Y = 1001)
C  0, U  0, i  4 0
Hardware Implementation
Optimizing the RTL Code
• UV  X  V
• Register Y not needed
• One operand is lost
Optimizing the RTL Code
C  0, U  0
Example
C  0, U  0, i  4 0
Booth’s Algorithm
• Multiplying unsigned 2’s-complement numbers
Example
• UV  X  Y, X = -3 (1101), Y = -5 (1011)
Example
Example
• UV
UV 
 X
X 
 Y, X = -3 (1101), Y = -5
Y, X = -3 (1101), Y = -5
(1011)
(1011)
RTL Code
Example
Optimized RTL Code
Hardware Implementation
Division
• A non-optimal method
Division
• A more typical method
Division
• Shifting results to align remainders
Shift-subtract Division Algorithm
Example: UV  X
(UV = 1001 0011, X = 1101)
RTL Code
Example
Hardware Implementation
Restoring Division Algorithm
Overflow Comparison
Example
RTL Code
Example
Hardware Implementation
Signed Notations
• Signed-magnitude
Signed Notations
Signed Notations
• Signed-magnitude
Signed-magnitude
• Signed-2
Signed-2’
’s complement
s complement
Signed Notations
Signed Notations
• Signed-magnitude
Signed-magnitude
• Signed-2
Signed-2’
’s complement
s complement
Value Signed-magnitude Signed-2
Value Signed-magnitude Signed-2’
’s complement
s complement
+3 0 0011 0 0011
+3 0 0011 0 0011
-3 1 0011 1 1101
-3 1 0011 1 1101
Addition and Subtraction
RTL Code
RTL Code
RTL Code
Examples
Examples
Examples
Hardware Implementation
Multiplication
Example
Binary Coded Decimal (BCD)
• Every 4 bits = 1 decimal digit
• 1 bit sign
• Example: +27 = 0 0010 0111
BCD Adder
Nine’s Complement
• Equivalent of 1’s complement in binary
Nine
Nine’
’s Complement
s Complement
• Equivalent of 1
Equivalent of 1’
’s complement in binary
s complement in binary
RTL Code
Examples
Examples
Examples
Hardware Implementation
Multiplication
• dshr: decimal shift right
Multiplication
Multiplication
• dshr: decimal shift right
dshr: decimal shift right
Example
Arithmetic Pipelines
• Increase throughput
Arithmetic Pipelines
Arithmetic Pipelines
• Increase throughput
Increase throughput
• Speedup:
Speedup:
Example
Example
Example
Example
Example
Steady State Speedup
Steady State Speedup
Steady State Speedup
Speedup with Latch Delays
Speedup with Latch Delays
Speedup with Latch Delays
Lookup Tables
Example
Wallace Trees
• Carry Save Adder
Wallace Trees
Wallace Trees
• Carry Save Adder
Carry Save Adder
Wallace Trees
• Partial products
Wallace Trees
Wallace Trees
• Partial products
Partial products
Example
Example
Example
4  4 Wallace Tree
8  8 Wallace Tree
Floating Point Numbers
• Sign, Significand, Exponent
• Normalized:
-1234.5678 = -.12345678  104
• NaN
• Biasing
Floating Point Numbers
• Precision
• Gap
• Range
• Round, Guard, Sticky bits
Rounding
• Round toward nearest
• Round toward 0
• Round toward +
• Round toward -
Example
Addition and Subtraction
Addition and Subtraction
RTL Code
Example: (.1101  23
) + (.1110  22
)
Example: (.1101  23
)- (.1110  22
)
Multiplication
• Check for special values
• Add exponents
• Multiply significands
• Normalize result
RTL Code
Example: (.1101  23
)  (.1110  22
)
IEEE 754 Floating Point Standard
• 1 significand < 2
• Single of double precision
IEEE 754 Floating Point Standard
IEEE 754 Floating Point Standard
Denormalized Values
• Used to express smaller numbers than possible with normalized
notation
• Smallest normalized value: 2-126
(single precision)
• Smallest denormalized value: 2-149
(single precision)
Summary
• Unsigned notations
• Signed notations
• Binary Coded Decimal
• Specialized arithmetic hardware
• Floating point numbers
• IEEE 754 floating point standard

Computer Organization - Computer Arithmetic.ppt