]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/s390/multiarch/wcsnlen-vx.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / s390 / multiarch / wcsnlen-vx.S
1 /* Vector optimized 32/64 bit S/390 version of wcsnlen.
2 Copyright (C) 2015-2018 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 /* size_t wcsnlen (const wchar_t *s, size_t maxlen)
27 Returns the number of characters in s or at most maxlen.
28
29 Register usage:
30 -r1=tmp
31 -r2=address of string
32 -r3=maxlen (number of characters to be read)
33 -r4=tmp
34 -r5=current_len and return_value
35 -v16=part of s
36 */
37 ENTRY(__wcsnlen_vx)
38
39 .machine "z13"
40 .machinemode "zarch_nohighgprs"
41
42 # if !defined __s390x__
43 llgfr %r3,%r3
44 # endif /* !defined __s390x__ */
45
46 clgfi %r3,0 /* if maxlen == 0, return 0. */
47 locgre %r2,%r3
48 ber %r14
49
50 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
51 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
52 llgfr %r1,%r1 /* Convert 32bit to 64bit. */
53
54 tmll %r2,3 /* Test if s is 4-byte aligned? */
55 jne .Lfallback /* And use common-code variant if not. */
56
57 /* Check range of maxlen and convert to byte-count. */
58 # ifdef __s390x__
59 tmhh %r3,49152 /* Test bit 0 or 1 of maxlen. */
60 lghi %r4,-4 /* Max byte-count is 18446744073709551612. */
61 # else
62 tmlh %r3,49152 /* Test bit 0 or 1 of maxlen. */
63 llilf %r4,4294967292 /* Max byte-count is 4294967292. */
64 # endif /* !__s390x__ */
65 sllg %r3,%r3,2 /* Convert character-count to byte-count. */
66 locgrne %r3,%r4 /* Use max byte-count, if bit 0/1 was one. */
67
68 vfenezf %v16,%v16,%v16 /* Find element not equal with zero search. */
69 clgr %r1,%r3
70 locgrh %r1,%r3 /* loaded_byte_count
71 = min (loaded_byte_count, maxlen) */
72
73 vlgvb %r5,%v16,7 /* Load zero index or 16 if not found. */
74 clrjl %r5,%r1,.Lend /* Found zero within loaded bytes -> return. */
75
76 clgr %r1,%r3 /* If loaded_byte_count == maxlen -> end. */
77 locgre %r5,%r3
78 je .Lend
79
80 /* Align s to 16 byte. */
81 risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
82 lghi %r5,16 /* current_len = 16. */
83 slr %r5,%r4 /* Compute bytes to 16bytes boundary. */
84
85 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
86 aghi %r1,64
87 clgrjl %r1,%r3,.Lloop64
88
89 /* Find zero in max 64byte with aligned s. */
90 .Llt64:
91 vl %v16,0(%r5,%r2) /* Load s. */
92 vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search. */
93 je .Lfound /* Jump away if zero was found. */
94 aghi %r5,16
95 clgrjhe %r5,%r3,.Lfound /* If current_len >= maxlen -> end. */
96 vl %v16,0(%r5,%r2)
97 vfenezfs %v16,%v16,%v16
98 je .Lfound
99 aghi %r5,16
100 clgrjhe %r5,%r3,.Lfound
101 vl %v16,0(%r5,%r2)
102 vfenezfs %v16,%v16,%v16
103 je .Lfound
104 aghi %r5,16
105 clgrjhe %r5,%r3,.Lfound
106 vl %v16,0(%r5,%r2)
107 vfenezfs %v16,%v16,%v16
108 j .Lfound
109
110 .Lfound48:
111 aghi %r5,16
112 .Lfound32:
113 aghi %r5,16
114 .Lfound16:
115 aghi %r5,16
116 .Lfound:
117 vlgvb %r4,%v16,7 /* Load byte index of zero or 16 if no zero. */
118 algr %r5,%r4
119
120 clgr %r5,%r3
121 locgrh %r5,%r3 /* Return min (current_len, maxlen). */
122 .Lend:
123 srlg %r2,%r5,2 /* Convert byte-count to character-count. */
124 br %r14
125
126 /* Find zero in 16byte aligned loop. */
127 .Lloop64:
128 vl %v16,0(%r5,%r2) /* Load s. */
129 vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search. */
130 je .Lfound /* Jump away if zero was found. */
131 vl %v16,16(%r5,%r2)
132 vfenezfs %v16,%v16,%v16
133 je .Lfound16
134 vl %v16,32(%r5,%r2)
135 vfenezfs %v16,%v16,%v16
136 je .Lfound32
137 vl %v16,48(%r5,%r2)
138 vfenezfs %v16,%v16,%v16
139 je .Lfound48
140
141 aghi %r5,64
142 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
143 aghi %r1,64
144 clgrjl %r1,%r3,.Lloop64
145
146 j .Llt64
147
148 .Lfallback:
149 jg __wcsnlen_c
150 END(__wcsnlen_vx)
151 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */