Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Intel Pentium Division Flaw

Similar presentations


Presentation on theme: "The Intel Pentium Division Flaw"— Presentation transcript:

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

2 The bug itself is (mathematically) neat!
Not So Well Known The bug itself is (mathematically) neat! A Lesson (for me anyway) So much incomplete information is out there.

3 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

4 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

5 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/ S is finite. Nicely computed on many platforms. Nicely checked his work.

6 Computer Science Prerequisites
Carry Save Addition. One’s vs. Two’s Complement.

7 Carry-save Addition 12 21 + 19 52

8 Carry-save Addition 12 21 + 19 52 20 Answer (mod 32)

9 Carry-save Addition 12 01100 21 10101 + 19 10011 52 10100 + 20
Answer (mod 32)

10 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 1 52
20 01100 10101 10011 10100 01100 10101 1 + + Sum Bits (s) Carry Bits (c) Answer (mod 32)

11 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 1 52
20 01100 10101 10011 10100 01100 10101 1 + + Sum Bits (s) Carry Bits (c) Answer (mod 32) s = xÅyÅz = x+y+z (mod 2) c = xÙy Ú xÙz Ú yÙz = (x+y+z | 2)

12 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 01 52
20 01100 10101 10011 10100 01100 10101 01 00 + + Sum Bits (s) Carry Bits (c) Answer (mod 32) s = xÅyÅz = x+y+z (mod 2) c = xÙy Ú xÙz Ú yÙz = (x+y+z | 2)

13 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 11001
52 20 01100 10101 10011 10100 01100 10101 11001 01000 + + Sum Bits (s) Carry Bits (c) Answer (mod 32) s = xÅyÅz = x+y+z (mod 2) c = xÙy Ú xÙz Ú yÙz = (x+y+z | 2)

14 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 11001
52 20 01100 10101 10011 10100 01100 10101 11001 01000 + + Sum Bits (s) Carry Bits (c) +10011 Answer (mod 32) s = xÅyÅz = x+y+z (mod 2) c = xÙy Ú xÙz Ú yÙz = (x+y+z | 2)

15 Carry-save Addition 12 01100 01100 21 10101 10101 + 19 10011 + 11001
52 20 01100 10101 10011 10100 01100 10101 11001 01000 + + Sum Bits (s) Carry Bits (c) +10011 00010 10010 Sum Bits (s) Answer (mod 32) Carry Bits (c) s = xÅyÅz = x+y+z (mod 2) c = xÙy Ú xÙz Ú yÙz = (x+y+z | 2)

16 One’s vs. Two’s Complement

17 One’s vs. Two’s Complement
Two’s Complement One’s Complement

18 One’s vs. Two’s Complement
Two’s Complement One’s Complement

19 Division Algorithms:

20 Long Division Example 7 30 28 20 14 60

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

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

23 Long Division Radix 10 S 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 = q i / 10 i S i=0

24 SRT Division Radix 4 S Compute q = p / d. Such qk exists?
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 = q i / 4 i S i=0 Such qk exists? Algorithm correct?

25 Such qk exists? S 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 = qi / 4i S i=0 qk := 0 qk := –2 qk := +2 qk := +1 qk := –1 3 8 d 2

26 Such qk exists? S -2 / 3d ≤ pk ≤ 2 / 3d pk+1 := 4(pk - 0)
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 = qi / 4i S i=0 2 3 d qk := 0 3 2 d 8 3 d 3 8 d 4(pk - 0) -2 / 3d ≤ pk ≤ 2 / 3d pk+1 := 4(pk - 0)

27 Such qk exists? S 4 / 3d ≤ pk ≤ 8 / 3d pk+1 := 4(pk - 2d)
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 = qi / 4i S i=0 qk := +2 8 3 d 3 8 d 3 4 d 4 / 3d ≤ pk ≤ 8 / 3d pk+1 := 4(pk - 2d)

28 Such qk exists? S 4/3 ≤ pk ≤ 8/3 pk+1 := 4(pk - 2d)
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 = qi / 4i S i=0 2 3 d pk - 2d 3 2 d qk := +2 8 3 d 3 8 d 4/3 ≤ pk ≤ 8/3 pk+1 := 4(pk - 2d)

29 Such qk exists? S 4 / 3d ≤ pk ≤ 8 / 3d pk+1 := 4(pk - 2d)
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 = qi / 4i S i=0 2 3 d pk - 2d 3 2 d qk := +2 8 3 d 3 8 d 4(pk - 2d) 4 / 3d ≤ pk ≤ 8 / 3d pk+1 := 4(pk - 2d)

30 A qk For Every Point qk := –2 qk := 0 qk := +2 qk := –1 qk := +1 2 3 d
8 3 d 3 8 d qk := –1 qk := +1

31 Algorithm Correct? Claim: Proof by Induction: p q1 qk-1 pk d 4 4k-1 d
pk+1 = 4(pk - qkd) Þ pk qk pk+1 d k d — = q0 + — ––– + –— 4-k — 4-k = — + —— 4-(k+1)

32 Algorithm Correct? Claim: Proof by Induction: p q1 qk-1 qk pk+1
d k k d Proof by Induction: pk+1 = 4(pk - qkd) Þ pk qk pk+1 d k d — = q0 + — ––– + — + ––— 4-(k+1) — 4-k = — + —— 4-(k+1)

33 Algorithm Correct? Claim: Proof by Induction: Letting k®¥ proves
p q qk qk pk+1 d k k d Proof by Induction: pk+1 = 4(pk - qkd) Þ pk qk pk+1 d k d Letting k®¥ proves p q1 q2 d — = q0 + — ––– + — + ––— 4-(k+1) — 4-k = — + —— 4-(k+1) — = q0 + — + —

34 Pentium Lookup Table (P-d plot)
Blue Green q := 2 q := 1 q := 0 q := -1 q:= -2 Shifted Partial Remainder 1.0000 1.0001 1.0010 1.0011 1.0100 1.0101 1.0110 1.0111 1.1000 1.1001 1.1010 1.1011 1.1100 1.1101 1.1110 1.1111 1/16 1/8 Divisor

35 Pentium Lookup Table (P-d plot)
Blue Green q := 2 q := 1 q := 0 q := -1 q:= -2 Shifted Partial Remainder 1.0000 1.0001 1.0010 1.0011 1.0100 1.0101 1.0110 1.0111 1.1000 1.1001 1.1010 1.1011 1.1100 1.1101 1.1110 1.1111 1/16 1/8 Divisor

36 A Close-up Look at One Column (D=1.0001)
2.875 1.5 1.375 0.375 0.25 -0.5 -0.625 -1.625 -1.75 -3 2 1 -1 -2

37 A Close-up Look at One Column (D=1.0001)
2.875 1.5 1.375 0.375 0.25 -0.5 -0.625 -1.625 -1.75 -3 2 1 -1 -2 2 Off the Chart Off the Chart Off the Chart Off the Chart Buggy Entry Foothold

38 Pentium Division Example: 1.875/1.000
1.875 = { S C qk:=–2 qk:=0 qk:=+2 qk:=–1 qk:=+1 pk+1 := 4(pk – qkd)

39 Pentium Division Example: 1.875/1.000
1.875 = { S C S C – 2´1 = qk:=–2 qk:=0 qk:=+2 = { qk:=–1 qk:=+1 pk+1 := 4(pk – qkd)

40 Pentium Division Example: 1.875/1.000
1.875 = { S C S C – 2´1 = qk:=0 qk:=–2 qk:=+2 qk:=+1 qk:=–1 -0.125´4 = -0.5 = { pk+1 := 4(pk – qkd)

41 Pentium Division Example: 1.875/1.000
1.875 = { S C S C S C –2´1 = qk:=–2 qk:=0 qk:=+2 qk:=–1 qk:=+1 – –1´1 = pk+1 := 4(pk – qkd)

42 Pentium Division Example: 1.875/1.000
1.875 = { S C S C S C S C S C –2´1 = qk:=–2 qk:=0 qk:=+2 qk:=–1 qk:=+1 – –1´1 = –2´1 = –0´1 = 2/1 + –1/4 + 2/16 + 0/64 = 1.875/1.000

43 ì í î 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 3/4 if qk = 0 1 if qk = 1 5/4 if qk = 2 Rk ≤ Rk º Max

44 Reaching the Flaw is Not Easy!
qk Pk+1 –2 ≤ Pbad - 1/8 –1 ≤ Pbad - 1/8 0 < Pbad - 1/8 1 < Pbad - 1/8 Pk < Pbad - 1/8 ≤ Pbad - 1/8 Pk = Pbad - 1/8 ≤ Pbad ì í î 2

45 foothold buggy entry

46 “Send More Money” Puzzle
intel 22 Mission College Blvd. Santa Clara, CA 95052 32¢ Massachusetts Institue of Technology 77 Massachusetts Ave. Cambridge, MA 02139 SEND +MORE MONEY

47 The Path to Failure ì í î Bad Divisors: d = 1.d1d2d3d4111111d11…
six ones .d2d3d .d2d3d40 0 0 q = –2 q = 2 bug

48 At Least Nine Steps to Failure
Step 1 Step 2 Step 3 Step 4 : 2 more steps Step 5 Step 6

49 At Least Nine Steps to Failure
Step 1 Step 2 Step 3 Step 4 : 2 more steps Step 5 Step 6

50 At Least Nine Steps to Failure
Step 1 Step 2 Step 3 Step 4 : 2 more steps Step 5 Step 6

51 At Least Nine Steps to Failure
Step 1 Step 2 Step 3 Step 4 : 2 more steps Step 5 Step 6

52 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.

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

54


Download ppt "The Intel Pentium Division Flaw"

Similar presentations


Ads by Google