memcpy.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #if defined __UCLIBC_HAS_SSP__
  27. jb HIDDEN_JUMPTARGET (__chk_fail)
  28. #endif
  29. END (__memcpy_chk)
  30. #endif
  31. ENTRY (BP_SYM (memcpy))
  32. /* Cutoff for the big loop is a size of 32 bytes since otherwise
  33. the loop will never be entered. */
  34. cmpq $32, %rdx
  35. movq %rdx, %rcx
  36. #if !MEMPCPY_P
  37. movq %rdi, %r10 /* Save value. */
  38. #endif
  39. /* We need this in any case. */
  40. cld
  41. jbe 1f
  42. /* Align destination. */
  43. movq %rdi, %rax
  44. negq %rax
  45. andq $7, %rax
  46. subq %rax, %rcx
  47. xchgq %rax, %rcx
  48. rep; movsb
  49. movq %rax, %rcx
  50. subq $32, %rcx
  51. js 2f
  52. /* Next 3 insns are 11 bytes total, make sure we decode them in one go */
  53. .p2align 4,,11
  54. 3:
  55. /* Now correct the loop counter. Please note that in the following
  56. code the flags are not changed anymore. */
  57. subq $32, %rcx
  58. movq (%rsi), %rax
  59. movq 8(%rsi), %rdx
  60. movq 16(%rsi), %r8
  61. movq 24(%rsi), %r9
  62. movq %rax, (%rdi)
  63. movq %rdx, 8(%rdi)
  64. movq %r8, 16(%rdi)
  65. movq %r9, 24(%rdi)
  66. leaq 32(%rsi), %rsi
  67. leaq 32(%rdi), %rdi
  68. jns 3b
  69. /* Correct extra loop counter modification. */
  70. 2: addq $32, %rcx
  71. 1: rep; movsb
  72. #if MEMPCPY_P
  73. movq %rdi, %rax /* Set return value. */
  74. #else
  75. movq %r10, %rax /* Set return value. */
  76. #endif
  77. ret
  78. END (BP_SYM (memcpy))
  79. #if !MEMPCPY_P
  80. libc_hidden_def(memcpy)
  81. #endif