strlen.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Determine the length of a string.
  2. For SPARC v7.
  3. Copyright (C) 1996, 1999, 2003 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 [%o0], %o5
  35. cmp %o5, 0
  36. be 1f
  37. add %o0, 1, %o0
  38. andcc %o0, 3, %g0
  39. be 4f
  40. or %o4, %lo(0x80808080), %o3
  41. ldub [%o0], %o5
  42. cmp %o5, 0
  43. be 2f
  44. add %o0, 1, %o0
  45. andcc %o0, 3, %g0
  46. be 5f
  47. sethi %hi(0x01010101), %o4
  48. ldub [%o0], %o5
  49. cmp %o5, 0
  50. be 3f
  51. add %o0, 1, %o0
  52. b 11f
  53. or %o4, %lo(0x01010101), %o2
  54. 1: retl
  55. mov 0, %o0
  56. 2: retl
  57. mov 1, %o0
  58. 3: retl
  59. mov 2, %o0
  60. .globl strlen
  61. .set strlen,__strlen
  62. .hidden __strlen
  63. ENTRY(__strlen)
  64. mov %o0, %o1
  65. andcc %o0, 3, %g0
  66. bne 10b
  67. sethi %hi(0x80808080), %o4
  68. or %o4, %lo(0x80808080), %o3
  69. 4: sethi %hi(0x01010101), %o4
  70. 5: or %o4, %lo(0x01010101), %o2
  71. 11: ld [%o0], %o5
  72. 12: sub %o5, %o2, %o4
  73. #ifdef EIGHTBIT_NOT_RARE
  74. andn %o4, %o5, %o4
  75. #endif
  76. andcc %o4, %o3, %g0
  77. be 11b
  78. add %o0, 4, %o0
  79. srl %o5, 24, %g5
  80. andcc %g5, 0xff, %g0
  81. be 13f
  82. add %o0, -4, %o4
  83. srl %o5, 16, %g5
  84. andcc %g5, 0xff, %g0
  85. be 13f
  86. add %o4, 1, %o4
  87. srl %o5, 8, %g5
  88. andcc %g5, 0xff, %g0
  89. be 13f
  90. add %o4, 1, %o4
  91. andcc %o5, 0xff, %g0
  92. bne,a 12b
  93. ld [%o0], %o5
  94. add %o4, 1, %o4
  95. 13: retl
  96. sub %o4, %o1, %o0
  97. END(__strlen)