blob: 65be7cfaf947228d454f2324541e5f5227d85183 [file] [log] [blame]
Jan Beulich8d379da2006-09-26 10:52:32 +02001#include <linux/linkage.h>
Borislav Petkovcd4d09e2016-01-26 22:12:04 +01002#include <asm/cpufeatures.h>
Fenghua Yue365c9d2011-05-17 15:29:14 -07003#include <asm/alternative-asm.h>
Jan Beulich8d379da2006-09-26 10:52:32 +02004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005/*
Borislav Petkov6620ef22015-01-18 12:57:41 +01006 * 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 */
16ENTRY(clear_page)
Borislav Petkov6620ef22015-01-18 12:57:41 +010017
18 ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \
19 "jmp clear_page_c_e", X86_FEATURE_ERMS
20
Jan Beulich8d379da2006-09-26 10:52:32 +020021 movl $4096/8,%ecx
22 xorl %eax,%eax
23 rep stosq
24 ret
Borislav Petkov6620ef22015-01-18 12:57:41 +010025ENDPROC(clear_page)
Jan Beulich8d379da2006-09-26 10:52:32 +020026
Borislav Petkov6620ef22015-01-18 12:57:41 +010027ENTRY(clear_page_orig)
Fenghua Yue365c9d2011-05-17 15:29:14 -070028
Andi Kleen7bcd3f32006-02-03 21:51:02 +010029 xorl %eax,%eax
30 movl $4096/64,%ecx
31 .p2align 4
32.Lloop:
33 decl %ecx
34#define PUT(x) movq %rax,x*8(%rdi)
35 movq %rax,(%rdi)
36 PUT(1)
37 PUT(2)
38 PUT(3)
39 PUT(4)
40 PUT(5)
41 PUT(6)
42 PUT(7)
43 leaq 64(%rdi),%rdi
44 jnz .Lloop
45 nop
46 ret
Borislav Petkov6620ef22015-01-18 12:57:41 +010047ENDPROC(clear_page_orig)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010048
Borislav Petkov6620ef22015-01-18 12:57:41 +010049ENTRY(clear_page_c_e)
Borislav Petkov6620ef22015-01-18 12:57:41 +010050 movl $4096,%ecx
51 xorl %eax,%eax
52 rep stosb
53 ret
Borislav Petkov6620ef22015-01-18 12:57:41 +010054ENDPROC(clear_page_c_e)