# The Intel Pentium Division Flaw

Document Sample

```					 The Intel Pentium
Division Flaw
Alan Edelman
Department of Mathematics
Laboratory for Computer Science
Massachusetts Institute of Technology

MIT
Not So Well Known
The bug itself is
(mathematically)
neat!
A Lesson (for me anyway)

So much incomplete
information is out there.
MIT
Interesting Related Topics
(but my topic is the bug)

 Risk  to Pentium owners
 Intel’s chip replacement blunder
 Kahan’s SRT division tester
 Moler, Coe, and Mathisen software
workaround
 Only the lawyers get rich
 Those ubiquitous Pentium jokes

MIT
Outline
 Nicely’s Discovery
 Computer Science Prerequisites
 Division (SRT=Sweeney,Robertson,Tocher)
 Pentium Lookup Table
 Division Example
 Six Ones Result
Inequality Analysis
“Send More Money” Puzzle
 Always   nearly five good digits
MIT
Nicely’s Twin Prime Bug Discovery

 Twin   primes: (5,7) (11,13) (17,19) (29,31) ...
 Nicely was summing twin prime reciprocals:
 S = 1/5 + 1/ 7 + 1/11 + 1/13 + 1/17 + 1/19 +
...
 S is finite.
 Nicely computed on many platforms.
 Nicely checked his work.

MIT
Computer Science Prerequisites

 One’s vs. Two’s Complement.

MIT
12
21
+ 19
52

MIT
12
21
+ 19
52
20

MIT
12        01100
21        10101
+ 19      + 10011
52        10100
20

MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011            1 Sum Bits (s)
52        10100           0 Carry Bits (c)
20

MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011            1 Sum Bits (s)
52        10100           0 Carry Bits (c)
20

s = xyz = x+y+z (mod 2)
c = xy  xz  yz = (x+y+z | 2)
MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011           01 Sum Bits (s)
52        10100          00 Carry Bits (c)
20

s = xyz = x+y+z (mod 2)
c = xy  xz  yz = (x+y+z | 2)
MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011        11001 Sum Bits (s)
52        10100        01000 Carry Bits (c)
20

s = xyz = x+y+z (mod 2)
c = xy  xz  yz = (x+y+z | 2)
MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011        11001 Sum Bits (s)
52        10100        01000 Carry Bits (c)
20                    +10011

s = xyz = x+y+z (mod 2)
c = xy  xz  yz = (x+y+z | 2)
MIT
12        01100        01100
21        10101      + 10101
+ 19      + 10011        11001     Sum Bits (s)
52        10100        01000     Carry Bits (c)
20                    +10011
00010     Sum Bits (s)
10010     Carry Bits (c)

s = xyz = x+y+z (mod 2)
c = xy  xz  yz = (x+y+z | 2)
MIT
One’s vs. Two’s Complement

Two’s Complement
3        00011
2       00010
1       00001
0       00000
-1       11111
-2       11110
-3       11101
MIT
One’s vs. Two’s Complement

Two’s Complement   One’s Complement
3         00011            00011
2        00010            00010
1        00001            00001
0        00000            00000
-1        11111            11110
-2        11110            11101
-3        11101            11100
MIT
One’s vs. Two’s Complement

Two’s Complement   One’s Complement
3         00011            00011
2        00010            00010
1        00001            00001
0        00000            00000
-1        11111            11110
-2        11110            11101
-3        11101            11100
MIT
 Division   Algorithms:

MIT
Long Division Example

1.42857
710.00000
7
30
28
20
14
60
MIT
Long Division Example
q0   q1q2q3q4q5   Chosen to satisfy
1.42857           usual inequalities

710.00000
7
30
28
20
14
60
MIT
Long Division Example
q0   q1q2q3q4q5
p = 10, d = 7            1.42857
10d = 70
710.00000           p0
7
pk+1 = 10(pk–qkd)        30                p1
0 ≤ pk+1 < 70
28
20              p2
14
60             p3

MIT
Compute q = p / d.

p0 := p

for k=0,1,...
Find the digit qk {0, 1, 2, …, 9} such that
pk+1 := 10(pk - qk d) satisfies pk +1 [0, 10)d
end

q=p/d=S q i / 10 i
i=0

MIT
Compute q = p / d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end

q = p / d =S q i / 4 i
i=0

Such qk exists?
Algorithm correct?
MIT
Such qk exists?
Given 1p,d<2. Compute q=p/d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end

S
q = p/d = i=0          qi / 4i

2d               2 d
8 d
qk := –2        3
qk := 0    3
qk := +2   8d
3                                                            3
qk := –1             qk := +1

MIT
Such qk exists?
Given 1p,d<2. Compute q=p/d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end
∞
q = p/d =S   i=0
qi / 4i

2d               2 d
8 d                 3
qk := 0     3                8d
3                                                     3
4(pk - 0)

-2 / 3d ≤ pk ≤ 2 / 3d
pk+1 := 4(pk - 0)                                           MIT
Such qk exists?
Given 1p,d<2. Compute q=p/d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end

q = p/d =S   i=0
qi / 4 i

8 d
qk := +2   8d
3                                        4 d              3
3

4 / 3d ≤ pk ≤ 8 / 3d
pk+1 := 4(pk - 2d)                                              MIT
Such qk exists?
Given 1p,d<2. Compute q=p/d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end

q = p/d =S   i=0
qi / 4 i

2d                  2 d
8 d                 3
pk - 2d   3
qk := +2   8d
3                                                        3

4/3 ≤ pk ≤ 8/3
pk+1 := 4(pk - 2d)                                             MIT
Such qk exists?
Given 1p,d<2. Compute q=p/d.
p0 := p

for k=0,1,...
Look up a digit qk -2,-1,0,1,2}such that
pk+1 := 4(pk - qk d) satisfies|pk +1|≤ (8/3)d
end

q = p/d =S   i=0
qi / 4 i

2d                  2 d
8 d                 3
pk - 2d   3
qk := +2   8d
3                                                        3
4(pk - 2d)

4 / 3d ≤ pk ≤ 8 / 3d
pk+1 := 4(pk - 2d)                                             MIT
A qk For Every Point

2d               2 d
8 d
qk := –2        3
qk := 0    3
qk := +2   8d
3                                                           3
qk := –1             qk := +1

MIT
Algorithm Correct?

Claim:
p        q1          qk-1 pk -k
— = q0 + — + . . . + ––– + –— 4
d        4           4k-1 d
Proof by Induction:
pk+1 = 4(pk - qkd) 
pk -k qk pk+1 -(k+1)
— 4 = — + —— 4
d        4k d

MIT
Algorithm Correct?

Claim:
p        q1          qk-1 qk pk+1 -(k+1)
— = q0 + — + . . . + ––– + — + ––— 4
d        4           4k-1 4k    d
Proof by Induction:
pk+1 = 4(pk - qkd) 
pk -k qk pk+1 -(k+1)
— 4 = — + —— 4
d        4k d

MIT
Algorithm Correct?

Claim:
p        q1          qk-1 qk pk+1 -(k+1)
— = q0 + — + . . . + ––– + — + ––— 4
d        4           4k-1 4k    d
Proof by Induction:
pk+1 = 4(pk - qkd) 
pk -k qk pk+1 -(k+1)
— 4 = — + —— 4
d        4k d
Letting k proves
p        q1 q2
— = q0 + — + — + . . .
d        4   42                            MIT
Pentium Lookup Table (P-d plot)
0101.000               Green
0100.000               q := 2

Shifted Partial Remainder   0011.000
0010.000               Blue
q := 1
0001.000
0000.000
q := 0
1111.000
1/8                               1110.000
1/16                                                            q := -1
1101.000
1100.000               q:= -2
1011.000
1.0111

1.1111
1.0011

1.1011
1.1100
1.1101
1.0110

1.1110
1.0000
1.0001
1.0010

1.0100
1.0101

1.1000
1.1001
1.1010
Divisor
MIT
Pentium Lookup Table (P-d plot)
0101.000               Green
0100.000               q := 2

Shifted Partial Remainder   0011.000
0010.000               Blue
q := 1
0001.000
0000.000
q := 0
1111.000
1/8                               1110.000
1/16                                                            q := -1
1101.000
1100.000               q:= -2
1011.000
1.0111

1.1111
1.0011

1.1011
1.1100
1.1101
1.0110

1.1110
1.0000
1.0001
1.0010

1.0100
1.0101

1.1000
1.1001
1.1010
Divisor
MIT
A Close-up Look at One Column (D=1.0001)
P
2.875
2
1.5
1.375
1
0.375
0.25
0
-0.5
-0.625
-1
-1.625
-1.75
-2
-3

MIT
A Close-up Look at One Column (D=1.0001)
P
2.875
0
2               0
3.375
3.25
Off the Chart
Off the Chart
1.5
1.375                   0   3.125   Off the Chart
1               0   3       Off the Chart
0.375                       2.875   Buggy Entry
0.25                    2   2.75    Foothold
0               2
-0.5                     2
-0.625                   2
-1              2
-1.625                   2
-1.75                    2
-2              2
-3                       2
2
MIT
Pentium Division Example: 1.875/1.000
0001.111 00000000000 S
1.875 =   {   0000.000 00000000000 C
qk:=–2       qk:=0       qk:=+2
qk:=–1       qk:=+1

pk+1 := 4(pk – qkd)                                       MIT
Pentium Division Example: 1.875/1.000
0001.111   00000000000
{
1.875 = 0000.000    00000000000
S
C
qk:=–2       qk:=0       qk:=+2
– 21 = 1101.111   11111111111
1100.000   11111111111
{                                S
qk:=–1       qk:=+1
-0.125 = 0011.110    00000000001   C

pk+1 := 4(pk – qkd)                                     MIT
Pentium Division Example: 1.875/1.000
0001.111   00000000000
{
1.875 = 0000.000    00000000000
S
C
qk:=–2       qk:=0       qk:=+2
– 21 = 1101.111   11111111111
0000.011   11111111100
{                               S
qk:=–1       qk:=+1
-0.1254 = -0.5 = 1111.000      00000000100   C

pk+1 := 4(pk – qkd)                                    MIT
Pentium Division Example: 1.875/1.000
0001.111   00000000000
{
1.875 = 0000.000    00000000000
S
C
qk:=–2       qk:=0       qk:=+2
–21 = 1101.111   11111111111
qk:=–1       qk:=+1                  0000.011   11111111100   S
1111.000   00000000100   C
– –11 = 0001.000   00000000000
1001.111   11111100000   S
1000.000   00000100000   C

pk+1 := 4(pk – qkd)                                    MIT
Pentium Division Example: 1.875/1.000
0001.111   00000000000
1.875 =   {   0000.000   00000000000
S
C
qk:=–2       qk:=0       qk:=+2
–21 =       1101.111   11111111111
qk:=–1       qk:=+1                       0000.011   11111111100   S
1111.000   00000000100   C
– –11 =      0001.000   00000000000
1001.111   11111100000   S
1000.000   00000100000   C
–21 =       1101.111   11111111111
0000.000   00011111100   S
1111.111   11100000100   C
–01 =       0000.000   00000000000
1111.111   11111100000   S
0000.000   00000100000   C
2/1 + –1/4 + 2/16 + 0/64 = 1.875/1.000                      MIT
Inequality Analysis

Pk ≤ pk ≤ Pk + 1/4
D ≤ d ≤ D+  D + 1/16
Pk+1 = 4(Pk – qkD+) + Rk

  3/4 if qk = –2
3/4 if qk = –1
Rk ≤ Rk
Max  3/4 if qk = 0

  1 if qk = 1
5/4 if qk = 2

MIT
Reaching the Flaw is Not Easy!
qk                    Pk+1
P < P
2  k

MIT
buggy entry

foothold

MIT
―Send More Money‖ Puzzle
intel
22 Mission College Blvd.
Santa Clara, CA 95052
32¢

Massachusetts Institue of Technology
77 Massachusetts Ave.

SEND
Cambridge, MA 02139

+MORE
MONEY

MIT
The Path to Failure




six ones

.. . . 1   1   1 11
q = –2   .. . . 1   1   1 11
.d2d3d41   1   111
.. 1 1 1   1   1
q=2      .1 1 1 1   1   1
.d2d3d40   0   0
.. 0 0 0
bug
.1 1 1 .
MIT
At Least Nine Steps to Failure
........................
Step 1   .00000000000000000000000
........................
........................
Step 2   ........................
........................
........................
Step 3   ........................
........................
........................
Step 4   ........................
........................
........................
Step 5   ........................
........................
....11111...............
Step 6   ....11111...............
.....1111...............   MIT
At Least Nine Steps to Failure
...................1....
Step 1   .00000000000000000000000
...................1....
................1.......
Step 2   ................1.......
................1.......
.............11.........
Step 3   .............11.........
.............11.........
..........111...........
Step 4   ..........111...........
..........111...........
.......1111.............
Step 5   .......1111.............
.......1111.............
....11111...............
Step 6   ....11111...............
.....1111...............   MIT
At Least Nine Steps to Failure
...................1....
Step 1   .00000000000000000000000
...................1....
................10......
Step 2   ................11......
................11......
.............110........
Step 3   .............111........
.............111........
..........1110..........
Step 4   ..........1111..........
..........1111..........
.......11110............
Step 5   .......11111............
.......11111............
....111110..............
Step 6   ....11111...............
.....1111...............   MIT
At Least Nine Steps to Failure
...................11111
Step 1   .00000000000000000000000
...................11111
................100000..
Step 2   ................11111...
................11111...
.............110000.....
Step 3   .............11111......
.............11111......
..........111000........
Step 4   ..........11111.........
..........11111.........
.......111100...........
Step 5   .......11111............
.......11111............
....111110..............
Step 6   ....11111...............
.....1111...............   MIT
Conclusions

 Mathematical  analysis is possible.
 Bug is more subtle and more interesting
than most people realize.
 One should not be so quick to laugh at
Intel’s Expense.

MIT
Thanks to Teddy Slottow for his technical
assistance in preparing this presentation

MIT

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 495 posted: 9/23/2010 language: English pages: 54
How are you planning on using Docstoc?