Docsity

Function Evaluation - Computer Arithmetic - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Part VI
Function Evaluation
Number Representation
Numbers and Arithmetic
Representing Signed Numbers
Redundant Number Systems
Residue Number Systems
Addition / Subtraction
Basic Addition and Counting
Carry-Lookahead Adders
Variations in Fast Adders
Multioperand Addition
Multiplication
Basic Multiplication Schemes
High-Radix Multipliers
Tree and Array Multipliers
Variations in Multipliers
Division
Basic Division Schemes
High-Radix Dividers
Variations in Dividers
Division by Convergence
Real Arithmetic
Floating-Point Reperesentations
Floating-Point Operations
Errors and Error Control
Precise and Certifiable Arithmetic
Function Evaluation
Square-Rooting Methods
The CORDIC Algorithms
Variations in Function Evaluation
Arithmetic by Table Lookup
Implementation Topics
High-Throughput Arithmetic
Low-Power Arithmetic
Fault-Tolerant Arithmetic
Past, Present, and Future
Parts Chapters
I.
II.
III.
IV.
V.
VI.
VII.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
25.
26.
27.
28.
21.
22.
23.
24.
17.
18.
19.
20.
13.
14.
15.
16.
Elementary Operations
28. Reconfigurable Arithmetic
Appendix: Past, Present, and Future
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53

Partial preview of the text

Download Function Evaluation - Computer Arithmetic - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Part VI

Function Evaluation

Number Representation

Numbers and ArithmeticRepresenting Signed Numbers Redundant Number SystemsResidue Number Systems

Addition / Subtraction

Basic Addition and CountingCarry-Look ahead Adders Variations in Fast AddersMultioperand Addition

Multiplication

Basic Multiplication SchemesHigh-Radix Multipliers Tree and Array MultipliersVariations in Multipliers

Division

Basic Division SchemesHigh-Radix Dividers Variations in DividersDivision by Convergence

Real Arithmetic

Floating-Point ReperesentationsFloating-Point Operations Errors and Error ControlPrecise and Certifiable Arithmetic

Function Evaluation

Square-Rooting MethodsThe CORDIC Algorithms Variations in Function EvaluationArithmetic by Table Lookup

Implementation Topics

High-Throughput ArithmeticLow-Power Arithmetic Fault-Tolerant ArithmeticPast, Present, and Future

Parts Chapters I.

II.

III.

IV.

V.

VI.

VII.

1.2. 3.4. 5.6. 7.8.

10.9. 11.12.

25.26. 27.28.

21.22. 23.24.

17.18. 19.20.

13.14. Elementary Operations 15.16.

  1. Reconfigurable Arithmetic Appendix: Past, Present, and Future

VI Function Evaluation

Topics in This Part

Chapter 21 Square-Rooting Methods

Chapter 22 The CORDIC Algorithms

Chapter 23 Variation in Function Evaluation

Chapter 24 Arithmetic by Table Lookup

Learn hardware algorithms for evaluating useful functions

  • Divisionlike square-rooting algorithms
  • Evaluating sin x , tanh x , ln x ,... by series expansion
  • Function evaluation via convergence computation
  • Use of tables: the ultimate in simplicity and flexibility

Square-Rooting Methods: Topics

Topics in This Chapter

21.1 The Pencil-and-Paper Algorithm

21.2 Restoring Shift / Subtract Algorithm

21.3 Binary Nonrestoring Algorithm

21.4 High-Radix Square-Rooting

21.5 Square-Rooting by Convergence

21.6 Fast Hardware Square-Rooters

21.1 The Pencil-and-Paper Algorithm

Notation for our discussion of division algorithms:

z Radicand z 2 k – 1 z 2 k – 2... z 3 z 2 z 1 z 0 q Square root qk – 1 qk – 2... q 1 q 0 s Remainder, z – q^2 sksk – 1 sk – 2... s 1 s 0

Remainder range, 0  s  2 q ( k + 1 digits) Justification: s  2 q + 1 would lead to z = q^2 + s  ( q + 1)^2

Fig. 21.3 Binary square-rooting in dot notation.

2

0

3

Radicand

Subtracted bit-matrix

