Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * arch/alpha/lib/strchr.S
0004  * Contributed by Richard Henderson (rth@tamu.edu)
0005  *
0006  * Return the address of a given character within a null-terminated
0007  * string, or null if it is not found.
0008  */
0009 #include <asm/export.h>
0010 #include <asm/regdef.h>
0011 
0012     .set noreorder
0013     .set noat
0014 
0015     .align 3
0016     .globl strchr
0017     .ent strchr
0018 strchr:
0019     .frame sp, 0, ra
0020     .prologue 0
0021 
0022     zapnot  a1, 1, a1   # e0    : zero extend the search character
0023     ldq_u   t0, 0(a0)   # .. e1 : load first quadword
0024     sll a1, 8, t5   # e0    : replicate the search character
0025     andnot  a0, 7, v0   # .. e1 : align our loop pointer
0026     or  t5, a1, a1  # e0    :
0027     lda t4, -1      # .. e1 : build garbage mask
0028     sll a1, 16, t5  # e0    :
0029     cmpbge  zero, t0, t2    # .. e1 : bits set iff byte == zero
0030     mskqh   t4, a0, t4  # e0    :
0031     or  t5, a1, a1  # .. e1 :
0032     sll a1, 32, t5  # e0    :
0033     cmpbge  zero, t4, t4    # .. e1 : bits set iff byte is garbage
0034     or  t5, a1, a1  # e0    :
0035     xor t0, a1, t1  # .. e1 : make bytes == c zero
0036     cmpbge  zero, t1, t3    # e0    : bits set iff byte == c
0037     or  t2, t3, t0  # e1    : bits set iff char match or zero match
0038     andnot  t0, t4, t0  # e0    : clear garbage bits
0039     bne t0, $found  # .. e1 (zdb)
0040 
0041 $loop:  ldq t0, 8(v0)   # e0    :
0042     addq    v0, 8, v0   # .. e1 :
0043     nop         # e0    :
0044     xor t0, a1, t1  # .. e1 (ev5 data stall)
0045     cmpbge  zero, t0, t2    # e0    : bits set iff byte == 0
0046     cmpbge  zero, t1, t3    # .. e1 : bits set iff byte == c
0047     or  t2, t3, t0  # e0    :
0048     beq t0, $loop   # .. e1 (zdb)
0049 
0050 $found: negq    t0, t1      # e0    : clear all but least set bit
0051     and     t0, t1, t0  # e1 (stall)
0052 
0053     and t0, t3, t1  # e0    : bit set iff byte was the char
0054     beq t1, $retnull    # .. e1 (zdb)
0055 
0056     and     t0, 0xf0, t2    # e0    : binary search for that set bit
0057     and t0, 0xcc, t3    # .. e1 :
0058     and t0, 0xaa, t4    # e0    :
0059     cmovne  t2, 4, t2   # .. e1 :
0060     cmovne  t3, 2, t3   # e0    :
0061     cmovne  t4, 1, t4   # .. e1 :
0062     addq    t2, t3, t2  # e0    :
0063     addq    v0, t4, v0  # .. e1 :
0064     addq    v0, t2, v0  # e0    :
0065     ret         # .. e1 :
0066 
0067 $retnull:
0068     mov zero, v0    # e0    :
0069     ret         # .. e1 :
0070 
0071     .end strchr
0072     EXPORT_SYMBOL(strchr)