memset.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. .type memset,@function
  33. memset:
  34. orcc.p gr10,gr0,gr5,icc3 ; GR5 = count
  35. andi gr9,#0xff,gr9
  36. or.p gr8,gr0,gr4 ; GR4 = address
  37. beqlr icc3,#0
  38. # conditionally write a byte to 2b-align the address
  39. setlos.p #1,gr6
  40. andicc gr4,#1,gr0,icc0
  41. ckne icc0,cc7
  42. cstb.p gr9,@(gr4,gr0) ,cc7,#1
  43. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  44. cadd.p gr4,gr6,gr4 ,cc7,#1
  45. beqlr icc3,#0
  46. # conditionally write a word to 4b-align the address
  47. andicc.p gr4,#2,gr0,icc0
  48. subicc gr5,#2,gr0,icc1
  49. setlos.p #2,gr6
  50. ckne icc0,cc7
  51. slli.p gr9,#8,gr12 ; need to double up the pattern
  52. cknc icc1,cc5
  53. or.p gr9,gr12,gr12
  54. andcr cc7,cc5,cc7
  55. csth.p gr12,@(gr4,gr0) ,cc7,#1
  56. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  57. cadd.p gr4,gr6,gr4 ,cc7,#1
  58. beqlr icc3,#0
  59. # conditionally write a dword to 8b-align the address
  60. andicc.p gr4,#4,gr0,icc0
  61. subicc gr5,#4,gr0,icc1
  62. setlos.p #4,gr6
  63. ckne icc0,cc7
  64. slli.p gr12,#16,gr13 ; need to quadruple-up the pattern
  65. cknc icc1,cc5
  66. or.p gr13,gr12,gr12
  67. andcr cc7,cc5,cc7
  68. cst.p gr12,@(gr4,gr0) ,cc7,#1
  69. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  70. cadd.p gr4,gr6,gr4 ,cc7,#1
  71. beqlr icc3,#0
  72. or.p gr12,gr12,gr13 ; need to octuple-up the pattern
  73. # the address is now 8b-aligned - loop around writing 64b chunks
  74. setlos #8,gr7
  75. subi.p gr4,#8,gr4 ; store with update index does weird stuff
  76. setlos #64,gr6
  77. subicc gr5,#64,gr0,icc0
  78. 0: cknc icc0,cc7
  79. cstdu gr12,@(gr4,gr7) ,cc7,#1
  80. cstdu gr12,@(gr4,gr7) ,cc7,#1
  81. cstdu gr12,@(gr4,gr7) ,cc7,#1
  82. cstdu gr12,@(gr4,gr7) ,cc7,#1
  83. cstdu gr12,@(gr4,gr7) ,cc7,#1
  84. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  85. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  86. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  87. subicc gr5,#64,gr0,icc0
  88. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  89. beqlr icc3,#0
  90. bnc icc0,#2,0b
  91. # now do 32-byte remnant
  92. subicc.p gr5,#32,gr0,icc0
  93. setlos #32,gr6
  94. cknc icc0,cc7
  95. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  96. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  97. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  98. setlos #16,gr6
  99. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  100. subicc gr5,#16,gr0,icc0
  101. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  102. beqlr icc3,#0
  103. # now do 16-byte remnant
  104. cknc icc0,cc7
  105. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  106. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  107. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  108. beqlr icc3,#0
  109. # now do 8-byte remnant
  110. subicc gr5,#8,gr0,icc1
  111. cknc icc1,cc7
  112. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  113. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  114. setlos.p #4,gr7
  115. beqlr icc3,#0
  116. # now do 4-byte remnant
  117. subicc gr5,#4,gr0,icc0
  118. addi.p gr4,#4,gr4
  119. cknc icc0,cc7
  120. cstu.p gr12,@(gr4,gr7) ,cc7,#1
  121. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  122. subicc.p gr5,#2,gr0,icc1
  123. beqlr icc3,#0
  124. # now do 2-byte remnant
  125. setlos #2,gr7
  126. addi.p gr4,#2,gr4
  127. cknc icc1,cc7
  128. csthu.p gr12,@(gr4,gr7) ,cc7,#1
  129. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  130. subicc.p gr5,#1,gr0,icc0
  131. beqlr icc3,#0
  132. # now do 1-byte remnant
  133. setlos #0,gr7
  134. addi.p gr4,#2,gr4
  135. cknc icc0,cc7
  136. cstb.p gr12,@(gr4,gr0) ,cc7,#1
  137. bralr
  138. .size memset, .-memset