memmove.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright (c) 1990 The Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * This code is derived from locore.s.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. All advertising materials mentioning features or use of this software
  16. * must display the following acknowledgement:
  17. * This product includes software developed by the University of
  18. * California, Berkeley and its contributors.
  19. * 4. Neither the name of the University nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. */
  35. #include <machine/asm.h>
  36. /*
  37. * memmove (dst,src,cnt)
  38. * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
  39. */
  40. ENTRY(bcopy)
  41. xchgq %rdi,%rsi
  42. /* fall into memmove */
  43. ENTRY(memmove)
  44. movq %rdi,%r11 /* save dest */
  45. movq %rdx,%rcx
  46. movq %rdi,%rax
  47. subq %rsi,%rax
  48. cmpq %rcx,%rax /* overlapping? */
  49. jb 1f
  50. jmp 2f /* nope */
  51. ENTRY(memcpy)
  52. movq %rdi,%r11 /* save dest */
  53. movq %rdx,%rcx
  54. 2:
  55. shrq $3,%rcx /* copy by words */
  56. rep
  57. movsq
  58. movq %rdx,%rcx
  59. andq $7,%rcx /* any bytes left? */
  60. rep
  61. movsb
  62. movq %r11,%rax
  63. ret
  64. 1:
  65. addq %rcx,%rdi /* copy backwards. */
  66. addq %rcx,%rsi
  67. std
  68. andq $7,%rcx /* any fractional bytes? */
  69. decq %rdi
  70. decq %rsi
  71. rep
  72. movsb
  73. movq %rdx,%rcx /* copy remainder by words */
  74. shrq $3,%rcx
  75. subq $7,%rsi
  76. subq $7,%rdi
  77. rep
  78. movsq
  79. movq %r11,%rax
  80. cld
  81. ret