1 /* strcpy/stpcpy - copy a string returning pointer to start/end.
2 Copyright (C) 2013-2023 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 <https://www.gnu.org/licenses/>. */
19 /* To build as stpcpy, define BUILD_STPCPY before compiling this file.
21 To test the page crossing code path more thoroughly, compile with
22 -DSTRCPY_TEST_PAGE_CROSS - this will force all unaligned copies through
23 the slower entry path. This option is not intended for production use. */
29 * ARMv8-a, AArch64, Advanced SIMD.
56 # define STRCPY __stpcpy
57 # define IFSTPCPY(X,...) X,__VA_ARGS__
59 # define STRCPY strcpy
60 # define IFSTPCPY(X,...)
65 For each 16-byte chunk we calculate a 64-bit nibble mask value with four bits
66 per byte. We take 4 bits of every comparison byte with shift right and narrow
67 by 4 instruction. Since the bits in the nibble mask reflect the order in
68 which things occur in the original string, counting leading zeros identifies
69 exactly which byte matched. */
75 ld1 {vdata.16b}, [src]
76 cmeq vhas_nul.16b, vdata.16b, 0
78 shrn vend.8b, vhas_nul.8h, 4
84 cmeq vhas_nul.16b, vdata.16b, 0
85 shrn vend.8b, vhas_nul.8h, 4
87 cbz synd, L(start_loop)
94 add len, tmp, len, lsr 2
98 ldr dataq2, [srcin, tmp]
100 str dataq2, [dstin, tmp]
101 IFSTPCPY (add result, dstin, len)
112 ldr data2, [srcin, tmp]
114 str data2, [dstin, tmp]
115 IFSTPCPY (add result, dstin, len)
123 ldr dataw2, [srcin, tmp]
125 str dataw2, [dstin, tmp]
126 IFSTPCPY (add result, dstin, len)
134 strb wzr, [dstin, len]
135 IFSTPCPY (add result, dstin, len)
140 sub tmp, srcin, dstin
147 cmeq vhas_nul.16b, vdata.16b, 0
148 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b
150 cbnz synd, L(loopend)
151 str dataq, [dst, -16]
152 ldr dataq, [src, 32]!
153 cmeq vhas_nul.16b, vdata.16b, 0
154 umaxp vend.16b, vhas_nul.16b, vhas_nul.16b
159 shrn vend.8b, vhas_nul.8h, 4 /* 128->64 */
162 #ifndef __AARCH64EB__
168 ldr dataq, [dst, tmp]
170 IFSTPCPY (add result, dst, 15)
176 weak_alias (__stpcpy, stpcpy)
177 libc_hidden_def (__stpcpy)
178 libc_hidden_builtin_def (stpcpy)
180 libc_hidden_builtin_def (strcpy)