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
25 /* expand byte value */
27 movabs $0x0101010101010101,%rax
38 * ISO C memset - set a memory block to a byte value. This function uses
39 * enhanced rep stosb to override the fast string function.
40 * The code is simpler and shorter than the fast string function as well.
46 * rax original destination
48 .section .altinstr_replacement, "ax", @progbits
66 /* expand byte value */
68 movabs $0x0101010101010101,%rax
76 .Lafter_bad_alignment:
96 /* Handle tail in loops. The loops should be faster than hard
97 to predict jump tables. */
129 movq %rax,(%rdi) /* unaligned store */
134 jmp .Lafter_bad_alignment
140 /* Some CPUs support enhanced REP MOVSB/STOSB feature.
141 * It is recommended to use this when possible.
143 * If enhanced REP MOVSB/STOSB feature is not available, use fast string
146 * Otherwise, use original memset function.
148 * In .altinstructions section, ERMS feature is placed after REG_GOOD
149 * feature to implement the right patch order.
151 .section .altinstructions,"a"
152 altinstruction_entry __memset,.Lmemset_c,X86_FEATURE_REP_GOOD,\
153 .Lfinal-__memset,.Lmemset_e-.Lmemset_c
154 altinstruction_entry __memset,.Lmemset_c_e,X86_FEATURE_ERMS, \
155 .Lfinal-__memset,.Lmemset_e_e-.Lmemset_c_e