strcpy.S 4.0 KB

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