Let the new byte table store and, for , . Thus it stores the number of leading zeros in an eight-bit argument: , , and . All entries fit in one byte.
countlz:
adr r3, lzbyte
movs r1, #0
lsrs r2, r0, #24
bne lz_found
movs r1, #8
lsrs r2, r0, #16
bne lz_found
movs r1, #16
lsrs r2, r0, #8
bne lz_found
movs r1, #24
movs r2, r0
lz_found:
ldrb r2, [r3, r2]
adds r0, r1, r2
bx lrThe high byte is tried first. A failed test proves that byte was zero, so the next right-shifted value is again a byte-sized index without masking: all higher bytes have already been proved zero. The offset in
r1 counts those skipped zero bytes in bits. Adding the table result for the first nonzero byte gives the leading-zero count. If every byte is zero, the last lookup contributes eight to the offset 24, giving 32. The example with high byte one gives 7. At most three conditional branches and one table read are needed; no per-bit loop is used. Articles by others on the same topic
There are currently no matching articles.