memset.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ! Copyright (C) 2008-2012 Imagination Technologies Ltd.
  2. .text
  3. .global _memset
  4. .type _memset,function
  5. ! D1Ar1 dst
  6. ! D0Ar2 c
  7. ! D1Ar3 cnt
  8. ! D0Re0 dst
  9. _memset:
  10. AND D0Ar2,D0Ar2,#0xFF ! Ensure a byte input value
  11. MULW D0Ar2,D0Ar2,#0x0101 ! Duplicate byte value into 0-15
  12. ANDS D0Ar4,D1Ar1,#7 ! Extract bottom LSBs of dst
  13. LSL D0Re0,D0Ar2,#16 ! Duplicate byte value into 16-31
  14. ADD A0.2,D0Ar2,D0Re0 ! Duplicate byte value into 4 (A0.2)
  15. MOV D0Re0,D1Ar1 ! Return dst
  16. BZ $LLongStub ! if start address is aligned
  17. ! start address is not aligned on an 8 byte boundary, so we
  18. ! need the number of bytes up to the next 8 byte address
  19. ! boundary, or the length of the string if less than 8, in D1Ar5
  20. MOV D0Ar2,#8 ! Need 8 - N in D1Ar5 ...
  21. SUB D1Ar5,D0Ar2,D0Ar4 ! ... subtract N
  22. CMP D1Ar3,D1Ar5
  23. MOVMI D1Ar5,D1Ar3
  24. B $LByteStub ! dst is mis-aligned, do $LByteStub
  25. !
  26. ! Preamble to LongLoop which generates 4*8 bytes per interation (5 cycles)
  27. !
  28. $LLongStub:
  29. LSRS D0Ar2,D1Ar3,#5
  30. AND D1Ar3,D1Ar3,#0x1F
  31. MOV A1.2,A0.2
  32. BEQ $LLongishStub
  33. SUB TXRPT,D0Ar2,#1
  34. CMP D1Ar3,#0
  35. $LLongLoop:
  36. SETL [D1Ar1++],A0.2,A1.2
  37. SETL [D1Ar1++],A0.2,A1.2
  38. SETL [D1Ar1++],A0.2,A1.2
  39. SETL [D1Ar1++],A0.2,A1.2
  40. BR $LLongLoop
  41. BZ $Lexit
  42. !
  43. ! Preamble to LongishLoop which generates 1*8 bytes per interation (2 cycles)
  44. !
  45. $LLongishStub:
  46. LSRS D0Ar2,D1Ar3,#3
  47. AND D1Ar3,D1Ar3,#0x7
  48. MOV D1Ar5,D1Ar3
  49. BEQ $LByteStub
  50. SUB TXRPT,D0Ar2,#1
  51. CMP D1Ar3,#0
  52. $LLongishLoop:
  53. SETL [D1Ar1++],A0.2,A1.2
  54. BR $LLongishLoop
  55. BZ $Lexit
  56. !
  57. ! This does a byte structured burst of up to 7 bytes
  58. !
  59. ! D1Ar1 should point to the location required
  60. ! D1Ar3 should be the remaining total byte count
  61. ! D1Ar5 should be burst size (<= D1Ar3)
  62. !
  63. $LByteStub:
  64. SUBS D1Ar3,D1Ar3,D1Ar5 ! Reduce count
  65. ADD D1Ar1,D1Ar1,D1Ar5 ! Advance pointer to end of area
  66. MULW D1Ar5,D1Ar5,#4 ! Scale to (1*4), (2*4), (3*4)
  67. SUB D1Ar5,D1Ar5,#(8*4) ! Rebase to -(7*4), -(6*4), -(5*4), ...
  68. MOV A1.2,D1Ar5
  69. SUB PC,CPC1,A1.2 ! Jump into table below
  70. SETB [D1Ar1+#(-7)],A0.2
  71. SETB [D1Ar1+#(-6)],A0.2
  72. SETB [D1Ar1+#(-5)],A0.2
  73. SETB [D1Ar1+#(-4)],A0.2
  74. SETB [D1Ar1+#(-3)],A0.2
  75. SETB [D1Ar1+#(-2)],A0.2
  76. SETB [D1Ar1+#(-1)],A0.2
  77. !
  78. ! Return if all data has been output, otherwise do $LLongStub
  79. !
  80. BNZ $LLongStub
  81. $Lexit:
  82. MOV PC,D1RtP
  83. .size _memset,.-_memset