memchr.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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, write to the Free
  25. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  26. 02111-1307 USA. */
  27. .text
  28. .align 4
  29. 0: cmp %o2, 0
  30. be 9f
  31. sethi %hi(0x80808080), %o4
  32. ldub [%o0], %g4
  33. cmp %g4, %o1
  34. be 1f
  35. add %o0, 1, %o0
  36. subcc %o2, 1, %o2
  37. be 9f
  38. andcc %o0, 3, %g0
  39. be 4f
  40. or %o4, %lo(0x80808080), %o3
  41. ldub [%o0], %g4
  42. cmp %g4, %o1
  43. be 1f
  44. add %o0, 1, %o0
  45. subcc %o2, 1, %o2
  46. be 9f
  47. andcc %o0, 3, %g0
  48. be 5f
  49. sethi %hi(0x01010101), %o5
  50. ldub [%o0], %g4
  51. cmp %g4, %o1
  52. be 1f
  53. add %o0, 1, %o0
  54. subcc %o2, 1, %o2
  55. bne,a 7f
  56. and %o2, 3, %g1
  57. retl
  58. clr %o0
  59. 1: retl
  60. sub %o0, 1, %o0
  61. .globl memchr
  62. .set memchr,__memchr
  63. .hidden __memchr
  64. ENTRY(__memchr)
  65. andcc %o1, 0xff, %o1
  66. sll %o1, 8, %g6
  67. andcc %o0, 3, %g0
  68. or %o1, %g6, %g6
  69. sll %g6, 16, %o3
  70. bne 0b
  71. or %o3, %g6, %g2
  72. sethi %hi(0x80808080), %o4
  73. or %o4, %lo(0x80808080), %o3
  74. 4: sethi %hi(0x01010101), %o5
  75. 5: and %o2, 3, %g1
  76. 7: andcc %o2, 0xfffffffc, %o2
  77. be 0f
  78. or %o5, %lo(0x01010101), %g6
  79. ld [%o0], %g4
  80. 6: xor %g4, %g2, %g5
  81. add %o0, 4, %o0
  82. sub %g5, %g6, %g5
  83. andcc %g5, %o3, %g0
  84. bne 8f
  85. subcc %o2, 4, %o2
  86. bne,a 6b
  87. ld [%o0], %g4
  88. 0: cmp %g1, 0
  89. 1: be 9f
  90. add %o0, 4, %o0
  91. ldub [%o0 - 4], %g4
  92. cmp %g4, %o1
  93. be 4f
  94. cmp %g1, 1
  95. be 9f
  96. ldub [%o0 - 3], %g4
  97. cmp %g4, %o1
  98. be 3f
  99. cmp %g1, 2
  100. be 9f
  101. ldub [%o0 - 2], %g4
  102. cmp %g4, %o1
  103. be 2f
  104. nop
  105. 9: retl
  106. clr %o0
  107. /* Check every byte. */
  108. 8: srl %g4, 24, %g5
  109. and %g5, 0xff, %g5
  110. cmp %g5, %o1
  111. be 4f
  112. srl %g4, 16, %g5
  113. and %g5, 0xff, %g5
  114. cmp %g5, %o1
  115. be 3f
  116. srl %g4, 8, %g5
  117. and %g5, 0xff, %g5
  118. cmp %g5, %o1
  119. be 2f
  120. and %g4, 0xff, %g5
  121. cmp %g5, %o1
  122. be 1f
  123. cmp %o2, 0
  124. bne,a 6b
  125. ld [%o0], %g4
  126. b 1b
  127. cmp %g1, 0
  128. 1: retl
  129. sub %o0, 1, %o0
  130. 2: retl
  131. sub %o0, 2, %o0
  132. 3: retl
  133. sub %o0, 3, %o0
  134. 4: retl
  135. sub %o0, 4, %o0
  136. END(__memchr)
  137. #if !__BOUNDED_POINTERS__
  138. weak_alias (__memchr, __ubp_memchr)
  139. #endif