# REDUCING LOOKUP TABLE SIZE USED FOR BITCOUNTING ALGORITHM

Eyas El-Qawasmeh and Wafa'a Al-Qarqaz
Computer Science Dept. Jordan University of Science and Technology P.O. Box 3030, Irbid 22110 Jordan eyas@just.edu.jo,walqarqaz@yahoo.com

ABSTRACT Bit-counting is the operation of counting the number of ones in a given computer word or binary vector. Nowadays there are several solutions for this problem. Among these solutions is the usage of lookup table. However, the lookup table can not be used for large sizes of binary vectors or computer words. This paper presents a new implementation of bit-counting problem based on lookup table. The advantage of the proposed algorithm is that it avoids the limitation of the table lookup. This is achieved by taking advantage of the regular behavior of the number of set bits in all possible values for a computer word. The regular pattern enables us to reduce the size of the lookup table. Performance results showed that the suggested techniques outperform other existing methods.
Keywords: BitCounting, Lookup Table, RemainingBits, NumberOfOnes, Comrade Group.

1. Introduction
Bit-counting, which is also called popcount, refers to the operation of counting the number of ones in a given computer word or binary vector. The bitcounting has been used in many applications including information retrieval systems, file processing systems, coding theory [Berkovich, et al., 2000], genetic algorithms, and Game theory. For example, information retrieval systems may represent search results in the form of a single bit attribute matrix representing tensor hundreds-of-thousands of documents indicating whether each document satisfies one or more search criteria. In this case, bit-counting operation is used to determine the number of documents satisfying the search criteria. Likewise, file comparison routines may be used to compare files having large numbers of elements. In this case, a count of the number of matching elements may be required to find an overall match metric. Genetic algorithms use the bit-counting

operation in many of its procedures [Goldberg, et al., 1992]. Currently, there are several software implementations for the bit counting operation. These implementations are: a) Sequential shifting, b) Arithmetic logic counting (AL), c) Emulated popcount, d) Lookup table e) Hamming distance bit vertical Counter (HC), and f) Frequency division [Berkovich et al., 2000] [Berkovich et al., 1998] [El-Qawasmeh, Hemidi, 2000] [Gutman, 2000] [Reingold et al., 1977]. These schemes are competing in the level of efficiency, both time and space efficiency. For example the lookup table algorithm beats the sequential shifting, arithmetic and logic, and parallel methods in favor of time efficiency, on the other hand its space requirements is a critical point when the binary vector (or computer word) size becomes large since it occupies a table of size 2vector size. This paper is interested in the lookup table algorithm. This table lookup has a sever

2 Arithmetic Logic Counting (AL) This method depends on doing the mask operation (AND) for a number with itself after subtracting one from it.3 Parallel Count The parallel counting successively groups the bits into sub-groups of 2. 4. Following is a listing of the most common methods: 2. the performance analysis of the suggested technique will be investigated and compared with other implementations of popcount. While the Number ≠ 0 do If the lowest bit of Number is 1 then increase Counter by one. While the Number ≠ 0 do Number = Number AND (Number –1) // AND is the bitwise logical operation Increase Counter by one. The same logic operation is repeated as long as the number does not equal to zero. In other words.to make more control over the table size. In addition. we can not use a lookup table of size 2 32 entries in general. The organization of this paper is as follows. section 3 describes the new suggested method. section 2 describes some of the existing software methods. Current Related Work Currently. The algorithm is shown in figure (1) below: Counter = 0.problem presented by the limitation of its size. For example. 2001]. 16. End while Figure (1): Sequential shifting method 2. This means that its performance is better in the case of sparse binary vectors of “1”s rather than in dense binary vectors of “1”s [ElQawasmeh. Shift the Number to the right one bit. Experimental results showed that the proposed scheme is the best among all known. Section 4 presents a performance analysis to the suggested algorithm. The conclusions are introduced in section 5. 8. The operational time of this algorithm is proportional to the number of “1”s rather than to the length of the computer word. End while Figure (2): Arithmetic Logic Counting (AL) method 2. The running time for the sequential shifting is O(n) where n is the number of bits in the computer word. This is due to the “While” loop that will continue to be executed for a number of times equal to the number of “1”s in a given computer word.1 Sequential Shifting: It loops and checks each bit alone until the number becomes zero. Counter = 0. it is O(ones(w)) where w is a computer word. The algorithm for the arithmetic logic counting is shown in figure (2). and . The main objective of this paper is to introduce a new enhancement to the lookup table algorithm by reducing the size of the lookup table. there are many different software implementations for bit-counting that vary in the level of efficiency. The reduction takes advantage from the regular behavior of the number of ones in any four consecutive binary values –the smallest one is a multiple of four value. 2.