0% found this document useful (0 votes)
96 views

Arithmetic Chapter1

The document discusses computer arithmetic and describes chapters covering topics like number representation, addition, subtraction, multiplication, division, real arithmetic, function evaluation, and implementation topics. It also lists learning objectives for the course such as explaining number systems used in arithmetic circuits, demonstrating acceleration algorithms and hardware for operations, and evaluating, designing, and optimizing arithmetic circuits.

Uploaded by

Shahrzad Ghasemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Arithmetic Chapter1

The document discusses computer arithmetic and describes chapters covering topics like number representation, addition, subtraction, multiplication, division, real arithmetic, function evaluation, and implementation topics. It also lists learning objectives for the course such as explaining number systems used in arithmetic circuits, demonstrating acceleration algorithms and hardware for operations, and evaluating, designing, and optimizing arithmetic circuits.

Uploaded by

Shahrzad Ghasemi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Computer Arithmetic

Chapter 1
Numbers and Arithmetic

Spring 2020
‹#›
Dr. Shadrokh Samavi 1
Computer Arithmetic

Text:
Parhami, Behrooz, “Computer Arithmetic: Algorithms and Hardware Designs”
Oxford University Press, 2010.
http://www.ece.ucsb.edu/Faculty/Parhami/text_comp_arit.htm

Part 1: Number Representation


Part 2: Addition/Subtraction
Part 3: Multiplication
Part 4: Division
Part 5: Real Arithmetic (Floating-Point)
Part 6: Function Evaluation
Part 7: Implementation Topics
Slides are intended to illustrate the content of Parhami’s book.

‹#›
Dr. Shadrokh Samavi 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
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
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
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
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
1.1 What Is Computer
Arithmetic?

‹#›
Dr. Shadrokh Samavi 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:


1.333 820 44...Correct quotient
c = 4 195 835=
3 145 727 1.333 739 06...
double FLP value;
accurate to only 14 bits
(worse than single!)

‹#›
Dr. Shadrokh Samavi 9
Scope of computer arithmetic.

‹#›
Dr. Shadrokh Samavi 10
1.2 A Motivating Example

‹#›
Dr. Shadrokh Samavi 11
‹#›
Dr. Shadrokh Samavi 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
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
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 -Note: added from right to left.
11011
‹#›
Dr. Shadrokh Samavi 15
Ripple-carry Structure

STEP 2 – Design a circuit

x31 y31 x1 y1 x0 y0

c31 c2 c1 c0=0

c32 z31 z1 z0

– Each box is a full-adder

‹#›
Dr. Shadrokh Samavi 16
Full-Adder Implementation

x y cin z cout xy
00 01 11 10
0 0 0 0 0 cin
0 0 1 1 0 0 0 1 0 1
0 1 0 1 0
0 1 1 0 1 1 1 0 1 0
1 0 0 1 0
1 0 1 0 1
z = cin x y + cin x y + cin x y + cin x y
1 1 0 0 1
1 1 1 1 1 = cin ⊕ x ⊕ y
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
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
Addition Paradigms

• right to left serial


1
147865
+30921
178786

• right to left, parallel


147865
+30921
177786
001000
178786

‹#›
Dr. Shadrokh Samavi 19
1.3 Numbers and Their Encodings

‹#›
Dr. Shadrokh Samavi 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 BCD representation


0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
‹#›
Dr. Shadrokh Samavi 21
Number Systems: “Roman” Numeral System

Symbolic Digits RULES:


symbol value • If symbol is repeated or lies to
I 1 the right of another higher-valued
V 5 symbol, value is additive
X 10 XX=10+10=20
L 50 CXX=100+10+10=120
C 100 • If symbol is repeated or lies to the
D 500 left of a higher-valued symbol,
M 1000 value is subtractive
XXC = - (10+10) + 100 = 80
XLVIII = -(10) + 50 + 5 + 3 = 48

‹#›
Dr. Shadrokh Samavi 22
Weighted Positional Number System

Example: “Arabic” Number System


symbol value
(digit) (in 1’s position)
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9

‹#›
Dr. Shadrokh Samavi 23
1.4 Fixed-Radix Positional
Number Systems

‹#›
Dr. Shadrokh Samavi 24
Binary Number System

• n-ordered sequence:
xn −1 xn −2  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
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. xi ∈ {0,1}
2. β =2
3. Addition operator defined by addition table
4. Multiplication operator defined by multiplication table
+ 0 1 • 0 1
0 0 1 0 0 0
1 1 10 1 0 1
‹#›
Dr. Shadrokh Samavi 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 <Xmin, incorrect
result occurs
•ALU should produce an error signal
‹#›
Dr. Shadrokh Samavi 27
Encoding of numbers in 4 bits

‹#›
Dr. Shadrokh Samavi 28
Encoding of numbers in 4 bits

‹#›
Dr. Shadrokh Samavi 29
Negative Radix Number System

‹#›
Dr. Shadrokh Samavi 30
Example
•Assume 4-bit registers, unsigned binary numbers
X min ≡ 00002 =
010 X max ≡ 11112 =
1510
[ X min , X max ] ≡ [00002 ,11112 ]

X max + 1 ≡ 100002 =1610

X max + 1 ∉ [00002 ,11112 ] =X (mod 16)

X 1101 13
Y + 0110 6 19(mod 16) = 3
1 0011 19
Answer in register is 00112=310
Overflow
‹#›
Dr. Shadrokh Samavi 31
Example

X = 7 ⋅ 84 + 6 ⋅ 83 + 2 ⋅ 81 + 4 ⋅ 80

Since octal is fixed-radix and positional,


we can rewrite this value using shorthand notation

X = 760248
Note the importance of the use of 0 to serve as a
coefficient of the weight value w2=82

