memset.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * Fill in the buffer with character c (alignment handled by the hardware)
  20. *
  21. * Parameters:
  22. * x0 - buf
  23. * x1 - c
  24. * x2 - n
  25. * Returns:
  26. * x0 - buf
  27. */
  28. ENTRY(memset)
  29. mov x4, x0
  30. and w1, w1, #0xff
  31. orr w1, w1, w1, lsl #8
  32. orr w1, w1, w1, lsl #16
  33. orr x1, x1, x1, lsl #32
  34. subs x2, x2, #8
  35. b.mi 2f
  36. 1: str x1, [x4], #8
  37. subs x2, x2, #8
  38. b.pl 1b
  39. 2: adds x2, x2, #4
  40. b.mi 3f
  41. sub x2, x2, #4
  42. str w1, [x4], #4
  43. 3: adds x2, x2, #2
  44. b.mi 4f
  45. sub x2, x2, #2
  46. strh w1, [x4], #2
  47. 4: adds x2, x2, #1
  48. b.mi 5f
  49. strb w1, [x4]
  50. 5: ret
  51. ENDPROC(memset)