]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/s390/multiarch/wmemchr-vx.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / s390 / multiarch / wmemchr-vx.S
CommitLineData
88eefd34 1/* Vector optimized 32/64 bit S/390 version of wmemchr.
688903eb 2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
88eefd34
SL
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/* wchar_t *wmemchr (const wchar_t *s, wchar_t 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*/
41ENTRY(__wmemchr_vx)
42 .machine "z13"
43 .machinemode "zarch_nohighgprs"
44
45# if !defined __s390x__
46 llgfr %r4,%r4
47# endif /* !defined __s390x__ */
48
49 clgije %r4,0,.Lnf_end /* If len == 0 then exit. */
50
51 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
52 lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
53 llgfr %r0,%r0 /* Convert 32bit to 64bit. */
54
55 tmll %r2,3 /* Test if s is 4-byte aligned? */
56 jne .Lfallback /* And use common-code variant if not. */
57
58 vlvgf %v18,%r3,0 /* Generate vector which elements are all c. */
59 vrepf %v18,%v18,0
60 lghi %r5,16 /* current_len = 16. */
61
62 /* Check range of maxlen and convert to byte-count. */
63# ifdef __s390x__
64 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
65 lghi %r1,-4 /* Max byte-count is 18446744073709551612. */
66# else
67 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
68 llilf %r1,4294967292 /* Max byte-count is 4294967292. */
69# endif /* !__s390x__ */
70 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
71 locgrne %r4,%r1 /* Use max byte-count, if bit 0/1 was one. */
72
73 clgrjhe %r0,%r4,.Llastcmp /* If (bytes to boundary) >= n,
74 jump to lastcmp. */
75
76 vfeefs %v17,%v16,%v18 /* Find c. */
77 vlgvb %r1,%v17,7 /* Load byte index of c. */
78 clgrjl %r1,%r0,.Lfound2 /* Found c is within loaded bytes. */
79
80 /* Align s to 16 byte. */
81 risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
82 slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
83
84 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
85 aghi %r0,64
86 clgrjl %r0,%r4,.Lloop64
87.Llt64:
88 vl %v16,0(%r5,%r2)
89 aghi %r5,16
90 clgrjhe %r5,%r4,.Llastcmp /* Do last compare if curr-len >= n. */
91 vfeefs %v17,%v16,%v18 /* Find c. */
92 jl .Lfound /* Jump away if c was found. */
93
94 vl %v16,0(%r5,%r2)
95 aghi %r5,16
96 clgrjhe %r5,%r4,.Llastcmp
97 vfeefs %v17,%v16,%v18
98 jl .Lfound
99
100 vl %v16,0(%r5,%r2)
101 aghi %r5,16
102 clgrjhe %r5,%r4,.Llastcmp
103 vfeefs %v17,%v16,%v18
104 jl .Lfound
105
106 vl %v16,0(%r5,%r2)
107 aghi %r5,16
108
109.Llastcmp:
110 /* Use comparision result only if located within first n characters.
111 %r5: current_len;
112 %r4: n;
113 (current_len - n): [0...16[
114 first ignored match index = vr-width - (current_len - n) ]0...16]
115 */
116 vfeefs %v17,%v16,%v18 /* Find c. */
117 slgrk %r4,%r5,%r4 /* %r5 = current_len - n. */
118 lghi %r0,16 /* Register width = 16. */
119 vlgvb %r1,%v17,7 /* Extract found index or 16 if all equal. */
120 slr %r0,%r4 /* %r0 = first ignored match index. */
121 clrjl %r1,%r0,.Lfound2 /* Go away if miscompare is below n bytes. */
122 /* c not found within n-bytes. */
123.Lnf_end:
124 lghi %r2,0 /* Return null. */
125 br %r14
126
127.Lfound48:
128 aghi %r5,16
129.Lfound32:
130 aghi %r5,16
131.Lfound16:
132 aghi %r5,16
133.Lfound0:
134 aghi %r5,16
135.Lfound:
136 vlgvb %r1,%v17,7 /* Load byte index of c. */
137.Lfound2:
138 slgfi %r5,16 /* current_len -=16 */
139 algr %r5,%r1 /* Zero byte index is added to current len. */
140 la %r2,0(%r5,%r2) /* Return pointer to c. */
141 br %r14
142
143.Lloop64:
144 vl %v16,0(%r5,%r2)
145 vfeefs %v17,%v16,%v18 /* Find c. */
146 jl .Lfound0 /* Jump away if c was found. */
147 vl %v16,16(%r5,%r2)
148 vfeefs %v17,%v16,%v18
149 jl .Lfound16
150 vl %v16,32(%r5,%r2)
151 vfeefs %v17,%v16,%v18
152 jl .Lfound32
153 vl %v16,48(%r5,%r2)
154 vfeefs %v17,%v16,%v18
155 jl .Lfound48
156
157 aghi %r5,64
158 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
159 aghi %r0,64
160 clgrjl %r0,%r4,.Lloop64
161
162 j .Llt64
163.Lfallback:
164 jg __wmemchr_c
165END(__wmemchr_vx)
166#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */