1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright 2002 Andi Kleen, SuSE Labs */
4 #include <linux/linkage.h>
5 #include <asm/cpufeatures.h>
6 #include <asm/alternative-asm.h>
11 * ISO C memset - set a memory block to a byte value. This function uses fast
12 * string to get better performance than the original function. The code is
13 * simpler and shorter than the original function as well.
19 * rax original destination
21 SYM_FUNC_START_ALIAS(memset)
22 SYM_FUNC_START(__memset)
24 * Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
25 * to use it when possible. If not available, use fast string instructions.
27 * Otherwise, use original memset function.
29 ALTERNATIVE_2 "jmp memset_orig", "", X86_FEATURE_REP_GOOD, \
30 "jmp memset_erms", X86_FEATURE_ERMS
36 /* expand byte value */
38 movabs $0x0101010101010101,%rax
45 SYM_FUNC_END(__memset)
46 SYM_FUNC_END_ALIAS(memset)
49 * ISO C memset - set a memory block to a byte value. This function uses
50 * enhanced rep stosb to override the fast string function.
51 * The code is simpler and shorter than the fast string function as well.
57 * rax original destination
59 SYM_FUNC_START(memset_erms)
66 SYM_FUNC_END(memset_erms)
68 SYM_FUNC_START(memset_orig)
71 /* expand byte value */
73 movabs $0x0101010101010101,%rax
80 .Lafter_bad_alignment:
100 /* Handle tail in loops. The loops should be faster than hard
101 to predict jump tables. */
132 movq %rax,(%rdi) /* unaligned store */
137 jmp .Lafter_bad_alignment
139 SYM_FUNC_END(memset_orig)