memset.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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, [r0], #1 @ 1
  21. strleb r1, [r0], #1 @ 1
  22. strb r1, [r0], #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. ands r3, r0, #3 @ 1 unaligned?
  30. bne 1b @ 1
  31. /*
  32. * we know that the pointer in r0 is aligned to a word boundary.
  33. */
  34. orr r1, r1, r1, lsl #8
  35. orr r1, r1, r1, lsl #16
  36. mov r3, r1
  37. cmp r2, #16
  38. blt 4f
  39. #if ! CALGN(1)+0
  40. /*
  41. * We need an extra register for this loop - save the return address and
  42. * use the LR
  43. */
  44. str lr, [sp, #-4]!
  45. mov ip, r1
  46. mov lr, r1
  47. 2: subs r2, r2, #64
  48. stmgeia r0!, {r1, r3, ip, lr} @ 64 bytes at a time.
  49. stmgeia r0!, {r1, r3, ip, lr}
  50. stmgeia r0!, {r1, r3, ip, lr}
  51. stmgeia r0!, {r1, r3, ip, lr}
  52. bgt 2b
  53. ldmeqfd sp!, {pc} @ Now <64 bytes to go.
  54. /*
  55. * No need to correct the count; we're only testing bits from now on
  56. */
  57. tst r2, #32
  58. stmneia r0!, {r1, r3, ip, lr}
  59. stmneia r0!, {r1, r3, ip, lr}
  60. tst r2, #16
  61. stmneia r0!, {r1, r3, ip, lr}
  62. ldr lr, [sp], #4
  63. #else
  64. /*
  65. * This version aligns the destination pointer in order to write
  66. * whole cache lines at once.
  67. */
  68. stmfd sp!, {r4-r7, lr}
  69. mov r4, r1
  70. mov r5, r1
  71. mov r6, r1
  72. mov r7, r1
  73. mov ip, r1
  74. mov lr, r1
  75. cmp r2, #96
  76. tstgt r0, #31
  77. ble 3f
  78. and ip, r0, #31
  79. rsb ip, ip, #32
  80. sub r2, r2, ip
  81. movs ip, ip, lsl #(32 - 4)
  82. stmcsia r0!, {r4, r5, r6, r7}
  83. stmmiia r0!, {r4, r5}
  84. tst ip, #(1 << 30)
  85. mov ip, r1
  86. strne r1, [r0], #4
  87. 3: subs r2, r2, #64
  88. stmgeia r0!, {r1, r3-r7, ip, lr}
  89. stmgeia r0!, {r1, r3-r7, ip, lr}
  90. bgt 3b
  91. ldmeqfd sp!, {r4-r7, pc}
  92. tst r2, #32
  93. stmneia r0!, {r1, r3-r7, ip, lr}
  94. tst r2, #16
  95. stmneia r0!, {r4-r7}
  96. ldmfd sp!, {r4-r7, lr}
  97. #endif
  98. 4: tst r2, #8
  99. stmneia r0!, {r1, r3}
  100. tst r2, #4
  101. strne r1, [r0], #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, [r0], #1
  108. strneb r1, [r0], #1
  109. tst r2, #1
  110. strneb r1, [r0], #1
  111. mov pc, lr
  112. ENDPROC(memset)