memmove.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* memmove.S: Simple memmove implementation.
  3. *
  4. * Copyright (C) 1997, 2004 David S. Miller (davem@redhat.com)
  5. * Copyright (C) 1996, 1997, 1998, 1999 Jakub Jelinek (jj@ultra.linux.cz)
  6. */
  7. #include <linux/linkage.h>
  8. #include <asm/export.h>
  9. .text
  10. ENTRY(memmove) /* o0=dst o1=src o2=len */
  11. brz,pn %o2, 99f
  12. mov %o0, %g1
  13. cmp %o0, %o1
  14. bleu,pt %xcc, 2f
  15. add %o1, %o2, %g7
  16. cmp %g7, %o0
  17. bleu,pt %xcc, memcpy
  18. add %o0, %o2, %o5
  19. sub %g7, 1, %o1
  20. sub %o5, 1, %o0
  21. 1: ldub [%o1], %g7
  22. subcc %o2, 1, %o2
  23. sub %o1, 1, %o1
  24. stb %g7, [%o0]
  25. bne,pt %icc, 1b
  26. sub %o0, 1, %o0
  27. 99:
  28. retl
  29. mov %g1, %o0
  30. /* We can't just call memcpy for these memmove cases. On some
  31. * chips the memcpy uses cache initializing stores and when dst
  32. * and src are close enough, those can clobber the source data
  33. * before we've loaded it in.
  34. */
  35. 2: or %o0, %o1, %g7
  36. or %o2, %g7, %g7
  37. andcc %g7, 0x7, %g0
  38. bne,pn %xcc, 4f
  39. nop
  40. 3: ldx [%o1], %g7
  41. add %o1, 8, %o1
  42. subcc %o2, 8, %o2
  43. add %o0, 8, %o0
  44. bne,pt %icc, 3b
  45. stx %g7, [%o0 - 0x8]
  46. ba,a,pt %xcc, 99b
  47. 4: ldub [%o1], %g7
  48. add %o1, 1, %o1
  49. subcc %o2, 1, %o2
  50. add %o0, 1, %o0
  51. bne,pt %icc, 4b
  52. stb %g7, [%o0 - 0x1]
  53. ba,a,pt %xcc, 99b
  54. ENDPROC(memmove)
  55. EXPORT_SYMBOL(memmove)