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).
26 ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
31 cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 0
35 addq $0, 8, $0 # addr += 8
36 nop # helps dual issue last two insns
40 found: blbs $2, done # make aligned case fast
56 done: subq $0, $16, $0