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