strchr.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Optimized version of the standard strchr() function.
  2. This file is part of the GNU C Library.
  3. Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
  4. Contributed by Dan Pop <Dan.Pop@cern.ch>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. /* Return: the address of the first occurence of chr in str or NULL
  18. Inputs:
  19. in0: str
  20. in1: chr
  21. A modified version of memchr.S, the search ends when the character is
  22. found or the terminating null character is encountered.
  23. This implementation assumes little endian mode. For big endian mode,
  24. the instruction czx1.r should be replaced by czx1.l. */
  25. #include "sysdep.h"
  26. #undef ret
  27. #define saved_lc r18
  28. #define poschr r19
  29. #define pos0 r20
  30. #define val1 r21
  31. #define val2 r22
  32. #define tmp r24
  33. #define chrx8 r25
  34. #define loopcnt r30
  35. #define str in0
  36. #define chr in1
  37. ENTRY(strchr)
  38. .prologue
  39. alloc r2 = ar.pfs, 2, 0, 0, 0
  40. .save ar.lc, saved_lc
  41. mov saved_lc = ar.lc /* save the loop counter */
  42. .body
  43. mov ret0 = str
  44. and tmp = 7, str /* tmp = str % 8 */
  45. mux1 chrx8 = chr, @brcst
  46. extr.u chr = chr, 0, 8 /* retain only the last byte */
  47. cmp.ne p8, p0 = r0, r0 /* clear p8 */
  48. ;;
  49. sub loopcnt = 8, tmp /* loopcnt = 8 - tmp */
  50. cmp.eq p6, p0 = tmp, r0
  51. (p6) br.cond.sptk .str_aligned;;
  52. adds loopcnt = -1, loopcnt;;
  53. mov ar.lc = loopcnt
  54. .l1:
  55. ld1 val2 = [ret0], 1
  56. ;;
  57. cmp.eq p6, p0 = val2, chr
  58. cmp.eq p7, p0 = val2, r0
  59. (p6) br.cond.spnt .restore_and_exit
  60. (p7) br.cond.spnt .notfound
  61. br.cloop.sptk .l1
  62. .str_aligned:
  63. ld8 val1 = [ret0], 8;;
  64. nop.b 0
  65. nop.b 0
  66. .l2:
  67. ld8.s val2 = [ret0], 8 /* don't bomb out here */
  68. czx1.r pos0 = val1
  69. xor tmp = val1, chrx8 /* if val1 contains chr, tmp will */
  70. ;; /* contain a zero in its position */
  71. czx1.r poschr = tmp
  72. cmp.ne p6, p0 = 8, pos0
  73. ;;
  74. cmp.ne p7, p0 = 8, poschr
  75. (p7) br.cond.spnt .foundit
  76. (p6) br.cond.spnt .notfound
  77. chk.s val2, .recovery
  78. .back:
  79. mov val1 = val2
  80. br.cond.dptk .l2
  81. .foundit:
  82. (p6) cmp.lt p8, p0 = pos0, poschr /* we found chr and null in the word */
  83. (p8) br.cond.spnt .notfound /* null was found before chr */
  84. add ret0 = ret0, poschr ;;
  85. adds ret0 = -15, ret0 ;; /* should be -16, but we decrement */
  86. .restore_and_exit: /* ret0 in the next instruction */
  87. adds ret0 = -1, ret0 /* ret0 was pointing 1 char too far */
  88. mov ar.lc = saved_lc /* restore the loop counter */
  89. br.ret.sptk.many b0
  90. .notfound:
  91. mov ret0 = r0 /* return NULL if null was found */
  92. mov ar.lc = saved_lc
  93. br.ret.sptk.many b0
  94. .recovery:
  95. adds ret0 = -8, ret0;;
  96. ld8 val2 = [ret0], 8 /* bomb out here */
  97. br.cond.sptk .back
  98. END(strchr)
  99. libc_hidden_def (strchr)
  100. #ifdef __UCLIBC_SUSV3_LEGACY__
  101. strong_alias (strchr, index)
  102. #endif