Download presentation
Presentation is loading. Please wait.
1
Binary Counters Integer Representations towards Efficient Counting in the Bit Probe Model (paper presented at TAMC 2011) Gerth Stølting Brodal (Aarhus Universitet) Mark Greve (Aarhus Universitet) Vineet Pandey (BITS Pilani, Indien) S. Srinivasa Rao (Seoul, Syd Korea) MADALGO Seminar, June 1, 2011
2 0
3
1
4
10
5
11
6
100
7
101
8
110
9
111
10
1000
11
1001
12
1010
13
1011
14
1100
15
1101
16
1110
17
1111
18
0000 - we are counting modulo 10000 2 = 16 10
19
1011 1∙2 3 + 0∙2 2 + 1∙2 1 + 1∙2 0 = 8+2+1 = 11 10
20
DecimalBinary 00000 10001 20010 30011 40100 501 60110 70111 81000 91001 101010 111011 121100 131101 141110 151111 00000 b3b2b1b0b3b2b1b0 b0b0 0 1 b1b1 b2b2 b3b3 ---1 --10 0000 -100 1000 Reads 4 bits Writes 4 bits DecimalBinary 00000 10001 20010 30011 40100 50101 60110 70111 81000 91001 1010 111011 121100 131101 141110 151111 00000 DecimalBinary 00000 10001 20010 30011 40100 50101 60110 70111 81000 91001 101010 111011 121100 131101 141110 151111 00000 Algorithm
21
DecimalBinaryReflected Gray code 00000 10001 200100011 3 0010 401000110 501010111 601100101 701110100 810001100 910011101 1010101111 1110111110 1211001010 1311011011 1411101001 1511111000 00000 "To get the next code, for a code with even parity, flip the rightmost bit. For a code with odd parity, find the rightmost ‘1’ and flip the bit to its left. The only special case is when the last bit b n is the only ‘1’ in the code. This is also the last code in the sequence." DecimalBinaryReflected Gray code 00000 10001 200100011 3 0010 401000110 501010111 601100101 701110100 810001100 910011101 1010101111 1110111110 1211001010 1311011011 1411101001 1511111000 00000 Always reads 4 bits Always writes 1 bit ---0 b0b0 b1b1 b2b2 --1----0 --0- --1--0-- b2b2 b2b2 b2b2 b1b1 0 1 0------1-1--1------1 ----0 b3b3 0 1 b3b3 b3b3 b3b3 b3b3 b3b3 b3b3 b3b3 b3b2b1b0b3b2b1b0
23
Question Does there exist a counter where one never needs to read all bits to increment the counter ?
24
Decimal 00000 10001 20100 30101 41101 51001 61100 71110 80110 90111 101111 111011 121000 131010 140010 150011 00000 Decimal 00000 10001 201000100 30101 41101 51001 611001100 71110 80110 90111 101111 111011 121000 131010 140010 150011 000 Decimal 00000 10001 201000100 30101 411011101 51001 611001100 711101110 80110 90111 1011111111 111011 121000 1310101010 140010 150011 00000 b3b2b1b0b3b2b1b0 -1-0-1-0 b0b0 b1b1 b1b1 ---1--1----10-----001----0-- b3b3 b3b3 b3b3 b2b2 0 1 Always reads 3 bits Always writes ≤ 2 bits [B., Greve, Pandey, Rao 2011]
25
b n-1 b n-2 ∙∙∙ b 6 b 5 b 4 b 3 b 2 b 1 b 0 Generalization to n bit counters Y 4 bits 3 reads 2 writes X n-4 bit Gray code n-4 reads 1 writes metode Increment(XY) inc(X) if (X == 0) inc(Y) Always reads n-1 bits Always writes ≤ 3 bits [B., Greve, Pandey, Rao 2011]
26
Theorem 4-bit counter 3 reads and 2 writes n-bit counter n-1 reads and 3 writes Open problems n-1 reads and 2 writes ? « n reads and writes ? [number of reads at least log 2 n] -1-0-1-0 b0b0 b1b1 b1b1 ---1--1----10-----001----0-- b3b3 b3b3 b3b3 b2b2 0 1 n=5 ? ? bits read bits written
27
Redundant Counters Represent L different values using d>log L bits Efficiency E = L / 2 d
28
b n b n-1 ∙∙∙ b log n b log n ∙∙∙ b 0 Redundant counter with E = 1/2 X L log n bit Gray code log n reads 1 write X H n-log n bits 1 read 1 write standard binary counter with delayed increment Idea: Each increment of X L performs one step of the delayed increment of X H n+1 bits2 n valueslog n + 2 reads3 writes [B., Greve, Pandey, Rao 2011] carry 1 bit 1 read 1 write
29
carryXHXH XLXL 101011000 101010001 101000011 001100010 001100110 001100111 001100101 001100100 101100000 001101001 Redundant counter with E = 1/2 increment … Value = Val(X L ) + 2 |X L | ·(Val(X H )+ carry·2 Val(X L ) ) n+1 bits2 n valueslog n + 2 reads3 writes
30
carryXHXH XLXL 101011000 101010001 101000011 101100010 001100110 001100111 001100101 001100100 101100000 101101001 Redundant counter with E = 1/2 increment … n+1 bits2 n valueslog n + 3 reads2 writes delayed reset
31
b n+t-1 ∙∙∙ b n b n-1 ∙∙∙ b log n b log n ∙∙∙ b 0 Redundant counter with E = 1-O(1/2 t ) X L log n bit Gray code log n reads 1 write X H n-log n bits 1 read 1 write delayed standard binary counter ”Carry” : part of counter = 0.. 2 t -3, set = 2 t -2, clear 2 t -1 n+t bits(2 t -2)·2 n values log n+t+2 reads4 writes [B., Greve, Pandey, Rao 2011] ”carry” t bits t read 1 write
32
Redundant Counters EfficiencySpaceReadsWrites 1/2n + 1 log n + 23 log n + 32 1-O(1/2 t )n + t log n + t + 34 log n + t + 43 Open problem 1 write and « n reads ?
33
Addition of Counters Numbers in the range 0..2 n -1 and 0..2 m -1 (m ≤ n) SpaceReadsWrites n + O(log n) Θ(m + log n) Θ(m)Θ(m) n + O(loglog n) Θ(m + log n·loglog n) n + O(1) Θ(m + log 2 n) Ideas: log n blocks of 2 0,2 0,2 1,2 2,…,2 i,2 i+1,… bits Incremental carry propagation
34
THANK YOU
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.