stpcpy.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
  2. For SPARC v7.
  3. Copyright (C) 1996, 1999, 2002, 2004 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, write to the Free
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  17. 02111-1307 USA. */
  18. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  19. to find out if any byte in xword could be zero. This is fast, but
  20. also gives false alarm for any byte in range 0x81-0xff. It does
  21. not matter for correctness, as if this test tells us there could
  22. be some zero byte, we check it byte by byte, but if bytes with
  23. high bits set are common in the strings, then this will give poor
  24. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  25. will use one tick slower, but more precise test
  26. ((xword - 0x01010101) & (~xword) & 0x80808080),
  27. which does not give any false alarms (but if some bits are set,
  28. one cannot assume from it which bytes are zero and which are not).
  29. It is yet to be measured, what is the correct default for glibc
  30. in these days for an average user.
  31. */
  32. .text
  33. .align 4
  34. 10: ldub [%o1], %o5
  35. stb %o5, [%o0]
  36. cmp %o5, 0
  37. add %o0, 1, %o0
  38. be 1f
  39. add %o1, 1, %o1
  40. andcc %o1, 3, %g0
  41. be 4f
  42. or %o4, %lo(0x80808080), %o3
  43. ldub [%o1], %o5
  44. stb %o5, [%o0]
  45. cmp %o5, 0
  46. add %o0, 1, %o0
  47. be 1f
  48. add %o1, 1, %o1
  49. andcc %o1, 3, %g0
  50. be 5f
  51. sethi %hi(0x01010101), %o4
  52. ldub [%o1], %o5
  53. stb %o5, [%o0]
  54. cmp %o5, 0
  55. add %o0, 1, %o0
  56. be 1f
  57. add %o1, 1, %o1
  58. b 6f
  59. or %o4, %lo(0x01010101), %o2
  60. 1: retl
  61. add %o0, -1, %o0
  62. ENTRY(__stpcpy)
  63. andcc %o1, 3, %g0
  64. bne 10b
  65. sethi %hi(0x80808080), %o4
  66. or %o4, %lo(0x80808080), %o3
  67. 4: sethi %hi(0x01010101), %o4
  68. 5: or %o4, %lo(0x01010101), %o2
  69. 6: andcc %o0, 3, %g0
  70. bne 16f
  71. sub %g0, 4, %g1
  72. 11: add %g1, 4, %g1
  73. ld [%o1 + %g1], %o5
  74. sub %o5, %o2, %o4
  75. #ifdef EIGHTBIT_NOT_RARE
  76. andn %o4, %o5, %o4
  77. #endif
  78. andcc %o4, %o3, %g0
  79. be,a 11b
  80. st %o5, [%o0 + %g1]
  81. /* Check every byte. */
  82. srl %o5, 24, %g5
  83. andcc %g5, 0xff, %g0
  84. be 14f
  85. srl %o5, 16, %g5
  86. andcc %g5, 0xff, %g0
  87. be 13f
  88. srl %o5, 8, %g5
  89. andcc %g5, 0xff, %g0
  90. be 12f
  91. andcc %o5, 0xff, %g0
  92. bne 11b
  93. st %o5, [%o0 + %g1]
  94. add %o0, %g1, %o0
  95. retl
  96. add %o0, 3, %o0
  97. 12: srl %o5, 16, %o5
  98. sth %o5, [%o0 + %g1]
  99. add %g1, 2, %g1
  100. stb %g0, [%o0 + %g1]
  101. retl
  102. add %o0, %g1, %o0
  103. 13: srl %o5, 16, %o5
  104. sth %o5, [%o0 + %g1]
  105. add %g1, 1, %g1
  106. retl
  107. add %o0, %g1, %o0
  108. 14: stb %g0, [%o0 + %g1]
  109. retl
  110. add %o0, %g1, %o0
  111. 15: srl %o5, 24, %o4
  112. srl %o5, 16, %g1
  113. stb %o4, [%o0]
  114. srl %o5, 8, %g4
  115. stb %g1, [%o0 + 1]
  116. stb %g4, [%o0 + 2]
  117. stb %o5, [%o0 + 3]
  118. add %o0, 4, %o0
  119. 16: ld [%o1], %o5
  120. sub %o5, %o2, %o4
  121. andcc %o4, %o3, %g0
  122. be 15b
  123. add %o1, 4, %o1
  124. /* Check every byte. */
  125. srl %o5, 24, %g5
  126. andcc %g5, 0xff, %g4
  127. be 19f
  128. stb %g4, [%o0]
  129. srl %o5, 16, %g5
  130. andcc %g5, 0xff, %g4
  131. be 18f
  132. stb %g4, [%o0 + 1]
  133. srl %o5, 8, %g5
  134. andcc %g5, 0xff, %g4
  135. be 17f
  136. stb %g4, [%o0 + 2]
  137. andcc %o5, 0xff, %g4
  138. stb %g4, [%o0 + 3]
  139. bne 16b
  140. add %o0, 4, %o0
  141. retl
  142. sub %o0, 1, %o0
  143. 17: retl
  144. add %o0, 2, %o0
  145. 18: retl
  146. add %o0, 1, %o0
  147. 19: retl
  148. nop
  149. END(__stpcpy)
  150. strong_alias(__stpcpy,stpcpy)