memset.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * linux/arch/m32r/lib/memset.S
  3. *
  4. * Copyright (C) 2001,2002 Hiroyuki Kondo, and Hirokazu Takata
  5. * Copyright (C) 2004 Hirokazu Takata
  6. *
  7. * void *memset(void *dst, int val, int len);
  8. *
  9. * dst: r0
  10. * val: r1
  11. * len: r2
  12. * ret: r0
  13. *
  14. */
  15. .text
  16. .global memset
  17. #ifdef CONFIG_ISA_DUAL_ISSUE
  18. .align 4
  19. memset:
  20. mv r4, r0 || cmpz r2
  21. jc r14
  22. cmpui r2, #16
  23. bnc qword_align_check
  24. cmpui r2, #4
  25. bc byte_set
  26. word_align_check: /* len >= 4 */
  27. and3 r3, r4, #3
  28. beqz r3, word_set
  29. addi r3, #-4
  30. neg r3, r3 /* r3 = -(r3 - 4) */
  31. align_word:
  32. stb r1, @r4 || addi r4, #1
  33. addi r2, #-1 || addi r3, #-1
  34. bnez r3, align_word
  35. cmpui r2, #4
  36. bc byte_set
  37. word_set:
  38. and3 r1, r1, #0x00ff /* r1: abababab <-- ??????ab */
  39. sll3 r3, r1, #8
  40. or r1, r3 || addi r4, #-4
  41. sll3 r3, r1, #16
  42. or r1, r3 || addi r2, #-4
  43. word_set_loop:
  44. st r1, @+r4 || addi r2, #-4
  45. bgtz r2, word_set_loop
  46. bnez r2, byte_set_wrap
  47. st r1, @+r4
  48. jmp r14
  49. qword_align_check: /* len >= 16 */
  50. and3 r3, r4, #15
  51. bnez r3, word_align_check
  52. qword_set:
  53. and3 r1, r1, #0x00ff /* r1: abababab <-- ??????ab */
  54. sll3 r3, r1, #8
  55. or r1, r3 || addi r4, #-4
  56. sll3 r3, r1, #16
  57. or r1, r3 || ldi r5, #16
  58. qword_set_loop:
  59. ld r3, @(4,r4) /* cache line allocate */
  60. st r1, @+r4 || addi r2, #-16
  61. st r1, @+r4 || cmpu r2, r5
  62. st r1, @+r4
  63. st r1, @+r4
  64. bnc qword_set_loop || cmpz r2
  65. jc r14
  66. set_remainder:
  67. cmpui r2, #4
  68. bc byte_set_wrap1
  69. addi r2, #-4
  70. bra word_set_loop
  71. byte_set_wrap:
  72. addi r2, #4
  73. cmpz r2
  74. jc r14
  75. byte_set_wrap1:
  76. addi r4, #4
  77. #if defined(CONFIG_ISA_M32R2)
  78. byte_set:
  79. addi r2, #-1 || stb r1, @r4+
  80. bnez r2, byte_set
  81. #elif defined(CONFIG_ISA_M32R)
  82. byte_set:
  83. addi r2, #-1 || stb r1, @r4
  84. addi r4, #1
  85. bnez r2, byte_set
  86. #else
  87. #error unknown isa configuration
  88. #endif
  89. end_memset:
  90. jmp r14
  91. #else /* not CONFIG_ISA_DUAL_ISSUE */
  92. .align 4
  93. memset:
  94. mv r4, r0
  95. beqz r2, end_memset
  96. cmpui r2, #16
  97. bnc qword_align_check
  98. cmpui r2, #4
  99. bc byte_set
  100. word_align_check: /* len >= 4 */
  101. and3 r3, r4, #3
  102. beqz r3, word_set
  103. addi r3, #-4
  104. neg r3, r3 /* r3 = -(r3 - 4) */
  105. align_word:
  106. stb r1, @r4
  107. addi r4, #1
  108. addi r2, #-1
  109. addi r3, #-1
  110. bnez r3, align_word
  111. cmpui r2, #4
  112. bc byte_set
  113. word_set:
  114. and3 r1, r1, #0x00ff /* r1: abababab <-- ??????ab */
  115. sll3 r3, r1, #8
  116. or r1, r3
  117. sll3 r3, r1, #16
  118. or r1, r3
  119. addi r2, #-4
  120. addi r4, #-4
  121. word_set_loop:
  122. st r1, @+r4
  123. addi r2, #-4
  124. bgtz r2, word_set_loop
  125. bnez r2, byte_set_wrap
  126. st r1, @+r4
  127. jmp r14
  128. qword_align_check: /* len >= 16 */
  129. and3 r3, r4, #15
  130. bnez r3, word_align_check
  131. qword_set:
  132. and3 r1, r1, #0x00ff /* r1: abababab <-- ??????ab */
  133. sll3 r3, r1, #8
  134. or r1, r3
  135. sll3 r3, r1, #16
  136. or r1, r3
  137. addi r4, #-4
  138. qword_set_loop:
  139. ld r3, @(4,r4) /* cache line allocate */
  140. addi r2, #-16
  141. st r1, @+r4
  142. st r1, @+r4
  143. cmpui r2, #16
  144. st r1, @+r4
  145. st r1, @+r4
  146. bnc qword_set_loop
  147. bnez r2, set_remainder
  148. jmp r14
  149. set_remainder:
  150. cmpui r2, #4
  151. bc byte_set_wrap1
  152. addi r2, #-4
  153. bra word_set_loop
  154. byte_set_wrap:
  155. addi r2, #4
  156. beqz r2, end_memset
  157. byte_set_wrap1:
  158. addi r4, #4
  159. byte_set:
  160. addi r2, #-1
  161. stb r1, @r4
  162. addi r4, #1
  163. bnez r2, byte_set
  164. end_memset:
  165. jmp r14
  166. #endif /* not CONFIG_ISA_DUAL_ISSUE */
  167. .end