memcpy.S 2.4 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
  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. .p2align 4
  51. 3:
  52. /* Now correct the loop counter. Please note that in the following
  53. code the flags are not changed anymore. */
  54. subq $32, %rcx
  55. movq (%rsi), %rax
  56. movq 8(%rsi), %rdx
  57. movq 16(%rsi), %r8
  58. movq 24(%rsi), %r9
  59. movq %rax, (%rdi)
  60. movq %rdx, 8(%rdi)
  61. movq %r8, 16(%rdi)
  62. movq %r9, 24(%rdi)
  63. leaq 32(%rsi), %rsi
  64. leaq 32(%rdi), %rdi
  65. jns 3b
  66. /* Correct extra loop counter modification. */
  67. 2: addq $32, %rcx
  68. 1: rep; movsb
  69. #if MEMPCPY_P
  70. movq %rdi, %rax /* Set return value. */
  71. #else
  72. movq %r10, %rax /* Set return value. */
  73. #endif
  74. ret
  75. END (BP_SYM (memcpy))
  76. #if !MEMPCPY_P
  77. libc_hidden_def(memcpy)
  78. #endif