CA Lecture 8
CA Lecture 8
Lecture 8.
. Computer Arithmetic.
Instructors
Pentium Division Bug (1994-95): Pentium’s radix-4 SRT algorithm occasionally gave incorrect
quotient
First noted in 1994 by Tom Nicely who computed sums of reciprocals of twin primes:
3
Aspects of, and Topics in, Computer
Arithmetic
Hardware (our focus in this lecture) Software
––––––––––––––––––––––––––––––––––––––––––––––––– ––––––––––––––––––––––––––––––––––––
Design of efficient digital circuits for Numerical methods for solving
primitive and other arithmetic operations systems of linear equations,
such as +, –, , , , log, sin, and cos partial differential eq’ns, and so on
Issues: Algorithms Issues: Algorithms
Error analysis Error analysis
Speed/cost trade-offs Computational complexity
Hardware implementation Programming
Testing, verification Testing, verification
General-purpose Special-purpose
–––––––––––––––––––––– –––––––––––––––––––––––
Flexible data paths Tailored to application
Fast primitive areas such as:
operations like Digital filtering
+, –, , , Image processing
Benchmarking Radar tracking
4
Number Systems
5
Decimal number system…
X = i xi10i
6
Binary Number System
7
Decimal to Binary conversion
• Integer and fractional parts are handled • e.g. 11.81 to 1011.11001 (approx)
separately, – 11/2 = 5 remainder 1
– Integer part is handled by repeating – 5/2 = 2 remainder 1
division by 2 – 2/2 = 1 remainder 0
– Factional part is handled by repeating – 1/2 = 0 remainder 1
multiplication by 2 – Binary number 1011
• E.g. convert decimal 11.81 to binary – .81x2 = 1.62 integral part 1
– Integer part 11 – .62x2 = 1.24 integral part 1
– Factional part .81 – .24x2 = 0.48 integral part 0
– .48x2 = 0.96 integral part 0
– .96x2 = 1.92 integral part 1
– Binary number .11001 (approximate)
8
Hexadecimal Notation:
9
Numbers and Their Encodings
10
Arithmetic & Logic Unit
requested
arithmetic Status e.g
operation overflow?
11
Integer Representation
12
Sign-Magnitude
14
Basis of Binary Arithmetic
15
Two’s Complement Benefits
16
Geometric Depiction of Twos Complement
Integers
In n bits, can
store integers from
–2n-1 to + 2n-1 – 1
neg pos
17
Range of Numbers
• 8 bit 2s complement
– +127 = 01111111 = 27 -1
– -128 = 10000000 = -27
• 16 bit 2s complement
– +32767 = 01111111 11111111 = 215 - 1
– -32768 = 10000000 00000000 = -215
18
Negation Special Case 1
0= 00000000
Bitwise not 11111111
Add 1 +1
Result 1 00000000
19
Carry vs. Overflow
20
Overflow is Implementation Dependent!
11111111
+1
1 00000000 for this addition
the answer is:
fixed number 0
of bits to with carry = 1
represent
carry values
21
Unsigned Interpretation -> Overflow
11111111 25510
+1
1 00000000
22
Signed Interpretation -> No Overflow
11111111 – 110
+1
1 00000000
• –1 + 1 = 0
• answer is correct!
• OVERFLOW did not occur (even though carry =1!)
• WHY? can represent 0 as an 8-bit signed integer!
23
Negation Special Case 2
– 128 = 10000000
bitwise not 01111111
Add 1 to lsb +1
Result 10000000
• Whoops!
– (– 128) = – 128 Problem! OVERFLOW!
24
Conversion Between Lengths, e.g. 8 -> 16
25
Addition and Subtraction
26
Adders
27
Multiplication
• Complex
• Work out partial product for each digit
• Take care with place value (column)
• Add partial products
• Note: need double length result – could easily overflow single word
28
Unsigned Binary Multiplication
29
Unsigned Binary Multiplication
30
Array Multiplier
31
Multiplying Negative Numbers
32
Booth’s Algorithm
33
Example of Booth’s Algorithm
34
Division
35
Division of Unsigned Binary Integers
36
Real Numbers
37
Floating Point
38
Floating Point Examples
39
Signs for Floating Point
40
Normalization //
41
FP Ranges
42
Expressible Numbers
43
IEEE 754
44
FP Arithmetic +/-
45
FP Arithmetic x/:
46
Floating Point
Division Multiplication
47
Encoding Numbers in 4 Bits
Unsigned integers
Signed-magnitude
3 + 1 fixed-point, xxx.x
2 + 2 floating-point, s 2 e e s
e in [-2, 1], s in [0, 3]
48
Conclusion
49