strcpy.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Optimized version of the standard strcpy() 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, see
  15. <http://www.gnu.org/licenses/>. */
  16. /* Return: dest
  17. Inputs:
  18. in0: dest
  19. in1: src
  20. In this form, it assumes little endian mode. For big endian mode, the
  21. the two shifts in .l2 must be inverted:
  22. shl value = r[1], sh1 // value = w0 << sh1
  23. shr.u tmp = r[0], sh2 // tmp = w1 >> sh2
  24. */
  25. #include <sysdep.h>
  26. #undef ret
  27. #define saved_lc r15
  28. #define saved_pr r16
  29. #define thresh r17
  30. #define dest r19
  31. #define src r20
  32. #define len r21
  33. #define asrc r22
  34. #define tmp r23
  35. #define pos r24
  36. #define w0 r25
  37. #define w1 r26
  38. #define c r27
  39. #define sh2 r28
  40. #define sh1 r29
  41. #define loopcnt r30
  42. #define value r31
  43. ENTRY(strcpy)
  44. .prologue
  45. alloc r2 = ar.pfs, 2, 0, 30, 32
  46. #define MEMLAT 2
  47. .rotr r[MEMLAT + 2]
  48. .rotp p[MEMLAT + 1]
  49. mov ret0 = in0 /* return value = dest */
  50. .save pr, saved_pr
  51. mov saved_pr = pr /* save the predicate registers */
  52. .save ar.lc, saved_lc
  53. mov saved_lc = ar.lc /* save the loop counter */
  54. .body
  55. sub tmp = r0, in0 ;; /* tmp = -dest */
  56. mov dest = in0 /* dest */
  57. mov src = in1 /* src */
  58. and loopcnt = 7, tmp ;; /* loopcnt = -dest % 8 */
  59. cmp.eq p6, p0 = loopcnt, r0
  60. adds loopcnt = -1, loopcnt /* --loopcnt */
  61. (p6) br.cond.sptk .dest_aligned ;;
  62. mov ar.lc = loopcnt
  63. .l1: /* copy -dest % 8 bytes */
  64. ld1 c = [src], 1 /* c = *src++ */
  65. ;;
  66. st1 [dest] = c, 1 /* *dest++ = c */
  67. cmp.eq p6, p0 = c, r0
  68. (p6) br.cond.dpnt .restore_and_exit
  69. br.cloop.dptk .l1 ;;
  70. .dest_aligned:
  71. and sh1 = 7, src /* sh1 = src % 8 */
  72. mov ar.lc = -1 /* "infinite" loop */
  73. and asrc = -8, src ;; /* asrc = src & -OPSIZ -- align src */
  74. sub thresh = 8, sh1
  75. mov pr.rot = 1 << 16 /* set rotating predicates */
  76. cmp.ne p7, p0 = r0, r0 /* clear p7 */
  77. shl sh1 = sh1, 3 ;; /* sh1 = 8 * (src % 8) */
  78. sub sh2 = 64, sh1 /* sh2 = 64 - sh1 */
  79. cmp.eq p6, p0 = sh1, r0 /* is the src aligned? */
  80. (p6) br.cond.sptk .src_aligned ;;
  81. ld8 r[1] = [asrc],8 ;;
  82. .align 32
  83. .l2:
  84. ld8.s r[0] = [asrc], 8
  85. shr.u value = r[1], sh1 ;; /* value = w0 >> sh1 */
  86. czx1.r pos = value ;; /* do we have an "early" zero */
  87. cmp.lt p7, p0 = pos, thresh /* in w0 >> sh1? */
  88. (p7) br.cond.dpnt .found0
  89. chk.s r[0], .recovery2 /* it is safe to do that only */
  90. .back2: /* after the previous test */
  91. shl tmp = r[0], sh2 /* tmp = w1 << sh2 */
  92. ;;
  93. or value = value, tmp ;; /* value |= tmp */
  94. czx1.r pos = value ;;
  95. cmp.ne p7, p0 = 8, pos
  96. (p7) br.cond.dpnt .found0
  97. st8 [dest] = value, 8 /* store val to dest */
  98. br.ctop.dptk .l2 ;;
  99. .src_aligned:
  100. .l3:
  101. (p[0]) ld8.s r[0] = [src], 8
  102. (p[MEMLAT]) chk.s r[MEMLAT], .recovery3
  103. .back3:
  104. (p[MEMLAT]) mov value = r[MEMLAT]
  105. (p[MEMLAT]) czx1.r pos = r[MEMLAT] ;;
  106. (p[MEMLAT]) cmp.ne p7, p0 = 8, pos
  107. (p7) br.cond.dpnt .found0
  108. (p[MEMLAT]) st8 [dest] = r[MEMLAT], 8
  109. br.ctop.dptk .l3 ;;
  110. .found0:
  111. mov ar.lc = pos
  112. .l4:
  113. extr.u c = value, 0, 8 /* c = value & 0xff */
  114. shr.u value = value, 8
  115. ;;
  116. st1 [dest] = c, 1
  117. br.cloop.dptk .l4 ;;
  118. .restore_and_exit:
  119. mov ar.lc = saved_lc /* restore the loop counter */
  120. mov pr = saved_pr, -1 /* restore the predicate registers */
  121. br.ret.sptk.many b0
  122. .recovery2:
  123. add tmp = -8, asrc ;;
  124. ld8 r[0] = [tmp]
  125. br.cond.sptk .back2
  126. .recovery3:
  127. add tmp = -(MEMLAT + 1) * 8, src ;;
  128. ld8 r[MEMLAT] = [tmp]
  129. br.cond.sptk .back3
  130. END(strcpy)
  131. libc_hidden_def (strcpy)