memset.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Cloned and hacked for uClibc by Paul Mundt, December 2003 */
  2. /* Modified by SuperH, Inc. September 2003 */
  3. !
  4. ! Fast SH memset
  5. !
  6. ! by Toshiyasu Morita (tm@netcom.com)
  7. !
  8. ! SH5 code by J"orn Rennecke (joern.rennecke@superh.com)
  9. ! Copyright 2002 SuperH Ltd.
  10. !
  11. #ifdef __LITTLE_ENDIAN__
  12. #define SHHI shlld
  13. #define SHLO shlrd
  14. #else
  15. #define SHHI shlrd
  16. #define SHLO shlld
  17. #endif
  18. .section .text..SHmedia32,"ax"
  19. .globl memset
  20. .set memset,__memset
  21. .globl __memset
  22. .hidden __memset
  23. .type __memset, @function
  24. .align 5
  25. __memset:
  26. pta/l multiquad, tr0
  27. andi r2, 7, r22
  28. ptabs r18, tr2
  29. mshflo.b r3,r3,r3
  30. add r4, r22, r23
  31. mperm.w r3, r63, r3 // Fill pattern now in every byte of r3
  32. movi 8, r9
  33. bgtu/u r23, r9, tr0 // multiquad
  34. beqi/u r4, 0, tr2 // Return with size 0 - ensures no mem accesses
  35. ldlo.q r2, 0, r7
  36. shlli r4, 2, r4
  37. movi -1, r8
  38. SHHI r8, r4, r8
  39. SHHI r8, r4, r8
  40. mcmv r7, r8, r3
  41. stlo.q r2, 0, r3
  42. blink tr2, r63
  43. multiquad:
  44. pta/l lastquad, tr0
  45. stlo.q r2, 0, r3
  46. shlri r23, 3, r24
  47. add r2, r4, r5
  48. beqi/u r24, 1, tr0 // lastquad
  49. pta/l loop, tr1
  50. sub r2, r22, r25
  51. andi r5, -8, r20 // calculate end address and
  52. addi r20, -7*8, r8 // loop end address; This might overflow, so we need
  53. // to use a different test before we start the loop
  54. bge/u r24, r9, tr1 // loop
  55. st.q r25, 8, r3
  56. st.q r20, -8, r3
  57. shlri r24, 1, r24
  58. beqi/u r24, 1, tr0 // lastquad
  59. st.q r25, 16, r3
  60. st.q r20, -16, r3
  61. beqi/u r24, 2, tr0 // lastquad
  62. st.q r25, 24, r3
  63. st.q r20, -24, r3
  64. lastquad:
  65. sthi.q r5, -1, r3
  66. blink tr2,r63
  67. loop:
  68. !!! alloco r25, 32 // QQQ comment out for short-term fix to SHUK #3895.
  69. // QQQ commenting out is locically correct, but sub-optimal
  70. // QQQ Sean McGoogan - 4th April 2003.
  71. st.q r25, 8, r3
  72. st.q r25, 16, r3
  73. st.q r25, 24, r3
  74. st.q r25, 32, r3
  75. addi r25, 32, r25
  76. bgeu/l r8, r25, tr1 // loop
  77. st.q r20, -40, r3
  78. st.q r20, -32, r3
  79. st.q r20, -24, r3
  80. st.q r20, -16, r3
  81. st.q r20, -8, r3
  82. sthi.q r5, -1, r3
  83. blink tr2,r63
  84. .size __memset,.-__memset