]>
Commit | Line | Data |
---|---|---|
9b593dc3 | 1 | /* Vector optimized 32/64 bit S/390 version of memccpy. |
d614a753 | 2 | Copyright (C) 2015-2020 Free Software Foundation, Inc. |
9b593dc3 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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
9b593dc3 | 18 | |
196655ba SL |
19 | #include <ifunc-memccpy.h> |
20 | ||
21 | #if HAVE_MEMCCPY_Z13 | |
9b593dc3 SL |
22 | |
23 | # include "sysdep.h" | |
24 | # include "asm-syntax.h" | |
25 | ||
26 | .text | |
27 | ||
28 | /* void *memccpy (void * dest, const void *src, int c, size_t n) | |
29 | Copies no more than n bytes from src to dest, | |
30 | stopping when the character c is found | |
31 | and returns pointer next to c in dest or null if c not found. | |
32 | ||
33 | Register usage: | |
34 | -r0=tmp | |
35 | -r1=tmp | |
36 | -r2=dest | |
37 | -r3=src | |
38 | -r4=c | |
39 | -r5=n | |
40 | -r6=current_len | |
41 | -v16=part of s | |
42 | -v17=index of found c | |
43 | -v18=c replicated | |
44 | -v19=part #2 of s | |
45 | -v31=save area for r6 | |
46 | */ | |
196655ba | 47 | ENTRY(MEMCCPY_Z13) |
9b593dc3 SL |
48 | .machine "z13" |
49 | .machinemode "zarch_nohighgprs" | |
50 | ||
51 | # if !defined __s390x__ | |
52 | llgfr %r5,%r5 | |
53 | # endif /* !defined __s390x__ */ | |
54 | ||
55 | vlvgp %v31,%r6,%r7 /* Save registers. */ | |
56 | clgije %r5,0,.Lnf_end /* If len == 0 then exit. */ | |
57 | ||
58 | vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */ | |
59 | lcbb %r0,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */ | |
60 | llgfr %r0,%r0 /* Convert 32bit to 64bit. */ | |
61 | ||
62 | vlvgb %v18,%r4,0 /* Generate vector which elements are all c. | |
63 | if c > 255, c will be truncated. */ | |
64 | vrepb %v18,%v18,0 | |
65 | lghi %r6,0 /* current_len = 0. */ | |
66 | ||
67 | clgrjle %r5,%r0,.Lremaining_v16 /* If maxlen <= loaded-bytes | |
68 | -> Process remaining. */ | |
69 | ||
70 | vfeebs %v17,%v16,%v18 /* Find c. */ | |
71 | vlgvb %r1,%v17,7 /* Load byte index of c. */ | |
72 | clgrjl %r1,%r0,.Lfound_v16 /* Found c is within loaded bytes. */ | |
73 | ||
74 | /* Align s to 16 byte. */ | |
75 | risbgn %r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */ | |
76 | lghi %r6,15 /* current_len = 15. */ | |
77 | slr %r6,%r1 /* Compute highest index to 16byte boundary. */ | |
78 | ||
79 | vstl %v16,%r6,0(%r2) /* Store prcessed bytes */ | |
80 | ahi %r6,1 | |
81 | ||
82 | .Lpreloop1: | |
83 | /* Now we are 16byte aligned, so we can load | |
84 | a full vreg without page fault. */ | |
85 | vl %v16,0(%r6,%r3) /* Load s. */ | |
86 | clgijl %r5,17,.Lremaining_v16 /* If n <= 16, | |
87 | process remaining bytes. */ | |
88 | lgr %r7,%r5 | |
89 | slgfi %r7,16 /* border_len = n - 16. */ | |
90 | j .Lloop1 | |
91 | ||
92 | .Lloop2: | |
93 | vl %v16,16(%r6,%r3) | |
94 | vst %v19,0(%r6,%r2) | |
95 | aghi %r6,16 | |
96 | ||
97 | .Lloop1: | |
98 | clgrjhe %r6,%r7,.Lremaining_v16 /* If current_len >= border | |
99 | then process remaining bytes. */ | |
100 | vfeebs %v17,%v16,%v18 /* Find c. */ | |
101 | jl .Lfound_v16 /* Jump away if c was found. */ | |
102 | vl %v19,16(%r6,%r3) /* Load next s part. */ | |
103 | vst %v16,0(%r6,%r2) /* Store previous part without c. */ | |
104 | aghi %r6,16 | |
105 | ||
106 | clgrjhe %r6,%r7,.Lremaining_v19 | |
107 | vfeebs %v17,%v19,%v18 | |
108 | jl .Lfound_v19 | |
109 | vl %v16,16(%r6,%r3) | |
110 | vst %v19,0(%r6,%r2) | |
111 | aghi %r6,16 | |
112 | ||
113 | clgrjhe %r6,%r7,.Lremaining_v16 | |
114 | vfeebs %v17,%v16,%v18 | |
115 | jl .Lfound_v16 | |
116 | vl %v19,16(%r6,%r3) | |
117 | vst %v16,0(%r6,%r2) | |
118 | aghi %r6,16 | |
119 | ||
120 | clgrjhe %r6,%r7,.Lremaining_v19 | |
121 | vfeebs %v17,%v19,%v18 | |
122 | jo .Lloop2 | |
123 | ||
124 | .Lfound_v19: | |
125 | vlr %v16,%v19 | |
126 | .Lfound_v16: | |
127 | /* v16 contains c. Store remaining bytes to c. currlen hasnĀ“t | |
128 | reached border, thus checking for maxlen is not needed! */ | |
129 | vlgvb %r1,%v17,7 /* Load byte index of c. */ | |
130 | la %r2,0(%r6,%r2) /* vstl has no support for index-register. */ | |
131 | .Lfound_v16_store: | |
132 | vstl %v16,%r1,0(%r2) /* Copy bytes including c. */ | |
133 | la %r2,1(%r1,%r2) /* Return pointer next to c in dest. */ | |
134 | vlgvg %r6,%v31,0 | |
135 | vlgvg %r7,%v31,1 | |
136 | br %r14 | |
137 | ||
138 | .Lremaining_v19: | |
139 | vlr %v16,%v19 | |
140 | .Lremaining_v16: | |
141 | /* v16 contains the remaining bytes [1...16]. | |
142 | Check and store remaining bytes. */ | |
143 | vfeebs %v17,%v16,%v18 | |
144 | slgrk %r7,%r5,%r6 /* Remaining bytes = maxlen - current_len. */ | |
145 | aghi %r7,-1 /* vstl needs highest index. */ | |
146 | la %r2,0(%r6,%r2) /* vstl has no index register. */ | |
147 | vlgvb %r1,%v17,7 /* Load index of c or 16 if not found. */ | |
148 | /* c in remaining bytes? -> Jump away (c-index <= max-index) */ | |
149 | clrjle %r1,%r7,.Lfound_v16_store | |
150 | vstl %v16,%r7,0(%r2) /* Store remaining bytes. */ | |
151 | ||
152 | .Lnf_end: | |
153 | vlgvg %r6,%v31,0 | |
154 | vlgvg %r7,%v31,1 | |
155 | lghi %r2,0 /* Return null. */ | |
156 | br %r14 | |
196655ba SL |
157 | END(MEMCCPY_Z13) |
158 | ||
159 | # if ! HAVE_MEMCCPY_IFUNC | |
160 | strong_alias (MEMCCPY_Z13, __memccpy) | |
161 | weak_alias (__memccpy, memccpy) | |
162 | # endif | |
163 | ||
164 | #endif /* HAVE_MEMCCPY_Z13 */ |