c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (1)
Branchless Search Programs
Amr Elmasry1 Jyrki Katajainen2,3
1 Alexandria University 2 University of Copenhagen 3 Jyrki Katajainen and Company
Branchless Search Programs Amr Elmasry 1 Jyrki Katajainen 2 , 3 1 - - PowerPoint PPT Presentation
Branchless Search Programs Amr Elmasry 1 Jyrki Katajainen 2 , 3 1 Alexandria University 2 University of Copenhagen 3 Jyrki Katajainen and Company Performance Engineering Laboratory c SEA 2013, Rome, June 7th, 2013 (1) Cause of the troubles:
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (1)
1 Alexandria University 2 University of Copenhagen 3 Jyrki Katajainen and Company
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (2)
if (x < y) goto λ; I1; I2; . . . λ: J1; J2; . . .
↓ λ ↓ (x < y) if (x < y) goto λ; I1 or J1?
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (3)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (4)
5).
2)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (5)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (6)
1 bool is_member (V const & v) { 2 N∗ y = nullptr ; // candidate node 3 N∗ x = root ; // current node 4 while (x != nullptr ) { 5 i f (less(v , (∗x) . element () )) { 6 x = (∗x) . left () ; 7
}
8 else { 9 y = x ; 10 x = (∗x) . right () ; 11
}
12
}
13 i f (y = = nullptr | | less ((∗y) . ← ֓ element () , v)) { 14 return false ; 15
}
16 return true ; 17 }
1 N∗ choose(bool c , N∗ x , N∗ y) { 2 return (N∗) ((char∗) y + c ∗ ((char ← ֓
∗) x − (char∗) y)) ;
3 } 4 5 bool is_member (V const & v) { 6 N∗ y = nullptr ; // candidate node 7 N∗ x = root ; // current node 8 while (x != nullptr ) { 9 bool c = less(v , (∗x) . element () ) ; 10 y = choose(c , y , x) ; 11 x = choose(c , (∗x) . left () , (∗x) . ← ֓ right () ) ; 12
}
13 i f (y = = nullptr | | less ((∗y) . ← ֓ element () , v)) { 14 return false ; 15
}
16 return true ; 17 }
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (7)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (8)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (9)
2 1 3 1 4
2 1 3 1 4
2 Skewed α = 1 3 Skewed α = 1 4 Balanced α = 1 2
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (10)
4 5 6 3 2 1 47 45 48 46 44 43
6
42
return (*x).left()
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (11)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (12)
4 5 6 3 2 1 47 45 48 46 44 43
6
42
j = i/F if i < ⌊F/2⌋ + j ∗ F return 2 ∗ i − j ∗ F + 1 else return F ∗ (2 ∗ i − (1 − F) ∗ j − F + 2)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (13)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (14)
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (15)
1 bool is_member (V const & v) { 2 N∗ y = nullptr ; // candidate node 3 N∗ x = root ; // current node 4 bool c ; 5 switch (height) { 6 case 31: 7 c = less(v , (∗x) . element () ) ; 8 y = choose(c , y , x) ; 9 x = choose(c , (∗x) . left () , (∗x) . right () ) ;
125 case 1: 126 c = less(v , (∗x) . element () ) ; 127 y = choose(c , y , x) ; 128 x = choose(c , (∗x) . left () , (∗x) . right () ) ; 129 default : 130 c = (x = = nullptr ) | | less(v , (∗x) . element () ) ; 131 y = choose(c , y , x) ; 132
}
133 i f ((y = = nullptr ) | | less ((∗y) . element () , v)) { 134 return false ; 135
}
136 return true ; 137 }
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (16)
i f (less(a [ j ] , a [ j + 1]) { j = j + 1;
}
j = j + less(a [ j ] , a [ j + 1]) ;
c
Performance Engineering Laboratory
SEA 2013, Rome, June 7th, 2013 (17) commercial break