strcpy.S 2.0 KB

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