xref: /openbmc/linux/arch/x86/lib/clear_page_64.S (revision d7a3d85e)
1#include <linux/linkage.h>
2#include <asm/dwarf2.h>
3#include <asm/cpufeature.h>
4#include <asm/alternative-asm.h>
5
6/*
7 * Most CPUs support enhanced REP MOVSB/STOSB instructions. It is
8 * recommended to use this when possible and we do use them by default.
9 * If enhanced REP MOVSB/STOSB is not available, try to use fast string.
10 * Otherwise, use original.
11 */
12
13/*
14 * Zero a page.
15 * %rdi	- page
16 */
17ENTRY(clear_page)
18	CFI_STARTPROC
19
20	ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \
21		      "jmp clear_page_c_e", X86_FEATURE_ERMS
22
23	movl $4096/8,%ecx
24	xorl %eax,%eax
25	rep stosq
26	ret
27	CFI_ENDPROC
28ENDPROC(clear_page)
29
30ENTRY(clear_page_orig)
31	CFI_STARTPROC
32
33	xorl   %eax,%eax
34	movl   $4096/64,%ecx
35	.p2align 4
36.Lloop:
37	decl	%ecx
38#define PUT(x) movq %rax,x*8(%rdi)
39	movq %rax,(%rdi)
40	PUT(1)
41	PUT(2)
42	PUT(3)
43	PUT(4)
44	PUT(5)
45	PUT(6)
46	PUT(7)
47	leaq	64(%rdi),%rdi
48	jnz	.Lloop
49	nop
50	ret
51	CFI_ENDPROC
52ENDPROC(clear_page_orig)
53
54ENTRY(clear_page_c_e)
55	CFI_STARTPROC
56	movl $4096,%ecx
57	xorl %eax,%eax
58	rep stosb
59	ret
60	CFI_ENDPROC
61ENDPROC(clear_page_c_e)
62