memset.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* memset.S: optimised assembly memset
  2. *
  3. * Copyright (C) 2003, 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This 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. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the Free
  18. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. .text
  21. .p2align 4
  22. ###############################################################################
  23. #
  24. # void *memset(void *p, char ch, size_t count)
  25. #
  26. # - NOTE: must not use any stack. exception detection performs function return
  27. # to caller's fixup routine, aborting the remainder of the set
  28. # GR4, GR7, GR8, and GR11 must be managed
  29. #
  30. ###############################################################################
  31. .globl memset
  32. .set memset,__memset
  33. .globl __memset
  34. .hidden __memset
  35. .type __memset,@function
  36. __memset:
  37. orcc.p gr10,gr0,gr5,icc3 ; GR5 = count
  38. andi gr9,#0xff,gr9
  39. or.p gr8,gr0,gr4 ; GR4 = address
  40. beqlr icc3,#0
  41. # conditionally write a byte to 2b-align the address
  42. setlos.p #1,gr6
  43. andicc gr4,#1,gr0,icc0
  44. ckne icc0,cc7
  45. cstb.p gr9,@(gr4,gr0) ,cc7,#1
  46. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  47. cadd.p gr4,gr6,gr4 ,cc7,#1
  48. beqlr icc3,#0
  49. # conditionally write a word to 4b-align the address
  50. andicc.p gr4,#2,gr0,icc0
  51. subicc gr5,#2,gr0,icc1
  52. setlos.p #2,gr6
  53. ckne icc0,cc7
  54. slli.p gr9,#8,gr12 ; need to double up the pattern
  55. cknc icc1,cc5
  56. or.p gr9,gr12,gr12
  57. andcr cc7,cc5,cc7
  58. csth.p gr12,@(gr4,gr0) ,cc7,#1
  59. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  60. cadd.p gr4,gr6,gr4 ,cc7,#1
  61. beqlr icc3,#0
  62. # conditionally write a dword to 8b-align the address
  63. andicc.p gr4,#4,gr0,icc0
  64. subicc gr5,#4,gr0,icc1
  65. setlos.p #4,gr6
  66. ckne icc0,cc7
  67. slli.p gr12,#16,gr13 ; need to quadruple-up the pattern
  68. cknc icc1,cc5
  69. or.p gr13,gr12,gr12
  70. andcr cc7,cc5,cc7
  71. cst.p gr12,@(gr4,gr0) ,cc7,#1
  72. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  73. cadd.p gr4,gr6,gr4 ,cc7,#1
  74. beqlr icc3,#0
  75. or.p gr12,gr12,gr13 ; need to octuple-up the pattern
  76. # the address is now 8b-aligned - loop around writing 64b chunks
  77. setlos #8,gr7
  78. subi.p gr4,#8,gr4 ; store with update index does weird stuff
  79. setlos #64,gr6
  80. subicc gr5,#64,gr0,icc0
  81. 0: cknc icc0,cc7
  82. cstdu gr12,@(gr4,gr7) ,cc7,#1
  83. cstdu gr12,@(gr4,gr7) ,cc7,#1
  84. cstdu gr12,@(gr4,gr7) ,cc7,#1
  85. cstdu gr12,@(gr4,gr7) ,cc7,#1
  86. cstdu gr12,@(gr4,gr7) ,cc7,#1
  87. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  88. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  89. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  90. subicc gr5,#64,gr0,icc0
  91. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  92. beqlr icc3,#0
  93. bnc icc0,#2,0b
  94. # now do 32-byte remnant
  95. subicc.p gr5,#32,gr0,icc0
  96. setlos #32,gr6
  97. cknc icc0,cc7
  98. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  99. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  100. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  101. setlos #16,gr6
  102. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  103. subicc gr5,#16,gr0,icc0
  104. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  105. beqlr icc3,#0
  106. # now do 16-byte remnant
  107. cknc icc0,cc7
  108. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  109. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  110. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  111. beqlr icc3,#0
  112. # now do 8-byte remnant
  113. subicc gr5,#8,gr0,icc1
  114. cknc icc1,cc7
  115. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  116. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  117. setlos.p #4,gr7
  118. beqlr icc3,#0
  119. # now do 4-byte remnant
  120. subicc gr5,#4,gr0,icc0
  121. addi.p gr4,#4,gr4
  122. cknc icc0,cc7
  123. cstu.p gr12,@(gr4,gr7) ,cc7,#1
  124. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  125. subicc.p gr5,#2,gr0,icc1
  126. beqlr icc3,#0
  127. # now do 2-byte remnant
  128. setlos #2,gr7
  129. addi.p gr4,#2,gr4
  130. cknc icc1,cc7
  131. csthu.p gr12,@(gr4,gr7) ,cc7,#1
  132. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  133. subicc.p gr5,#1,gr0,icc0
  134. beqlr icc3,#0
  135. # now do 1-byte remnant
  136. setlos #0,gr7
  137. addi.p gr4,#2,gr4
  138. cknc icc0,cc7
  139. cstb.p gr12,@(gr4,gr0) ,cc7,#1
  140. bralr
  141. .size __memset, .-__memset