Subject: improved strlen.S

From: Matthew Wilcox <[email-masked]>
Date: Tue, 21 Apr 1998 13:30:20 +0100 (BST)

Thanks to Mark Wooding for providing me with the improved detect-zero-byte
code.  I found a bug in the pre-word case.  This should be suitable for
linux but is /not/ suitable for libc as it does not have the correct
behaviour when the character being searched for is the zero byte.
44 instructions, but 2 fewer in the inner loop, and a couple removed
from the direct path in.  Anyway:

strchr:
   stmfd   r13!, {r14}
   tst     r0, #3
   beq     2f
1: ldrb    r2, [r0], #1
   cmp     r2, r1
   cmpne   r2, #0
   tstne   r0, #3
   bne     1b
   bcs     6f
2: orr     r1, r1, r1, LSL #8
   orr     r1, r1, r1, LSL #16
   mov     r14, #1
   orr     r14, r14, r14, LSL #8
   orr     r14, r14, r14, LSL #16
3: ldr     r2, [r0], #4
   eor     r3, r2, r1
   sub     ip, r3, r14
   bic     ip, ip, r3
   tst     ip, r14, lsl #7
   beq     5f
   sub     ip, r2, r14
   bic     ip, ip, r2
   tst     ip, r14, lsl #7
   bne     3b
   b       7f
5: tst     r2, #&000000ff
   beq     7f
   tst     r3, #&000000ff
   subeq   r0, r0, #1
   tstne   r3, #&0000ff00
   subeq   r0, r0, #2
   ldmeqfd r13!, {pc}
   tst     r2, #&0000ff00
   tstne   r2, #&00ff0000
   beq     7f
   tst     r3, #&00ff0000
   subeq   r0, r0, #1
   tstne   r3, #&ff000000
   ldmeqfd r13!, {pc}
   b       7f
6: cmp     r2, #0
   subne   r0, r0, #1
7: moveq   r0, #0
   ldmfd   r13!, {pc}

-- 
Set Alias$Case Set Alias$[ |||| |MSet Alias$Otherwise Set Alias$[ \ Matthew
"" |MSet Alias$When If %0=%%0 Then Set Alias$[ "" ||MIf %0=%%0    \ Wilcox
Then Set Alias$Otherwise Set Alias$[ |||||||||||||||| ||MIf       \
%0=%%0 Then Set Alias$When Set Alias$[ ||||||||||||||||
unsubscribe: body of `unsubscribe linux-arm' to [email-masked]