binary counters
play

Binary Counters Integer Representations towards Efficient Counting - PowerPoint PPT Presentation

Binary Counters Integer Representations towards Efficient Counting in the Bit Probe Model (paper presented at TAMC 2011) Gerth Stlting Brodal (Aarhus Universitet) Mark Greve (Aarhus Universitet) Vineet Pandey (BITS Pilani, Indien) S.


  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. - we are counting modulo 10000 2 = 16 10

  3. 1 ∙2 3 + 0 ∙2 2 + 1 ∙2 1 + 1 ∙2 0 = 8+2+1 = 11 10

  4. Decimal Binary Decimal Binary Decimal Binary Algorithm 0 0 0 0000 0000 0000 1 1 1 0001 0001 0001 2 2 2 0010 0010 0010 3 3 3 0011 0011 0011 b 0 4 4 4 0100 0100 0100 0 1 b 3 b 2 b 1 b 0 5 5 5 0101 0101 0101 ---1 b 1 6 6 6 0110 0110 0110 7 7 7 0111 0111 0111 0 1 8 8 8 1000 1000 1000 Reads 4 bits b 2 --10 9 9 9 1001 1001 1001 Writes 4 bits 0 1 10 10 10 1010 1010 1010 11 11 11 1011 1011 1011 b 3 -100 12 12 12 1100 1100 1100 0 1 13 13 13 1101 1101 1101 14 14 14 1110 1110 1110 1000 0000 15 15 15 1111 1111 1111 0 0 0 0000 0000 0000

  5. Decimal Decimal Binary Reflected Gray code Binary Reflected Gray code 0 0 0000 0000 0000 0000 1 1 0001 0001 0001 0001 2 2 0010 0010 0011 0011 3 3 0011 0011 0010 0010 4 4 0100 0100 0110 0110 b 3 b 2 b 1 b 0 b 0 5 5 0101 0101 0111 0111 0 1 6 6 0110 0110 0101 0101 b 1 b 1 7 7 0111 0111 0100 0100 8 8 1000 1000 1100 1100 0 1 0 1 9 9 1001 1001 1101 1101 b 2 b 2 b 2 b 2 10 10 1010 1010 1111 1111 0 1 0 1 0 1 0 1 11 11 1011 1011 1110 1110 b 3 b 3 b 3 b 3 b 3 b 3 b 3 b 3 12 12 1100 1100 1010 1010 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 13 13 1101 1101 1011 1011 ---1 --1- -1-- ---0 1--- ---0 ---1 --0- 0--- ---0 ---1 --0- ---1 --1- -0-- ----0 14 14 1110 1110 1001 1001 Always reads 4 bits 15 15 1111 1111 1000 1000 Always writes 1 bit 0 0 0000 0000 0000 0000

  6. Question Does there exist a counter where one never needs to read all bits to increment the counter ?

  7. Decimal Decimal Decimal [B., Greve , Pandey, Rao 2011] 0 0 0 0000 0000 0000 1 1 1 0001 0001 0001 b 3 b 2 b 1 b 0 2 2 2 0100 0100 0100 3 3 3 0101 0101 0101 b 0 4 4 4 1101 1101 1101 0 1 5 5 5 1001 1001 1001 b 1 b 2 6 6 6 1100 1100 1100 7 7 7 1110 1110 1110 0 1 0 1 b 3 b 3 b 1 b 3 8 8 8 0110 0110 0110 9 9 9 0111 0111 0111 0 1 0 1 0 1 0 1 10 10 10 1111 1111 1111 ---1 --1- ---1 0--- -1-0 --00 1--- -0-- 11 11 11 1011 1011 1011 12 12 12 1000 1000 1000 13 13 13 1010 1010 1010 14 14 14 0010 0010 0010 Always reads 3 bits 15 15 15 0011 0011 0011 Always writes ≤ 2 bits 0 0 0 0000 0000 0000

  8. [B., Greve , Pandey, Rao 2011] Generalization to n bit counters b n -1 b n -2 ∙∙∙ b 6 b 5 b 4 b 3 b 2 b 1 b 0 X Y n -4 bit Gray code 4 bits n -4 reads 3 reads 1 writes 2 writes metode Increment( XY ) inc( X ) if ( X == 0) inc( Y ) Always reads n -1 bits Always writes ≤ 3 bits

  9. 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 ] b 0 bits read n =5 0 1 b 1 b 2 ? bits written ? 0 1 0 1 b 3 b 3 b 1 b 3 0 1 0 1 0 1 0 1 ---1 --1- ---1 0--- -1-0 --00 1--- -0--

  10. Redundant Counters Represent L different values using d >log L bits Efficiency E = L / 2 d

  11. [B., Greve , Pandey, Rao 2011] Redundant counter with E = 1/2 b n b n -1 ∙∙∙ b log n b log n ∙∙∙ b 0 carry X H X L 1 bit n -log n bits log n bit Gray code 1 read 1 read log n reads 1 write 1 write 1 write standard binary counter with delayed increment Idea: Each increment of X L performs one step of the delayed increment of X H 2 n values n +1 bits log n + 2 reads 3 writes

  12. Redundant counter with E = 1/2 carry X H X L 1 0 1 0 1 1 0 0 0 increment 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 … 0 0 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 Value = Val( X L ) + 2 | X L | ·(Val( X H )+ carry·2 Val( X L ) ) 2 n values n +1 bits log n + 2 reads 3 writes

  13. Redundant counter with E = 1/2 carry X H X L 1 0 1 0 1 1 0 0 0 increment 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 … delayed reset 1 0 1 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 0 0 delayed reset 1 0 1 1 0 1 0 0 1 2 n values n +1 bits log n + 3 reads 2 writes

  14. [B., Greve , Pandey, Rao 2011] Redundant counter with E = 1-O(1/2 t ) b n + t -1 ∙∙∙ b n b n -1 ∙∙∙ b log n b log n ∙∙∙ b 0 ” carry ” X H X L t bits n -log n bits log n bit Gray code t read 1 read log n reads 1 write 1 write 1 write delayed standard binary counter ” Carry ” : part of counter = 0.. 2 t -3, set = 2 t -2, clear 2 t -1 (2 t -2)·2 n values log n + t +2 reads 4 writes n + t bits

  15. Redundant Counters Efficiency Space Reads Writes log n + 2 3 1/2 n + 1 log n + 3 2 log n + t + 3 4 1-O(1/2 t ) n + t log n + t + 4 3 Open problem 1 write and « n reads ?

  16. Addition of Counters Numbers in the range 0..2 n -1 and 0..2 m -1 ( m ≤ n ) Space Reads Writes n + O(log n ) Θ ( m + log n ) n + O(loglog n ) Θ ( m + log n· loglog n ) Θ ( m ) Θ ( m + log 2 n ) n + O(1) Ideas: log n blocks of 2 0 ,2 0 ,2 1 ,2 2 ,…,2 i ,2 i +1 ,… bits Incremental carry propagation

Recommend


More recommend