]>
Commit | Line | Data |
---|---|---|
b3a0c176 | 1 | /* Vector optimized 32/64 bit S/390 version of stpncpy. |
f7a9f785 | 2 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
b3a0c176 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 | /* char * stpncpy (char *dest, const char *src, size_t n) | |
27 | Copies at most n characters of string src to dest | |
28 | returning a pointer to its end or dest+n | |
29 | if src is smaller than n. | |
30 | ||
31 | Register usage: | |
32 | -%r0 = return value | |
33 | -%r1 = zero byte index | |
34 | -%r2 = curr dst pointer | |
35 | -%r3 = curr src pointer | |
36 | -%r4 = n | |
37 | -%r5 = current_len | |
38 | -%r6 = loaded bytes | |
39 | -%r7 = border, tmp | |
40 | */ | |
41 | ENTRY(__stpncpy_vx) | |
42 | .machine "z13" | |
43 | .machinemode "zarch_nohighgprs" | |
44 | ||
45 | # if !defined __s390x__ | |
46 | llgfr %r4,%r4 | |
47 | # endif /* !defined __s390x__ */ | |
48 | ||
49 | clgfi %r4,0 | |
50 | ber %r14 /* Nothing to do, if n == 0. */ | |
51 | ||
52 | la %r0,0(%r4,%r2) /* Save destination pointer + n for return. */ | |
53 | vlvgp %v31,%r6,%r7 /* Save registers. */ | |
54 | ||
55 | vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */ | |
56 | lcbb %r6,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */ | |
57 | llgfr %r6,%r6 /* Convert 32bit to 64bit. */ | |
58 | ||
59 | lghi %r5,0 /* current_len = 0. */ | |
60 | ||
61 | clgrjle %r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes | |
62 | -> process remaining. */ | |
63 | ||
64 | /* n > loaded-byte-count */ | |
65 | vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */ | |
66 | vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */ | |
67 | clrjl %r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes, | |
68 | copy and return. */ | |
69 | ||
70 | /* Align s to 16 byte. */ | |
71 | risbgn %r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */ | |
72 | lghi %r5,15 /* current_len = 15. */ | |
73 | slr %r5,%r7 /* Compute highest index to 16byte boundary. */ | |
74 | ||
75 | /* Zero not found and n > loaded-byte-count. */ | |
76 | vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */ | |
77 | ahi %r5,1 /* Start loop at next character. */ | |
78 | ||
79 | /* Now we are 16byte aligned, so we can load a full vreg | |
80 | without page fault. */ | |
81 | lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */ | |
82 | aghi %r1,64 | |
83 | clgrjl %r1,%r4,.Lloop64 | |
84 | ||
85 | vl %v16,0(%r5,%r3) /* Load s. */ | |
86 | clgijl %r4,17,.Lremaining_v16 /* If n <= 16, process remaining | |
87 | bytes. */ | |
88 | .Llt64: | |
89 | lgr %r7,%r4 | |
90 | slgfi %r7,16 /* border_len = n - 16. */ | |
91 | ||
92 | clgrjhe %r5,%r7,.Lremaining_v16 /* If current_len >= border | |
93 | then process remaining bytes. */ | |
94 | vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */ | |
95 | je .Lfound_v16 /* Jump away if zero was found. */ | |
96 | vl %v18,16(%r5,%r3) /* Load next part of s. */ | |
97 | vst %v16,0(%r5,%r2) /* Save previous part without zero to dst. */ | |
98 | aghi %r5,16 | |
99 | ||
100 | clgrjhe %r5,%r7,.Lremaining_v18 | |
101 | vfenezbs %v17,%v18,%v18 | |
102 | je .Lfound_v18 | |
103 | vl %v16,16(%r5,%r3) | |
104 | vst %v18,0(%r5,%r2) | |
105 | aghi %r5,16 | |
106 | ||
107 | clgrjhe %r5,%r7,.Lremaining_v16 | |
108 | vfenezbs %v17,%v16,%v16 | |
109 | je .Lfound_v16 | |
110 | vl %v18,16(%r5,%r3) | |
111 | vst %v16,0(%r5,%r2) | |
112 | aghi %r5,16 | |
113 | ||
114 | .Lremaining_v18: | |
115 | vlr %v16,%v18 | |
116 | .Lremaining_v16: | |
117 | /* v16 contains the remaining bytes [1...16]. | |
118 | Store remaining bytes and append string-termination. */ | |
119 | vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */ | |
120 | slgrk %r7,%r4,%r5 /* Remaining bytes = maxlen - current_len */ | |
121 | aghi %r7,-1 /* vstl needs highest index. */ | |
122 | la %r2,0(%r5,%r2) /* vstl has no index register. */ | |
123 | vlgvb %r1,%v17,7 /* Load zero index or 16 if not found. */ | |
124 | /* Zero in remaining bytes? -> jump away (zero-index <= max-index). */ | |
125 | clrjle %r1,%r7,.Lfound_v16_store | |
126 | vstl %v16,%r7,0(%r2) /* Store remaining bytes without null | |
127 | termination! */ | |
128 | .Lend: | |
129 | /* Restore saved registers. */ | |
130 | vlgvg %r6,%v31,0 | |
131 | vlgvg %r7,%v31,1 | |
132 | lgr %r2,%r0 /* Load saved dest-ptr. */ | |
133 | br %r14 | |
134 | ||
135 | .Lfound_v16_32: | |
136 | aghi %r5,32 | |
137 | j .Lfound_v16 | |
138 | .Lfound_v18_48: | |
139 | aghi %r5,32 | |
140 | .Lfound_v18_16: | |
141 | aghi %r5,16 | |
142 | .Lfound_v18: | |
143 | vlr %v16,%v18 | |
144 | .Lfound_v16: | |
145 | /* v16 contains a zero. Store remaining bytes to zero. current_len | |
146 | has not reached border, thus checking for n is not needed! */ | |
147 | vlgvb %r1,%v17,7 /* Load byte index of zero. */ | |
148 | la %r2,0(%r5,%r2) /* vstl has no support for index-register. */ | |
149 | .Lfound_v16_store: | |
150 | vstl %v16,%r1,0(%r2) /* Copy characters including zero. */ | |
151 | /* Fill remaining bytes with zero - remaining count always > 0. */ | |
152 | algr %r5,%r1 /* Remaining bytes (=%r4) = ... */ | |
153 | slgr %r4,%r5 /* = maxlen - (currlen + zero_index + 1) */ | |
154 | la %r2,0(%r1,%r2) /* Pointer to zero. start filling beyond. */ | |
155 | lgr %r0,%r2 /* Save return-pointer to found zero. */ | |
156 | clgije %r4,1,.Lend /* Skip zero-filling, if found zero is last | |
157 | possible character. | |
158 | (1 is substracted from r4 below!). */ | |
159 | aghi %r4,-2 /* mvc with exrl needs count - 1. | |
160 | (additional -1, see remaining bytes above) */ | |
161 | srlg %r6,%r4,8 /* Split into 256 byte blocks. */ | |
162 | ltgr %r6,%r6 | |
163 | je .Lzero_lt256 | |
164 | .Lzero_loop256: | |
165 | mvc 1(256,%r2),0(%r2) /* Fill 256 zeros at once. */ | |
166 | la %r2,256(%r2) | |
167 | brctg %r6,.Lzero_loop256 /* Loop until all blocks are processed. */ | |
168 | .Lzero_lt256: | |
169 | exrl %r4,.Lmvc_lt256 | |
170 | j .Lend | |
171 | .Lmvc_lt256: | |
172 | mvc 1(1,%r2),0(%r2) | |
173 | ||
174 | .Lloop64: | |
175 | vl %v16,0(%r5,%r3) | |
176 | vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */ | |
177 | je .Lfound_v16 /* Jump away if zero was found. */ | |
178 | vl %v18,16(%r5,%r3) /* Load next part of s. */ | |
179 | vst %v16,0(%r5,%r2) /* Save previous part without zero to dst. */ | |
180 | vfenezbs %v17,%v18,%v18 | |
181 | je .Lfound_v18_16 | |
182 | vl %v16,32(%r5,%r3) | |
183 | vst %v18,16(%r5,%r2) | |
184 | vfenezbs %v17,%v16,%v16 | |
185 | je .Lfound_v16_32 | |
186 | vl %v18,48(%r5,%r3) | |
187 | vst %v16,32(%r5,%r2) | |
188 | vfenezbs %v17,%v18,%v18 | |
189 | je .Lfound_v18_48 | |
190 | vst %v18,48(%r5,%r2) | |
191 | ||
192 | aghi %r5,64 | |
193 | lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */ | |
194 | aghi %r1,64 | |
195 | clgrjl %r1,%r4,.Lloop64 | |
196 | ||
197 | vl %v16,0(%r5,%r3) /* Load s. */ | |
198 | j .Llt64 | |
199 | END(__stpncpy_vx) | |
200 | #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */ |