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>
7 #include <asm/export.h>
12 * ISO C memset - set a memory block to a byte value. This function uses fast
13 * string to get better performance than the original function. The code is
14 * simpler and shorter than the original function as well.
20 * rax original destination
25 * Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
26 * to use it when possible. If not available, use fast string instructions.
28 * Otherwise, use original memset function.
30 ALTERNATIVE_2 "jmp memset_orig", "", X86_FEATURE_REP_GOOD, \
31 "jmp memset_erms", X86_FEATURE_ERMS
37 /* expand byte value */
39 movabs $0x0101010101010101,%rax
49 EXPORT_SYMBOL(__memset)
52 * ISO C memset - set a memory block to a byte value. This function uses
53 * enhanced rep stosb to override the fast string function.
54 * The code is simpler and shorter than the fast string function as well.
60 * rax original destination
74 /* expand byte value */
76 movabs $0x0101010101010101,%rax
83 .Lafter_bad_alignment:
103 /* Handle tail in loops. The loops should be faster than hard
104 to predict jump tables. */
135 movq %rax,(%rdi) /* unaligned store */
140 jmp .Lafter_bad_alignment