0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <asm/export.h>
0016 .set noreorder
0017 .set noat
0018
0019 .align 3
0020
0021 .globl strlen
0022 .ent strlen
0023
0024 strlen:
0025 ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
0026 lda $2, -1($31)
0027 insqh $2, $16, $2
0028 andnot $16, 7, $0
0029 or $2, $1, $1
0030 cmpbge $31, $1, $2 # $2 <- bitmask: bit i == 1 <==> i-th byte == 0
0031 bne $2, found
0032
0033 loop: ldq $1, 8($0)
0034 addq $0, 8, $0 # addr += 8
0035 nop # helps dual issue last two insns
0036 cmpbge $31, $1, $2
0037 beq $2, loop
0038
0039 found: blbs $2, done # make aligned case fast
0040 negq $2, $3
0041 and $2, $3, $2
0042
0043 and $2, 0x0f, $1
0044 addq $0, 4, $3
0045 cmoveq $1, $3, $0
0046
0047 and $2, 0x33, $1
0048 addq $0, 2, $3
0049 cmoveq $1, $3, $0
0050
0051 and $2, 0x55, $1
0052 addq $0, 1, $3
0053 cmoveq $1, $3, $0
0054
0055 done: subq $0, $16, $0
0056 ret $31, ($26)
0057
0058 .end strlen
0059 EXPORT_SYMBOL(strlen)