]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/s390/multiarch/memchr-vx.S
875eee2b4334fe9c815aab0ac55cf3db97751397
[thirdparty/glibc.git] / sysdeps / s390 / multiarch / memchr-vx.S
1 /* Vector optimized 32/64 bit S/390 version of memchr.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
20
21 # include "sysdep.h"
22 # include "asm-syntax.h"
23
24 .text
25
26 /* void *memchr (const void *s, int c, size_t n)
27 Scans memory for character c
28 and returns pointer to first c.
29
30 Register usage:
31 -r0=tmp
32 -r1=tmp
33 -r2=s
34 -r3=c
35 -r4=n
36 -r5=current_len
37 -v16=part of s
38 -v17=index of found c
39 -v18=c replicated
40 */
41 ENTRY(__memchr_vx)
42
43 .machine "z13"
44 .machinemode "zarch_nohighgprs"
45
46 # if !defined __s390x__
47 llgfr %r4,%r4
48 # endif /* !defined __s390x__ */
49
50 clgije %r4,0,.Lnf_end /* If len == 0 then exit. */
51
52 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
53 lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
54 llgfr %r0,%r0 /* Convert 32bit to 64bit. */
55
56 vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
57 if c > 255, c will be truncated. */
58 vrepb %v18,%v18,0
59 lghi %r5,16 /* current_len = 16. */
60
61 clgrjhe %r0,%r4,.Llastcmp /* If (bytes to boundary) >= n,
62 jump to lastcmp. */
63
64 vfeebs %v17,%v16,%v18 /* Find c. */
65 vlgvb %r1,%v17,7 /* Load byte index of c. */
66 clgrjl %r1,%r0,.Lfound2 /* Found c is within loaded bytes. */
67
68 /* Align s to 16 byte. */
69 risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
70 slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
71
72 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
73 aghi %r0,64
74 clgrjl %r0,%r4,.Lloop64
75 .Llt64:
76 vl %v16,0(%r5,%r2)
77 aghi %r5,16
78 clgrjhe %r5,%r4,.Llastcmp /* Do last compare if curr-len >= n. */
79 vfeebs %v17,%v16,%v18 /* Find c. */
80 jl .Lfound /* Jump away if c was found. */
81
82 vl %v16,0(%r5,%r2)
83 aghi %r5,16
84 clgrjhe %r5,%r4,.Llastcmp
85 vfeebs %v17,%v16,%v18
86 jl .Lfound
87
88 vl %v16,0(%r5,%r2)
89 aghi %r5,16
90 clgrjhe %r5,%r4,.Llastcmp
91 vfeebs %v17,%v16,%v18
92 jl .Lfound
93
94 vl %v16,0(%r5,%r2)
95 aghi %r5,16
96
97 .Llastcmp:
98 /* Use comparision result only if located within first n characters.
99 %r5: current_len;
100 %r4: n;
101 (current_len - n): [0...16[
102 first ignored match index: vr-width - (current_len - n) ]0...16]
103 */
104 vfeebs %v17,%v16,%v18 /* Find c. */
105 slgrk %r4,%r5,%r4 /* %r5 = current_len - n. */
106 lghi %r0,16 /* Register width = 16. */
107 vlgvb %r1,%v17,7 /* Extract found index or 16 if all equal. */
108 slr %r0,%r4 /* %r0 = first ignored match index. */
109 clrjl %r1,%r0,.Lfound2 /* Go away if miscompare is below n bytes. */
110 /* c not found within n-bytes. */
111 .Lnf_end:
112 lghi %r2,0 /* Return null. */
113 br %r14
114
115 .Lfound48:
116 aghi %r5,16
117 .Lfound32:
118 aghi %r5,16
119 .Lfound16:
120 aghi %r5,16
121 .Lfound0:
122 aghi %r5,16
123 .Lfound:
124 vlgvb %r1,%v17,7 /* Load byte index of c. */
125 .Lfound2:
126 slgfi %r5,16 /* current_len -=16 */
127 algr %r5,%r1 /* Zero byte index is added to current len. */
128 la %r2,0(%r5,%r2) /* Return pointer to c. */
129 br %r14
130
131
132 .Lloop64:
133 vl %v16,0(%r5,%r2)
134 vfeebs %v17,%v16,%v18 /* Find c. */
135 jl .Lfound0 /* Jump away if c was found. */
136 vl %v16,16(%r5,%r2)
137 vfeebs %v17,%v16,%v18
138 jl .Lfound16
139 vl %v16,32(%r5,%r2)
140 vfeebs %v17,%v16,%v18
141 jl .Lfound32
142 vl %v16,48(%r5,%r2)
143 vfeebs %v17,%v16,%v18
144 jl .Lfound48
145
146 aghi %r5,64
147 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
148 aghi %r0,64
149 clgrjl %r0,%r4,.Lloop64
150
151 j .Llt64
152 END(__memchr_vx)
153
154 # define memchr __memchr_c
155 # undef libc_hidden_builtin_def
156 # define libc_hidden_builtin_def(name) strong_alias(__memchr_c, __GI_memchr)
157 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
158
159 #include <memchr.S>