strlen.S 5.7 KB

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