memset.S 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * Based on linux/arch/arm/lib/memset.S
  5. * Copyright (C) 1995-2000 Russell King
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * ASM optimised string functions
  12. */
  13. #include <asm/asm.h>
  14. /*
  15. * r12: void *b
  16. * r11: int c
  17. * r10: size_t len
  18. *
  19. * Returns b in r12
  20. */
  21. .text
  22. .global memset
  23. .type memset, @function
  24. .align 5
  25. memset:
  26. mov r9, r12
  27. mov r8, r12
  28. or r11, r11, r11 << 8
  29. andl r9, 3, COH
  30. brne 1f
  31. 2: or r11, r11, r11 << 16
  32. sub r10, 4
  33. brlt 5f
  34. /* Let's do some real work */
  35. 4: st.w r8++, r11
  36. sub r10, 4
  37. brge 4b
  38. /*
  39. * When we get here, we've got less than 4 bytes to set. r10
  40. * might be negative.
  41. */
  42. 5: sub r10, -4
  43. reteq r12
  44. /* Fastpath ends here, exactly 32 bytes from memset */
  45. /* Handle unaligned count or pointer */
  46. bld r10, 1
  47. brcc 6f
  48. st.b r8++, r11
  49. st.b r8++, r11
  50. bld r10, 0
  51. retcc r12
  52. 6: st.b r8++, r11
  53. retal r12
  54. /* Handle unaligned pointer */
  55. 1: sub r10, 4
  56. brlt 5b
  57. add r10, r9
  58. lsl r9, 1
  59. add pc, r9
  60. st.b r8++, r11
  61. st.b r8++, r11
  62. st.b r8++, r11
  63. rjmp 2b
  64. .size memset, . - memset