CopyMem.S 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #------------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
  4. # This program and the accompanying materials
  5. # are licensed and made available under the terms and conditions of the BSD License
  6. # which accompanies this distribution. The full text of the license may be found at
  7. # http://opensource.org/licenses/bsd-license.php.
  8. #
  9. # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. #
  12. # Module Name:
  13. #
  14. # CopyMem.asm
  15. #
  16. # Abstract:
  17. #
  18. # CopyMem function
  19. #
  20. # Notes:
  21. #
  22. #------------------------------------------------------------------------------
  23. ASM_GLOBAL ASM_PFX(InternalMemCopyMem)
  24. #------------------------------------------------------------------------------
  25. # VOID *
  26. # EFIAPI
  27. # InternalMemCopyMem (
  28. # IN VOID *Destination,
  29. # IN VOID *Source,
  30. # IN UINTN Count
  31. # );
  32. #------------------------------------------------------------------------------
  33. ASM_PFX(InternalMemCopyMem):
  34. push %esi
  35. push %edi
  36. movl 16(%esp), %esi # esi <- Source
  37. movl 12(%esp), %edi # edi <- Destination
  38. movl 20(%esp), %edx # edx <- Count
  39. leal -1(%esi,%edx,), %eax # eax <- End of Source
  40. cmpl %edi, %esi
  41. jae L0
  42. cmpl %edi, %eax # Overlapped?
  43. jae L_CopyBackward # Copy backward if overlapped
  44. L0:
  45. xorl %ecx, %ecx
  46. subl %edi, %ecx
  47. andl $15, %ecx # ecx + edi aligns on 16-byte boundary
  48. jz L1
  49. cmpl %edx, %ecx
  50. cmova %edx, %ecx
  51. subl %ecx, %edx # edx <- remaining bytes to copy
  52. rep
  53. movsb
  54. L1:
  55. movl %edx, %ecx
  56. andl $15, %edx
  57. shrl $4, %ecx # ecx <- # of DQwords to copy
  58. jz L_CopyBytes
  59. addl $-16, %esp
  60. movdqu %xmm0, (%esp)
  61. L2:
  62. movdqu (%esi), %xmm0
  63. movntdq %xmm0, (%edi)
  64. addl $16, %esi
  65. addl $16, %edi
  66. loop L2
  67. mfence
  68. movdqu (%esp),%xmm0
  69. addl $16, %esp # stack cleanup
  70. jmp L_CopyBytes
  71. L_CopyBackward:
  72. movl %eax, %esi # esi <- Last byte in Source
  73. leal -1(%edi,%edx,), %edi # edi <- Last byte in Destination
  74. std
  75. L_CopyBytes:
  76. movl %edx, %ecx
  77. rep
  78. movsb
  79. cld
  80. movl 12(%esp), %eax # eax <- Destination as return value
  81. pop %edi
  82. pop %esi
  83. ret