memset.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * r12: void *b
  24. * r11: int c
  25. * r10: size_t len
  26. *
  27. * Returns b in r12
  28. */
  29. .section .text.memset, "ax", @progbits
  30. .global memset
  31. .type memset, @function
  32. .align 2
  33. memset:
  34. mov r9, r12
  35. mov r8, r12
  36. or r11, r11, r11 << 8
  37. andl r9, 3, COH
  38. brne 1f
  39. 2: or r11, r11, r11 << 16
  40. sub r10, 4
  41. brlt 5f
  42. /* Let's do some real work */
  43. 4: st.w r8++, r11
  44. sub r10, 4
  45. brge 4b
  46. /*
  47. * When we get here, we've got less than 4 bytes to set. r10
  48. * might be negative.
  49. */
  50. 5: sub r10, -4
  51. reteq r12
  52. /* Fastpath ends here, exactly 32 bytes from memset */
  53. /* Handle unaligned count or pointer */
  54. bld r10, 1
  55. brcc 6f
  56. st.b r8++, r11
  57. st.b r8++, r11
  58. bld r10, 0
  59. retcc r12
  60. 6: st.b r8++, r11
  61. mov pc, lr
  62. /* Handle unaligned pointer */
  63. 1: sub r10, 4
  64. brlt 5b
  65. add r10, r9
  66. lsl r9, 1
  67. add pc, r9
  68. st.b r8++, r11
  69. st.b r8++, r11
  70. st.b r8++, r11
  71. rjmp 2b
  72. .size memset, . - memset