1 /* Vector optimized 32/64 bit S/390 version of memccpy.
2 Copyright (C) 2015-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <ifunc-memccpy.h>
24 # include "asm-syntax.h"
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.
49 .machinemode "zarch_nohighgprs"
51 # if !defined __s390x__
53 # endif /* !defined __s390x__ */
55 vlvgp %v31,%r6,%r7 /* Save registers. */
56 clgije %r5,0,.Lnf_end /* If len == 0 then exit. */
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. */
62 vlvgb %v18,%r4,0 /* Generate vector which elements are all c.
63 if c > 255, c will be truncated. */
65 lghi %r6,0 /* current_len = 0. */
67 clgrjle %r5,%r0,.Lremaining_v16 /* If maxlen <= loaded-bytes
68 -> Process remaining. */
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. */
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. */
79 vstl %v16,%r6,0(%r2) /* Store prcessed bytes */
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. */
89 slgfi %r7,16 /* border_len = n - 16. */
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. */
106 clgrjhe %r6,%r7,.Lremaining_v19
107 vfeebs %v17,%v19,%v18
113 clgrjhe %r6,%r7,.Lremaining_v16
114 vfeebs %v17,%v16,%v18
120 clgrjhe %r6,%r7,.Lremaining_v19
121 vfeebs %v17,%v19,%v18
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. */
132 vstl %v16,%r1,0(%r2) /* Copy bytes including c. */
133 la %r2,1(%r1,%r2) /* Return pointer next to c in dest. */
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. */
155 lghi %r2,0 /* Return null. */
159 # if ! HAVE_MEMCCPY_IFUNC
160 strong_alias (MEMCCPY_Z13, __memccpy)
161 weak_alias (__memccpy, memccpy)
164 #endif /* HAVE_MEMCCPY_Z13 */