2 * strlen.S (c) 1995 David Mosberger (davidm@cs.arizona.edu)
4 * Finds length of a 0-terminated string. Optimized for the
7 * - memory accessed as aligned quadwords only
8 * - uses bcmpge to compare 8 bytes in parallel
9 * - does binary search to find 0 byte in last
10 * quadword (HAKMEM needed 12 instructions to
11 * do this instead of the 9 instructions that
12 * binary search needs).
14 #include <asm/export.h>
24 ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
29 cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 0
33 addq $0, 8, $0 # addr += 8
34 nop # helps dual issue last two insns
38 found: blbs $2, done # make aligned case fast
54 done: subq $0, $16, $0