strlen.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. ENTRY(__strlen)
  37. sethi %hi(0x01010101), %g1 /* IEU0 Group */
  38. ldub [%o0], %o3 /* Load */
  39. or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
  40. mov %o0, %o1 /* IEU1 */
  41. sllx %g1, 32, %g4 /* IEU0 Group */
  42. andcc %o0, 7, %g0 /* IEU1 */
  43. or %g1, %g4, %g1 /* IEU0 Group */
  44. brz,pn %o3, 13f /* CTI+IEU1 */
  45. sllx %g1, 7, %g4 /* IEU0 Group */
  46. bne,a,pn %icc, 15f /* CTI */
  47. add %o0, 1, %o0 /* IEU1 */
  48. /* %g1 = 0x0101010101010101 *
  49. * %g4 = 0x8080808080808080 *
  50. * %o0 = string pointer *
  51. * %o1 = start of string */
  52. 1: ldx [%o0], %o3 /* Load Group */
  53. add %o0, 8, %o0 /* IEU1 */
  54. 2: sub %o3, %g1, %o2 /* IEU0 Group */
  55. #ifdef EIGHTBIT_NOT_RARE
  56. andn %o2, %o3, %o5 /* IEU0 Group */
  57. ldxa [%o0] ASI_PNF, %o3 /* Load */
  58. andcc %o5, %g4, %g0 /* IEU1 Group */
  59. #else
  60. ldxa [%o0] ASI_PNF, %o3 /* Load */
  61. andcc %o2, %g4, %g0 /* IEU1 Group */
  62. #endif
  63. be,pt %xcc, 2b /* CTI */
  64. add %o0, 8, %o0 /* IEU0 */
  65. addcc %o2, %g1, %g5 /* IEU1 Group */
  66. #ifdef EIGHTBIT_NOT_RARE
  67. srlx %o5, 32, %o5 /* IEU0 */
  68. 3: andcc %o5, %g4, %g0 /* IEU1 Group */
  69. #else
  70. srlx %o2, 32, %o2 /* IEU0 */
  71. 3: andcc %o2, %g4, %g0 /* IEU1 Group */
  72. #endif
  73. be,pn %xcc, 4f /* CTI */
  74. srlx %g5, 56, %o2 /* IEU0 */
  75. andcc %o2, 0xff, %g0 /* IEU1 Group */
  76. be,pn %icc, 12f /* CTI */
  77. srlx %g5, 48, %o2 /* IEU0 */
  78. andcc %o2, 0xff, %g0 /* IEU1 Group */
  79. be,pn %icc, 11f /* CTI */
  80. srlx %g5, 40, %o2 /* IEU0 */
  81. andcc %o2, 0xff, %g0 /* IEU1 Group */
  82. be,pn %icc, 10f /* CTI */
  83. srlx %g5, 32, %o2 /* IEU0 */
  84. andcc %o2, 0xff, %g0 /* IEU1 Group */
  85. be,pn %icc, 9f /* CTI */
  86. 4: srlx %g5, 24, %o2 /* IEU0 */
  87. andcc %o2, 0xff, %g0 /* IEU1 Group */
  88. be,pn %icc, 8f /* CTI */
  89. srlx %g5, 16, %o2 /* IEU0 */
  90. andcc %o2, 0xff, %g0 /* IEU1 Group */
  91. be,pn %icc, 7f /* CTI */
  92. srlx %g5, 8, %o2 /* IEU0 */
  93. andcc %o2, 0xff, %g0 /* IEU1 Group */
  94. be,pn %icc, 6f /* CTI */
  95. sub %o3, %g1, %o2 /* IEU0 */
  96. andcc %g5, 0xff, %g0 /* IEU1 Group */
  97. be,pn %icc, 5f /* CTI */
  98. ldxa [%o0] ASI_PNF, %o3 /* Load */
  99. andcc %o2, %g4, %g0 /* IEU1 Group */
  100. be,pt %xcc, 2b /* CTI */
  101. add %o0, 8, %o0 /* IEU0 */
  102. addcc %o2, %g1, %g5 /* IEU1 Group */
  103. ba,pt %xcc, 3b /* CTI */
  104. srlx %o2, 32, %o2 /* IEU0 */
  105. 5: add %o0, -9, %o0 /* IEU0 Group */
  106. retl /* CTI+IEU1 Group */
  107. sub %o0, %o1, %o0 /* IEU0 */
  108. 6: add %o0, -10, %o0 /* IEU0 Group */
  109. retl /* CTI+IEU1 Group */
  110. sub %o0, %o1, %o0 /* IEU0 */
  111. 7: add %o0, -11, %o0 /* IEU0 Group */
  112. retl /* CTI+IEU1 Group */
  113. sub %o0, %o1, %o0 /* IEU0 */
  114. 8: add %o0, -12, %o0 /* IEU0 Group */
  115. retl /* CTI+IEU1 Group */
  116. sub %o0, %o1, %o0 /* IEU0 */
  117. 9: add %o0, -13, %o0 /* IEU0 Group */
  118. retl /* CTI+IEU1 Group */
  119. sub %o0, %o1, %o0 /* IEU0 */
  120. 10: add %o0, -14, %o0 /* IEU0 Group */
  121. retl /* CTI+IEU1 Group */
  122. sub %o0, %o1, %o0 /* IEU0 */
  123. 11: add %o0, -15, %o0 /* IEU0 Group */
  124. retl /* CTI+IEU1 Group */
  125. sub %o0, %o1, %o0 /* IEU0 */
  126. 12: add %o0, -16, %o0 /* IEU0 Group */
  127. retl /* CTI+IEU1 Group */
  128. sub %o0, %o1, %o0 /* IEU0 */
  129. 13: retl /* CTI+IEU1 Group */
  130. mov 0, %o0 /* IEU0 */
  131. nop
  132. 15: ldub [%o0], %o3 /* Load Group */
  133. 16: andcc %o0, 7, %g0 /* IEU1 */
  134. be,pn %icc, 1b /* CTI */
  135. nop /* IEU0 Group */
  136. add %o0, 1, %o0 /* IEU1 */
  137. andcc %o3, 0xff, %g0 /* IEU1 Group */
  138. bne,a,pt %icc, 16b /* CTI */
  139. lduba [%o0] ASI_PNF, %o3 /* Load */
  140. add %o0, -1, %o0 /* IEU0 Group */
  141. retl /* CTI+IEU1 Group */
  142. sub %o0, %o1, %o0 /* IEU0 */
  143. END(__strlen)
  144. strong_alias(__strlen,strlen)