1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 ARM Ltd.
4 * Copyright (C) 2013 Linaro.
6 * This code is based on glibc cortex strings work originally authored by Linaro
9 * http://bazaar.launchpad.net/~linaro-toolchain-dev/cortex-strings/trunk/
10 * files/head:/src/aarch64/
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
15 #include <asm/cache.h>
18 * Fill in the buffer with character c (alignment handled by the hardware)
48 mov dst, dstin /* Preserve return value. */
50 orr A_lw, A_lw, A_lw, lsl #8
51 orr A_lw, A_lw, A_lw, lsl #16
52 orr A_l, A_l, A_l, lsl #32
56 /*All store maybe are non-aligned..*/
72 /*Whether the start address is aligned with 16.*/
77 * The count is not less than 16, we can use stp to store the start 16 bytes,
78 * then adjust the dst aligned with 16.This process will make the current
79 * memory address at alignment boundary.
81 stp A_l, A_l, [dst] /*non-aligned store..*/
82 /*make the dst aligned..*/
83 sub count, count, tmp2
93 ands tmp1, count, #0x30
98 stp A_l, A_l, [dst], #16
100 stp A_l, A_l, [dst], #16
102 stp A_l, A_l, [dst], #16
104 * The last store length is less than 16,use stp to write last 16 bytes.
105 * It will lead some bytes written twice and the access is non-aligned.
108 ands count, count, #15
111 stp A_l, A_l, [dst, #-16] /* Repeat some/all of last store. */
116 * Critical loop. Start at a new cache line boundary. Assuming
117 * 64 bytes per line, this ensures the entire loop is in one line.
119 .p2align L1_CACHE_SHIFT
121 sub dst, dst, #16/* Pre-bias. */
122 sub count, count, #64
124 stp A_l, A_l, [dst, #16]
125 stp A_l, A_l, [dst, #32]
126 stp A_l, A_l, [dst, #48]
127 stp A_l, A_l, [dst, #64]!
128 subs count, count, #64
137 * For zeroing memory, check to see if we can use the ZVA feature to
138 * zero entire 'cache' lines.
144 * For zeroing small amounts of memory, it's not worth setting up
145 * the line-clear code.
148 b.lt .Lnot_short /*count is at least 128 bytes*/
151 tbnz tmp1, #4, .Lnot_short
153 and zva_len, tmp1w, #15 /* Safety: other bits reserved. */
154 lsl zva_len, tmp3w, zva_len
156 ands tmp3w, zva_len, #63
158 * ensure the zva_len is not less than 64.
159 * It is not meaningful to use ZVA if the block size is less than 64.
164 * Compute how far we need to go to become suitably aligned. We're
165 * already at quad-word alignment.
168 b.lt .Lnot_short /* Not enough to reach alignment. */
169 sub zva_bits_x, zva_len_x, #1
171 ands tmp2, tmp2, zva_bits_x
172 b.eq 2f /* Already aligned. */
173 /* Not aligned, check that there's enough to copy after alignment.*/
174 sub tmp1, count, tmp2
176 * grantee the remain length to be ZVA is bigger than 64,
177 * avoid to make the 2f's process over mem range.*/
179 ccmp tmp1, zva_len_x, #8, ge /* NZCV=0b1000 */
182 * We know that there's at least 64 bytes to zero and that it's safe
183 * to overrun by 64 bytes.
188 stp A_l, A_l, [dst, #16]
189 stp A_l, A_l, [dst, #32]
191 stp A_l, A_l, [dst, #48]
194 /* We've overrun a bit, so adjust dst downwards.*/
197 sub count, count, zva_len_x
200 add dst, dst, zva_len_x
201 subs count, count, zva_len_x
203 ands count, count, zva_bits_x
204 b.ne .Ltail_maybe_long
207 EXPORT_SYMBOL(memset)
209 EXPORT_SYMBOL(__memset)