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.h>
7 #include <asm/export.h>
9 .section .noinstr.text, "ax"
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
22 * The FSRS alternative should be done inline (avoiding the call and
23 * the disgusting return handling), but that would require some help
24 * from the compiler for better calling conventions.
26 * The 'rep stosb' itself is small enough to replace the call, but all
27 * the register moves blow up the code. And two of them are "needed"
28 * only for the return value that is the same as the source input,
29 * which the compiler could/should do much better anyway.
31 SYM_FUNC_START(__memset)
32 ALTERNATIVE "jmp memset_orig", "", X86_FEATURE_FSRS
40 SYM_FUNC_END(__memset)
41 EXPORT_SYMBOL(__memset)
43 SYM_FUNC_ALIAS_MEMFUNC(memset, __memset)
46 SYM_FUNC_START_LOCAL(memset_orig)
49 /* expand byte value */
51 movabs $0x0101010101010101,%rax
58 .Lafter_bad_alignment:
78 /* Handle tail in loops. The loops should be faster than hard
79 to predict jump tables. */
110 movq %rax,(%rdi) /* unaligned store */
115 jmp .Lafter_bad_alignment
117 SYM_FUNC_END(memset_orig)