z

s Remainder

q Root

  • q 2 6
  • q 2 4
  • q (^) 1 2 2
  • q ( q 2 0

( q

( q

( q (1)

(0)

(2) (3)

0 0 0 0

2

0

q 3 q q (^) 1 q

) ) ) )

Root Digit Selection Rule

The root thus far is denoted by q ( i )^ = ( qk – 1 qk – 2... qk – i )ten

Attaching the next digit qk – i – 1 , partial root becomes q ( i +1)^ = 10 q ( i )^ + qk – i – 1

The square of q ( i +1)^ is 100( q ( i ))^2 + 20 q ( i )^ qk – i – 1 + ( qk – i – 1 )^2

100( q ( i ))^2 = (10 q ( i ))^2 subtracted from partial remainder in previous steps

Must subtract (10(2 q ( i )) + qk – i – 1 )  qk – i – 1 to get the new partial remainder

More generally, in radix r , must subtract ( r (2 q ( i )) + qk – i – 1 )  qk – i – 1

In radix 2, must subtract (4 q ( i )^ + qk – i – 1 )  qk – i – 1 , which is

4 q ( i )^ + 1 for qk – i – 1 = 1, and 0 otherwise Thus, we use ( qk – 1 qk – 2... qk – I 0 1)two in a trial subtraction

Example of Binary Square-Rooting

Fig. 21.2 Extracting the square root of a binary integer using the pencil-and-paper algorithm.

Root digit q 3 q 2 q 1 q 0  q q (0)^ = 0  0 11 10 11 0  01? Yes q 3 = 1 q (1)^ = 1 0 1  0 0 1 1  101? No q 2 = 0 q (2)^ = 10 0 0 0  0 1 1 0 1  1001? Yes q 1 = 1 q (3)^ = 101 1 0 0 1  0 1 0 0 1 0  10101? No q 0 = 0 q (4)^ = 1010 ^ 0 0 0 0 0 1 0 0 1 0  s = (18)ten q = (1010)two = (10)ten

Check: 10^2 + 18 = 118 = (0111 0110)two^ Partial root

Finding the Sq. Root of

z = 1.

via the Restoring Algorithm

================================ z (radicand = 118/64) 0 1. 1 1 0 1 1 0 ================================ s (0)^ = z – 1 0 0 0. 1 1 0 1 1 0 q 0 = 1 1. 2 s (0)^ 0 0 1. 1 0 1 1 0 0

  • [2  (1.)+2–^1 ] 1 0. 1 ––––––––––––––––––––––––––––––––– s (1)^ 1 1 1. 0 0 1 1 0 0 q – 1 = 0 1. s (1)^ = 2 s (0)^ Restore 0 0 1. 1 0 1 1 0 0 2 s (1)^ 0 1 1. 0 1 1 0 0 0
  • [2  (1.0)+2–^2 ] 1 0. 0 1 ––––––––––––––––––––––––––––––––– s (2)^ 0 0 1. 0 0 1 0 0 0 q – 2 = 1 1. 2 s (2)^ 0 1 0. 0 1 0 0 0 0
  • [2  (1.01)+2–^3 ] 1 0. 1 0 1 ––––––––––––––––––––––––––––––––– s (3)^ 1 1 1. 1 0 1 0 0 0 q – 3 = 0 1. s (3)^ = 2 s (2)^ Restore 0 1 0. 0 1 0 0 0 0 2 s (3) 1 0 0. 1 0 0 0 0 0
  • [2  (1.010)+2–^4 ] 1 0. 1 0 0 1 ––––––––––––––––––––––––––––––––– s (4)^ 0 0 1. 1 1 1 1 0 0 q – 4 = 1 1. 2 s (4)^ 0 1 1. 1 1 1 0 0 0
  • [2  (1.0101)+2–^5 ] 1 0. 1 0 1 0 1 ––––––––––––––––––––––––––––––––– s (5)^ 0 0 1. 0 0 1 1 1 0 q – 5 = 1 1. 2 s (5)^ 0 1 0. 0 1 1 1 0 0
  • [2(1.01011)+2–^6 ] 1 0. 1 0 1 1 0 1 ––––––––––––––––––––––––––––––––– s (6)^ 1 1 1. 1 0 1 1 1 1 q – 6 = 0 1. s (6)^ = 2 s (5)^ Restore 0 1 0. 0 1 1 1 0 0 s (remainder = 156/64) 0. 0 0 0 0 1 0 0 1 1 1 0 0 q (root = 86/64) 1. 0 1 0 1 1 0 ================================

