strcpy-vx.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Vector optimized 32/64 bit S/390 version of strcpy.
  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-strcpy.h>
  16. #include "sysdep.h"
  17. #include "asm-syntax.h"
  18. .text
  19. #if HAVE_STRCPY_Z13
  20. /* char * strcpy (const char *dest, const char *src)
  21. Copy string src to dest.
  22. Register usage:
  23. -r1=tmp
  24. -r2=dest and return_value
  25. -r3=src
  26. -r4=tmp
  27. -r5=current_len
  28. -v16=part of src
  29. -v17=index of zero
  30. -v18=part of src
  31. */
  32. ENTRY(STRCPY_Z13)
  33. .machine "z13"
  34. .machinemode "zarch_nohighgprs"
  35. vlbb %v16,0(%r3),6 /* Load s until next 4k-byte boundary. */
  36. lcbb %r1,0(%r3),6 /* Get bytes to 4k-byte boundary or 16. */
  37. vfenezb %v17,%v16,%v16 /* Find element not equal with zero search. */
  38. vlgvb %r5,%v17,7 /* Load zero index or 16 if not found. */
  39. clrjl %r5,%r1,.Lfound_align /* If found zero within loaded bytes,
  40. copy bytes before and return. */
  41. /* Align s to 16 byte. */
  42. risbgn %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
  43. lghi %r5,15 /* current_len = 15. */
  44. slr %r5,%r4 /* Compute highest index to 16byte boundary. */
  45. vstl %v16,%r5,0(%r2) /* Copy loaded characters - no zero. */
  46. ahi %r5,1 /* Start loop at next character. */
  47. /* Find zero in 16byte aligned loop. */
  48. .Lloop:
  49. vl %v16,0(%r5,%r3) /* Load s. */
  50. vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search. */
  51. je .Lfound_v16_0 /* Jump away if zero was found. */
  52. vl %v18,16(%r5,%r3)/* Load next part of s. */
  53. vst %v16,0(%r5,%r2) /* Store previous part without zero to dst. */
  54. vfenezbs %v17,%v18,%v18
  55. je .Lfound_v18_16
  56. vl %v16,32(%r5,%r3)
  57. vst %v18,16(%r5,%r2)
  58. vfenezbs %v17,%v16,%v16
  59. je .Lfound_v16_32
  60. vl %v18,48(%r5,%r3)
  61. vst %v16,32(%r5,%r2)
  62. vfenezbs %v17,%v18,%v18
  63. je .Lfound_v18_48
  64. vst %v18,48(%r5,%r2)
  65. aghi %r5,64
  66. j .Lloop /* No zero found -> loop. */
  67. .Lfound_v16_32:
  68. aghi %r5,32
  69. .Lfound_v16_0:
  70. la %r3,0(%r5,%r2)
  71. vlgvb %r4,%v17,7 /* Load byte index of zero. */
  72. vstl %v16,%r4,0(%r3) /* Store characters including zero. */
  73. br %r14
  74. .Lfound_v18_48:
  75. aghi %r5,32
  76. .Lfound_v18_16:
  77. la %r3,16(%r5,%r2)
  78. vlgvb %r4,%v17,7 /* Load byte index of zero. */
  79. vstl %v18,%r4,0(%r3) /* Store characters including zero. */
  80. br %r14
  81. .Lfound_align:
  82. vstl %v16,%r5,0(%r2) /* Copy characters including zero. */
  83. br %r14
  84. END(STRCPY_Z13)
  85. # if ! HAVE_STRCPY_IFUNC
  86. strong_alias (STRCPY_Z13, strcpy)
  87. # endif
  88. # if ! HAVE_STRCPY_Z900_G5 && defined SHARED && IS_IN (libc)
  89. strong_alias (STRCPY_Z13, __GI_strcpy)
  90. # endif
  91. #endif