memset.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. lsl r3, r1, #8
  29. orr r1, r3
  30. lsl r3, r1, #16
  31. orr r1, r3
  32. mov r3, #3
  33. 1: @ Fill up to the first word boundary
  34. tst r0, r3
  35. beq 1f
  36. strb r1, [r0]
  37. add r0, r0, #1
  38. sub r2, r2, #1
  39. b 1b
  40. 1: @ Fill aligned words
  41. str r1, [r0]
  42. add r0, r0, #4
  43. sub r2, r2, #4
  44. cmp r2, #4
  45. bcs 1b
  46. 2: @ Fill the remaining bytes
  47. cmp r2, #0
  48. beq 2f
  49. 1:
  50. strb r1, [r0]
  51. add r0, r0, #1
  52. sub r2, r2, #1
  53. bne 1b
  54. 2:
  55. mov r0, ip
  56. bx lr
  57. #else
  58. memset:
  59. mov a4, a1
  60. cmp a3, $8 @ at least 8 bytes to do?
  61. blo 2f
  62. orr a2, a2, a2, lsl $8
  63. orr a2, a2, a2, lsl $16
  64. 1:
  65. tst a4, $3 @ aligned yet?
  66. #if defined(__thumb2__)
  67. itt ne
  68. strbne a2, [a4], $1
  69. subne a3, a3, $1
  70. #else
  71. strneb a2, [a4], $1
  72. subne a3, a3, $1
  73. #endif
  74. bne 1b
  75. mov ip, a2
  76. 1:
  77. cmp a3, $8 @ 8 bytes still to do?
  78. blo 2f
  79. stmia a4!, {a2, ip}
  80. sub a3, a3, $8
  81. cmp a3, $8 @ 8 bytes still to do?
  82. blo 2f
  83. stmia a4!, {a2, ip}
  84. sub a3, a3, $8
  85. cmp a3, $8 @ 8 bytes still to do?
  86. blo 2f
  87. stmia a4!, {a2, ip}
  88. sub a3, a3, $8
  89. cmp a3, $8 @ 8 bytes still to do?
  90. #if defined(__thumb2__)
  91. itt hs
  92. stmiahs a4!, {a2, ip}
  93. subhs a3, a3, $8
  94. #else
  95. stmhsia a4!, {a2, ip}
  96. subhs a3, a3, $8
  97. #endif
  98. bhs 1b
  99. 2:
  100. movs a3, a3 @ anything left?
  101. IT(t, eq)
  102. BXC(eq, lr) @ nope
  103. #if defined (__thumb2__)
  104. 1:
  105. strb a2, [a4], #1
  106. subs a3, a3, #1
  107. bne 1b
  108. bx lr
  109. #else
  110. rsb a3, a3, $7
  111. add pc, pc, a3, lsl $2
  112. mov r0, r0
  113. strb a2, [a4], $1
  114. strb a2, [a4], $1
  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. BX(lr)
  121. #endif
  122. #endif
  123. .size memset,.-memset
  124. libc_hidden_def(memset)