Fig. 21. Example of sequential binary square-rooting using the restoring algorithm.

Root digit Partial root

q – 7 = 1, so round up

Hardware for Restoring Square-Rooting

Fig. 21.5 Sequential shift/subtract restoring square-rooter.

Partial Remainder

Square-Root

Load

sub

(l+2)-bit adder

Trial Difference

l+

cout cin

Complement

q–j

2s (j–1)

MSB of

Put z – 1 here at the outset

Select Root Digit

l+

Quotient q

Mux

c out Adder

0 1

Partial remainder s (initial value z )

Divisor d

Shift

Shift

Load

c in^1

( j )

Quotientdigit selector

qk – j

MSB of 2 s ( j – 1) k k

k

Trial difference

Fig. 13.5 Shift/subtract sequential restoring divider (for comparison).

21.3 Binary Nonrestoring Algorithm

As in nonrestoring division, nonrestoring square-rooting implies:

Root digits in {1, 1} On-the-fly conversion to binary Possible final correction

The case q – j = 1 (nonnegative partial remainder), is handled as in the restoring algorithm; i.e., it leads to the trial subtraction of

q – j [2 q ( j – 1)^ + 2– j^ q – j ] = 2 q ( j – 1)^ + 2– j

For q – j = 1, we must subtract

q – j [2 q ( j – 1)^ + 2– j^ q – j ] = – [2 q ( j – 1)^ – 2 – j^ ]

which is equivalent to adding 2 q ( j – 1)^ – 2 – j

Slight complication, compared with nonrestoring division

This term cannot be formed by concatenation

Finding the Sq. Root of z = 1. via the

Nonrestoring

Algorithm

================================ z (radicand = 118/64) 0 1. 1 1 0 1 1 0 ================================ s (0)^ = z – 1 0 0 0. 1 1 0 1 1 0 q 0 = 1 1. 2 s (0)^ 0 0 1. 1 0 1 1 0 0 q – 1 = 1 1.

  • [2  (1.)+2–^1 ] 1 0. 1 ––––––––––––––––––––––––––––––––– s (1)^ 1 1 1. 0 0 1 1 0 0 q – 2 =  1 1. 2 s (1)^ 1 1 0. 0 1 1 0 0 0 +[2  (1.1) 2 –^2 ] 1 0. 1 1 ––––––––––––––––––––––––––––––––– s (2)^ 0 0 1. 0 0 1 0 0 0 q – 3 = 1 1. 2 s (2)^ 0 1 0. 0 1 0 0 0 0
  • [2  (1.01)+2–^3 ] 1 0. 1 0 1 ––––––––––––––––––––––––––––––––– s (3)^ 1 1 1. 1 0 1 0 0 0 q – 4 =  1 1. 2 s (3) 1 1 1. 0 1 0 0 0 0 +[2  (1.011) 2 –^4 ] 1 0. 1 0 1 1 ––––––––––––––––––––––––––––––––– s (4)^ 0 0 1. 1 1 1 1 0 0 q – 5 = 1 1. 2 s (4)^ 0 1 1. 1 1 1 0 0 0
  • [2  (1.0101)+2–^5 ] 1 0. 1 0 1 0 1 ––––––––––––––––––––––––––––––––– s (5)^ 0 0 1. 0 0 1 1 1 0 q – 6 = 1 1. 2 s (5)^ 0 1 0. 0 1 1 1 0 0
  • [2(1.01011)+2–^6 ] 1 0. 1 0 1 1 0 1 ––––––––––––––––––––––––––––––––– s (6)^ 1 1 1. 1 0 1 1 1 1 Negative; (17/64) +[2(1.01011) 2 –^6 ] 1 0. 1 0 1 1 0 1 Correct ––––––––––––––––––––––––––––––––– s (6)^ Corrected 0 1 0. 0 1 1 1 0 0 (156/64) s (remainder = 156/64) 0. 0 0 0 0 1 0 0 1 1 1 0 0 (156/64^2 ) q (binary) 1. 0 1 0 1 1 1 (87/64) q (corrected binary) 1. 0 1 0 1 1 0 (86/64) ================================

