copy_page_64.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Written 2003 by Andi Kleen, based on a kernel by Evandro Menezes */
  2. #include <linux/linkage.h>
  3. #include <asm/dwarf2.h>
  4. #include <asm/alternative-asm.h>
  5. ALIGN
  6. copy_page_c:
  7. CFI_STARTPROC
  8. movl $4096/8,%ecx
  9. rep movsq
  10. ret
  11. CFI_ENDPROC
  12. ENDPROC(copy_page_c)
  13. /* Don't use streaming store because it's better when the target
  14. ends up in cache. */
  15. /* Could vary the prefetch distance based on SMP/UP */
  16. ENTRY(copy_page)
  17. CFI_STARTPROC
  18. subq $2*8,%rsp
  19. CFI_ADJUST_CFA_OFFSET 2*8
  20. movq %rbx,(%rsp)
  21. CFI_REL_OFFSET rbx, 0
  22. movq %r12,1*8(%rsp)
  23. CFI_REL_OFFSET r12, 1*8
  24. movl $(4096/64)-5,%ecx
  25. .p2align 4
  26. .Loop64:
  27. dec %rcx
  28. movq (%rsi), %rax
  29. movq 8 (%rsi), %rbx
  30. movq 16 (%rsi), %rdx
  31. movq 24 (%rsi), %r8
  32. movq 32 (%rsi), %r9
  33. movq 40 (%rsi), %r10
  34. movq 48 (%rsi), %r11
  35. movq 56 (%rsi), %r12
  36. prefetcht0 5*64(%rsi)
  37. movq %rax, (%rdi)
  38. movq %rbx, 8 (%rdi)
  39. movq %rdx, 16 (%rdi)
  40. movq %r8, 24 (%rdi)
  41. movq %r9, 32 (%rdi)
  42. movq %r10, 40 (%rdi)
  43. movq %r11, 48 (%rdi)
  44. movq %r12, 56 (%rdi)
  45. leaq 64 (%rsi), %rsi
  46. leaq 64 (%rdi), %rdi
  47. jnz .Loop64
  48. movl $5,%ecx
  49. .p2align 4
  50. .Loop2:
  51. decl %ecx
  52. movq (%rsi), %rax
  53. movq 8 (%rsi), %rbx
  54. movq 16 (%rsi), %rdx
  55. movq 24 (%rsi), %r8
  56. movq 32 (%rsi), %r9
  57. movq 40 (%rsi), %r10
  58. movq 48 (%rsi), %r11
  59. movq 56 (%rsi), %r12
  60. movq %rax, (%rdi)
  61. movq %rbx, 8 (%rdi)
  62. movq %rdx, 16 (%rdi)
  63. movq %r8, 24 (%rdi)
  64. movq %r9, 32 (%rdi)
  65. movq %r10, 40 (%rdi)
  66. movq %r11, 48 (%rdi)
  67. movq %r12, 56 (%rdi)
  68. leaq 64(%rdi),%rdi
  69. leaq 64(%rsi),%rsi
  70. jnz .Loop2
  71. movq (%rsp),%rbx
  72. CFI_RESTORE rbx
  73. movq 1*8(%rsp),%r12
  74. CFI_RESTORE r12
  75. addq $2*8,%rsp
  76. CFI_ADJUST_CFA_OFFSET -2*8
  77. ret
  78. .Lcopy_page_end:
  79. CFI_ENDPROC
  80. ENDPROC(copy_page)
  81. /* Some CPUs run faster using the string copy instructions.
  82. It is also a lot simpler. Use this when possible */
  83. #include <asm/cpufeature.h>
  84. .section .altinstr_replacement,"ax"
  85. 1: .byte 0xeb /* jmp <disp8> */
  86. .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
  87. 2:
  88. .previous
  89. .section .altinstructions,"a"
  90. altinstruction_entry copy_page, 1b, X86_FEATURE_REP_GOOD, \
  91. .Lcopy_page_end-copy_page, 2b-1b
  92. .previous