memset.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Set a block of memory to some byte value.
  2. For SPARC v7.
  3. Copyright (C) 1996, 1999, 2003 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by David S. Miller <davem@caip.rutgers.edu> and
  6. Jakub Jelinek <jj@ultra.linux.cz>.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library; if not, write to the Free
  17. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA. */
  19. /* Store 64 bytes at (BASE + OFFSET) using value SOURCE. */
  20. #define ZERO_BIG_BLOCK(base, offset, source) \
  21. std source, [base + offset + 0x00]; \
  22. std source, [base + offset + 0x08]; \
  23. std source, [base + offset + 0x10]; \
  24. std source, [base + offset + 0x18]; \
  25. std source, [base + offset + 0x20]; \
  26. std source, [base + offset + 0x28]; \
  27. std source, [base + offset + 0x30]; \
  28. std source, [base + offset + 0x38];
  29. #define ZERO_LAST_BLOCKS(base, offset, source) \
  30. std source, [base - offset - 0x38]; \
  31. std source, [base - offset - 0x30]; \
  32. std source, [base - offset - 0x28]; \
  33. std source, [base - offset - 0x20]; \
  34. std source, [base - offset - 0x18]; \
  35. std source, [base - offset - 0x10]; \
  36. std source, [base - offset - 0x08]; \
  37. std source, [base - offset - 0x00];
  38. .text
  39. .align 4
  40. ENTRY(__bzero)
  41. b 1f
  42. mov %g0, %g3
  43. 3: cmp %o2, 3
  44. be 2f
  45. stb %g3, [%o0]
  46. cmp %o2, 2
  47. be 2f
  48. stb %g3, [%o0 + 0x01]
  49. stb %g3, [%o0 + 0x02]
  50. 2: sub %o2, 4, %o2
  51. add %o1, %o2, %o1
  52. b 4f
  53. sub %o0, %o2, %o0
  54. END(__bzero)
  55. .globl memset
  56. .set memset,__memset
  57. .hidden __memset
  58. ENTRY(__memset)
  59. and %o1, 0xff, %g3
  60. sll %g3, 8, %g2
  61. or %g3, %g2, %g3
  62. sll %g3, 16, %g2
  63. or %g3, %g2, %g3
  64. orcc %o2, %g0, %o1
  65. 1: cmp %o1, 7
  66. bleu 7f
  67. mov %o0, %g1
  68. andcc %o0, 3, %o2
  69. bne 3b
  70. 4: andcc %o0, 4, %g0
  71. be 2f
  72. mov %g3, %g2
  73. st %g3, [%o0]
  74. sub %o1, 4, %o1
  75. add %o0, 4, %o0
  76. 2: andcc %o1, 0xffffff80, %o3
  77. be 9f
  78. andcc %o1, 0x78, %o2
  79. 4: ZERO_BIG_BLOCK (%o0, 0x00, %g2)
  80. subcc %o3, 128, %o3
  81. ZERO_BIG_BLOCK (%o0, 0x40, %g2)
  82. bne 4b
  83. add %o0, 128, %o0
  84. orcc %o2, %g0, %g0
  85. 9: be 6f
  86. andcc %o1, 7, %o1
  87. mov %o7, %g4
  88. 101: call 100f
  89. srl %o2, 1, %o3
  90. mov %g4, %o7
  91. jmpl %o4 + (20f + 64 - 101b), %g0
  92. add %o0, %o2, %o0
  93. 100: retl
  94. sub %o7, %o3, %o4
  95. 20: ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
  96. ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
  97. 6: be 8f
  98. andcc %o1, 4, %g0
  99. be 1f
  100. andcc %o1, 2, %g0
  101. st %g3, [%o0]
  102. add %o0, 4, %o0
  103. 1: be 1f
  104. andcc %o1, 1, %g0
  105. sth %g3, [%o0]
  106. add %o0, 2, %o0
  107. 1: bne,a 8f
  108. stb %g3, [%o0]
  109. 8: retl
  110. mov %g1, %o0
  111. 7: orcc %o1, 0, %g0
  112. be 0f
  113. subcc %o1, 1, %o1
  114. stb %g3, [%o0]
  115. be 0f
  116. subcc %o1, 1, %o1
  117. stb %g3, [%o0 + 1]
  118. be 0f
  119. subcc %o1, 1, %o1
  120. stb %g3, [%o0 + 2]
  121. be 0f
  122. subcc %o1, 1, %o1
  123. stb %g3, [%o0 + 3]
  124. be 0f
  125. subcc %o1, 1, %o1
  126. stb %g3, [%o0 + 4]
  127. be 0f
  128. subcc %o1, 1, %o1
  129. stb %g3, [%o0 + 5]
  130. be 0f
  131. subcc %o1, 1, %o1
  132. stb %g3, [%o0 + 6]
  133. 0: retl
  134. nop
  135. END(__memset)
  136. weak_alias (__bzero, bzero)