Fig. 21. Example of nonrestoring binary square-rooting.

Root digit Partial root

21.4 High-Radix Square-Rooting

Basic recurrence for fractional radix- r square-rooting:

s ( j )^ = rs ( j – 1)^ – q – j (2 q ( j – 1)^ + r – j^ q – j )

As in radix-2 nonrestoring algorithm, we can use two registers Q and Q* to hold q ( j – 1)^ and its diminished version q ( j – 1)^ – r – j +1, respectively, suitably updating them in each step

2

0

3

Radicand

Subtracted bit-matrix

z

s Remainder

q Root

  • q 2 6
  • q 2 4
  • q (^) 1 2 2
  • q ( q 2 0

( q

( q

( q (1)

(0)

(2) (3)

0 0 0 0

2

0

q 3 q q (^) 1 q

) ) ) )

Fig. 21.3 Radix-4 square-rooting in dot notation

An Implementation of Radix-4 Square-Rooting

r = 4, root digit set [–2, 2]

Q* holds q ( j – 1)^ – 4 – j +1^ = q ( j – 1)^ – 2 –^2 j +2. Then, one of the following values must be subtracted from, or added to, the shifted partial remainder rs ( j – 1)

q – j = 2 Subtract 4 q ( j – 1)^ + 2–^2 j +2^ double-shift Q 010 q – j = 1 Subtract 2 q ( j – 1)^ + 2–^2 j^ shift Q 001 q – j =  1 Add 2 q ( j – 1)^ – 2 –^2 j^ shift Q* q – j =  2 Add 4 q ( j – 1)^ – 2 –^2 j +2^ double-shift Q*

Updating rules for Q and Q* registers:

q – j = 2  Q := Q 10 Q* := Q 01 q – j = 1  Q := Q 01 Q* := Q 00 q – j = 0  Q := Q 00 Q* := Q* q – j =  1  Q := Q11 Q := Q* q – j =  2  Q := Q10 Q := Q*

Note that the root is obtained in binary form (no conversion needed!)

s ( j )^ = rs ( j – 1)^ – q – j (2 q ( j – 1)^ + r – j^ q – j )

21.5 Square-Rooting by Convergence

x

f ( x )

z

z

Newton-Raphson method

Choose f ( x ) = x^2 – z with a root at x =  z

x ( i +1)^ = x ( i )^ – f ( x ( i )) / f ( x ( i )) x ( i +1)^ = 0.5( x ( i )^ + z / x ( i ))

Each iteration: division, addition, 1-bit shift Convergence is quadratic

For 0.5  z < 1, a good starting approximation is (1 + z )/

This approximation needs no arithmetic

The error is 0 at z = 1 and has a max of 6.07% at z = 0.

The hardware approximation method of Schwarz and Flynn, using the tree circuit of a fast multiplier, can provide a much better approximation (e.g., to 16 bits, needing only two iterations for 64 bits of precision)

Initial Approximation Using Table Lookup

Table-lookup can yield a better starting estimate x (0)^ for  z

For example, with an initial estimate accurate to within 2–^8 , three iterations suffice to increase the accuracy of the root to 64 bits

x ( i +1)^ = 0.5( x ( i )^ + z / x ( i ))

Example 21.1: Compute the square root of z = (2.4)ten

x (0)^ read out from table = 1.5 accurate to 10–^1 x (1)^ = 0.5( x (0)^ + 2.4 / x (0)) = 1.550 000 000 accurate to 10–^2 x (2)^ = 0.5( x (1)^ + 2.4 / x (1)) = 1.549 193 548 accurate to 10–^4 x (3)^ = 0.5( x (2)^ + 2.4 / x (2)) = 1.549 193 338 accurate to 10–^8

Check: (1.549 193 338)^2 = 2.399 999 999