memset.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. .text
  15. .align 5
  16. .word 0
  17. 1: subs r2, r2, #4 @ 1 do we have enough
  18. blt 5f @ 1 bytes to align with?
  19. cmp r3, #2 @ 1
  20. strltb r1, [ip], #1 @ 1
  21. strleb r1, [ip], #1 @ 1
  22. strb r1, [ip], #1 @ 1
  23. add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3))
  24. /*
  25. * The pointer is now aligned and the length is adjusted. Try doing the
  26. * memset again.
  27. */
  28. ENTRY(memset)
  29. /*
  30. * Preserve the contents of r0 for the return value.
  31. */
  32. mov ip, r0
  33. ands r3, ip, #3 @ 1 unaligned?
  34. bne 1b @ 1
  35. /*
  36. * we know that the pointer in ip is aligned to a word boundary.
  37. */
  38. orr r1, r1, r1, lsl #8
  39. orr r1, r1, r1, lsl #16
  40. mov r3, r1
  41. cmp r2, #16
  42. blt 4f
  43. #if ! CALGN(1)+0
  44. /*
  45. * We need 2 extra registers for this loop - use r8 and the LR
  46. */
  47. stmfd sp!, {r8, lr}
  48. mov r8, r1
  49. mov lr, r1
  50. 2: subs r2, r2, #64
  51. stmgeia ip!, {r1, r3, r8, lr} @ 64 bytes at a time.
  52. stmgeia ip!, {r1, r3, r8, lr}
  53. stmgeia ip!, {r1, r3, r8, lr}
  54. stmgeia ip!, {r1, r3, r8, lr}
  55. bgt 2b
  56. ldmeqfd sp!, {r8, pc} @ Now <64 bytes to go.
  57. /*
  58. * No need to correct the count; we're only testing bits from now on
  59. */
  60. tst r2, #32
  61. stmneia ip!, {r1, r3, r8, lr}
  62. stmneia ip!, {r1, r3, r8, lr}
  63. tst r2, #16
  64. stmneia ip!, {r1, r3, r8, lr}
  65. ldmfd sp!, {r8, lr}
  66. #else
  67. /*
  68. * This version aligns the destination pointer in order to write
  69. * whole cache lines at once.
  70. */
  71. stmfd sp!, {r4-r8, lr}
  72. mov r4, r1
  73. mov r5, r1
  74. mov r6, r1
  75. mov r7, r1
  76. mov r8, r1
  77. mov lr, r1
  78. cmp r2, #96
  79. tstgt ip, #31
  80. ble 3f
  81. and r8, ip, #31
  82. rsb r8, r8, #32
  83. sub r2, r2, r8
  84. movs r8, r8, lsl #(32 - 4)
  85. stmcsia ip!, {r4, r5, r6, r7}
  86. stmmiia ip!, {r4, r5}
  87. tst r8, #(1 << 30)
  88. mov r8, r1
  89. strne r1, [ip], #4
  90. 3: subs r2, r2, #64
  91. stmgeia ip!, {r1, r3-r8, lr}
  92. stmgeia ip!, {r1, r3-r8, lr}
  93. bgt 3b
  94. ldmeqfd sp!, {r4-r8, pc}
  95. tst r2, #32
  96. stmneia ip!, {r1, r3-r8, lr}
  97. tst r2, #16
  98. stmneia ip!, {r4-r7}
  99. ldmfd sp!, {r4-r8, lr}
  100. #endif
  101. 4: tst r2, #8
  102. stmneia ip!, {r1, r3}
  103. tst r2, #4
  104. strne r1, [ip], #4
  105. /*
  106. * When we get here, we've got less than 4 bytes to zero. We
  107. * may have an unaligned pointer as well.
  108. */
  109. 5: tst r2, #2
  110. strneb r1, [ip], #1
  111. strneb r1, [ip], #1
  112. tst r2, #1
  113. strneb r1, [ip], #1
  114. mov pc, lr
  115. ENDPROC(memset)