memset.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <features.h>
  17. #include <sys/syscall.h>
  18. #include <bits/arm_asm.h>
  19. .text
  20. .global memset
  21. .type memset,%function
  22. .align 4
  23. #if defined(THUMB1_ONLY)
  24. .thumb_func
  25. memset:
  26. mov ip, r0
  27. cmp r2, #8 @ at least 8 bytes to do?
  28. bcc 2f
  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. blt 2f
  63. orr a2, a2, a2, lsl $8
  64. orr a2, a2, a2, lsl $16
  65. 1:
  66. tst a4, $3 @ aligned yet?
  67. #if defined(__thumb2__)
  68. itt ne
  69. strbne a2, [a4], $1
  70. subne a3, a3, $1
  71. #else
  72. strneb a2, [a4], $1
  73. subne a3, a3, $1
  74. #endif
  75. bne 1b
  76. mov ip, a2
  77. 1:
  78. cmp a3, $8 @ 8 bytes still to do?
  79. blt 2f
  80. stmia a4!, {a2, ip}
  81. sub a3, a3, $8
  82. cmp a3, $8 @ 8 bytes still to do?
  83. blt 2f
  84. stmia a4!, {a2, ip}
  85. sub a3, a3, $8
  86. cmp a3, $8 @ 8 bytes still to do?
  87. blt 2f
  88. stmia a4!, {a2, ip}
  89. sub a3, a3, $8
  90. cmp a3, $8 @ 8 bytes still to do?
  91. #if defined(__thumb2__)
  92. itt ge
  93. stmiage a4!, {a2, ip}
  94. subge a3, a3, $8
  95. #else
  96. stmgeia a4!, {a2, ip}
  97. subge a3, a3, $8
  98. #endif
  99. bge 1b
  100. 2:
  101. movs a3, a3 @ anything left?
  102. IT(t, eq)
  103. #if defined(__USE_BX__)
  104. bxeq lr
  105. #else
  106. moveq pc, lr @ nope
  107. #endif
  108. #if defined (__thumb2__)
  109. 1:
  110. strb a2, [a4], #1
  111. subs a3, a3, #1
  112. bne 1b
  113. bx lr
  114. #else
  115. rsb a3, a3, $7
  116. add pc, pc, a3, lsl $2
  117. mov r0, r0
  118. strb a2, [a4], $1
  119. strb a2, [a4], $1
  120. strb a2, [a4], $1
  121. strb a2, [a4], $1
  122. strb a2, [a4], $1
  123. strb a2, [a4], $1
  124. strb a2, [a4], $1
  125. #if defined(__USE_BX__)
  126. bx lr
  127. #else
  128. mov pc, lr
  129. #endif
  130. #endif
  131. #endif
  132. .size memset,.-memset
  133. libc_hidden_def(memset)