‹#›
Dr. Shadrokh Samavi 32
Fixed-Radix Systems
Register of length n can represent a number with a
fractional part and an integral part
k – number of integral digits
m – number of fractional digits

.
n=k+m
xk −1 xk −2  x1 x0 x−1  x− m
radix point
X xk −1β k −1 + xk −2 β k −2 +  + x1β 1 + x0 β 0
=
k −1
+ x −1 β −1 +  + x − m β − m =∑ i
x β
i= −m
i

A programmer can use an implied radix point in any position


‹#›
Dr. Shadrokh Samavi 33
Scaling Factors
Fixed point arithmetic can utilize scaling factors to
adjust radix point position
a – scaling factor

aX ± aY = a ( X ± Y )
2
aX ⋅ aY =a XY
aX X
=
aY Y

‹#›
Dr. Shadrokh Samavi 34
Unit in the Last Position (ulp)

• Given w0=r-m and n, the position of the radix point is determined

• Simpler to disregard position of the radix point in fixed


point by using unit in least (significant) position ulp
−m
For fractions ulp = r
For integers ulp = 1
Example
98.67510
1 ulp = 1×10-3=0.001
1 ulp is the smallest amount a fixed point number
may increase or decrease
‹#›
Dr. Shadrokh Samavi 35
1.5 Number Radix Conversion

‹#›
Dr. Shadrokh Samavi 36
Radix Conversion
Converting whole part w: (105)ten = (?)five
Repeatedly divide by five Quotient Remainder
105 0
21 1
4 4
0
Therefore, (105)ten = (410)five

Converting fractional part v: (105.486)ten = (410.?)


Repeatedly multiply by five Whole Part Fraction
.486
2 .430
2 .150
0 .750
3 .750
3 .750
Therefore, (105.486)ten ≅ (410.22033)five = w.v
‹#›
Dr. Shadrokh Samavi 37
Radix Conversion

Horner’s rule used to convert (22033)five to decimal.

‹#›
Dr. Shadrokh Samavi 38
Radix Conversion

Horner’s rule used to convert (0.22033)five to decimal.


‹#›
Dr. Shadrokh Samavi 39
Radix Conversion

Given a number in old radix r, conversion to the new


radix R representation

- can be accomplished doing the arithmetic in the old or


new radix

- old and new representations may not be exactly equal

‹#›
Dr. Shadrokh Samavi 40
Radix Conversion

Given a value X represented in source system with radix βs,


represent the same number in a destination system with radix βd

Consider the integral part of the number, XI, in the βd system


X I xk −1 β d k −1 + xk − 2 β d k − 2 +  + x1 β d 1 + x0 β d 0
=
= {[( xk −1 β d + xk − 2 ) β d +  + x2 ]β d + x1}β d + x0
0 ≤ xi < β d
If XI is divided by βd , we obtain x0 as a remainder and quotient

=Q {[( xk −1 β d + xk − 2 ) β d +  + x2 ]β d + x1}
Desired LSD = x0
Can Repeatedly Divide to Obtain Converted Value

‹#›
Dr. Shadrokh Samavi 41
Radix Conversion Example

XI = 34610 βs=10 βd =3
Fixed-point Decimal to Ternary Integer Conversion,
(arithmetic in old radix)

XI = 1102113

Check by evaluating the radix polynomial


1× 35 + 1× 34 + 0 × 33 + 2 × 32 + 1× 31 + 1× 30
= [243 + 81 + 18 + 3 + 1]10= 34610
‹#›
Dr. Shadrokh Samavi 42
Radix Conversion (fractional)

Consider the fractional part of the value in βd Fixed point


system

X
= F x β
−1 d
−1
+ x β
−2 d
−2
+  + x β
− ( m −1) d
− ( m −1)
+ x β
−m d
−m

= β d −1{x−1 + β d −1[ x−2 + β d −1 ( x−3 + )]}


β d ⋅ X F =PI + PF
PI = x−1
PF = β d −1[ x−2 + β d −1 ( x−3 + )]

Thus, PI is the desired digit


We can repeatedly multiply by the βd value
‹#›
Dr. Shadrokh Samavi 43
Radix Conversion Example
XI = 0.29110 βs=10 βd =5
Fixed-point Decimal to Pentary Fractional Conversion
(arithmetic in old radix)
0.291=
× 5 1.455 → 1
0.455=
× 5 2.275 → 2
0.275=
× 5 1.375 → 1
0.375=
× 5 1.875 → 1
0.875=
× 5 4.375 → 4
0.375=
× 5 1.875 → 1
0.875=
× 5 4.375 → 4
0.29110 = (0.12114141414)5
0.29110 is Finite Fraction for βs=10, but infinite fraction for βd =5
‹#›
Dr. Shadrokh Samavi 44
1.6 Classes of Number
Representations

‹#›
Dr. Shadrokh Samavi 45
Classes of Number Representations

1. Integers (fixed-point), unsigned & signed


2. Signed-magnitude, biased, complement
3. Signed-digit (redundant numbers )
4. Residue number system: (RNS)
5. Real numbers, floating-point
6. Real numbers, exact

‹#›
Dr. Shadrokh Samavi 46
Machine Representations
Most familiar number systems are:
1. Non-redundant – every value is uniquely represented
by a radix polynomial
2. Weighted – sequence of weights
wn −1 , wn −2 , , w2 , w1 , w0
determines the value of the n-tuple formed from
the digit set
xn −1 , xn −2 , , x2 , x1 , x0
n −1
X = ∑ xi wi
i =0

3. Positional – wi depends only on position i


4. Conventional number systems wi = β i
where ß is a constant. These are fixed-radix systems.

‹#›
Dr. Shadrokh Samavi 47

You might also like