2. Dr. Shadrokh Samavi. 2. Computer Arithmetic. Website: ... 2 Representing Signed Numbers ... 1. explain the relative merits of number systems used ... 8. write a paper compatible with journal format .... decimal code (27)ten 11011 radix-2 or binary code (11011)two ... Cardinality of digit set (2) is equal to radix value.
Numbers and Arithmetic
Dr. Shadrokh Samavi
1
1
Computer Arithmetic Website: http://ece.iut.ac.ir/faculty/samavi/computer_arithmetic.htm
Text: Parhami, Behrooz, “Computer Arithmetic: Algorithms and Hardware Designs” Oxford University Press, 2000. http://www.ece.ucsb.edu/Faculty/Parhami/text_comp_arit.htm
Part Part Part Part Part Part Part
1: 2: 3: 4: 5: 6: 7:
Number Representation Addition/Subtraction Multiplication Division Real Arithmetic (Floating-Point) Function Evaluation Implementation Topics
Slides are intended to illustrate the content of Parhami’s book. Dr. Shadrokh Samavi
2
2
Part I Number Representation
Part III Multiplication
1 Numbers and Arithmetic
9 Basic Multiplication Schemes
2 Representing Signed Numbers
10 High-Radix Multipliers
3 Redundant Number Systems
11 Tree and Array Multipliers
4 Residue Number Systems
12 Variations in Multipliers
Part II Addition/Subtraction 5 Basic Addition and Counting
6 Carry-Lookahead Adders 7 Variations in Fast Adders 8 Multioperand Addition
Dr. Shadrokh Samavi
3
3
Part IV Division
Part VI Function Evaluation
13 Basic Division Schemes
21 Square-Rooting Methods
14 High-Radix Dividers
22 The CORDIC Algorithms
15 Variations in Dividers
23 Variations in Function Evaluation
16 Division by Convergence
24 Arithmetic by Table Lookup
Part V Real Arithmetic
Part VII Implementation Topics
17 Floating-Point Representations
25 High-Throughput Arithmetic
18 Floating-Point Operations
26 Low-Power Arithmetic
19 Errors and Error Control
27 Fault-Tolerant Arithmetic
20 Precise and Certifiable Arithmetic
28 Past, Present, and Future
Dr. Shadrokh Samavi
4
4
Course Learning Objectives 1. explain the relative merits of number systems used by arithmetic circuits including both fixed- and floating-point number systems. 2. demonstrate the use of key acceleration algorithms and hardware for addition/subtraction, multiplication, and division, plus certain functions.
3. distinguish between the relative theoretical merits of the different acceleration schemes.
Dr. Shadrokh Samavi
5
5
Course Learning Objectives
4. identify the implementation limitations constraining the speed of acceleration schemes 5. evaluate, design, and optimize arithmetic circuits for low-power 6. evaluate, design, and optimize arithmetic circuits for precision
Dr. Shadrokh Samavi
6
6
Course Learning Objectives 7. design, simulate, and evaluate an arithmetic circuit using appropriate references including current journal and conference literature. 8. write a paper compatible with journal format standards on an arithmetic design. 9. make a professional presentation with strong technical content and audience interaction.
Dr. Shadrokh Samavi
7
7
1.1 What Is Computer Arithmetic?
Dr. Shadrokh Samavi
8
8
Pentium Division Bug (1994-95): Pentium’s radix-4 SRT algorithm occasionally produced an incorrect quotient. First noted in 1994 by T. Nicely who computed sums of reciprocals of twin primes: 1/5 + 1/7 + 1/11 + 1/13 + . . . +1/p + 1/(p + 2) + . . . Worst-case example of division error in Pentium: c = 4 195 835= 3 145 727
1.333 820 44...Correct quotient 1.333 739 06...
Dr. Shadrokh Samavi
double FLP value; accurate to only 14 bits (worse than single!)
9
9
Scope of computer arithmetic.
Dr. Shadrokh Samavi
10
10
1.2 A Motivating Example
Dr. Shadrokh Samavi
11
11
Dr. Shadrokh Samavi
12
12
Patriot Missile
Patriot Missile battery once failed to intercept an incoming Scud missile which killed 28. Reported cause: “software problem” (inaccurate calculation of the time since boot). Specifics of the problem: time in tenths of second as measured by the system’s internal clock was multiplied by 1/10 to get the time in seconds. Internal registers were
24 bits wide
Dr. Shadrokh Samavi
13
13
Patriot Missile
1/10 = 0.0001 1001 1001 1001 1001 100 (chopped to 24 b) Error ≅ 0.1100 1100 × 2–23 ≅ 9.5 × 10–8 Error in 100-hr operation period: ≅ 9.5 × 10–8 × 100 × 60 × 60 × 10 = 0.34 s Distance traveled by Scud = (0.34 s) × (1676 m/s) ≅ 570 m This put the Scud outside the Patriot’s “range gate”. Ironically, the fact that the bad time calculation had been improved in some (but not all) code parts. It meant that inaccuracies did not cancel out.
Dr. Shadrokh Samavi
14
14
Importance of Computer Arithmetic 3.2 GHz Pentium has a clock cycle of 0.31 ns. Can one integer addition be done < 0.31 ns in execution stage of Pipeline? What if you had to build a 32-bit adder – ripple carry and a gate delay was approximately 0.1 ns?
STEP 1
1101 1110 11011
-Note: added from right to left.
Dr. Shadrokh Samavi
15
15
Ripple-carry Structure STEP 2 – Design a circuit x31 y31
x1 y1 c31
c32 z31
c2
x0 y0 c1
z1
c0=0 z0
– Each box is a full-adder
Dr. Shadrokh Samavi
16
16
Full-Adder Implementation x 0 0 0 0 1 1 1 1
y 0 0 1 1 0 0 1 1
cin 0 1 0 1 0 1 0 1
z 0 1 1 0 1 0 0 1
xy cout 00 01 11 10 0 cin 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 z cin x y cin x y cin x y cin x y 1 cin x y 1 xy 00 01 11 10 cin 0
0
0
1
0
1
0
1
1
1
cout = cinx + ciny + x y
cout cin ( x y ) xy
Dr. Shadrokh Samavi
17
17
Adder Circuit Analysis
STEP 3 – Analysis Critical Path is carry chain, 2 gate delays/bit 2 32 = 64 (64)(0.1ns) = 6.4ns 6.4ns >> 0.31ns Must Use Faster Adder and/or Pipeline More!!!!
Dr. Shadrokh Samavi
18
18
Addition Paradigms • right to left serial 1 147865 +30921 178786
• right to left, parallel 147865 +30921 177786 001000 178786 Dr. Shadrokh Samavi
19
19
1.3 Numbers and Their Encodings
Dr. Shadrokh Samavi
20
20
Numbers versus their representations (numerals) The number “twenty-seven” can be represented in different ways using numerals or numeration systems: ||||| ||||| ||||| ||||| ||||| || sticks or unary code 27 radix-10 or decimal code (27)ten 11011 radix-2 or binary code (11011)two XXVII Roman numerals Encoding of digit sets as binary strings: BCD example
Digit 0 1 2 3 4 5 6 7 8 9
BCD representation 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1
Dr. Shadrokh Samavi
21
21
Number Systems: Roman Numeral System
Symbolic Digits symbol I V X L C D M
value 1 5 10 50 100 500 1000
RULES: • If symbol is repeated or lies to the right of another higher-valued symbol, value is additive XX=10+10=20 CXX=100+10+10=120 • If symbol is repeated or lies to the left of a higher-valued symbol, value is subtractive XXC = - (10+10) + 100 = 80 XLVIII = -(10) + 50 + 5 + 3 = 48
Dr. Shadrokh Samavi
22
22
Weighted Positional Number System Example: Arabic Number System symbol (digit) 0 1 2 3 4 5 6 7 8 9
value (in 1’s position) 0 1 2 3 4 5 6 7 8 9
Dr. Shadrokh Samavi
23
23
1.4 Fixed-Radix Positional Number Systems
Dr. Shadrokh Samavi
24
24
Binary Number System • n-ordered sequence:
xn1 xn2
x2 x1 x0
• each xi{0,1} is a BInary digiT (BIT) • magnitude of n is important • sequence is a short-hand notation • more precise definition is:
• This is a radix-polynomial form Dr. Shadrokh Samavi
25
25
Number System A Number System is defined if the followings exist 1. A digit set 2. A radix or base value 3. An addition operation 4. A multiplication operation
Example: The binary number system 1. 2. 3. 4.
xi {0,1} 2 Addition operator defined by addition table Multiplication operator defined by multiplication table + 0 1
0 0 1
1 1 10
Dr. Shadrokh Samavi
0 1
0 0 0
1 0 1 26
26
Number System Observations • Cardinality of digit set (2) is equal to radix value • Addition operator XOR, Multiplication is AND •How many integers exist? Mathematically, there are an infinite number, In computer, finite range due to register length X min smallest representable number X max largest representable number [ X min , X max ] range of representable numbers [-inclusive; (-exclusive interval bounds
•When ALU produces a result >Xmax or