memset.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * linux/arch/arm/lib/memset.S
  3. *
  4. * Copyright (C) 1995-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * ASM optimised string functions
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/assembler.h>
  14. #include <asm/unwind.h>
  15. .text
  16. .align 5
  17. ENTRY(mmioset)
  18. ENTRY(memset)
  19. UNWIND( .fnstart )
  20. ands r3, r0, #3 @ 1 unaligned?
  21. mov ip, r0 @ preserve r0 as return value
  22. bne 6f @ 1
  23. /*
  24. * we know that the pointer in ip is aligned to a word boundary.
  25. */
  26. 1: orr r1, r1, r1, lsl #8
  27. orr r1, r1, r1, lsl #16
  28. mov r3, r1
  29. cmp r2, #16
  30. blt 4f
  31. #if ! CALGN(1)+0
  32. /*
  33. * We need 2 extra registers for this loop - use r8 and the LR
  34. */
  35. stmfd sp!, {r8, lr}
  36. UNWIND( .fnend )
  37. UNWIND( .fnstart )
  38. UNWIND( .save {r8, lr} )
  39. mov r8, r1
  40. mov lr, r1
  41. 2: subs r2, r2, #64
  42. stmgeia ip!, {r1, r3, r8, lr} @ 64 bytes at a time.
  43. stmgeia ip!, {r1, r3, r8, lr}
  44. stmgeia ip!, {r1, r3, r8, lr}
  45. stmgeia ip!, {r1, r3, r8, lr}
  46. bgt 2b
  47. ldmeqfd sp!, {r8, pc} @ Now <64 bytes to go.
  48. /*
  49. * No need to correct the count; we're only testing bits from now on
  50. */
  51. tst r2, #32
  52. stmneia ip!, {r1, r3, r8, lr}
  53. stmneia ip!, {r1, r3, r8, lr}
  54. tst r2, #16
  55. stmneia ip!, {r1, r3, r8, lr}
  56. ldmfd sp!, {r8, lr}
  57. UNWIND( .fnend )
  58. #else
  59. /*
  60. * This version aligns the destination pointer in order to write
  61. * whole cache lines at once.
  62. */
  63. stmfd sp!, {r4-r8, lr}
  64. UNWIND( .fnend )
  65. UNWIND( .fnstart )
  66. UNWIND( .save {r4-r8, lr} )
  67. mov r4, r1
  68. mov r5, r1
  69. mov r6, r1
  70. mov r7, r1
  71. mov r8, r1
  72. mov lr, r1
  73. cmp r2, #96
  74. tstgt ip, #31
  75. ble 3f
  76. and r8, ip, #31
  77. rsb r8, r8, #32
  78. sub r2, r2, r8
  79. movs r8, r8, lsl #(32 - 4)
  80. stmcsia ip!, {r4, r5, r6, r7}
  81. stmmiia ip!, {r4, r5}
  82. tst r8, #(1 << 30)
  83. mov r8, r1
  84. strne r1, [ip], #4
  85. 3: subs r2, r2, #64
  86. stmgeia ip!, {r1, r3-r8, lr}
  87. stmgeia ip!, {r1, r3-r8, lr}
  88. bgt 3b
  89. ldmeqfd sp!, {r4-r8, pc}
  90. tst r2, #32
  91. stmneia ip!, {r1, r3-r8, lr}
  92. tst r2, #16
  93. stmneia ip!, {r4-r7}
  94. ldmfd sp!, {r4-r8, lr}
  95. UNWIND( .fnend )
  96. #endif
  97. UNWIND( .fnstart )
  98. 4: tst r2, #8
  99. stmneia ip!, {r1, r3}
  100. tst r2, #4
  101. strne r1, [ip], #4
  102. /*
  103. * When we get here, we've got less than 4 bytes to zero. We
  104. * may have an unaligned pointer as well.
  105. */
  106. 5: tst r2, #2
  107. strneb r1, [ip], #1
  108. strneb r1, [ip], #1
  109. tst r2, #1
  110. strneb r1, [ip], #1
  111. ret lr
  112. 6: subs r2, r2, #4 @ 1 do we have enough
  113. blt 5b @ 1 bytes to align with?
  114. cmp r3, #2 @ 1
  115. strltb r1, [ip], #1 @ 1
  116. strleb r1, [ip], #1 @ 1
  117. strb r1, [ip], #1 @ 1
  118. add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3))
  119. b 1b
  120. UNWIND( .fnend )
  121. ENDPROC(memset)
  122. ENDPROC(mmioset)