Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/19/01 13:50
Read: times


 
#15055 - RE: Counting bits
Hi Joe,

the table method, was the fastest, but most code size eaten.

You can be a little slower, but many times smaller, if you use a table for every nibble (only 16 byte table size):

;input: a = byte
;output: a = bit count

count_bits_fast:
mov r0, a
anl a, #0Fh
add a, #cbf3 - cbf1
movc a, @a+pc
cbf1:
xch a, r0
swap a
anl a, #0Fh
add a, #cbf3 - cbf2
movc a, @a+pc
cbf2:
add a, r0
ret
cbf3:
db 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4


It's four times faster, than your and Eriks code


Peter


List of 8 messages in thread
TopicAuthorDate
Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      
RE: Counting bits            01/01/70 00:00      

Back to Subject List