2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / rawmemchr.S
blobd3a69fa63c7a31aeaefc48bd278da89dce2914e8
1 /* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 /* Return pointer to first occurrence of CH in STR.  */
21 #include <sysdep.h>
23         .set noreorder
24         .set noat
26 ENTRY(__rawmemchr)
27 #ifdef PROF
28         ldgp    gp, 0(pv)
29         lda     AT, _mcount
30         jsr     AT, (AT), _mcount
31         .prologue 1
32 #else
33         .prologue 0
34 #endif
36         zapnot  a1, 1, a1       # e0    : zero extend the search character
37         ldq_u   t0, 0(a0)       # .. e1 : load first quadword
38         sll     a1, 8, t5       # e0    : replicate the search character
39         andnot  a0, 7, v0       # .. e1 : align our loop pointer
41         or      t5, a1, a1      # e0    :
42         lda     t4, -1          # .. e1 : build garbage mask
43         sll     a1, 16, t5      # e0    :
44         unop                    #       :
46         mskqh   t4, a0, t4      # e0    :
47         or      t5, a1, a1      # .. e1 :
48         sll     a1, 32, t5      # e0    :
49         cmpbge  zero, t4, t4    # .. e1 : bits set iff byte is garbage
51         or      t5, a1, a1      # e0    :
52         xor     t0, a1, t1      # .. e1 : make bytes == c zero
53         cmpbge  zero, t1, t3    # e0    : bits set iff byte == c
54         unop                    #       :
56         andnot  t3, t4, t0      # e0    : clear garbage bits
57         fnop                    # .. fa :
58         unop                    #       :
59         bne     t0, $found      # .. e1 (zdb)
61         .align 4
62 $loop:
63         ldq     t0, 8(v0)       # e0    :
64         addq    v0, 8, v0       # .. e1 :
65         nop                     # e0    :
66         xor     t0, a1, t1      # .. e1 (ev5 data stall)
68         cmpbge  zero, t1, t0    # e0    : bits set iff byte == c
69         beq     t0, $loop       # .. e1 (zdb)
71 $found:
72         negq    t0, t1          # e0    : clear all but least set bit
73         and     t0, t1, t0      # e1 (stall)
74         and     t0, 0xf0, t2    # e0    : binary search for that set bit
75         and     t0, 0xcc, t3    # .. e1 :
77         and     t0, 0xaa, t4    # e0    :
78         cmovne  t2, 4, t2       # .. e1 :
79         cmovne  t3, 2, t3       # e0    :
80         cmovne  t4, 1, t4       # .. e1 :
82         addq    t2, t3, t2      # e0    :
83         addq    v0, t4, v0      # .. e1 :
84         addq    v0, t2, v0      # e0    :
85         ret                     # .. e1 :
87         END(__rawmemchr)
89 libc_hidden_def (__rawmemchr)
90 weak_alias (__rawmemchr, rawmemchr)