celt_pitch_xcorr_arm.s 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. ; Copyright (c) 2007-2008 CSIRO
  2. ; Copyright (c) 2007-2009 Xiph.Org Foundation
  3. ; Copyright (c) 2013 Parrot
  4. ; Written by Aurélien Zanelli
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions
  8. ; are met:
  9. ;
  10. ; - Redistributions of source code must retain the above copyright
  11. ; notice, this list of conditions and the following disclaimer.
  12. ;
  13. ; - Redistributions in binary form must reproduce the above copyright
  14. ; notice, this list of conditions and the following disclaimer in the
  15. ; documentation and/or other materials provided with the distribution.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  21. ; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. AREA |.text|, CODE, READONLY
  29. GET celt/arm/armopts.s
  30. IF OPUS_ARM_MAY_HAVE_EDSP
  31. EXPORT celt_pitch_xcorr_edsp
  32. ENDIF
  33. IF OPUS_ARM_MAY_HAVE_NEON
  34. EXPORT celt_pitch_xcorr_neon
  35. ENDIF
  36. IF OPUS_ARM_MAY_HAVE_NEON
  37. ; Compute sum[k]=sum(x[j]*y[j+k],j=0...len-1), k=0...3
  38. xcorr_kernel_neon PROC
  39. xcorr_kernel_neon_start
  40. ; input:
  41. ; r3 = int len
  42. ; r4 = opus_val16 *x
  43. ; r5 = opus_val16 *y
  44. ; q0 = opus_val32 sum[4]
  45. ; output:
  46. ; q0 = opus_val32 sum[4]
  47. ; preserved: r0-r3, r6-r11, d2, q4-q7, q9-q15
  48. ; internal usage:
  49. ; r12 = int j
  50. ; d3 = y_3|y_2|y_1|y_0
  51. ; q2 = y_B|y_A|y_9|y_8|y_7|y_6|y_5|y_4
  52. ; q3 = x_7|x_6|x_5|x_4|x_3|x_2|x_1|x_0
  53. ; q8 = scratch
  54. ;
  55. ; Load y[0...3]
  56. ; This requires len>0 to always be valid (which we assert in the C code).
  57. VLD1.16 {d5}, [r5]!
  58. SUBS r12, r3, #8
  59. BLE xcorr_kernel_neon_process4
  60. ; Process 8 samples at a time.
  61. ; This loop loads one y value more than we actually need. Therefore we have to
  62. ; stop as soon as there are 8 or fewer samples left (instead of 7), to avoid
  63. ; reading past the end of the array.
  64. xcorr_kernel_neon_process8
  65. ; This loop has 19 total instructions (10 cycles to issue, minimum), with
  66. ; - 2 cycles of ARM insrtuctions,
  67. ; - 10 cycles of load/store/byte permute instructions, and
  68. ; - 9 cycles of data processing instructions.
  69. ; On a Cortex A8, we dual-issue the maximum amount (9 cycles) between the
  70. ; latter two categories, meaning the whole loop should run in 10 cycles per
  71. ; iteration, barring cache misses.
  72. ;
  73. ; Load x[0...7]
  74. VLD1.16 {d6, d7}, [r4]!
  75. ; Unlike VMOV, VAND is a data processsing instruction (and doesn't get
  76. ; assembled to VMOV, like VORR would), so it dual-issues with the prior VLD1.
  77. VAND d3, d5, d5
  78. SUBS r12, r12, #8
  79. ; Load y[4...11]
  80. VLD1.16 {d4, d5}, [r5]!
  81. VMLAL.S16 q0, d3, d6[0]
  82. VEXT.16 d16, d3, d4, #1
  83. VMLAL.S16 q0, d4, d7[0]
  84. VEXT.16 d17, d4, d5, #1
  85. VMLAL.S16 q0, d16, d6[1]
  86. VEXT.16 d16, d3, d4, #2
  87. VMLAL.S16 q0, d17, d7[1]
  88. VEXT.16 d17, d4, d5, #2
  89. VMLAL.S16 q0, d16, d6[2]
  90. VEXT.16 d16, d3, d4, #3
  91. VMLAL.S16 q0, d17, d7[2]
  92. VEXT.16 d17, d4, d5, #3
  93. VMLAL.S16 q0, d16, d6[3]
  94. VMLAL.S16 q0, d17, d7[3]
  95. BGT xcorr_kernel_neon_process8
  96. ; Process 4 samples here if we have > 4 left (still reading one extra y value).
  97. xcorr_kernel_neon_process4
  98. ADDS r12, r12, #4
  99. BLE xcorr_kernel_neon_process2
  100. ; Load x[0...3]
  101. VLD1.16 d6, [r4]!
  102. ; Use VAND since it's a data processing instruction again.
  103. VAND d4, d5, d5
  104. SUB r12, r12, #4
  105. ; Load y[4...7]
  106. VLD1.16 d5, [r5]!
  107. VMLAL.S16 q0, d4, d6[0]
  108. VEXT.16 d16, d4, d5, #1
  109. VMLAL.S16 q0, d16, d6[1]
  110. VEXT.16 d16, d4, d5, #2
  111. VMLAL.S16 q0, d16, d6[2]
  112. VEXT.16 d16, d4, d5, #3
  113. VMLAL.S16 q0, d16, d6[3]
  114. ; Process 2 samples here if we have > 2 left (still reading one extra y value).
  115. xcorr_kernel_neon_process2
  116. ADDS r12, r12, #2
  117. BLE xcorr_kernel_neon_process1
  118. ; Load x[0...1]
  119. VLD2.16 {d6[],d7[]}, [r4]!
  120. ; Use VAND since it's a data processing instruction again.
  121. VAND d4, d5, d5
  122. SUB r12, r12, #2
  123. ; Load y[4...5]
  124. VLD1.32 {d5[]}, [r5]!
  125. VMLAL.S16 q0, d4, d6
  126. VEXT.16 d16, d4, d5, #1
  127. ; Replace bottom copy of {y5,y4} in d5 with {y3,y2} from d4, using VSRI
  128. ; instead of VEXT, since it's a data-processing instruction.
  129. VSRI.64 d5, d4, #32
  130. VMLAL.S16 q0, d16, d7
  131. ; Process 1 sample using the extra y value we loaded above.
  132. xcorr_kernel_neon_process1
  133. ; Load next *x
  134. VLD1.16 {d6[]}, [r4]!
  135. ADDS r12, r12, #1
  136. ; y[0...3] are left in d5 from prior iteration(s) (if any)
  137. VMLAL.S16 q0, d5, d6
  138. MOVLE pc, lr
  139. ; Now process 1 last sample, not reading ahead.
  140. ; Load last *y
  141. VLD1.16 {d4[]}, [r5]!
  142. VSRI.64 d4, d5, #16
  143. ; Load last *x
  144. VLD1.16 {d6[]}, [r4]!
  145. VMLAL.S16 q0, d4, d6
  146. MOV pc, lr
  147. ENDP
  148. ; opus_val32 celt_pitch_xcorr_neon(opus_val16 *_x, opus_val16 *_y,
  149. ; opus_val32 *xcorr, int len, int max_pitch)
  150. celt_pitch_xcorr_neon PROC
  151. ; input:
  152. ; r0 = opus_val16 *_x
  153. ; r1 = opus_val16 *_y
  154. ; r2 = opus_val32 *xcorr
  155. ; r3 = int len
  156. ; output:
  157. ; r0 = int maxcorr
  158. ; internal usage:
  159. ; r4 = opus_val16 *x (for xcorr_kernel_neon())
  160. ; r5 = opus_val16 *y (for xcorr_kernel_neon())
  161. ; r6 = int max_pitch
  162. ; r12 = int j
  163. ; q15 = int maxcorr[4] (q15 is not used by xcorr_kernel_neon())
  164. STMFD sp!, {r4-r6, lr}
  165. LDR r6, [sp, #16]
  166. VMOV.S32 q15, #1
  167. ; if (max_pitch < 4) goto celt_pitch_xcorr_neon_process4_done
  168. SUBS r6, r6, #4
  169. BLT celt_pitch_xcorr_neon_process4_done
  170. celt_pitch_xcorr_neon_process4
  171. ; xcorr_kernel_neon parameters:
  172. ; r3 = len, r4 = _x, r5 = _y, q0 = {0, 0, 0, 0}
  173. MOV r4, r0
  174. MOV r5, r1
  175. VEOR q0, q0, q0
  176. ; xcorr_kernel_neon only modifies r4, r5, r12, and q0...q3.
  177. ; So we don't save/restore any other registers.
  178. BL xcorr_kernel_neon_start
  179. SUBS r6, r6, #4
  180. VST1.32 {q0}, [r2]!
  181. ; _y += 4
  182. ADD r1, r1, #8
  183. VMAX.S32 q15, q15, q0
  184. ; if (max_pitch < 4) goto celt_pitch_xcorr_neon_process4_done
  185. BGE celt_pitch_xcorr_neon_process4
  186. ; We have less than 4 sums left to compute.
  187. celt_pitch_xcorr_neon_process4_done
  188. ADDS r6, r6, #4
  189. ; Reduce maxcorr to a single value
  190. VMAX.S32 d30, d30, d31
  191. VPMAX.S32 d30, d30, d30
  192. ; if (max_pitch <= 0) goto celt_pitch_xcorr_neon_done
  193. BLE celt_pitch_xcorr_neon_done
  194. ; Now compute each remaining sum one at a time.
  195. celt_pitch_xcorr_neon_process_remaining
  196. MOV r4, r0
  197. MOV r5, r1
  198. VMOV.I32 q0, #0
  199. SUBS r12, r3, #8
  200. BLT celt_pitch_xcorr_neon_process_remaining4
  201. ; Sum terms 8 at a time.
  202. celt_pitch_xcorr_neon_process_remaining_loop8
  203. ; Load x[0...7]
  204. VLD1.16 {q1}, [r4]!
  205. ; Load y[0...7]
  206. VLD1.16 {q2}, [r5]!
  207. SUBS r12, r12, #8
  208. VMLAL.S16 q0, d4, d2
  209. VMLAL.S16 q0, d5, d3
  210. BGE celt_pitch_xcorr_neon_process_remaining_loop8
  211. ; Sum terms 4 at a time.
  212. celt_pitch_xcorr_neon_process_remaining4
  213. ADDS r12, r12, #4
  214. BLT celt_pitch_xcorr_neon_process_remaining4_done
  215. ; Load x[0...3]
  216. VLD1.16 {d2}, [r4]!
  217. ; Load y[0...3]
  218. VLD1.16 {d3}, [r5]!
  219. SUB r12, r12, #4
  220. VMLAL.S16 q0, d3, d2
  221. celt_pitch_xcorr_neon_process_remaining4_done
  222. ; Reduce the sum to a single value.
  223. VADD.S32 d0, d0, d1
  224. VPADDL.S32 d0, d0
  225. ADDS r12, r12, #4
  226. BLE celt_pitch_xcorr_neon_process_remaining_loop_done
  227. ; Sum terms 1 at a time.
  228. celt_pitch_xcorr_neon_process_remaining_loop1
  229. VLD1.16 {d2[]}, [r4]!
  230. VLD1.16 {d3[]}, [r5]!
  231. SUBS r12, r12, #1
  232. VMLAL.S16 q0, d2, d3
  233. BGT celt_pitch_xcorr_neon_process_remaining_loop1
  234. celt_pitch_xcorr_neon_process_remaining_loop_done
  235. VST1.32 {d0[0]}, [r2]!
  236. VMAX.S32 d30, d30, d0
  237. SUBS r6, r6, #1
  238. ; _y++
  239. ADD r1, r1, #2
  240. ; if (--max_pitch > 0) goto celt_pitch_xcorr_neon_process_remaining
  241. BGT celt_pitch_xcorr_neon_process_remaining
  242. celt_pitch_xcorr_neon_done
  243. VMOV.32 r0, d30[0]
  244. LDMFD sp!, {r4-r6, pc}
  245. ENDP
  246. ENDIF
  247. IF OPUS_ARM_MAY_HAVE_EDSP
  248. ; This will get used on ARMv7 devices without NEON, so it has been optimized
  249. ; to take advantage of dual-issuing where possible.
  250. xcorr_kernel_edsp PROC
  251. xcorr_kernel_edsp_start
  252. ; input:
  253. ; r3 = int len
  254. ; r4 = opus_val16 *_x (must be 32-bit aligned)
  255. ; r5 = opus_val16 *_y (must be 32-bit aligned)
  256. ; r6...r9 = opus_val32 sum[4]
  257. ; output:
  258. ; r6...r9 = opus_val32 sum[4]
  259. ; preserved: r0-r5
  260. ; internal usage
  261. ; r2 = int j
  262. ; r12,r14 = opus_val16 x[4]
  263. ; r10,r11 = opus_val16 y[4]
  264. STMFD sp!, {r2,r4,r5,lr}
  265. LDR r10, [r5], #4 ; Load y[0...1]
  266. SUBS r2, r3, #4 ; j = len-4
  267. LDR r11, [r5], #4 ; Load y[2...3]
  268. BLE xcorr_kernel_edsp_process4_done
  269. LDR r12, [r4], #4 ; Load x[0...1]
  270. ; Stall
  271. xcorr_kernel_edsp_process4
  272. ; The multiplies must issue from pipeline 0, and can't dual-issue with each
  273. ; other. Every other instruction here dual-issues with a multiply, and is
  274. ; thus "free". There should be no stalls in the body of the loop.
  275. SMLABB r6, r12, r10, r6 ; sum[0] = MAC16_16(sum[0],x_0,y_0)
  276. LDR r14, [r4], #4 ; Load x[2...3]
  277. SMLABT r7, r12, r10, r7 ; sum[1] = MAC16_16(sum[1],x_0,y_1)
  278. SUBS r2, r2, #4 ; j-=4
  279. SMLABB r8, r12, r11, r8 ; sum[2] = MAC16_16(sum[2],x_0,y_2)
  280. SMLABT r9, r12, r11, r9 ; sum[3] = MAC16_16(sum[3],x_0,y_3)
  281. SMLATT r6, r12, r10, r6 ; sum[0] = MAC16_16(sum[0],x_1,y_1)
  282. LDR r10, [r5], #4 ; Load y[4...5]
  283. SMLATB r7, r12, r11, r7 ; sum[1] = MAC16_16(sum[1],x_1,y_2)
  284. SMLATT r8, r12, r11, r8 ; sum[2] = MAC16_16(sum[2],x_1,y_3)
  285. SMLATB r9, r12, r10, r9 ; sum[3] = MAC16_16(sum[3],x_1,y_4)
  286. LDRGT r12, [r4], #4 ; Load x[0...1]
  287. SMLABB r6, r14, r11, r6 ; sum[0] = MAC16_16(sum[0],x_2,y_2)
  288. SMLABT r7, r14, r11, r7 ; sum[1] = MAC16_16(sum[1],x_2,y_3)
  289. SMLABB r8, r14, r10, r8 ; sum[2] = MAC16_16(sum[2],x_2,y_4)
  290. SMLABT r9, r14, r10, r9 ; sum[3] = MAC16_16(sum[3],x_2,y_5)
  291. SMLATT r6, r14, r11, r6 ; sum[0] = MAC16_16(sum[0],x_3,y_3)
  292. LDR r11, [r5], #4 ; Load y[6...7]
  293. SMLATB r7, r14, r10, r7 ; sum[1] = MAC16_16(sum[1],x_3,y_4)
  294. SMLATT r8, r14, r10, r8 ; sum[2] = MAC16_16(sum[2],x_3,y_5)
  295. SMLATB r9, r14, r11, r9 ; sum[3] = MAC16_16(sum[3],x_3,y_6)
  296. BGT xcorr_kernel_edsp_process4
  297. xcorr_kernel_edsp_process4_done
  298. ADDS r2, r2, #4
  299. BLE xcorr_kernel_edsp_done
  300. LDRH r12, [r4], #2 ; r12 = *x++
  301. SUBS r2, r2, #1 ; j--
  302. ; Stall
  303. SMLABB r6, r12, r10, r6 ; sum[0] = MAC16_16(sum[0],x,y_0)
  304. LDRHGT r14, [r4], #2 ; r14 = *x++
  305. SMLABT r7, r12, r10, r7 ; sum[1] = MAC16_16(sum[1],x,y_1)
  306. SMLABB r8, r12, r11, r8 ; sum[2] = MAC16_16(sum[2],x,y_2)
  307. SMLABT r9, r12, r11, r9 ; sum[3] = MAC16_16(sum[3],x,y_3)
  308. BLE xcorr_kernel_edsp_done
  309. SMLABT r6, r14, r10, r6 ; sum[0] = MAC16_16(sum[0],x,y_1)
  310. SUBS r2, r2, #1 ; j--
  311. SMLABB r7, r14, r11, r7 ; sum[1] = MAC16_16(sum[1],x,y_2)
  312. LDRH r10, [r5], #2 ; r10 = y_4 = *y++
  313. SMLABT r8, r14, r11, r8 ; sum[2] = MAC16_16(sum[2],x,y_3)
  314. LDRHGT r12, [r4], #2 ; r12 = *x++
  315. SMLABB r9, r14, r10, r9 ; sum[3] = MAC16_16(sum[3],x,y_4)
  316. BLE xcorr_kernel_edsp_done
  317. SMLABB r6, r12, r11, r6 ; sum[0] = MAC16_16(sum[0],tmp,y_2)
  318. CMP r2, #1 ; j--
  319. SMLABT r7, r12, r11, r7 ; sum[1] = MAC16_16(sum[1],tmp,y_3)
  320. LDRH r2, [r5], #2 ; r2 = y_5 = *y++
  321. SMLABB r8, r12, r10, r8 ; sum[2] = MAC16_16(sum[2],tmp,y_4)
  322. LDRHGT r14, [r4] ; r14 = *x
  323. SMLABB r9, r12, r2, r9 ; sum[3] = MAC16_16(sum[3],tmp,y_5)
  324. BLE xcorr_kernel_edsp_done
  325. SMLABT r6, r14, r11, r6 ; sum[0] = MAC16_16(sum[0],tmp,y_3)
  326. LDRH r11, [r5] ; r11 = y_6 = *y
  327. SMLABB r7, r14, r10, r7 ; sum[1] = MAC16_16(sum[1],tmp,y_4)
  328. SMLABB r8, r14, r2, r8 ; sum[2] = MAC16_16(sum[2],tmp,y_5)
  329. SMLABB r9, r14, r11, r9 ; sum[3] = MAC16_16(sum[3],tmp,y_6)
  330. xcorr_kernel_edsp_done
  331. LDMFD sp!, {r2,r4,r5,pc}
  332. ENDP
  333. celt_pitch_xcorr_edsp PROC
  334. ; input:
  335. ; r0 = opus_val16 *_x (must be 32-bit aligned)
  336. ; r1 = opus_val16 *_y (only needs to be 16-bit aligned)
  337. ; r2 = opus_val32 *xcorr
  338. ; r3 = int len
  339. ; output:
  340. ; r0 = maxcorr
  341. ; internal usage
  342. ; r4 = opus_val16 *x
  343. ; r5 = opus_val16 *y
  344. ; r6 = opus_val32 sum0
  345. ; r7 = opus_val32 sum1
  346. ; r8 = opus_val32 sum2
  347. ; r9 = opus_val32 sum3
  348. ; r1 = int max_pitch
  349. ; r12 = int j
  350. STMFD sp!, {r4-r11, lr}
  351. MOV r5, r1
  352. LDR r1, [sp, #36]
  353. MOV r4, r0
  354. TST r5, #3
  355. ; maxcorr = 1
  356. MOV r0, #1
  357. BEQ celt_pitch_xcorr_edsp_process1u_done
  358. ; Compute one sum at the start to make y 32-bit aligned.
  359. SUBS r12, r3, #4
  360. ; r14 = sum = 0
  361. MOV r14, #0
  362. LDRH r8, [r5], #2
  363. BLE celt_pitch_xcorr_edsp_process1u_loop4_done
  364. LDR r6, [r4], #4
  365. MOV r8, r8, LSL #16
  366. celt_pitch_xcorr_edsp_process1u_loop4
  367. LDR r9, [r5], #4
  368. SMLABT r14, r6, r8, r14 ; sum = MAC16_16(sum, x_0, y_0)
  369. LDR r7, [r4], #4
  370. SMLATB r14, r6, r9, r14 ; sum = MAC16_16(sum, x_1, y_1)
  371. LDR r8, [r5], #4
  372. SMLABT r14, r7, r9, r14 ; sum = MAC16_16(sum, x_2, y_2)
  373. SUBS r12, r12, #4 ; j-=4
  374. SMLATB r14, r7, r8, r14 ; sum = MAC16_16(sum, x_3, y_3)
  375. LDRGT r6, [r4], #4
  376. BGT celt_pitch_xcorr_edsp_process1u_loop4
  377. MOV r8, r8, LSR #16
  378. celt_pitch_xcorr_edsp_process1u_loop4_done
  379. ADDS r12, r12, #4
  380. celt_pitch_xcorr_edsp_process1u_loop1
  381. LDRHGE r6, [r4], #2
  382. ; Stall
  383. SMLABBGE r14, r6, r8, r14 ; sum = MAC16_16(sum, *x, *y)
  384. SUBSGE r12, r12, #1
  385. LDRHGT r8, [r5], #2
  386. BGT celt_pitch_xcorr_edsp_process1u_loop1
  387. ; Restore _x
  388. SUB r4, r4, r3, LSL #1
  389. ; Restore and advance _y
  390. SUB r5, r5, r3, LSL #1
  391. ; maxcorr = max(maxcorr, sum)
  392. CMP r0, r14
  393. ADD r5, r5, #2
  394. MOVLT r0, r14
  395. SUBS r1, r1, #1
  396. ; xcorr[i] = sum
  397. STR r14, [r2], #4
  398. BLE celt_pitch_xcorr_edsp_done
  399. celt_pitch_xcorr_edsp_process1u_done
  400. ; if (max_pitch < 4) goto celt_pitch_xcorr_edsp_process2
  401. SUBS r1, r1, #4
  402. BLT celt_pitch_xcorr_edsp_process2
  403. celt_pitch_xcorr_edsp_process4
  404. ; xcorr_kernel_edsp parameters:
  405. ; r3 = len, r4 = _x, r5 = _y, r6...r9 = sum[4] = {0, 0, 0, 0}
  406. MOV r6, #0
  407. MOV r7, #0
  408. MOV r8, #0
  409. MOV r9, #0
  410. BL xcorr_kernel_edsp_start ; xcorr_kernel_edsp(_x, _y+i, xcorr+i, len)
  411. ; maxcorr = max(maxcorr, sum0, sum1, sum2, sum3)
  412. CMP r0, r6
  413. ; _y+=4
  414. ADD r5, r5, #8
  415. MOVLT r0, r6
  416. CMP r0, r7
  417. MOVLT r0, r7
  418. CMP r0, r8
  419. MOVLT r0, r8
  420. CMP r0, r9
  421. MOVLT r0, r9
  422. STMIA r2!, {r6-r9}
  423. SUBS r1, r1, #4
  424. BGE celt_pitch_xcorr_edsp_process4
  425. celt_pitch_xcorr_edsp_process2
  426. ADDS r1, r1, #2
  427. BLT celt_pitch_xcorr_edsp_process1a
  428. SUBS r12, r3, #4
  429. ; {r10, r11} = {sum0, sum1} = {0, 0}
  430. MOV r10, #0
  431. MOV r11, #0
  432. LDR r8, [r5], #4
  433. BLE celt_pitch_xcorr_edsp_process2_loop_done
  434. LDR r6, [r4], #4
  435. LDR r9, [r5], #4
  436. celt_pitch_xcorr_edsp_process2_loop4
  437. SMLABB r10, r6, r8, r10 ; sum0 = MAC16_16(sum0, x_0, y_0)
  438. LDR r7, [r4], #4
  439. SMLABT r11, r6, r8, r11 ; sum1 = MAC16_16(sum1, x_0, y_1)
  440. SUBS r12, r12, #4 ; j-=4
  441. SMLATT r10, r6, r8, r10 ; sum0 = MAC16_16(sum0, x_1, y_1)
  442. LDR r8, [r5], #4
  443. SMLATB r11, r6, r9, r11 ; sum1 = MAC16_16(sum1, x_1, y_2)
  444. LDRGT r6, [r4], #4
  445. SMLABB r10, r7, r9, r10 ; sum0 = MAC16_16(sum0, x_2, y_2)
  446. SMLABT r11, r7, r9, r11 ; sum1 = MAC16_16(sum1, x_2, y_3)
  447. SMLATT r10, r7, r9, r10 ; sum0 = MAC16_16(sum0, x_3, y_3)
  448. LDRGT r9, [r5], #4
  449. SMLATB r11, r7, r8, r11 ; sum1 = MAC16_16(sum1, x_3, y_4)
  450. BGT celt_pitch_xcorr_edsp_process2_loop4
  451. celt_pitch_xcorr_edsp_process2_loop_done
  452. ADDS r12, r12, #2
  453. BLE celt_pitch_xcorr_edsp_process2_1
  454. LDR r6, [r4], #4
  455. ; Stall
  456. SMLABB r10, r6, r8, r10 ; sum0 = MAC16_16(sum0, x_0, y_0)
  457. LDR r9, [r5], #4
  458. SMLABT r11, r6, r8, r11 ; sum1 = MAC16_16(sum1, x_0, y_1)
  459. SUB r12, r12, #2
  460. SMLATT r10, r6, r8, r10 ; sum0 = MAC16_16(sum0, x_1, y_1)
  461. MOV r8, r9
  462. SMLATB r11, r6, r9, r11 ; sum1 = MAC16_16(sum1, x_1, y_2)
  463. celt_pitch_xcorr_edsp_process2_1
  464. LDRH r6, [r4], #2
  465. ADDS r12, r12, #1
  466. ; Stall
  467. SMLABB r10, r6, r8, r10 ; sum0 = MAC16_16(sum0, x_0, y_0)
  468. LDRHGT r7, [r4], #2
  469. SMLABT r11, r6, r8, r11 ; sum1 = MAC16_16(sum1, x_0, y_1)
  470. BLE celt_pitch_xcorr_edsp_process2_done
  471. LDRH r9, [r5], #2
  472. SMLABT r10, r7, r8, r10 ; sum0 = MAC16_16(sum0, x_0, y_1)
  473. SMLABB r11, r7, r9, r11 ; sum1 = MAC16_16(sum1, x_0, y_2)
  474. celt_pitch_xcorr_edsp_process2_done
  475. ; Restore _x
  476. SUB r4, r4, r3, LSL #1
  477. ; Restore and advance _y
  478. SUB r5, r5, r3, LSL #1
  479. ; maxcorr = max(maxcorr, sum0)
  480. CMP r0, r10
  481. ADD r5, r5, #2
  482. MOVLT r0, r10
  483. SUB r1, r1, #2
  484. ; maxcorr = max(maxcorr, sum1)
  485. CMP r0, r11
  486. ; xcorr[i] = sum
  487. STR r10, [r2], #4
  488. MOVLT r0, r11
  489. STR r11, [r2], #4
  490. celt_pitch_xcorr_edsp_process1a
  491. ADDS r1, r1, #1
  492. BLT celt_pitch_xcorr_edsp_done
  493. SUBS r12, r3, #4
  494. ; r14 = sum = 0
  495. MOV r14, #0
  496. BLT celt_pitch_xcorr_edsp_process1a_loop_done
  497. LDR r6, [r4], #4
  498. LDR r8, [r5], #4
  499. LDR r7, [r4], #4
  500. LDR r9, [r5], #4
  501. celt_pitch_xcorr_edsp_process1a_loop4
  502. SMLABB r14, r6, r8, r14 ; sum = MAC16_16(sum, x_0, y_0)
  503. SUBS r12, r12, #4 ; j-=4
  504. SMLATT r14, r6, r8, r14 ; sum = MAC16_16(sum, x_1, y_1)
  505. LDRGE r6, [r4], #4
  506. SMLABB r14, r7, r9, r14 ; sum = MAC16_16(sum, x_2, y_2)
  507. LDRGE r8, [r5], #4
  508. SMLATT r14, r7, r9, r14 ; sum = MAC16_16(sum, x_3, y_3)
  509. LDRGE r7, [r4], #4
  510. LDRGE r9, [r5], #4
  511. BGE celt_pitch_xcorr_edsp_process1a_loop4
  512. celt_pitch_xcorr_edsp_process1a_loop_done
  513. ADDS r12, r12, #2
  514. LDRGE r6, [r4], #4
  515. LDRGE r8, [r5], #4
  516. ; Stall
  517. SMLABBGE r14, r6, r8, r14 ; sum = MAC16_16(sum, x_0, y_0)
  518. SUBGE r12, r12, #2
  519. SMLATTGE r14, r6, r8, r14 ; sum = MAC16_16(sum, x_1, y_1)
  520. ADDS r12, r12, #1
  521. LDRHGE r6, [r4], #2
  522. LDRHGE r8, [r5], #2
  523. ; Stall
  524. SMLABBGE r14, r6, r8, r14 ; sum = MAC16_16(sum, *x, *y)
  525. ; maxcorr = max(maxcorr, sum)
  526. CMP r0, r14
  527. ; xcorr[i] = sum
  528. STR r14, [r2], #4
  529. MOVLT r0, r14
  530. celt_pitch_xcorr_edsp_done
  531. LDMFD sp!, {r4-r11, pc}
  532. ENDP
  533. ENDIF
  534. END