strcat-vx.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Vector optimized 32/64 bit S/390 version of strcat.
  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-strcat.h>
  16. #if HAVE_STRCAT_Z13
  17. # include "sysdep.h"
  18. # include "asm-syntax.h"
  19. .text
  20. /* char * strcat (const char *dest, const char *src)
  21. Concatenate two strings.
  22. Register usage:
  23. -r0=saved dest pointer for return
  24. -r1=tmp
  25. -r2=dest
  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(STRCAT_Z13)
  34. .machine "z13"
  35. .machinemode "zarch_nohighgprs"
  36. lgr %r0,%r2 /* Save destination pointer for return. */
  37. /* STRLEN
  38. r1 = loaded bytes (tmp)
  39. r4 = zero byte index (tmp)
  40. r2 = dst
  41. */
  42. vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
  43. lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
  44. vfenezb %v16,%v16,%v16 /* Find element not equal with zero search. */
  45. vlgvb %r5,%v16,7 /* Load zero index or 16 if not found. */
  46. clrjl %r5,%r1,.Llen_end /* Found zero within loaded bytes, end. */
  47. /* Align s to 16 byte. */
  48. risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
  49. lghi %r5,16 /* current_len = 16. */
  50. slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
  51. /* Find zero in 16byte aligned loop. */
  52. .Llen_loop:
  53. vl %v16,0(%r5,%r2) /* Load s. */
  54. vfenezbs %v16,%v16,%v16 /* Find element not equal with zero search. */
  55. je .Llen_found /* Jump away if zero was found. */
  56. vl %v16,16(%r5,%r2)
  57. vfenezbs %v16,%v16,%v16
  58. je .Llen_found16
  59. vl %v16,32(%r5,%r2)
  60. vfenezbs %v16,%v16,%v16
  61. je .Llen_found32
  62. vl %v16,48(%r5,%r2)
  63. vfenezbs %v16,%v16,%v16
  64. je .Llen_found48
  65. aghi %r5,64
  66. j .Llen_loop /* No zero -> loop. */
  67. .Llen_found48:
  68. aghi %r5,16
  69. .Llen_found32:
  70. aghi %r5,16
  71. .Llen_found16:
  72. aghi %r5,16
  73. .Llen_found:
  74. vlgvb %r4,%v16,7 /* Load byte index of zero. */
  75. algr %r5,%r4
  76. .Llen_end:
  77. /* STRCPY
  78. %r1 = loaded bytes (tmp)
  79. %r4 = zero byte index (tmp)
  80. %r3 = curr src pointer
  81. %r2 = curr dst pointer
  82. */
  83. la %r2,0(%r5,%r2) /* strcpy at end of dst-string. */
  84. vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
  85. lcbb %r1,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
  86. vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
  87. vlgvb %r5,%v17,7 /* Load zero index or 16 if not found. */
  88. clrjl %r5,%r1,.Lcpy_found_align /* If found zero within loaded bytes,
  89. copy bytes before and return. */
  90. /* Align s to 16 byte. */
  91. risbgn %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
  92. lghi %r5,15 /* current_len = 15. */
  93. slr %r5,%r4 /* Compute highest index to 16byte boundary. */
  94. vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
  95. ahi %r5,1 /* Start loop at next character. */
  96. /* Find zero in 16byte aligned loop. */
  97. .Lcpy_loop:
  98. vl %v16,0(%r5,%r3) /* Load s. */
  99. vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
  100. je .Lcpy_found_v16_0 /* Jump away if zero was found. */
  101. vl %v18,16(%r5,%r3)/* Load next part of s. */
  102. vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
  103. vfenezbs %v17,%v18,%v18
  104. je .Lcpy_found_v18_16
  105. vl %v16,32(%r5,%r3)
  106. vst %v18,16(%r5,%r2)
  107. vfenezbs %v17,%v16,%v16
  108. je .Lcpy_found_v16_32
  109. vl %v18,48(%r5,%r3)
  110. vst %v16,32(%r5,%r2)
  111. vfenezbs %v17,%v18,%v18
  112. je .Lcpy_found_v18_48
  113. vst %v18,48(%r5,%r2)
  114. aghi %r5,64
  115. j .Lcpy_loop /* No zero -> loop. */
  116. .Lcpy_found_v16_32:
  117. aghi %r5,32
  118. .Lcpy_found_v16_0:
  119. la %r4,0(%r5,%r2)
  120. vlgvb %r1,%v17,7 /* Load byte index of zero. */
  121. vstl %v16,%r1,0(%r4) /* Copy characters including zero. */
  122. lgr %r2,%r0 /* Load saved dest-ptr. */
  123. br %r14
  124. .Lcpy_found_v18_48:
  125. aghi %r5,32
  126. .Lcpy_found_v18_16:
  127. la %r4,16(%r5,%r2)
  128. vlgvb %r1,%v17,7 /* Load byte index of zero. */
  129. vstl %v18,%r1,0(%r4) /* Copy characters including zero. */
  130. lgr %r2,%r0 /* Load saved dest-ptr. */
  131. br %r14
  132. .Lcpy_found_align:
  133. vstl %v16,%r5,0(%r2) /* Copy characters including zero. */
  134. lgr %r2,%r0 /* Load saved dest-ptr. */
  135. br %r14
  136. END(STRCAT_Z13)
  137. # if ! HAVE_STRCAT_IFUNC
  138. strong_alias (STRCAT_Z13, strcat)
  139. # endif
  140. # if ! HAVE_STRCAT_C && defined SHARED && IS_IN (libc)
  141. strong_alias (STRCAT_Z13, __GI_strcat)
  142. # endif
  143. #endif