1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <linux/linkage.h>
3 #include <asm/export.h>
4 
5 /*
6  * Most CPUs support enhanced REP MOVSB/STOSB instructions. It is
7  * recommended to use this when possible and we do use them by default.
8  * If enhanced REP MOVSB/STOSB is not available, try to use fast string.
9  * Otherwise, use original.
10  */
11 
12 /*
13  * Zero a page.
14  * %rdi	- page
15  */
16 SYM_FUNC_START(clear_page_rep)
17 	movl $4096/8,%ecx
18 	xorl %eax,%eax
19 	rep stosq
20 	RET
21 SYM_FUNC_END(clear_page_rep)
22 EXPORT_SYMBOL_GPL(clear_page_rep)
23 
24 SYM_FUNC_START(clear_page_orig)
25 	xorl   %eax,%eax
26 	movl   $4096/64,%ecx
27 	.p2align 4
28 .Lloop:
29 	decl	%ecx
30 #define PUT(x) movq %rax,x*8(%rdi)
31 	movq %rax,(%rdi)
32 	PUT(1)
33 	PUT(2)
34 	PUT(3)
35 	PUT(4)
36 	PUT(5)
37 	PUT(6)
38 	PUT(7)
39 	leaq	64(%rdi),%rdi
40 	jnz	.Lloop
41 	nop
42 	RET
43 SYM_FUNC_END(clear_page_orig)
44 EXPORT_SYMBOL_GPL(clear_page_orig)
45 
46 SYM_FUNC_START(clear_page_erms)
47 	movl $4096,%ecx
48 	xorl %eax,%eax
49 	rep stosb
50 	RET
51 SYM_FUNC_END(clear_page_erms)
52 EXPORT_SYMBOL_GPL(clear_page_erms)
53