memset.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Copyright (C) 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Philip Blundell <philb@gnu.org>
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <features.h>
  16. #include <bits/arm_asm.h>
  17. #include <bits/arm_bx.h>
  18. .text
  19. .global memset
  20. .type memset,%function
  21. .align 4
  22. #if defined(THUMB1_ONLY)
  23. .thumb_func
  24. memset:
  25. mov ip, r0
  26. cmp r2, #8 @ at least 8 bytes to do?
  27. bcc 2f
  28. and r1, r1, #0xFF
  29. lsl r3, r1, #8
  30. orr r1, r3
  31. lsl r3, r1, #16
  32. orr r1, r3
  33. mov r3, #3
  34. 1: @ Fill up to the first word boundary
  35. tst r0, r3
  36. beq 1f
  37. strb r1, [r0]
  38. add r0, r0, #1
  39. sub r2, r2, #1
  40. b 1b
  41. 1: @ Fill aligned words
  42. str r1, [r0]
  43. add r0, r0, #4
  44. sub r2, r2, #4
  45. cmp r2, #4
  46. bcs 1b
  47. 2: @ Fill the remaining bytes
  48. cmp r2, #0
  49. beq 2f
  50. 1:
  51. strb r1, [r0]
  52. add r0, r0, #1
  53. sub r2, r2, #1
  54. bne 1b
  55. 2:
  56. mov r0, ip
  57. bx lr
  58. #else
  59. memset:
  60. mov a4, a1
  61. cmp a3, $8 @ at least 8 bytes to do?
  62. blo 2f
  63. and a2, a2, #0xFF
  64. orr a2, a2, a2, lsl $8
  65. orr a2, a2, a2, lsl $16
  66. 1:
  67. tst a4, $3 @ aligned yet?
  68. #if defined(__thumb2__)
  69. itt ne
  70. strbne a2, [a4], $1
  71. subne a3, a3, $1
  72. #else
  73. strneb a2, [a4], $1
  74. subne a3, a3, $1
  75. #endif
  76. bne 1b
  77. mov ip, a2
  78. 1:
  79. cmp a3, $8 @ 8 bytes still to do?
  80. blo 2f
  81. stmia a4!, {a2, ip}
  82. sub a3, a3, $8
  83. cmp a3, $8 @ 8 bytes still to do?
  84. blo 2f
  85. stmia a4!, {a2, ip}
  86. sub a3, a3, $8
  87. cmp a3, $8 @ 8 bytes still to do?
  88. blo 2f
  89. stmia a4!, {a2, ip}
  90. sub a3, a3, $8
  91. cmp a3, $8 @ 8 bytes still to do?
  92. #if defined(__thumb2__)
  93. itt hs
  94. stmiahs a4!, {a2, ip}
  95. subhs a3, a3, $8
  96. #else
  97. stmhsia a4!, {a2, ip}
  98. subhs a3, a3, $8
  99. #endif
  100. bhs 1b
  101. 2:
  102. movs a3, a3 @ anything left?
  103. IT(t, eq)
  104. BXC(eq, lr) @ nope
  105. #if defined (__thumb2__)
  106. 1:
  107. strb a2, [a4], #1
  108. subs a3, a3, #1
  109. bne 1b
  110. bx lr
  111. #else
  112. rsb a3, a3, $7
  113. add pc, pc, a3, lsl $2
  114. mov r0, r0
  115. strb a2, [a4], $1
  116. strb a2, [a4], $1
  117. strb a2, [a4], $1
  118. strb a2, [a4], $1
  119. strb a2, [a4], $1
  120. strb a2, [a4], $1
  121. strb a2, [a4], $1
  122. BX(lr)
  123. #endif
  124. #endif
  125. .size memset,.-memset
  126. libc_hidden_def(memset)