2.9
[glibc/nacl-glibc.git] / sysdeps / alpha / alphaev67 / rawmemchr.S
blob8c7e9423b09f4173d50dca57de761b99c9a1ab7d
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         .arch ev6
24         .set noreorder
25         .set noat
27 ENTRY(__rawmemchr)
28 #ifdef PROF
29         ldgp    gp, 0(pv)
30         lda     AT, _mcount
31         jsr     AT, (AT), _mcount
32         .prologue 1
33 #else
34         .prologue 0
35 #endif
37         ldq_u   t0, 0(a0)       # L : load first quadword Latency=3
38         and     a1, 0xff, t3    # E : 00000000000000ch
39         insbl   a1, 1, t5       # U : 000000000000ch00
40         insbl   a1, 7, a2       # U : ch00000000000000
42         insbl   t3, 6, a3       # U : 00ch000000000000
43         or      t5, t3, a1      # E : 000000000000chch
44         andnot  a0, 7, v0       # E : align our loop pointer
45         lda     t4, -1          # E : build garbage mask
47         mskqh   t4, a0, t4      # U : only want relevant part of first quad
48         or      a2, a3, a2      # E : chch000000000000
49         inswl   a1, 2, t5       # E : 00000000chch0000
50         inswl   a1, 4, a3       # E : 0000chch00000000
52         or      a1, a2, a1      # E : chch00000000chch
53         or      a3, t5, t5      # E : 0000chchchch0000
54         cmpbge  zero, t4, t4    # E : bits set iff byte is garbage
55         nop                     # E :
57         /* This quad is _very_ serialized.  Lots of stalling happens */
58         or      t5, a1, a1      # E : chchchchchchchch
59         xor     t0, a1, t1      # E : make bytes == c zero
60         cmpbge  zero, t1, t0    # E : bits set iff byte == c
61         andnot  t0, t4, t0      # E : clear garbage bits
63         cttz    t0, a2          # U0 : speculative (in case we get a match)
64         nop                     # E :
65         nop                     # E :
66         bne     t0, $found      # U :
68         /*
69          * Yuk.  This loop is going to stall like crazy waiting for the
70          * data to be loaded.  Not much can be done about it unless it's
71          * unrolled multiple times, which is generally unsafe.
72          */
73 $loop:
74         ldq     t0, 8(v0)       # L : Latency=3
75         addq    v0, 8, v0       # E :
76         xor     t0, a1, t1      # E :
77         cmpbge  zero, t1, t0    # E : bits set iff byte == c
79         cttz    t0, a2          # U0 : speculative (in case we get a match)
80         nop                     # E :
81         nop                     # E :
82         beq     t0, $loop       # U :
84 $found:
85         negq    t0, t1          # E : clear all but least set bit
86         and     t0, t1, t0      # E :
87         addq    v0, a2, v0      # E : Add in the bit number from above
88         ret                     # L0 :
90         END(__rawmemchr)
92 libc_hidden_def (__rawmemchr)
93 weak_alias (__rawmemchr, rawmemchr)