memset.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * memzero 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. /*
  40. * We need an extra register for this loop - save the return address and
  41. * use the LR
  42. */
  43. str lr, [sp, #-4]!
  44. mov ip, r1
  45. mov lr, r1
  46. 2: subs r2, r2, #64
  47. stmgeia r0!, {r1, r3, ip, lr} @ 64 bytes at a time.
  48. stmgeia r0!, {r1, r3, ip, lr}
  49. stmgeia r0!, {r1, r3, ip, lr}
  50. stmgeia r0!, {r1, r3, ip, lr}
  51. bgt 2b
  52. ldmeqfd sp!, {pc} @ Now <64 bytes to go.
  53. /*
  54. * No need to correct the count; we're only testing bits from now on
  55. */
  56. tst r2, #32
  57. stmneia r0!, {r1, r3, ip, lr}
  58. stmneia r0!, {r1, r3, ip, lr}
  59. tst r2, #16
  60. stmneia r0!, {r1, r3, ip, lr}
  61. ldr lr, [sp], #4
  62. 4: tst r2, #8
  63. stmneia r0!, {r1, r3}
  64. tst r2, #4
  65. strne r1, [r0], #4
  66. /*
  67. * When we get here, we've got less than 4 bytes to zero. We
  68. * may have an unaligned pointer as well.
  69. */
  70. 5: tst r2, #2
  71. strneb r1, [r0], #1
  72. strneb r1, [r0], #1
  73. tst r2, #1
  74. strneb r1, [r0], #1
  75. mov pc, lr