Professional Documents
Culture Documents
Using an FMA
Nicolas Louvet, Jean-Michel Muller, Adrien Panhaleux
Abstract
Keywords
oating-point arithmetic; decimal oating-point arithmetic; division
algorithm; Newton-Raphson iterations
1. Introduction
When a oating-point Fused-Multiply and Add (FMA)
instruction is available in hardware, a common method
is to implement the division operation in software using Newton-Raphsons iterations. In binary oating-point
arithmetic, this is already the case for example on the
Itanium architecture. The FMA instruction allows to efciently compute a correctly rounded quotient, even when
the working precision used to perform the iterations is the
same as the precision of the quotient [2], [8]. Moreover,
Nicolas Louvet is with UCBL, LIP (CNRS, ENS de Lyon, INRIA,
UCBL), Universite de Lyon. E-mail: nicolas.louvet@ens-lyon.fr
Jean-Michel Muller is with CNRS, LIP (CNRS, ENS de Lyon, INRIA,
UCBL), Universite de Lyon. E-mail: jean-michel.muller@ens-lyon.fr
978-1-4244-6967-3/10/$26.00
c 2010 IEEE
1.1. Notations
In this article, we assume that no overow nor underow occurs, and that the inputs are normal numbers.
We note F,p the set of radix-, precision-p oating-point
200
ASAP 2010
Marksteins iteration
x
0 = 0.10101010101
r1 =1.1101100010 25
x
1 = 0.10100000110
r2 = 1.1100111010 29
x
2 = 0.10100001011
r0 = RN(a b
y0 )
2
rn+1
)
rn+2 = RN(
Goldschmidt
(6)
yn + rn+1 x
n )
yn+1 = RN(
1.3. Outline
Section 2 shows how to prove a faithful rounding, and
how the information of faithful rounding can be used
in the Newton-Raphson division algorithms. Section 3
then introduces necessary conditions that prove the correct
rounding of these algorithms. Section 4 gives error bounds
on the different variations of Newton-Raphsons iterations.
Finally, Section 5 shows an example on how to prove a
correct rounding of a Newton-Raphson based algorithm.
(1)
Then yn = a
xn is taken as an initial approximation to a/b
that can be improved using
n (a b
yn ) .
yn+1 = yn + x
Goldschmidts iteration
x
0 = 0.10101010101
r1 =1.11011000100 25
x
1 = 0.10100000110 // r2 ...
x
2 = 0.10100001010 // r3 ...
(
xn remains the same)
(2)
r1 = RN(1 b
x0 )
2
rn+1
)
rn+2 = RN(
(4)
Goldschmidt
xn + rn+1 x
n )
x
n+1 = RN(
2. Faithful rounding
In some cases explained in Section 3, a faithful rounding is required in order to guarantee correct rounding of the
quotient a/b. One may also only need a faithful rounding
of the quotient or the reciprocal. This section provides a
sufcient condition to ensure a faithful rounding of the
2
201
ASAP 2010
Theorem 1. Let x
R be an approximation to z R.
= RN(
x). If
Let x
F,p be such that x
|
x z| <
1
ulp(z),
2
(7)
then x
is a faithful rounding of z.
The condition of Theorem 1 is tight: Assuming is
1
= z 2
ulp(z) will round to a
even, if z = k , then x
value that is not a faithful rounding of z, as illustrated on
Figure 1.
x
z = k
1
2
ulp(z)
pi ,po
1 pi po
.
(8)
a
= m + ea/b +1 .
b
(9)
2B po = 2A po 1ea/b 2BM B.
3. Round-to-nearest
(10)
ASAP 2010
Exclusion interval
a
b
n
binary64
decimal128
212pi
1
1
= 0. 100
. . . 0 100
. . . 0 1 . . .
= + 21pi +
b
2
1 2pi
pi bits
pi bits
4
68
3
5
86
3
6
86
19
7
86
22
There is a particular worst case that is worth mentioning: When b = 1/2 ulp(), the correctly rounded
reciprocal is 1/ +ulp(1/), but if the starting point given
by the lookup table is not RN,pw (1/b), even Marksteins
iterations cannot give a correct rounding, as shown in
Example 3.
ea/b +1
212pi
.
1 2pi
The following result can also be seen as a consequence
of Theorem 3 (see [8, chap. 8] or [9, p.163] for a proof).
212pi pi ,pi
b=
x
=
r =
x
=
is
Theorem 5. In binary arithmetic, when pw = po , if x
a correct rounding of 1/b and y is a faithful rounding of
a/b, then an extra Marksteins iteration yields RNpo (a/b).
1.1111111111
0.1 = Table-lookup(b)
211 (exact)
0.1
Hence, x
will always equals 0.1, which is not the correct
rounding of RN(1/b).
A common method [8] to deal with this case is to
tweak the lookup table for this value. If the lookup
table is addressed by the rst k digits of b, then the
output corresponding to the address 1k should be
1/ + pw .
3
68
1
2
2
1
(11)
po =11
4
203
ASAP 2010
p
b1
b2
decimal64
decimal128
16
34
1.67772160. . . 0 1.12589990684262400. . . 0
8.38860800. . . 0 5.62949953421312000. . . 0
a = 2.000005,
decimal32
7
2.048000
2.048000
a/b = 1.000002 5
ln(2) ln(10)
ln(2)
z1 = p i po
, z2 = pi po
.
ln(5)
ln(5)
ln(5)
z pi po
.
ln 5
ln 5
ln 5
The difference between the two bounds is ln 10/ ln 5
1.43. Therefore, there can be at most two integers z
between the two bounds.
Using Theorem 7, we isolate the at most two values
of b whose reciprocal is a midpoint. These values are
checked separately when proving the correct rounding of
the reciprocal. Table 2 gives the corresponding b when
pi = po , for the IEEE 754-2008 decimal formats.
pi po
a=1, b = 1.01010011001111000011011
y=0.110000010010111111111111 (faithful)
r=1.01010011000111000011011 224 (exact)
y + ry)
y =0. 11000001001
1000000000000 = RN24 (
11 bits
y )
y =0.11000001010 = RN11 (
Due to the double rounding, y is not RN11 (a/b).
ASAP 2010
or to the quotient a/b obtained after a series of NewtonRaphson iterations. As our aim is to analyze any reasonable
sequence combining both Marksteins or Goldschmidts
iterations, we only give the basic results needed to analyze
one step of these iterations. The analysis of a whole
sequence of iterations can be obtained by combining the
induction relations proposed here: This is a kind of running
error analysis (see [9, chap. 6]) that can be used together
with the results of Sections 3.1 and 3.2 to ensure correct
rounding.
All the arithmetic operations are assumed to be performed at precision pw , which is the precision used for
intermediate computations. Let us denote by the unit
roundoff: In round-to-nearest rounding mode, one has
= 12 1pw . In the following, we note
=
=
=
=
=
RN(a
x)
RN(a b
y0 )
RN(
y0 + r1 x
)
RN(a b
y1 )
RN(
y1 + r2 x
)
= 1.000003
=0.000003
= 1.000002
= 0.000003
= 1.000003
n :=|
xn 1/b|,
yn a/b|,
n :=|
rn (1 b
xn1 )|,
n :=|
n :=|
xn 1/b|,
n :=|
yn a/b|,
n :=|
rn (a b
yn1 )|.
(12)
(13)
(14)
The initial value of the recurrence depends on the lookuptable used for the rst approximation to 1/b. Inequality (12) together with (14) can then be used to ensure
either faithful or correct rounding for all values of b in
[1, ), using Theorems 1 or 3.
At iteration n, if x
n is a faithful rounding of 1/b, then
Theorem 2 implies n+1 = 0. Hence in this case one has
n+1 2n , which means that no more accuracy improvement can be expected with Newton-Raphson iterations.
Moreover, if we exclude the case b = 1, since b belongs
to [1, ) by hypothesis, it follows that 1/b is in ( 1 , 1).
Since x
n is assumed to be a faithful rounding of 1/b, one
has ulp(
xn ) = ulp(1/b), and we deduce
4. Error bounds
xn ),
n+1 |b|2n + 1/2 ulp(
(15)
ASAP 2010
x
=
r =
x
=
x
=
x
=
y =
r =
y =
r =
y =
(17)
(18)
x
=
r =
x
=
x
=
r =
x
=
r =
x
=
y =
r =
y =
r =
y =
n+1 |b|n .
Again, if yn is a faithful rounding of a/b, due to the exact
residual theorem 2, one has n+1 |b|n m , which is
the best accuracy improvement that can be expected from
one Newton-Raphson iteration.
4.2.2. Division with the Goldschmidt iteration (5).
Using the same method as in 4.1.2, we now bound
n+1 :
n+1
Table-lookup(b);
RN113 (1 b
x);
x + rx
);
RN113 (
x + rx
);
RN113 (
x + rx
);
RN113 (
x);
RN113 (a
y );
RN113 (a b
y + rx
);
RN113 (
y );
RN113 (a b
y + rx
);
RN53 (
(1 + )(
n + |b|n1 )(|b|n1 + |b|m +
n )
(20)
+(1 + )
n + |a|.
Table-lookup(b);
x);
RN53 (1 b
x + rx
);
RN53 (
x + rx
);
RN53 (
x);
RN53 (1 b
x + rx
);
RN53 (
x);
RN53 (1 b
x + rx
);
RN53 (
x);
RN53 (a
y );
RN53 (a b
y + rx
);
RN53 (
y );
RN53 (a b
y + rx
);
RN53 (
5. Experiments
Algorithm 2 yields a correct rounding of the division, even
for the midpoint cases.
Algorithm 3 computes the quotient of two binary64
numbers, with pi = pw = po = 53. Since binary arithmetic
is used and pw = po , there are no midpoints for division.
is less than 2 e1/b +1 53,53 .
After the MR4 iteration, x
Hence, by excluding two worst cases as explained in
Section 3.2, and checking thoses cases, we ensure a correct
rounding of the reciprocal using Theorem 3. Since a
faithful rounding of a/b at iteration MD1 is ensured by
the error bounds of Section 4, Theorem 5 proves that the
next Marksteins iteration outputs a correct rounding.
Algorithm 4 computes the quotient of two decimal128
numbers, with pi = pw = po = 34. The starting error
given by the lookup table is less than 5 105 . Since
pw = po , Algorithm 1 is needed to ensure the correct
rounding of the division. Notice that to improve the latency,
bs in Algorithm 1 can be computed concurrently with the
rst Newton-Raphson iterations. As shown in Figure 3(c),
ASAP 2010
x
=
r =
x
=
x
=
x
=
y =
r =
y =
r =
Call
2-20
Table-lookup(b);
| | bs = b ulp( ab );
x);
RN34 (1 b
RN34 (
x + rx
); {MR1 } | | r = RN34 (
r2 );
RN34 (
x + rx
); {GR2 } | | r = RN34 (
r2 );
RN34 (
x + rx
); {GR3 }
RN34 (a
x);
{y0 }
RN34 (a b
y );
RN34 (
y + rx
); {MD1 }
RN34 (a b
y );
Algorithm 1.
Certified error
2-40
2-60
2-80
2-100
2-120
Faithful rounding
-140
2-160
Correct rounding
2-180
MR1
GR2
GR3
y0
MD1
MD2
Certified error
2-20
2-40
Faithful rounding
2-60
2-80
2-100
Conclusion
Correct rounding
MR1
GR2
MR3
MR4
y0
MD1
MD2
10
10-20
10-30
Faithful rounding
10-40
MR1
GR2
GR3
y0
MD1
References
Figure 3. Absolute error before rounding
for each algorithm considered. (M/G: Markstein/Goldschmidt, R/D: reciprocal/division)
207
ASAP 2010