1 /* Copyright (C) 2018-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/>. */
20 #include "memset-reg.h"
23 # define MEMSET __memset_base64
26 /* To disable DC ZVA, set this threshold to 0. */
27 #ifndef DC_ZVA_THRESHOLD
28 # define DC_ZVA_THRESHOLD 512
33 * ARMv8-a, AArch64, unaligned accesses
37 ENTRY_ALIGN (MEMSET, 6)
43 bfi valw, valw, 16, 16
46 add dstend, dstin, count
53 /* Set 0..15 bytes. */
62 str valw, [dstend, -4]
67 strh valw, [dstend, -2]
71 /* Set 16..96 bytes. */
74 tbnz count, 6, L(set96)
75 stp val, val, [dstend, -16]
77 stp val, val, [dstin, 16]
78 stp val, val, [dstend, -32]
82 /* Set 64..96 bytes. Write 64 bytes from the start and
83 32 bytes from the end. */
85 stp val, val, [dstin, 16]
86 stp val, val, [dstin, 32]
87 stp val, val, [dstin, 48]
88 stp val, val, [dstend, -32]
89 stp val, val, [dstend, -16]
97 cmp count, DC_ZVA_THRESHOLD
101 /* Small-size or non-zero memset does not use DC ZVA. */
102 sub count, dstend, dst
105 * Adjust count and bias for loop. By substracting extra 1 from count,
106 * it is easy to use tbz instruction to check whether loop tailing
107 * count is less than 33 bytes, so as to bypass 2 unneccesary stps.
109 sub count, count, 64+16+1
112 /* Align loop on 16-byte boundary, this might be friendly to i-cache. */
116 1: stp val, val, [dst, 16]
117 stp val, val, [dst, 32]
118 stp val, val, [dst, 48]
119 stp val, val, [dst, 64]!
120 subs count, count, 64
123 tbz count, 5, 1f /* Remaining count is less than 33 bytes? */
124 stp val, val, [dst, 16]
125 stp val, val, [dst, 32]
126 1: stp val, val, [dstend, -32]
127 stp val, val, [dstend, -16]
133 stp val, val, [dst, 16]
134 stp val, val, [dst, 32]
135 stp val, val, [dst, 48]
139 * Previous memory writes might cross cache line boundary, and cause
140 * cache line partially dirty. Zeroing this kind of cache line using
141 * DC ZVA will incur extra cost, for it requires loading untouched
142 * part of the line from memory before zeoring.
144 * So, write the first 64 byte aligned block using stp to force
145 * fully dirty cache line.
147 stp val, val, [dst, 64]
148 stp val, val, [dst, 80]
149 stp val, val, [dst, 96]
150 stp val, val, [dst, 112]
152 sub count, dstend, dst
154 * Adjust count and bias for loop. By substracting extra 1 from count,
155 * it is easy to use tbz instruction to check whether loop tailing
156 * count is less than 33 bytes, so as to bypass 2 unneccesary stps.
158 sub count, count, 128+64+64+1
162 /* DC ZVA sets 64 bytes each time. */
165 subs count, count, 64
169 * Write the last 64 byte aligned block using stp to force fully
172 stp val, val, [dst, 0]
173 stp val, val, [dst, 16]
174 stp val, val, [dst, 32]
175 stp val, val, [dst, 48]
177 tbz count, 5, 1f /* Remaining count is less than 33 bytes? */
178 stp val, val, [dst, 64]
179 stp val, val, [dst, 80]
180 1: stp val, val, [dstend, -32]
181 stp val, val, [dstend, -16]
186 libc_hidden_builtin_def (MEMSET)