clear_page_64.S 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <linux/linkage.h>
  2. #include <asm/cpufeatures.h>
  3. #include <asm/alternative-asm.h>
  4. #include <asm/export.h>
  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. * Zero a page.
  13. * %rdi - page
  14. */
  15. ENTRY(clear_page)
  16. ALTERNATIVE_2 "jmp clear_page_orig", "", X86_FEATURE_REP_GOOD, \
  17. "jmp clear_page_c_e", X86_FEATURE_ERMS
  18. movl $4096/8,%ecx
  19. xorl %eax,%eax
  20. rep stosq
  21. ret
  22. ENDPROC(clear_page)
  23. EXPORT_SYMBOL(clear_page)
  24. ENTRY(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. ENDPROC(clear_page_orig)
  44. ENTRY(clear_page_c_e)
  45. movl $4096,%ecx
  46. xorl %eax,%eax
  47. rep stosb
  48. ret
  49. ENDPROC(clear_page_c_e)