rawmemchr.S 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2000-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /* Return pointer to first occurrence of CH in STR. */
  15. #include <sysdep.h>
  16. .set noreorder
  17. .set noat
  18. ENTRY(__rawmemchr)
  19. #ifdef PROF
  20. ldgp gp, 0(pv)
  21. lda AT, _mcount
  22. jsr AT, (AT), _mcount
  23. .prologue 1
  24. #else
  25. .prologue 0
  26. #endif
  27. zapnot a1, 1, a1 # e0 : zero extend the search character
  28. ldq_u t0, 0(a0) # .. e1 : load first quadword
  29. sll a1, 8, t5 # e0 : replicate the search character
  30. andnot a0, 7, v0 # .. e1 : align our loop pointer
  31. or t5, a1, a1 # e0 :
  32. lda t4, -1 # .. e1 : build garbage mask
  33. sll a1, 16, t5 # e0 :
  34. unop # :
  35. mskqh t4, a0, t4 # e0 :
  36. or t5, a1, a1 # .. e1 :
  37. sll a1, 32, t5 # e0 :
  38. cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage
  39. or t5, a1, a1 # e0 :
  40. xor t0, a1, t1 # .. e1 : make bytes == c zero
  41. cmpbge zero, t1, t3 # e0 : bits set iff byte == c
  42. unop # :
  43. andnot t3, t4, t0 # e0 : clear garbage bits
  44. fnop # .. fa :
  45. unop # :
  46. bne t0, $found # .. e1 (zdb)
  47. .align 4
  48. $loop:
  49. ldq t0, 8(v0) # e0 :
  50. addq v0, 8, v0 # .. e1 :
  51. nop # e0 :
  52. xor t0, a1, t1 # .. e1 (ev5 data stall)
  53. cmpbge zero, t1, t0 # e0 : bits set iff byte == c
  54. beq t0, $loop # .. e1 (zdb)
  55. $found:
  56. negq t0, t1 # e0 : clear all but least set bit
  57. and t0, t1, t0 # e1 (stall)
  58. and t0, 0xf0, t2 # e0 : binary search for that set bit
  59. and t0, 0xcc, t3 # .. e1 :
  60. and t0, 0xaa, t4 # e0 :
  61. cmovne t2, 4, t2 # .. e1 :
  62. cmovne t3, 2, t3 # e0 :
  63. cmovne t4, 1, t4 # .. e1 :
  64. addq t2, t3, t2 # e0 :
  65. addq v0, t4, v0 # .. e1 :
  66. addq v0, t2, v0 # e0 :
  67. ret # .. e1 :
  68. END(__rawmemchr)
  69. libc_hidden_def (__rawmemchr)
  70. weak_alias (__rawmemchr, rawmemchr)