strlen.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Determine the length of a string. For SPARC v9.
  2. Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
  5. 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. #include <asm/asi.h>
  19. /* Normally, this uses
  20. ((xword - 0x0101010101010101) & 0x8080808080808080) test
  21. to find out if any byte in xword could be zero. This is fast, but
  22. also gives false alarm for any byte in range 0x81-0xff. It does
  23. not matter for correctness, as if this test tells us there could
  24. be some zero byte, we check it byte by byte, but if bytes with
  25. high bits set are common in the strings, then this will give poor
  26. performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
  27. will use one tick slower, but more precise test
  28. ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
  29. which does not give any false alarms (but if some bits are set,
  30. one cannot assume from it which bytes are zero and which are not).
  31. It is yet to be measured, what is the correct default for glibc
  32. in these days for an average user.
  33. */
  34. .text
  35. .align 32
  36. .globl strlen
  37. .set strlen,__strlen
  38. .hidden __strlen
  39. ENTRY(__strlen)
  40. sethi %hi(0x01010101), %g1 /* IEU0 Group */
  41. ldub [%o0], %o3 /* Load */
  42. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  43. mov %o0, %o1 /* IEU1 */
  44. sllx %g1, 32, %g4 /* IEU0 Group */
  45. andcc %o0, 7, %g0 /* IEU1 */
  46. or %g1, %g4, %g1 /* IEU0 Group */
  47. brz,pn %o3, 13f /* CTI+IEU1 */
  48. sllx %g1, 7, %g4 /* IEU0 Group */
  49. bne,a,pn %icc, 15f /* CTI */
  50. add %o0, 1, %o0 /* IEU1 */
  51. /* %g1 = 0x0101010101010101 *
  52. * %g4 = 0x8080808080808080 *
  53. * %o0 = string pointer *
  54. * %o1 = start of string */
  55. 1: ldx [%o0], %o3 /* Load Group */
  56. add %o0, 8, %o0 /* IEU1 */
  57. 2: sub %o3, %g1, %o2 /* IEU0 Group */
  58. #ifdef EIGHTBIT_NOT_RARE
  59. andn %o2, %o3, %o5 /* IEU0 Group */
  60. ldxa [%o0] ASI_PNF, %o3 /* Load */
  61. andcc %o5, %g4, %g0 /* IEU1 Group */
  62. #else
  63. ldxa [%o0] ASI_PNF, %o3 /* Load */
  64. andcc %o2, %g4, %g0 /* IEU1 Group */
  65. #endif
  66. be,pt %xcc, 2b /* CTI */
  67. add %o0, 8, %o0 /* IEU0 */
  68. addcc %o2, %g1, %g5 /* IEU1 Group */
  69. #ifdef EIGHTBIT_NOT_RARE
  70. srlx %o5, 32, %o5 /* IEU0 */
  71. 3: andcc %o5, %g4, %g0 /* IEU1 Group */
  72. #else
  73. srlx %o2, 32, %o2 /* IEU0 */
  74. 3: andcc %o2, %g4, %g0 /* IEU1 Group */
  75. #endif
  76. be,pn %xcc, 4f /* CTI */
  77. srlx %g5, 56, %o2 /* IEU0 */
  78. andcc %o2, 0xff, %g0 /* IEU1 Group */
  79. be,pn %icc, 12f /* CTI */
  80. srlx %g5, 48, %o2 /* IEU0 */
  81. andcc %o2, 0xff, %g0 /* IEU1 Group */
  82. be,pn %icc, 11f /* CTI */
  83. srlx %g5, 40, %o2 /* IEU0 */
  84. andcc %o2, 0xff, %g0 /* IEU1 Group */
  85. be,pn %icc, 10f /* CTI */
  86. srlx %g5, 32, %o2 /* IEU0 */
  87. andcc %o2, 0xff, %g0 /* IEU1 Group */
  88. be,pn %icc, 9f /* CTI */
  89. 4: srlx %g5, 24, %o2 /* IEU0 */
  90. andcc %o2, 0xff, %g0 /* IEU1 Group */
  91. be,pn %icc, 8f /* CTI */
  92. srlx %g5, 16, %o2 /* IEU0 */
  93. andcc %o2, 0xff, %g0 /* IEU1 Group */
  94. be,pn %icc, 7f /* CTI */
  95. srlx %g5, 8, %o2 /* IEU0 */
  96. andcc %o2, 0xff, %g0 /* IEU1 Group */
  97. be,pn %icc, 6f /* CTI */
  98. sub %o3, %g1, %o2 /* IEU0 */
  99. andcc %g5, 0xff, %g0 /* IEU1 Group */
  100. be,pn %icc, 5f /* CTI */
  101. ldxa [%o0] ASI_PNF, %o3 /* Load */
  102. andcc %o2, %g4, %g0 /* IEU1 Group */
  103. be,pt %xcc, 2b /* CTI */
  104. add %o0, 8, %o0 /* IEU0 */
  105. addcc %o2, %g1, %g5 /* IEU1 Group */
  106. ba,pt %xcc, 3b /* CTI */
  107. srlx %o2, 32, %o2 /* IEU0 */
  108. 5: add %o0, -9, %o0 /* IEU0 Group */
  109. retl /* CTI+IEU1 Group */
  110. sub %o0, %o1, %o0 /* IEU0 */
  111. 6: add %o0, -10, %o0 /* IEU0 Group */
  112. retl /* CTI+IEU1 Group */
  113. sub %o0, %o1, %o0 /* IEU0 */
  114. 7: add %o0, -11, %o0 /* IEU0 Group */
  115. retl /* CTI+IEU1 Group */
  116. sub %o0, %o1, %o0 /* IEU0 */
  117. 8: add %o0, -12, %o0 /* IEU0 Group */
  118. retl /* CTI+IEU1 Group */
  119. sub %o0, %o1, %o0 /* IEU0 */
  120. 9: add %o0, -13, %o0 /* IEU0 Group */
  121. retl /* CTI+IEU1 Group */
  122. sub %o0, %o1, %o0 /* IEU0 */
  123. 10: add %o0, -14, %o0 /* IEU0 Group */
  124. retl /* CTI+IEU1 Group */
  125. sub %o0, %o1, %o0 /* IEU0 */
  126. 11: add %o0, -15, %o0 /* IEU0 Group */
  127. retl /* CTI+IEU1 Group */
  128. sub %o0, %o1, %o0 /* IEU0 */
  129. 12: add %o0, -16, %o0 /* IEU0 Group */
  130. retl /* CTI+IEU1 Group */
  131. sub %o0, %o1, %o0 /* IEU0 */
  132. 13: retl /* CTI+IEU1 Group */
  133. mov 0, %o0 /* IEU0 */
  134. nop
  135. 15: ldub [%o0], %o3 /* Load Group */
  136. 16: andcc %o0, 7, %g0 /* IEU1 */
  137. be,pn %icc, 1b /* CTI */
  138. nop /* IEU0 Group */
  139. add %o0, 1, %o0 /* IEU1 */
  140. andcc %o3, 0xff, %g0 /* IEU1 Group */
  141. bne,a,pt %icc, 16b /* CTI */
  142. lduba [%o0] ASI_PNF, %o3 /* Load */
  143. add %o0, -1, %o0 /* IEU0 Group */
  144. retl /* CTI+IEU1 Group */
  145. sub %o0, %o1, %o0 /* IEU0 */
  146. END(__strlen)