memchr.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less
  2. than N.
  3. For SPARC v7.
  4. Copyright (C) 1996, 1999, 2000, 2003 Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  6. Contributed by Jakub Jelinek <jj@ultra.linux.cz> and
  7. David S. Miller <davem@caip.rutgers.edu>.
  8. This version is developed using the same algorithm as the fast C
  9. version which carries the following introduction:
  10. Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
  11. with help from Dan Sahlin (dan@sics.se) and
  12. commentary by Jim Blandy (jimb@ai.mit.edu);
  13. adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
  14. and implemented by Roland McGrath (roland@ai.mit.edu).
  15. The GNU C Library is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU Lesser General Public
  17. License as published by the Free Software Foundation; either
  18. version 2.1 of the License, or (at your option) any later version.
  19. The GNU C Library is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. Lesser General Public License for more details.
  23. You should have received a copy of the GNU Lesser General Public
  24. License along with the GNU C Library; if not, see
  25. <http://www.gnu.org/licenses/>. */
  26. .text
  27. .align 4
  28. 0: cmp %o2, 0
  29. be 9f
  30. sethi %hi(0x80808080), %o4
  31. ldub [%o0], %g4
  32. cmp %g4, %o1
  33. be 1f
  34. add %o0, 1, %o0
  35. subcc %o2, 1, %o2
  36. be 9f
  37. andcc %o0, 3, %g0
  38. be 4f
  39. or %o4, %lo(0x80808080), %o3
  40. ldub [%o0], %g4
  41. cmp %g4, %o1
  42. be 1f
  43. add %o0, 1, %o0
  44. subcc %o2, 1, %o2
  45. be 9f
  46. andcc %o0, 3, %g0
  47. be 5f
  48. sethi %hi(0x01010101), %o5
  49. ldub [%o0], %g4
  50. cmp %g4, %o1
  51. be 1f
  52. add %o0, 1, %o0
  53. subcc %o2, 1, %o2
  54. bne,a 7f
  55. and %o2, 3, %g1
  56. retl
  57. clr %o0
  58. 1: retl
  59. sub %o0, 1, %o0
  60. ENTRY(memchr)
  61. andcc %o1, 0xff, %o1
  62. sll %o1, 8, %g6
  63. andcc %o0, 3, %g0
  64. or %o1, %g6, %g6
  65. sll %g6, 16, %o3
  66. bne 0b
  67. or %o3, %g6, %g2
  68. sethi %hi(0x80808080), %o4
  69. or %o4, %lo(0x80808080), %o3
  70. 4: sethi %hi(0x01010101), %o5
  71. 5: and %o2, 3, %g1
  72. 7: andcc %o2, 0xfffffffc, %o2
  73. be 0f
  74. or %o5, %lo(0x01010101), %g6
  75. ld [%o0], %g4
  76. 6: xor %g4, %g2, %g5
  77. add %o0, 4, %o0
  78. sub %g5, %g6, %g5
  79. andcc %g5, %o3, %g0
  80. bne 8f
  81. subcc %o2, 4, %o2
  82. bne,a 6b
  83. ld [%o0], %g4
  84. 0: cmp %g1, 0
  85. 1: be 9f
  86. add %o0, 4, %o0
  87. ldub [%o0 - 4], %g4
  88. cmp %g4, %o1
  89. be 4f
  90. cmp %g1, 1
  91. be 9f
  92. ldub [%o0 - 3], %g4
  93. cmp %g4, %o1
  94. be 3f
  95. cmp %g1, 2
  96. be 9f
  97. ldub [%o0 - 2], %g4
  98. cmp %g4, %o1
  99. be 2f
  100. nop
  101. 9: retl
  102. clr %o0
  103. /* Check every byte. */
  104. 8: srl %g4, 24, %g5
  105. and %g5, 0xff, %g5
  106. cmp %g5, %o1
  107. be 4f
  108. srl %g4, 16, %g5
  109. and %g5, 0xff, %g5
  110. cmp %g5, %o1
  111. be 3f
  112. srl %g4, 8, %g5
  113. and %g5, 0xff, %g5
  114. cmp %g5, %o1
  115. be 2f
  116. and %g4, 0xff, %g5
  117. cmp %g5, %o1
  118. be 1f
  119. cmp %o2, 0
  120. bne,a 6b
  121. ld [%o0], %g4
  122. b 1b
  123. cmp %g1, 0
  124. 1: retl
  125. sub %o0, 1, %o0
  126. 2: retl
  127. sub %o0, 2, %o0
  128. 3: retl
  129. sub %o0, 3, %o0
  130. 4: retl
  131. sub %o0, 4, %o0
  132. END(memchr)
  133. libc_hidden_def(memchr)
  134. weak_alias(memchr,__ubp_memchr)