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
64 /* expand byte value */
66 movabs $0x0101010101010101,%rax
74 .Lafter_bad_alignment:
94 /* Handle tail in loops. The loops should be faster than hard
95 to predict jump tables. */
127 movq %rax,(%rdi) /* unaligned store */
132 jmp .Lafter_bad_alignment
138 /* Some CPUs support enhanced REP MOVSB/STOSB feature.
139 * It is recommended to use this when possible.
141 * If enhanced REP MOVSB/STOSB feature is not available, use fast string
144 * Otherwise, use original memset function.
146 * In .altinstructions section, ERMS feature is placed after REG_GOOD
147 * feature to implement the right patch order.
149 .section .altinstructions,"a"
150 altinstruction_entry memset,.Lmemset_c,X86_FEATURE_REP_GOOD,\
151 .Lfinal-memset,.Lmemset_e-.Lmemset_c
152 altinstruction_entry memset,.Lmemset_c_e,X86_FEATURE_ERMS, \
153 .Lfinal-memset,.Lmemset_e_e-.Lmemset_c_e