blob: e8508156c99d5e0a8f3aa8a6dc2ad659d59c021e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Written 2003 by Andi Kleen, based on a kernel by Evandro Menezes */
Dave Jones038b0a62006-10-04 03:38:54 -04002
Jan Beulich8d379da2006-09-26 10:52:32 +02003#include <linux/linkage.h>
Borislav Petkovcd4d09e2016-01-26 22:12:04 +01004#include <asm/cpufeatures.h>
Andy Lutomirski59e97e42011-07-13 09:24:10 -04005#include <asm/alternative-asm.h>
Al Viro784d5692016-01-11 11:04:34 -05006#include <asm/export.h>
Jan Beulich8d379da2006-09-26 10:52:32 +02007
Borislav Petkov090a3f62015-01-12 18:19:40 +01008/*
9 * Some CPUs run faster using the string copy instructions (sane microcode).
10 * It is also a lot simpler. Use this when possible. But, don't use streaming
11 * copy unless the CPU indicates X86_FEATURE_REP_GOOD. Could vary the
12 * prefetch distance based on SMP/UP.
13 */
Jan Beulich8d379da2006-09-26 10:52:32 +020014 ALIGN
Borislav Petkov090a3f62015-01-12 18:19:40 +010015ENTRY(copy_page)
Borislav Petkov090a3f62015-01-12 18:19:40 +010016 ALTERNATIVE "jmp copy_page_regs", "", X86_FEATURE_REP_GOOD
Ma Ling269833b2012-10-18 03:52:45 +080017 movl $4096/8, %ecx
18 rep movsq
Jan Beulich8d379da2006-09-26 10:52:32 +020019 ret
Borislav Petkov090a3f62015-01-12 18:19:40 +010020ENDPROC(copy_page)
Al Viro784d5692016-01-11 11:04:34 -050021EXPORT_SYMBOL(copy_page)
Jan Beulich8d379da2006-09-26 10:52:32 +020022
Borislav Petkov090a3f62015-01-12 18:19:40 +010023ENTRY(copy_page_regs)
Ma Ling269833b2012-10-18 03:52:45 +080024 subq $2*8, %rsp
Ma Ling269833b2012-10-18 03:52:45 +080025 movq %rbx, (%rsp)
Ma Ling269833b2012-10-18 03:52:45 +080026 movq %r12, 1*8(%rsp)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010027
Ma Ling269833b2012-10-18 03:52:45 +080028 movl $(4096/64)-5, %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010029 .p2align 4
30.Loop64:
Ma Ling269833b2012-10-18 03:52:45 +080031 dec %rcx
32 movq 0x8*0(%rsi), %rax
33 movq 0x8*1(%rsi), %rbx
34 movq 0x8*2(%rsi), %rdx
35 movq 0x8*3(%rsi), %r8
36 movq 0x8*4(%rsi), %r9
37 movq 0x8*5(%rsi), %r10
38 movq 0x8*6(%rsi), %r11
39 movq 0x8*7(%rsi), %r12
Andi Kleen7bcd3f32006-02-03 21:51:02 +010040
41 prefetcht0 5*64(%rsi)
42
Ma Ling269833b2012-10-18 03:52:45 +080043 movq %rax, 0x8*0(%rdi)
44 movq %rbx, 0x8*1(%rdi)
45 movq %rdx, 0x8*2(%rdi)
46 movq %r8, 0x8*3(%rdi)
47 movq %r9, 0x8*4(%rdi)
48 movq %r10, 0x8*5(%rdi)
49 movq %r11, 0x8*6(%rdi)
50 movq %r12, 0x8*7(%rdi)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010051
Ma Ling269833b2012-10-18 03:52:45 +080052 leaq 64 (%rsi), %rsi
53 leaq 64 (%rdi), %rdi
Andi Kleen7bcd3f32006-02-03 21:51:02 +010054
Ma Ling269833b2012-10-18 03:52:45 +080055 jnz .Loop64
Andi Kleen7bcd3f32006-02-03 21:51:02 +010056
Ma Ling269833b2012-10-18 03:52:45 +080057 movl $5, %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010058 .p2align 4
59.Loop2:
Ma Ling269833b2012-10-18 03:52:45 +080060 decl %ecx
Andi Kleen7bcd3f32006-02-03 21:51:02 +010061
Ma Ling269833b2012-10-18 03:52:45 +080062 movq 0x8*0(%rsi), %rax
63 movq 0x8*1(%rsi), %rbx
64 movq 0x8*2(%rsi), %rdx
65 movq 0x8*3(%rsi), %r8
66 movq 0x8*4(%rsi), %r9
67 movq 0x8*5(%rsi), %r10
68 movq 0x8*6(%rsi), %r11
69 movq 0x8*7(%rsi), %r12
Andi Kleen7bcd3f32006-02-03 21:51:02 +010070
Ma Ling269833b2012-10-18 03:52:45 +080071 movq %rax, 0x8*0(%rdi)
72 movq %rbx, 0x8*1(%rdi)
73 movq %rdx, 0x8*2(%rdi)
74 movq %r8, 0x8*3(%rdi)
75 movq %r9, 0x8*4(%rdi)
76 movq %r10, 0x8*5(%rdi)
77 movq %r11, 0x8*6(%rdi)
78 movq %r12, 0x8*7(%rdi)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010079
Ma Ling269833b2012-10-18 03:52:45 +080080 leaq 64(%rdi), %rdi
81 leaq 64(%rsi), %rsi
Andi Kleen7bcd3f32006-02-03 21:51:02 +010082 jnz .Loop2
83
Ma Ling269833b2012-10-18 03:52:45 +080084 movq (%rsp), %rbx
Ma Ling269833b2012-10-18 03:52:45 +080085 movq 1*8(%rsp), %r12
Ma Ling269833b2012-10-18 03:52:45 +080086 addq $2*8, %rsp
Andi Kleen7bcd3f32006-02-03 21:51:02 +010087 ret
Borislav Petkov090a3f62015-01-12 18:19:40 +010088ENDPROC(copy_page_regs)