strchrnul-vx.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Vector optimized 32/64 bit S/390 version of strchrnul.
  2. Copyright (C) 2015-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <ifunc-strchrnul.h>
  16. #if HAVE_STRCHRNUL_Z13
  17. # include "sysdep.h"
  18. # include "asm-syntax.h"
  19. .text
  20. /* char *strchrnul (const char *s, int c)
  21. Returns pointer to first c or to \0 if c not found.
  22. Register usage:
  23. -r1=tmp
  24. -r2=s and return pointer
  25. -r3=c
  26. -r4=tmp
  27. -r5=current_len
  28. -v16=part of s
  29. -v18=vector with c replicated in every byte
  30. */
  31. ENTRY(STRCHRNUL_Z13)
  32. .machine "z13"
  33. .machinemode "zarch_nohighgprs"
  34. vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
  35. lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
  36. lghi %r5,0 /* current_len = 0. */
  37. vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
  38. If c > 255, c will be truncated. */
  39. vrepb %v18,%v18,0
  40. vfeezbs %v16,%v16,%v18 /* Find element equal with zero search. */
  41. vlgvb %r4,%v16,7 /* Load byte index of character or zero. */
  42. clrjl %r4,%r1,.Lfound /* Return if c/zero is in loaded bytes. */
  43. /* Align s to 16 byte. */
  44. risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
  45. lghi %r5,16 /* current_len = 16. */
  46. slr %r5,%r4 /* Compute bytes to 16bytes boundary. */
  47. /* Find c/zero in 16byte aligned loop */
  48. .Lloop:
  49. vl %v16,0(%r5,%r2) /* Load s */
  50. vfeezbs %v16,%v16,%v18 /* Find element equal with zero search. */
  51. jno .Lfound /* Found c/zero (cc=0|1|2). */
  52. vl %v16,16(%r5,%r2)
  53. vfeezbs %v16,%v16,%v18
  54. jno .Lfound16
  55. vl %v16,32(%r5,%r2)
  56. vfeezbs %v16,%v16,%v18
  57. jno .Lfound32
  58. vl %v16,48(%r5,%r2)
  59. vfeezbs %v16,%v16,%v18
  60. jno .Lfound48
  61. aghi %r5,64
  62. j .Lloop /* No character and no zero -> loop. */
  63. /* Found character or zero */
  64. .Lfound48:
  65. aghi %r5,16
  66. .Lfound32:
  67. aghi %r5,16
  68. .Lfound16:
  69. aghi %r5,16
  70. .Lfound:
  71. vlgvb %r1,%v16,7 /* Load byte index of character. */
  72. algr %r5,%r1
  73. la %r2,0(%r5,%r2) /* Return pointer to character. */
  74. .Lend:
  75. br %r14
  76. END(STRCHRNUL_Z13)
  77. # if ! HAVE_STRCHRNUL_IFUNC
  78. libc_hidden_def (__strchrnul)
  79. strong_alias (STRCHRNUL_Z13, __strchrnul)
  80. weak_alias (__strchrnul, strchrnul)
  81. # endif
  82. #endif /* HAVE_STRCHRNUL_Z13 */