Docsity

Algorithms & Representations for Floating Point & Multi-Precision Arithmetic: A Comparison, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Algorithms & Representations for Floating Point & Multi-Precision Arithmetic: A Comparison and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Multi-Precision Arithmetic

in Software

Lecture 11

Floating Point Operations

Floating Point Operations

Table 17.1 Some features of the ANSI/IEEE standard

floatingpoint number representation formats

Fig. 17.4 Denormals in the IEEE single-precision format.

Fig. 18.5 Block diagram of a floating-point multiplier.

Fig. 18.6 Block diagram of a floating-point divider.

Fig. 18.1 Block diagram of a floating-point adder/subtractor.

Arithmetic Operations

in Software

Little-Endian vs. Big-Endian Representation

A0 B1 C2 D3 E4 F5 67 89 16

MSB LSB

MSB = A

B

C

D

E

F

LSB = 89

Big-Endian Little-Endian

LSB = 89

MAX

F

E

D

C

B

MSB = A

address

Little-Endian vs. Big-Endian Camps

Big-Endian Little-Endian

MAX

address

MSB

LSB

LSB

MSB

Motorola 68xx, 680x0 Intel

IBM

Hewlett-Packard

DEC VAX

Internet TCP/IP

Sun SuperSPARC

Bi-Endian

Motorola Power PC

Silicon Graphics MIPS RS 232

Origin of the terms

Little-Endian vs. Big-Endian

Jonathan Swift, Gulliver’s Travels

  • A law requiring all citizens of Lilliput to break their soft-eggs

at the little ends only

  • A civil war breaking between the Little Endians and

the Big-Endians, resulting in the Big Endians taking refuge on

a nearby island, the kingdom of Blefuscu

  • Satire over holy wars between Protestant Church of England

and the Catholic Church of France

Little-Endian vs. Big-Endian

Big-Endian Little-Endian

  • easier to determine a sign of

the number

  • easier to compare two numbers
  • easier to divide two numbers
  • easier to print
    • easier to write multiple precision

routines, especially addition and

multiplication

  • easier to load and store multibyte

numbers

Advantages and Disadvantages

Pointers (1)

F

E

D

C

B

A

Big-Endian Little-Endian

MAX

address

int * iptr;

(* iptr) = 8967; (* iptr) = 6789;

iptr+

An-1 An-2... A 1 A 0 An-1 An-2... A 1 A 0

D 0

D 1

D 2

C2n-1 C2n-2... Cn+1 Cn Cn-1 Cn-2... C 1 C 0

D2n- D2n- D2n-

3 words 3 words

A

A

C

2 words

2 words

D 0 = A 02

D 1 = 2A 0 A 1

D 2 = 2A 0 A 2 + A 12

D2n-4 = 2An-3An-1 + An-2^2 D2n-3 = 2An-2An- D2n-2 = An-1^2

1 word = l bytes = λ bits

Paper-and-Pencil Algorithm of Squaring

Assertion: lg 2 n ≤ λ

x + + + + +

Paper-and-Pencil Algorithm of Multiplication

Run Time Assuming Purely Sequential Execution of Instructions

tMUL (N) = tM (1 + (1 + )) paper-and-pencil

N^2 l^2

tA tM

4 l N

l - word length in bytes

N - operand length in bytes tM - time of a single word multiplication

tA - time of a single word addition

paper-and-pencil

tMUL = θ (N^2 )

Paper-and-Pencil Algorithm of Squaring

Run Time Assuming Purely Sequential Execution of Instructions

paper-and-pencil

tMUL

paper-and-pencil

tMUL

paper-and-pencil

tSQR

< < 1

1 2

=

1 2

(1 + )

5 + τ 4+n (1 + τ)

τ (^) = (^) =

tM tA

time of a single word multiplication

time of a single word addition

For large n

paper-and-pencil

tSQR ≈

1 2

Karatsuba Algorithm of Multiplication

Basic Recursive Step (1)

A 1 A 0

B 1 B 0

n

2 words^ =^ ν^ bits

A

B

n words = N bytes

D 1 = A 1 B 1 D 0 = A 0 B 0

D 0

D 1

D 2 = (A 1 -A 0 )(B 0 -B 1 )

C 3 C 2 C 1 C 0

24 ν^23 ν^22 ν^2 ν^0

C

x

A = (A 1 , A 0 ) 2 νννν

B = (B 1 , B 0 ) 2 νννν

C = (C 3 , C 2 , C 1 , C 0 )

Karatsuba Algorithm of Multiplication

Basic Recursive Step (2)

C = A B = (A 1 2 ν^ + A 0 ) (B 1 2 ν^ + B 0 ) =

= A 1 B 1 22 ν^ + [(A 1 -A 0 )(B 0 -B 1 )+ A 0 B 0 +A 1 B 1 ] 2ν^ + A 0 B 0

D 1 D 2 D 0 D 1 D 0

Karatsuba Algorithm of Multiplication

Tree of Recursive Calls

n = 2α

2 α-1^2 α-1^2 α-

2 α-2^2 α-2^2 α-2^2 α-2^2 α-2^2 α-2^2 α-2^2 α-2^2 α-

.....

Comparison of Software Multiplication Algorithms

Name Complexity^ Limitations

Optimizations

for Squaring

Paper-and-pencil

(classical)

Karatsuba

(Karatsuba-Ofman)

Shönhage-Strassen

θ(n^2 )

θ(n )

θ(n ln n)

log 23

none

n=2k

n of the special

form

tSQR

tMOD

tSQR

tMOD

tSQR

tMOD