memset.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include <features.h>
  21. .text
  22. .p2align 4
  23. ###############################################################################
  24. #
  25. # void *memset(void *p, char ch, size_t count)
  26. #
  27. # - NOTE: must not use any stack. exception detection performs function return
  28. # to caller's fixup routine, aborting the remainder of the set
  29. # GR4, GR7, GR8, and GR11 must be managed
  30. #
  31. ###############################################################################
  32. .globl memset
  33. .type memset,@function
  34. memset:
  35. orcc.p gr10,gr0,gr5,icc3 ; GR5 = count
  36. andi gr9,#0xff,gr9
  37. or.p gr8,gr0,gr4 ; GR4 = address
  38. beqlr icc3,#0
  39. # conditionally write a byte to 2b-align the address
  40. setlos.p #1,gr6
  41. andicc gr4,#1,gr0,icc0
  42. ckne icc0,cc7
  43. cstb.p gr9,@(gr4,gr0) ,cc7,#1
  44. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  45. cadd.p gr4,gr6,gr4 ,cc7,#1
  46. beqlr icc3,#0
  47. # conditionally write a word to 4b-align the address
  48. andicc.p gr4,#2,gr0,icc0
  49. subicc gr5,#2,gr0,icc1
  50. setlos.p #2,gr6
  51. ckne icc0,cc7
  52. slli.p gr9,#8,gr12 ; need to double up the pattern
  53. cknc icc1,cc5
  54. or.p gr9,gr12,gr12
  55. andcr cc7,cc5,cc7
  56. csth.p gr12,@(gr4,gr0) ,cc7,#1
  57. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  58. cadd.p gr4,gr6,gr4 ,cc7,#1
  59. beqlr icc3,#0
  60. # conditionally write a dword to 8b-align the address
  61. andicc.p gr4,#4,gr0,icc0
  62. subicc gr5,#4,gr0,icc1
  63. setlos.p #4,gr6
  64. ckne icc0,cc7
  65. slli.p gr12,#16,gr13 ; need to quadruple-up the pattern
  66. cknc icc1,cc5
  67. or.p gr13,gr12,gr12
  68. andcr cc7,cc5,cc7
  69. cst.p gr12,@(gr4,gr0) ,cc7,#1
  70. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  71. cadd.p gr4,gr6,gr4 ,cc7,#1
  72. beqlr icc3,#0
  73. or.p gr12,gr12,gr13 ; need to octuple-up the pattern
  74. # the address is now 8b-aligned - loop around writing 64b chunks
  75. setlos #8,gr7
  76. subi.p gr4,#8,gr4 ; store with update index does weird stuff
  77. setlos #64,gr6
  78. subicc gr5,#64,gr0,icc0
  79. 0: cknc icc0,cc7
  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 gr12,@(gr4,gr7) ,cc7,#1
  85. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  86. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  87. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  88. subicc gr5,#64,gr0,icc0
  89. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  90. beqlr icc3,#0
  91. bnc icc0,#2,0b
  92. # now do 32-byte remnant
  93. subicc.p gr5,#32,gr0,icc0
  94. setlos #32,gr6
  95. cknc icc0,cc7
  96. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  97. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  98. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  99. setlos #16,gr6
  100. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  101. subicc gr5,#16,gr0,icc0
  102. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  103. beqlr icc3,#0
  104. # now do 16-byte remnant
  105. cknc icc0,cc7
  106. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  107. csubcc gr5,gr6,gr5 ,cc7,#1 ; also set ICC3
  108. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  109. beqlr icc3,#0
  110. # now do 8-byte remnant
  111. subicc gr5,#8,gr0,icc1
  112. cknc icc1,cc7
  113. cstdu.p gr12,@(gr4,gr7) ,cc7,#1
  114. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  115. setlos.p #4,gr7
  116. beqlr icc3,#0
  117. # now do 4-byte remnant
  118. subicc gr5,#4,gr0,icc0
  119. addi.p gr4,#4,gr4
  120. cknc icc0,cc7
  121. cstu.p gr12,@(gr4,gr7) ,cc7,#1
  122. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  123. subicc.p gr5,#2,gr0,icc1
  124. beqlr icc3,#0
  125. # now do 2-byte remnant
  126. setlos #2,gr7
  127. addi.p gr4,#2,gr4
  128. cknc icc1,cc7
  129. csthu.p gr12,@(gr4,gr7) ,cc7,#1
  130. csubcc gr5,gr7,gr5 ,cc7,#1 ; also set ICC3
  131. subicc.p gr5,#1,gr0,icc0
  132. beqlr icc3,#0
  133. # now do 1-byte remnant
  134. setlos #0,gr7
  135. addi.p gr4,#2,gr4
  136. cknc icc0,cc7
  137. cstb.p gr12,@(gr4,gr0) ,cc7,#1
  138. bralr
  139. .size memset, .-memset