memcpy.S 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include "_glibc_inc.h"
  18. /* BEWARE: `#ifdef memcpy' means that memcpy is redefined as `mempcpy',
  19. and the return value is the byte after the last one copied in
  20. the destination. */
  21. #define MEMPCPY_P (defined memcpy)
  22. .text
  23. #if defined __PIC__ && !defined NOT_IN_libc && defined __UCLIBC_HAS_FORTIFY__
  24. ENTRY (__memcpy_chk)
  25. cmpq %rdx, %rcx
  26. jb HIDDEN_JUMPTARGET (__chk_fail)
  27. END (__memcpy_chk)
  28. #endif
  29. ENTRY (BP_SYM (memcpy))
  30. /* Cutoff for the big loop is a size of 32 bytes since otherwise
  31. the loop will never be entered. */
  32. cmpq $32, %rdx
  33. movq %rdx, %rcx
  34. #if !MEMPCPY_P
  35. movq %rdi, %r10 /* Save value. */
  36. #endif
  37. /* We need this in any case. */
  38. cld
  39. jbe 1f
  40. /* Align destination. */
  41. movq %rdi, %rax
  42. negq %rax
  43. andq $7, %rax
  44. subq %rax, %rcx
  45. xchgq %rax, %rcx
  46. rep; movsb
  47. movq %rax, %rcx
  48. subq $32, %rcx
  49. js 2f
  50. /* Next 3 insns are 11 bytes total, make sure we decode them in one go */
  51. .p2align 4,,11
  52. 3:
  53. /* Now correct the loop counter. Please note that in the following
  54. code the flags are not changed anymore. */
  55. subq $32, %rcx
  56. movq (%rsi), %rax
  57. movq 8(%rsi), %rdx
  58. movq 16(%rsi), %r8
  59. movq 24(%rsi), %r9
  60. movq %rax, (%rdi)
  61. movq %rdx, 8(%rdi)
  62. movq %r8, 16(%rdi)
  63. movq %r9, 24(%rdi)
  64. leaq 32(%rsi), %rsi
  65. leaq 32(%rdi), %rdi
  66. jns 3b
  67. /* Correct extra loop counter modification. */
  68. 2: addq $32, %rcx
  69. 1: rep; movsb
  70. #if MEMPCPY_P
  71. movq %rdi, %rax /* Set return value. */
  72. #else
  73. movq %r10, %rax /* Set return value. */
  74. #endif
  75. ret
  76. END (BP_SYM (memcpy))
  77. #if !MEMPCPY_P
  78. libc_hidden_def(memcpy)
  79. #endif