memset-thumb.s 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. TO = 1
  2. TOE = 2
  3. N = 3
  4. TMP = 3 /* N and TMP don't overlap */
  5. TEXT memset(SB), $0
  6. MOVW R0, R(TO)
  7. MOVW data+4(FP), R(4)
  8. MOVW n+8(FP), R(N)
  9. ADD R(N), R(TO), R(TOE) /* to end pointer */
  10. CMP $4, R(N) /* need at least 4 bytes to copy */
  11. BLT _1tail
  12. AND $0xFF, R(4) /* it's a byte */
  13. SLL $8, R(4), R(TMP) /* replicate to a word */
  14. ORR R(TMP), R(4)
  15. SLL $16, R(4), R(TMP)
  16. ORR R(TMP), R(4)
  17. _4align: /* align on 4 */
  18. AND.S $3, R(TO), R(TMP)
  19. BEQ _4aligned
  20. MOVBU.P R(4), 1(R(TO)) /* implicit write back */
  21. B _4align
  22. _4aligned:
  23. SUB $31, R(TOE), R(TMP) /* do 32-byte chunks if possible */
  24. CMP R(TMP), R(TO)
  25. BHS _4tail
  26. MOVW R4, R5 /* replicate */
  27. MOVW R4, R6
  28. MOVW R4, R7
  29. MOVW R4, R8
  30. MOVW R4, R9
  31. MOVW R4, R10
  32. MOVW R4, R11
  33. _f32loop:
  34. CMP R(TMP), R(TO)
  35. BHS _4tail
  36. MOVM.IA.W [R4-R11], (R(TO))
  37. B _f32loop
  38. _4tail:
  39. SUB $3, R(TOE), R(TMP) /* do remaining words if possible */
  40. _4loop:
  41. CMP R(TMP), R(TO)
  42. BHS _1tail
  43. MOVW.P R(4), 4(R(TO)) /* implicit write back */
  44. B _4loop
  45. _1tail:
  46. CMP R(TO), R(TOE)
  47. BEQ _return
  48. MOVBU.P R(4), 1(R(TO)) /* implicit write back */
  49. B _1tail
  50. _return:
  51. RET