memcpy.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Highly optimized version for x86-64.
  2. Copyright (C) 1997, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Based on i586 version contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "_glibc_inc.h"
  17. /* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
  18. and the return value is the byte after the last one copied in
  19. the destination. */
  20. #define MEMPCPY_P (defined memcpy)
  21. .text
  22. ENTRY (BP_SYM (memcpy))
  23. /* Cutoff for the big loop is a size of 32 bytes since otherwise
  24. the loop will never be entered. */
  25. cmpq $32, %rdx
  26. movq %rdx, %rcx
  27. #if !MEMPCPY_P
  28. movq %rdi, %r10 /* Save value. */
  29. #endif
  30. /* We need this in any case. */
  31. cld
  32. jbe 1f
  33. /* Align destination. */
  34. movq %rdi, %rax
  35. negq %rax
  36. andq $7, %rax
  37. subq %rax, %rcx
  38. xchgq %rax, %rcx
  39. rep; movsb
  40. movq %rax, %rcx
  41. subq $32, %rcx
  42. js 2f
  43. /* Next 3 insns are 11 bytes total, make sure we decode them in one go */
  44. .p2align 4,,11
  45. 3:
  46. /* Now correct the loop counter. Please note that in the following
  47. code the flags are not changed anymore. */
  48. subq $32, %rcx
  49. movq (%rsi), %rax
  50. movq 8(%rsi), %rdx
  51. movq 16(%rsi), %r8
  52. movq 24(%rsi), %r9
  53. movq %rax, (%rdi)
  54. movq %rdx, 8(%rdi)
  55. movq %r8, 16(%rdi)
  56. movq %r9, 24(%rdi)
  57. leaq 32(%rsi), %rsi
  58. leaq 32(%rdi), %rdi
  59. jns 3b
  60. /* Correct extra loop counter modification. */
  61. 2: addq $32, %rcx
  62. 1: rep; movsb
  63. #if MEMPCPY_P
  64. movq %rdi, %rax /* Set return value. */
  65. #else
  66. movq %r10, %rax /* Set return value. */
  67. #endif
  68. ret
  69. END (BP_SYM (memcpy))
  70. #if !MEMPCPY_P
  71. libc_hidden_def(memcpy)
  72. #endif