memchr.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ENTRY(__memchr)
  62. andcc %o1, 0xff, %o1
  63. sll %o1, 8, %g6
  64. andcc %o0, 3, %g0
  65. or %o1, %g6, %g6
  66. sll %g6, 16, %o3
  67. bne 0b
  68. or %o3, %g6, %g2
  69. sethi %hi(0x80808080), %o4
  70. or %o4, %lo(0x80808080), %o3
  71. 4: sethi %hi(0x01010101), %o5
  72. 5: and %o2, 3, %g1
  73. 7: andcc %o2, 0xfffffffc, %o2
  74. be 0f
  75. or %o5, %lo(0x01010101), %g6
  76. ld [%o0], %g4
  77. 6: xor %g4, %g2, %g5
  78. add %o0, 4, %o0
  79. sub %g5, %g6, %g5
  80. andcc %g5, %o3, %g0
  81. bne 8f
  82. subcc %o2, 4, %o2
  83. bne,a 6b
  84. ld [%o0], %g4
  85. 0: cmp %g1, 0
  86. 1: be 9f
  87. add %o0, 4, %o0
  88. ldub [%o0 - 4], %g4
  89. cmp %g4, %o1
  90. be 4f
  91. cmp %g1, 1
  92. be 9f
  93. ldub [%o0 - 3], %g4
  94. cmp %g4, %o1
  95. be 3f
  96. cmp %g1, 2
  97. be 9f
  98. ldub [%o0 - 2], %g4
  99. cmp %g4, %o1
  100. be 2f
  101. nop
  102. 9: retl
  103. clr %o0
  104. /* Check every byte. */
  105. 8: srl %g4, 24, %g5
  106. and %g5, 0xff, %g5
  107. cmp %g5, %o1
  108. be 4f
  109. srl %g4, 16, %g5
  110. and %g5, 0xff, %g5
  111. cmp %g5, %o1
  112. be 3f
  113. srl %g4, 8, %g5
  114. and %g5, 0xff, %g5
  115. cmp %g5, %o1
  116. be 2f
  117. and %g4, 0xff, %g5
  118. cmp %g5, %o1
  119. be 1f
  120. cmp %o2, 0
  121. bne,a 6b
  122. ld [%o0], %g4
  123. b 1b
  124. cmp %g1, 0
  125. 1: retl
  126. sub %o0, 1, %o0
  127. 2: retl
  128. sub %o0, 2, %o0
  129. 3: retl
  130. sub %o0, 3, %o0
  131. 4: retl
  132. sub %o0, 4, %o0
  133. END(__memchr)
  134. strong_alias(__memchr,memchr)
  135. #if !__BOUNDED_POINTERS__
  136. weak_alias(__memchr,__ubp_memchr)
  137. #endif