strlen.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ENTRY(__strlen)
  61. mov %o0, %o1
  62. andcc %o0, 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. 11: ld [%o0], %o5
  69. 12: sub %o5, %o2, %o4
  70. #ifdef EIGHTBIT_NOT_RARE
  71. andn %o4, %o5, %o4
  72. #endif
  73. andcc %o4, %o3, %g0
  74. be 11b
  75. add %o0, 4, %o0
  76. srl %o5, 24, %g5
  77. andcc %g5, 0xff, %g0
  78. be 13f
  79. add %o0, -4, %o4
  80. srl %o5, 16, %g5
  81. andcc %g5, 0xff, %g0
  82. be 13f
  83. add %o4, 1, %o4
  84. srl %o5, 8, %g5
  85. andcc %g5, 0xff, %g0
  86. be 13f
  87. add %o4, 1, %o4
  88. andcc %o5, 0xff, %g0
  89. bne,a 12b
  90. ld [%o0], %o5
  91. add %o4, 1, %o4
  92. 13: retl
  93. sub %o4, %o1, %o0
  94. END(__strlen)
  95. strong_alias(__strlen,strlen)