1 /* Copyright 2002 Andi Kleen, SuSE Labs */
3 #include <linux/linkage.h>
4 #include <asm/dwarf2.h>
5 #include <asm/cpufeature.h>
6 #include <asm/alternative-asm.h>
9 * ISO C memset - set a memory block to a byte value. This function uses fast
10 * string to get better performance than the original function. The code is
11 * simpler and shorter than the orignal function as well.
17 * rax original destination
19 .section .altinstr_replacement, "ax", @progbits
26 /* expand byte value */
28 movabs $0x0101010101010101,%rax
29 mulq %rsi /* with rax, clobbers rdx */
39 * ISO C memset - set a memory block to a byte value. This function uses
40 * enhanced rep stosb to override the fast string function.
41 * The code is simpler and shorter than the fast string function as well.
47 * rax original destination
49 .section .altinstr_replacement, "ax", @progbits
66 /* expand byte value */
68 movabs $0x0101010101010101,%rax
69 mul %rcx /* with rax, clobbers rdx */
76 .Lafter_bad_alignment:
96 /* Handle tail in loops. The loops should be faster than hard
97 to predict jump tables. */
130 movq %rax,(%rdi) /* unaligned store */
135 jmp .Lafter_bad_alignment
141 /* Some CPUs support enhanced REP MOVSB/STOSB feature.
142 * It is recommended to use this when possible.
144 * If enhanced REP MOVSB/STOSB feature is not available, use fast string
147 * Otherwise, use original memset function.
149 * In .altinstructions section, ERMS feature is placed after REG_GOOD
150 * feature to implement the right patch order.
152 .section .altinstructions,"a"
153 altinstruction_entry memset,.Lmemset_c,X86_FEATURE_REP_GOOD,\
154 .Lfinal-memset,.Lmemset_e-.Lmemset_c
155 altinstruction_entry memset,.Lmemset_c_e,X86_FEATURE_ERMS, \
156 .Lfinal-memset,.Lmemset_e_e-.Lmemset_c_e