strcpy.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Cloned and hacked for uClibc by Paul Mundt, December 2003 */
  2. /* Modified by SuperH, Inc. September 2003 */
  3. ! Entry: arg0: destination
  4. ! arg1: source
  5. ! Exit: result: destination
  6. !
  7. ! SH5 code Copyright 2002 SuperH Ltd.
  8. #include <features.h>
  9. #include <endian.h>
  10. #if __BYTE_ORDER == __LITTLE_ENDIAN
  11. #define SHHI shlld
  12. #define SHLO shlrd
  13. #else
  14. #define SHHI shlrd
  15. #define SHLO shlld
  16. #endif
  17. .section .text..SHmedia32,"ax"
  18. .globl strcpy
  19. .type strcpy, @function
  20. .align 5
  21. strcpy:
  22. pta/l shortstring,tr1
  23. ldlo.q r3,0,r4
  24. ptabs r18,tr4
  25. shlli r3,3,r7
  26. addi r2, 8, r0
  27. mcmpeq.b r4,r63,r6
  28. SHHI r6,r7,r6
  29. bnei/u r6,0,tr1 /* shortstring */
  30. pta/l no_lddst, tr2
  31. ori r3,-8,r23
  32. sub r2, r23, r0
  33. sub r3, r2, r21
  34. addi r21, 8, r20
  35. ldx.q r0, r21, r5
  36. pta/l loop, tr0
  37. ori r2,-8,r22
  38. mcmpeq.b r5, r63, r6
  39. bgt/u r22, r23, tr2 /* no_lddst */
  40. /* r22 < r23 : Need to do a load from the destination. */
  41. /* r22 == r23 : Doesn't actually need to load from destination, */
  42. /* but still can be handled here. */
  43. ldlo.q r2, 0, r9
  44. movi -1, r8
  45. SHLO r8, r7, r8
  46. mcmv r4, r8, r9
  47. stlo.q r2, 0, r9
  48. beqi/l r6, 0, tr0 /* loop */
  49. add r5, r63, r4
  50. addi r0, 8, r0
  51. blink tr1, r63 /* shortstring */
  52. no_lddst:
  53. /* r22 > r23: note that for r22 == r23 the sthi.q would clobber */
  54. /* bytes before the destination region. */
  55. stlo.q r2, 0, r4
  56. SHHI r4, r7, r4
  57. sthi.q r0, -1, r4
  58. beqi/l r6, 0, tr0 /* loop */
  59. add r5, r63, r4
  60. addi r0, 8, r0
  61. shortstring:
  62. #if __BYTE_ORDER != __LITTLE_ENDIAN
  63. pta/l shortstring2,tr1
  64. byterev r4,r4
  65. #endif
  66. shortstring2:
  67. st.b r0,-8,r4
  68. andi r4,0xff,r5
  69. shlri r4,8,r4
  70. addi r0,1,r0
  71. bnei/l r5,0,tr1
  72. blink tr4,r63 /* return */
  73. .balign 8
  74. loop:
  75. stlo.q r0, 0, r5
  76. ldx.q r0, r20, r4
  77. addi r0, 16, r0
  78. sthi.q r0, -9, r5
  79. mcmpeq.b r4, r63, r6
  80. bnei/u r6, 0, tr1 /* shortstring */
  81. ldx.q r0, r21, r5
  82. stlo.q r0, -8, r4
  83. sthi.q r0, -1, r4
  84. mcmpeq.b r5, r63, r6
  85. beqi/l r6, 0, tr0 /* loop */
  86. add r5, r63, r4
  87. addi r0, 8, r0
  88. blink tr1, r63 /* shortstring */
  89. .size strcpy,.-strcpy
  90. libc_hidden_def(strcpy)