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