stpcpy.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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, see
  16. <http://www.gnu.org/licenses/>. */
  17. /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
  18. to find out if any byte in xword could be zero. This is fast, but
  19. also gives false alarm for any byte in range 0x81-0xff. It does
  20. not matter for correctness, as if this test tells us there could
  21. be some zero byte, we check it byte by byte, but if bytes with
  22. high bits set are common in the strings, then this will give poor
  23. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  24. will use one tick slower, but more precise test
  25. ((xword - 0x01010101) & (~xword) & 0x80808080),
  26. which does not give any false alarms (but if some bits are set,
  27. one cannot assume from it which bytes are zero and which are not).
  28. It is yet to be measured, what is the correct default for glibc
  29. in these days for an average user.
  30. */
  31. .text
  32. .align 4
  33. 10: ldub [%o1], %o5
  34. stb %o5, [%o0]
  35. cmp %o5, 0
  36. add %o0, 1, %o0
  37. be 1f
  38. add %o1, 1, %o1
  39. andcc %o1, 3, %g0
  40. be 4f
  41. or %o4, %lo(0x80808080), %o3
  42. ldub [%o1], %o5
  43. stb %o5, [%o0]
  44. cmp %o5, 0
  45. add %o0, 1, %o0
  46. be 1f
  47. add %o1, 1, %o1
  48. andcc %o1, 3, %g0
  49. be 5f
  50. sethi %hi(0x01010101), %o4
  51. ldub [%o1], %o5
  52. stb %o5, [%o0]
  53. cmp %o5, 0
  54. add %o0, 1, %o0
  55. be 1f
  56. add %o1, 1, %o1
  57. b 6f
  58. or %o4, %lo(0x01010101), %o2
  59. 1: retl
  60. add %o0, -1, %o0
  61. ENTRY(stpcpy)
  62. andcc %o1, 3, %g0
  63. bne 10b
  64. sethi %hi(0x80808080), %o4
  65. or %o4, %lo(0x80808080), %o3
  66. 4: sethi %hi(0x01010101), %o4
  67. 5: or %o4, %lo(0x01010101), %o2
  68. 6: andcc %o0, 3, %g0
  69. bne 16f
  70. sub %g0, 4, %g1
  71. 11: add %g1, 4, %g1
  72. ld [%o1 + %g1], %o5
  73. sub %o5, %o2, %o4
  74. #ifdef EIGHTBIT_NOT_RARE
  75. andn %o4, %o5, %o4
  76. #endif
  77. andcc %o4, %o3, %g0
  78. be,a 11b
  79. st %o5, [%o0 + %g1]
  80. /* Check every byte. */
  81. srl %o5, 24, %g5
  82. andcc %g5, 0xff, %g0
  83. be 14f
  84. srl %o5, 16, %g5
  85. andcc %g5, 0xff, %g0
  86. be 13f
  87. srl %o5, 8, %g5
  88. andcc %g5, 0xff, %g0
  89. be 12f
  90. andcc %o5, 0xff, %g0
  91. bne 11b
  92. st %o5, [%o0 + %g1]
  93. add %o0, %g1, %o0
  94. retl
  95. add %o0, 3, %o0
  96. 12: srl %o5, 16, %o5
  97. sth %o5, [%o0 + %g1]
  98. add %g1, 2, %g1
  99. stb %g0, [%o0 + %g1]
  100. retl
  101. add %o0, %g1, %o0
  102. 13: srl %o5, 16, %o5
  103. sth %o5, [%o0 + %g1]
  104. add %g1, 1, %g1
  105. retl
  106. add %o0, %g1, %o0
  107. 14: stb %g0, [%o0 + %g1]
  108. retl
  109. add %o0, %g1, %o0
  110. 15: srl %o5, 24, %o4
  111. srl %o5, 16, %g1
  112. stb %o4, [%o0]
  113. srl %o5, 8, %g4
  114. stb %g1, [%o0 + 1]
  115. stb %g4, [%o0 + 2]
  116. stb %o5, [%o0 + 3]
  117. add %o0, 4, %o0
  118. 16: ld [%o1], %o5
  119. sub %o5, %o2, %o4
  120. andcc %o4, %o3, %g0
  121. be 15b
  122. add %o1, 4, %o1
  123. /* Check every byte. */
  124. srl %o5, 24, %g5
  125. andcc %g5, 0xff, %g4
  126. be 19f
  127. stb %g4, [%o0]
  128. srl %o5, 16, %g5
  129. andcc %g5, 0xff, %g4
  130. be 18f
  131. stb %g4, [%o0 + 1]
  132. srl %o5, 8, %g5
  133. andcc %g5, 0xff, %g4
  134. be 17f
  135. stb %g4, [%o0 + 2]
  136. andcc %o5, 0xff, %g4
  137. stb %g4, [%o0 + 3]
  138. bne 16b
  139. add %o0, 4, %o0
  140. retl
  141. sub %o0, 1, %o0
  142. 17: retl
  143. add %o0, 2, %o0
  144. 18: retl
  145. add %o0, 1, %o0
  146. 19: retl
  147. nop
  148. END(stpcpy)
  149. libc_hidden_def(stpcpy)