wcpcpy-vx.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Vector optimized 32/64 bit S/390 version of wcpcpy.
  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-wcpcpy.h>
  16. #if HAVE_WCPCPY_Z13
  17. # include "sysdep.h"
  18. # include "asm-syntax.h"
  19. .text
  20. /* wchar_t * wcpcpy (const wchar_t *dest, const wchar_t *src)
  21. Copy string src to dest returning a pointer to its end.
  22. Register usage:
  23. -r0=border-len for switching to vector-instructions
  24. -r1=tmp
  25. -r2=dest and return value
  26. -r3=src
  27. -r4=tmp
  28. -r5=current_len
  29. -v16=part of src
  30. -v17=index of zero
  31. -v18=part of src
  32. */
  33. ENTRY(WCPCPY_Z13)
  34. .machine "z13"
  35. .machinemode "zarch_nohighgprs"
  36. vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
  37. lcbb %r1,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
  38. tmll %r3,3 /* Test if s is 4-byte aligned? */
  39. jne .Lfallback /* And use common-code variant if not. */
  40. vfenezf %v17,%v16,%v16 /* Find element not equal with zero search. */
  41. vlgvb %r5,%v17,7 /* Load zero index or 16 if not found. */
  42. clrjl %r5,%r1,.Lfound_align /* If found zero within loaded bytes,
  43. copy bytes before and return. */
  44. /* Align s to 16 byte. */
  45. risbgn %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
  46. lghi %r5,15 /* current_len = 15. */
  47. slr %r5,%r4 /* Compute highest index to 16byte boundary. */
  48. vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
  49. ahi %r5,1 /* Start loop at next character. */
  50. /* Find zero in 16byte aligned loop. */
  51. .Lloop:
  52. vl %v16,0(%r5,%r3) /* Load s. */
  53. vfenezfs %v17,%v16,%v16 /* Find element not equal with zero search. */
  54. je .Lfound_v16_0 /* Jump away if zero was found. */
  55. vl %v18,16(%r5,%r3) /* Load next part of s. */
  56. vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
  57. vfenezfs %v17,%v18,%v18
  58. je .Lfound_v18_16
  59. vl %v16,32(%r5,%r3)
  60. vst %v18,16(%r5,%r2)
  61. vfenezfs %v17,%v16,%v16
  62. je .Lfound_v16_32
  63. vl %v18,48(%r5,%r3)
  64. vst %v16,32(%r5,%r2)
  65. vfenezfs %v17,%v18,%v18
  66. je .Lfound_v18_48
  67. vst %v18,48(%r5,%r2)
  68. aghi %r5,64
  69. j .Lloop /* No zero found -> loop. */
  70. .Lfound_v16_32:
  71. aghi %r5,32
  72. .Lfound_v16_0:
  73. la %r3,0(%r5,%r2)
  74. vlgvb %r1,%v17,7 /* Load byte index of zero. */
  75. aghi %r1,3 /* Also copy remaining bytes of zero. */
  76. vstl %v16,%r1,0(%r3) /* Copy characters including zero. */
  77. lay %r2,-3(%r1,%r3) /* Return pointer to zero. */
  78. br %r14
  79. .Lfound_v18_48:
  80. aghi %r5,32
  81. .Lfound_v18_16:
  82. la %r3,16(%r5,%r2)
  83. vlgvb %r1,%v17,7 /* Load byte index of zero. */
  84. aghi %r1,3 /* Also copy remaining bytes of zero. */
  85. vstl %v18,%r1,0(%r3) /* Copy characters including zero. */
  86. lay %r2,-3(%r1,%r3) /* Return pointer to zero. */
  87. br %r14
  88. .Lfound_align:
  89. aghi %r5,3 /* Also copy remaining bytes of zero. */
  90. vstl %v16,%r5,0(%r2) /* Copy characters including zero. */
  91. lay %r2,-3(%r5,%r2) /* Return pointer to zero. */
  92. br %r14
  93. .Lfallback:
  94. jg WCPCPY_C
  95. END(WCPCPY_Z13)
  96. # if ! HAVE_WCPCPY_IFUNC
  97. strong_alias (WCPCPY_Z13, __wcpcpy)
  98. weak_alias (__wcpcpy, wcpcpy)
  99. # endif
  100. #endif