Subject: first cut at strrchr.S

From: Matthew Wilcox <[email-masked]>
Date: Tue, 21 Apr 1998 14:40:56 +0100 (BST)

This includes the improvement that mdw told me about with respect to
strchr.  It's 53 instructions, a little more complicated than strchr.
But if it's worth optimising strchr, it's worth optimising strrchr since
it's likely to have to churn through more data.  Again, this is untested
and I'd welcome testers.  Does anyone object to me posting these bits
of assembler?  Would you prefer I placed them on ftp.barnet.ac.uk and
only announced them here?

-- 
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$[ ||||||||||||||||

strrchr:
   stmfd   r13!, {r4, r14}
   mov     ip, #0
   tst     r0, #3
   beq     3f
1: ldrb    r2, [r0], #1
   teq     r2, r1
   subeq   ip, r0, #1
   cmp     r2, #0
   tstne   r0, #3
   bne     1b
   bcs     5f
3: orr     r1, r1, r1, LSL #8
   orr     r1, r1, r1, LSL #16
   mov     r4, #1
   orr     r4, r4, r4, LSL #8
   orr     r4, r4, r4, LSL #16
4: ldr     r2, [r0], #4
   eor     r3, r2, r1
   sub     r14, r3, r4
   bic     r14, r14, r3
   tst     r14, r4, lsl #7
   moveq   r3, ip
   subeq   ip, r0, #4
   sub     r14, r2, r4
   bic     r14, ip, r2
   tst     r14, r4, lsl #7
   bne     4b
5: teq     ip, #0
   beq     6f
   tst     ip, #3
   bne     6f
   ldr     r2, [ip]
   eor     r0, r2, r1
   tst     r2, #&000000ff
   tstne   r2, #&0000ff00
   orreq   r0, r0, #&000ff000
   tstne   r2, #&00ff0000
   orreq   r0, r0, #&ff000000
   mvn     r2, #0
   tst     r0, #&ff000000
   addeq   r2, r2, #1
   tstne   r0, #&00ff0000
   addeq   r2, r2, #1
   tstne   r0, #&0000ff00
   addeq   r2, r2, #1
   tstne   r0, #&000000ff
   addeqs  r2, r2, #1
   addge   r0, ip, r2
   ldmgefd r13!, {r4, pc}
   mov     ip, r3
   b       5b
6: mov     r0, ip
   mov     pc, r14

unsubscribe: body of `unsubscribe linux-arm' to [email-masked]