memmove.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2013 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/assembler.h>
  18. /*
  19. * Move a buffer from src to test (alignment handled by the hardware).
  20. * If dest <= src, call memcpy, otherwise copy in reverse order.
  21. *
  22. * Parameters:
  23. * x0 - dest
  24. * x1 - src
  25. * x2 - n
  26. * Returns:
  27. * x0 - dest
  28. */
  29. ENTRY(memmove)
  30. cmp x0, x1
  31. b.ls memcpy
  32. add x4, x0, x2
  33. add x1, x1, x2
  34. subs x2, x2, #8
  35. b.mi 2f
  36. 1: ldr x3, [x1, #-8]!
  37. subs x2, x2, #8
  38. str x3, [x4, #-8]!
  39. b.pl 1b
  40. 2: adds x2, x2, #4
  41. b.mi 3f
  42. ldr w3, [x1, #-4]!
  43. sub x2, x2, #4
  44. str w3, [x4, #-4]!
  45. 3: adds x2, x2, #2
  46. b.mi 4f
  47. ldrh w3, [x1, #-2]!
  48. sub x2, x2, #2
  49. strh w3, [x4, #-2]!
  50. 4: adds x2, x2, #1
  51. b.mi 5f
  52. ldrb w3, [x1, #-1]
  53. strb w3, [x4, #-1]
  54. 5: ret
  55. ENDPROC(memmove)