memset.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 1998-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /* Thumb requires excessive IT insns here. */
  15. #define NO_THUMB
  16. #include <sysdep.h>
  17. .text
  18. .syntax unified
  19. /* void *memset (dstpp, c, len) */
  20. ENTRY(memset)
  21. mov r3, r0
  22. cmp r2, #8
  23. bcc 2f @ less than 8 bytes to move
  24. 1:
  25. tst r3, #3 @ aligned yet?
  26. strbne r1, [r3], #1
  27. subne r2, r2, #1
  28. bne 1b
  29. and r1, r1, #255 @ clear any sign bits
  30. orr r1, r1, r1, lsl $8
  31. orr r1, r1, r1, lsl $16
  32. mov ip, r1
  33. 1:
  34. subs r2, r2, #8
  35. stmiacs r3!, {r1, ip} @ store up to 32 bytes per loop iteration
  36. subscs r2, r2, #8
  37. stmiacs r3!, {r1, ip}
  38. subscs r2, r2, #8
  39. stmiacs r3!, {r1, ip}
  40. subscs r2, r2, #8
  41. stmiacs r3!, {r1, ip}
  42. bcs 1b
  43. and r2, r2, #7
  44. 2:
  45. subs r2, r2, #1 @ store up to 4 bytes per loop iteration
  46. strbcs r1, [r3], #1
  47. subscs r2, r2, #1
  48. strbcs r1, [r3], #1
  49. subscs r2, r2, #1
  50. strbcs r1, [r3], #1
  51. subscs r2, r2, #1
  52. strbcs r1, [r3], #1
  53. bcs 2b
  54. DO_RET(lr)
  55. END(memset)
  56. libc_hidden_builtin_def (memset)