Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

memcpy_audio.S 4.7KB

pirms 8 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Teensyduino Audio Memcpy
  2. * Copyright (c) 2016 Frank Bösing
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * 1. The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * 2. If the Software is incorporated into a build system that allows
  16. * selection among a list of target devices, then similar target
  17. * devices manufactured by PJRC.COM must be included in the list of
  18. * target devices and selectable in the same manner.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  24. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  25. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  26. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. * SOFTWARE.
  28. */
  29. #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
  30. #include <AudioStream.h>
  31. .cpu cortex-m4
  32. .syntax unified
  33. .thumb
  34. .text
  35. .align 2
  36. /* void memcpy_tointerleave(short *dst, short *srcL, short *srcR); */
  37. .global memcpy_tointerleaveLR
  38. .thumb_func
  39. memcpy_tointerleaveLR:
  40. @ r0: dst
  41. @ r1: srcL
  42. @ r2: srcR
  43. #if AUDIO_BLOCK_SAMPLES > 8
  44. push {r4-r11,r14}
  45. add r14,r0,#(AUDIO_BLOCK_SAMPLES*2)
  46. .align 2
  47. .loopLR:
  48. //Load 2*4 words
  49. ldmia r1!, {r5,r7,r9,r11} //1+4
  50. ldmia r2!, {r6,r8,r10,r12} //1+4
  51. pkhbt r3,r5,r6,LSL #16 //1
  52. pkhtb r4,r6,r5,ASR #16 //1
  53. pkhbt r5,r7,r8,LSL #16 //1
  54. pkhtb r6,r8,r7,ASR #16 //1
  55. pkhbt r7,r9,r10,LSL #16 //1
  56. pkhtb r8,r10,r9,ASR #16 //1
  57. pkhbt r9,r11,r12,LSL #16 //1
  58. pkhtb r10,r12,r11,ASR #16 //1
  59. //Write 8 Words
  60. stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} //1+8 -> 5+5+8+9 = 27 Cycles to interleave 32 bytes.
  61. cmp r14, r0
  62. bne .loopLR
  63. pop {r4-r11,r14}
  64. #elif AUDIO_BLOCK_SAMPLES == 8
  65. push {r4-r8,r14}
  66. ldmia r1!, {r5,r7}
  67. ldmia r2!, {r6,r8}
  68. pkhbt r3,r5,r6,LSL #16
  69. pkhtb r4,r6,r5,ASR #16
  70. pkhbt r5,r7,r8,LSL #16
  71. pkhtb r6,r8,r7,ASR #16
  72. stmia r0!, {r3,r4,r5,r6}
  73. pop {r4-r8,r14}
  74. #endif
  75. BX lr
  76. /* void memcpy_tointerleaveL(short *dst, short *srcL); */
  77. .global memcpy_tointerleaveL
  78. .thumb_func
  79. memcpy_tointerleaveL:
  80. @ r0: dst
  81. @ r1: srcL
  82. mov r2, #0
  83. #if AUDIO_BLOCK_SAMPLES > 8
  84. push {r4-r11}
  85. add r12,r0,#(AUDIO_BLOCK_SAMPLES*2)
  86. .align 2
  87. .loopL:
  88. //Load 4 words
  89. ldmia r1!, {r5,r7,r9,r11} //1+4
  90. pkhbt r3,r5,r2 //1
  91. pkhtb r4,r2,r5,ASR #16 //1
  92. pkhbt r5,r7,r2 //1
  93. pkhtb r6,r2,r7,ASR #16 //1
  94. pkhbt r7,r9,r2 //1
  95. pkhtb r8,r2,r9,ASR #16 //1
  96. pkhbt r9,r11,r2 //1
  97. pkhtb r10,r2,r11,ASR #16 //1
  98. //Write 8 Words
  99. stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} //1+8
  100. cmp r12, r0
  101. bne .loopL
  102. pop {r4-r11}
  103. #elif AUDIO_BLOCK_SAMPLES == 8
  104. push {r4-r7}
  105. ldmia r1!, {r5,r7}
  106. pkhbt r3,r5,r2
  107. pkhtb r4,r2,r5,ASR #16
  108. pkhbt r5,r7,r2 //1
  109. pkhtb r6,r2,r7,ASR #16
  110. stmia r0!, {r3,r4,r5,r6}
  111. pop {r4-r7}
  112. #endif
  113. BX lr
  114. /* void memcpy_tointerleaveL(short *dst, short *srcR); */
  115. .global memcpy_tointerleaveR
  116. .thumb_func
  117. memcpy_tointerleaveR:
  118. @ r0: dst
  119. @ r1: srcR
  120. mov r2, #0
  121. #if AUDIO_BLOCK_SAMPLES > 8
  122. push {r4-r11}
  123. add r12,r0,#(AUDIO_BLOCK_SAMPLES*2)
  124. .align 2
  125. .loopR:
  126. //Load 4 words
  127. ldmia r1!, {r5,r7,r9,r11}
  128. pkhbt r3,r2,r5,LSL #16
  129. pkhtb r4,r5,r2
  130. pkhbt r5,r2,r7,LSL #16
  131. pkhtb r6,r7,r2
  132. pkhbt r7,r2,r9,LSL #16
  133. pkhtb r8,r9,r2
  134. pkhbt r9,r2,r11,LSL #16
  135. pkhtb r10,r11,r2
  136. //Write 8 Words
  137. stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10}
  138. cmp r12, r0
  139. bne .loopR
  140. pop {r4-r11}
  141. #elif AUDIO_BLOCK_SAMPLES == 8
  142. push {r4-r7}
  143. ldmia r1!, {r5,r7}
  144. pkhbt r3,r2,r5,LSL #16
  145. pkhtb r4,r5,r2
  146. pkhbt r5,r2,r7,LSL #16
  147. pkhtb r6,r7,r2
  148. stmia r0!, {r3,r4,r5,r6}
  149. pop {r4-r7}
  150. #endif
  151. BX lr
  152. /* void memcpy_tointerleaveQuad(int16_t *dst, const int16_t *src1, const int16_t *src2, const int16_t *src3, const int16_t *src4) */
  153. .global memcpy_tointerleaveQuad
  154. .thumb_func
  155. memcpy_tointerleaveQuad:
  156. @ r0: dst
  157. @ r1: src1
  158. @ r2: src2
  159. @ r3: src3
  160. @ r4: src4
  161. push {r4-r11}
  162. ldr r4, [sp, #(0+32)] //5th parameter is saved on the stack
  163. add r11,r0,#(AUDIO_BLOCK_SAMPLES*4)
  164. .align 2
  165. .loopQuad:
  166. ldr r5, [r1],4
  167. ldr r6, [r3],4
  168. pkhbt r7,r5,r6,LSL #16
  169. pkhtb r9,r6,r5,ASR #16
  170. ldr r5, [r2],4
  171. ldr r6, [r4],4
  172. pkhbt r8,r5,r6,LSL #16
  173. pkhtb r10,r6,r5,ASR #16
  174. stmia r0!, {r7-r10}
  175. cmp r11, r0
  176. bne .loopQuad
  177. pop {r4-r11}
  178. BX lr
  179. .END
  180. #endif