memset.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <features.h>
  9. #define s r12
  10. #define c r11
  11. #define n r10
  12. .text
  13. .global memset
  14. .type memset, @function
  15. .global __memset
  16. .hidden __memset
  17. .type __memset, @function
  18. .align 1
  19. memset:
  20. __memset:
  21. cp.w n, 32
  22. mov r9, s
  23. brge .Llarge_memset
  24. sub n, 1
  25. retlt s
  26. 1: st.b s++, c
  27. sub n, 1
  28. brge 1b
  29. retal r9
  30. .Llarge_memset:
  31. mov r8, r11
  32. mov r11, 3
  33. bfins r8, r8, 8, 8
  34. bfins r8, r8, 16, 16
  35. tst s, r11
  36. breq 2f
  37. 1: st.b s++, r8
  38. sub n, 1
  39. tst s, r11
  40. brne 1b
  41. 2: mov r11, r9
  42. mov r9, r8
  43. sub n, 8
  44. 3: st.d s++, r8
  45. sub n, 8
  46. brge 3b
  47. /* If we are done, n == -8 and we'll skip all st.b insns below */
  48. neg n
  49. lsl n, 1
  50. add pc, n
  51. .rept 7
  52. st.b s++, r8
  53. .endr
  54. retal r11
  55. .size memset, . - memset
  56. libc_hidden_def(memset)