Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arm_conv_partial_fast_q15.c 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 17. January 2013
  5. * $Revision: V1.4.1
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_conv_partial_fast_q15.c
  9. *
  10. * Description: Fast Q15 Partial convolution.
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * - Neither the name of ARM LIMITED nor the names of its contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. * -------------------------------------------------------------------- */
  40. #include "arm_math.h"
  41. /**
  42. * @ingroup groupFilters
  43. */
  44. /**
  45. * @addtogroup PartialConv
  46. * @{
  47. */
  48. /**
  49. * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4.
  50. * @param[in] *pSrcA points to the first input sequence.
  51. * @param[in] srcALen length of the first input sequence.
  52. * @param[in] *pSrcB points to the second input sequence.
  53. * @param[in] srcBLen length of the second input sequence.
  54. * @param[out] *pDst points to the location where the output result is written.
  55. * @param[in] firstIndex is the first output sample to start with.
  56. * @param[in] numPoints is the number of output points to be computed.
  57. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  58. *
  59. * See <code>arm_conv_partial_q15()</code> for a slower implementation of this function which uses a 64-bit accumulator to avoid wrap around distortion.
  60. */
  61. arm_status arm_conv_partial_fast_q15(
  62. q15_t * pSrcA,
  63. uint32_t srcALen,
  64. q15_t * pSrcB,
  65. uint32_t srcBLen,
  66. q15_t * pDst,
  67. uint32_t firstIndex,
  68. uint32_t numPoints)
  69. {
  70. #ifndef UNALIGNED_SUPPORT_DISABLE
  71. q15_t *pIn1; /* inputA pointer */
  72. q15_t *pIn2; /* inputB pointer */
  73. q15_t *pOut = pDst; /* output pointer */
  74. q31_t sum, acc0, acc1, acc2, acc3; /* Accumulator */
  75. q15_t *px; /* Intermediate inputA pointer */
  76. q15_t *py; /* Intermediate inputB pointer */
  77. q15_t *pSrc1, *pSrc2; /* Intermediate pointers */
  78. q31_t x0, x1, x2, x3, c0;
  79. uint32_t j, k, count, check, blkCnt;
  80. int32_t blockSize1, blockSize2, blockSize3; /* loop counters */
  81. arm_status status; /* status of Partial convolution */
  82. /* Check for range of output samples to be calculated */
  83. if((firstIndex + numPoints) > ((srcALen + (srcBLen - 1u))))
  84. {
  85. /* Set status as ARM_MATH_ARGUMENT_ERROR */
  86. status = ARM_MATH_ARGUMENT_ERROR;
  87. }
  88. else
  89. {
  90. /* The algorithm implementation is based on the lengths of the inputs. */
  91. /* srcB is always made to slide across srcA. */
  92. /* So srcBLen is always considered as shorter or equal to srcALen */
  93. if(srcALen >=srcBLen)
  94. {
  95. /* Initialization of inputA pointer */
  96. pIn1 = pSrcA;
  97. /* Initialization of inputB pointer */
  98. pIn2 = pSrcB;
  99. }
  100. else
  101. {
  102. /* Initialization of inputA pointer */
  103. pIn1 = pSrcB;
  104. /* Initialization of inputB pointer */
  105. pIn2 = pSrcA;
  106. /* srcBLen is always considered as shorter or equal to srcALen */
  107. j = srcBLen;
  108. srcBLen = srcALen;
  109. srcALen = j;
  110. }
  111. /* Conditions to check which loopCounter holds
  112. * the first and last indices of the output samples to be calculated. */
  113. check = firstIndex + numPoints;
  114. blockSize3 = ((int32_t) check - (int32_t) srcALen);
  115. blockSize3 = (blockSize3 > 0) ? blockSize3 : 0;
  116. blockSize1 = (((int32_t) srcBLen - 1) - (int32_t) firstIndex);
  117. blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1u)) ? blockSize1 :
  118. (int32_t) numPoints) : 0;
  119. blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) +
  120. (int32_t) firstIndex);
  121. blockSize2 = (blockSize2 > 0) ? blockSize2 : 0;
  122. /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */
  123. /* The function is internally
  124. * divided into three stages according to the number of multiplications that has to be
  125. * taken place between inputA samples and inputB samples. In the first stage of the
  126. * algorithm, the multiplications increase by one for every iteration.
  127. * In the second stage of the algorithm, srcBLen number of multiplications are done.
  128. * In the third stage of the algorithm, the multiplications decrease by one
  129. * for every iteration. */
  130. /* Set the output pointer to point to the firstIndex
  131. * of the output sample to be calculated. */
  132. pOut = pDst + firstIndex;
  133. /* --------------------------
  134. * Initializations of stage1
  135. * -------------------------*/
  136. /* sum = x[0] * y[0]
  137. * sum = x[0] * y[1] + x[1] * y[0]
  138. * ....
  139. * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0]
  140. */
  141. /* In this stage the MAC operations are increased by 1 for every iteration.
  142. The count variable holds the number of MAC operations performed.
  143. Since the partial convolution starts from firstIndex
  144. Number of Macs to be performed is firstIndex + 1 */
  145. count = 1u + firstIndex;
  146. /* Working pointer of inputA */
  147. px = pIn1;
  148. /* Working pointer of inputB */
  149. pSrc2 = pIn2 + firstIndex;
  150. py = pSrc2;
  151. /* ------------------------
  152. * Stage1 process
  153. * ----------------------*/
  154. /* For loop unrolling by 4, this stage is divided into two. */
  155. /* First part of this stage computes the MAC operations less than 4 */
  156. /* Second part of this stage computes the MAC operations greater than or equal to 4 */
  157. /* The first part of the stage starts here */
  158. while((count < 4u) && (blockSize1 > 0))
  159. {
  160. /* Accumulator is made zero for every iteration */
  161. sum = 0;
  162. /* Loop over number of MAC operations between
  163. * inputA samples and inputB samples */
  164. k = count;
  165. while(k > 0u)
  166. {
  167. /* Perform the multiply-accumulates */
  168. sum = __SMLAD(*px++, *py--, sum);
  169. /* Decrement the loop counter */
  170. k--;
  171. }
  172. /* Store the result in the accumulator in the destination buffer. */
  173. *pOut++ = (q15_t) (sum >> 15);
  174. /* Update the inputA and inputB pointers for next MAC calculation */
  175. py = ++pSrc2;
  176. px = pIn1;
  177. /* Increment the MAC count */
  178. count++;
  179. /* Decrement the loop counter */
  180. blockSize1--;
  181. }
  182. /* The second part of the stage starts here */
  183. /* The internal loop, over count, is unrolled by 4 */
  184. /* To, read the last two inputB samples using SIMD:
  185. * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */
  186. py = py - 1;
  187. while(blockSize1 > 0)
  188. {
  189. /* Accumulator is made zero for every iteration */
  190. sum = 0;
  191. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  192. k = count >> 2u;
  193. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  194. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  195. while(k > 0u)
  196. {
  197. /* Perform the multiply-accumulates */
  198. /* x[0], x[1] are multiplied with y[srcBLen - 1], y[srcBLen - 2] respectively */
  199. sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum);
  200. /* x[2], x[3] are multiplied with y[srcBLen - 3], y[srcBLen - 4] respectively */
  201. sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum);
  202. /* Decrement the loop counter */
  203. k--;
  204. }
  205. /* For the next MAC operations, the pointer py is used without SIMD
  206. * So, py is incremented by 1 */
  207. py = py + 1u;
  208. /* If the count is not a multiple of 4, compute any remaining MACs here.
  209. ** No loop unrolling is used. */
  210. k = count % 0x4u;
  211. while(k > 0u)
  212. {
  213. /* Perform the multiply-accumulates */
  214. sum = __SMLAD(*px++, *py--, sum);
  215. /* Decrement the loop counter */
  216. k--;
  217. }
  218. /* Store the result in the accumulator in the destination buffer. */
  219. *pOut++ = (q15_t) (sum >> 15);
  220. /* Update the inputA and inputB pointers for next MAC calculation */
  221. py = ++pSrc2 - 1u;
  222. px = pIn1;
  223. /* Increment the MAC count */
  224. count++;
  225. /* Decrement the loop counter */
  226. blockSize1--;
  227. }
  228. /* --------------------------
  229. * Initializations of stage2
  230. * ------------------------*/
  231. /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0]
  232. * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0]
  233. * ....
  234. * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0]
  235. */
  236. /* Working pointer of inputA */
  237. px = pIn1;
  238. /* Working pointer of inputB */
  239. pSrc2 = pIn2 + (srcBLen - 1u);
  240. py = pSrc2;
  241. /* count is the index by which the pointer pIn1 to be incremented */
  242. count = 0u;
  243. /* --------------------
  244. * Stage2 process
  245. * -------------------*/
  246. /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed.
  247. * So, to loop unroll over blockSize2,
  248. * srcBLen should be greater than or equal to 4 */
  249. if(srcBLen >= 4u)
  250. {
  251. /* Loop unroll over blockSize2, by 4 */
  252. blkCnt = ((uint32_t) blockSize2 >> 2u);
  253. while(blkCnt > 0u)
  254. {
  255. py = py - 1u;
  256. /* Set all accumulators to zero */
  257. acc0 = 0;
  258. acc1 = 0;
  259. acc2 = 0;
  260. acc3 = 0;
  261. /* read x[0], x[1] samples */
  262. x0 = *__SIMD32(px);
  263. /* read x[1], x[2] samples */
  264. x1 = _SIMD32_OFFSET(px+1);
  265. px+= 2u;
  266. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  267. k = srcBLen >> 2u;
  268. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  269. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  270. do
  271. {
  272. /* Read the last two inputB samples using SIMD:
  273. * y[srcBLen - 1] and y[srcBLen - 2] */
  274. c0 = *__SIMD32(py)--;
  275. /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */
  276. acc0 = __SMLADX(x0, c0, acc0);
  277. /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */
  278. acc1 = __SMLADX(x1, c0, acc1);
  279. /* Read x[2], x[3] */
  280. x2 = *__SIMD32(px);
  281. /* Read x[3], x[4] */
  282. x3 = _SIMD32_OFFSET(px+1);
  283. /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */
  284. acc2 = __SMLADX(x2, c0, acc2);
  285. /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */
  286. acc3 = __SMLADX(x3, c0, acc3);
  287. /* Read y[srcBLen - 3] and y[srcBLen - 4] */
  288. c0 = *__SIMD32(py)--;
  289. /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */
  290. acc0 = __SMLADX(x2, c0, acc0);
  291. /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */
  292. acc1 = __SMLADX(x3, c0, acc1);
  293. /* Read x[4], x[5] */
  294. x0 = _SIMD32_OFFSET(px+2);
  295. /* Read x[5], x[6] */
  296. x1 = _SIMD32_OFFSET(px+3);
  297. px += 4u;
  298. /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */
  299. acc2 = __SMLADX(x0, c0, acc2);
  300. /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */
  301. acc3 = __SMLADX(x1, c0, acc3);
  302. } while(--k);
  303. /* For the next MAC operations, SIMD is not used
  304. * So, the 16 bit pointer if inputB, py is updated */
  305. /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
  306. ** No loop unrolling is used. */
  307. k = srcBLen % 0x4u;
  308. if(k == 1u)
  309. {
  310. /* Read y[srcBLen - 5] */
  311. c0 = *(py+1);
  312. #ifdef ARM_MATH_BIG_ENDIAN
  313. c0 = c0 << 16u;
  314. #else
  315. c0 = c0 & 0x0000FFFF;
  316. #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
  317. /* Read x[7] */
  318. x3 = *__SIMD32(px);
  319. px++;
  320. /* Perform the multiply-accumulates */
  321. acc0 = __SMLAD(x0, c0, acc0);
  322. acc1 = __SMLAD(x1, c0, acc1);
  323. acc2 = __SMLADX(x1, c0, acc2);
  324. acc3 = __SMLADX(x3, c0, acc3);
  325. }
  326. if(k == 2u)
  327. {
  328. /* Read y[srcBLen - 5], y[srcBLen - 6] */
  329. c0 = _SIMD32_OFFSET(py);
  330. /* Read x[7], x[8] */
  331. x3 = *__SIMD32(px);
  332. /* Read x[9] */
  333. x2 = _SIMD32_OFFSET(px+1);
  334. px += 2u;
  335. /* Perform the multiply-accumulates */
  336. acc0 = __SMLADX(x0, c0, acc0);
  337. acc1 = __SMLADX(x1, c0, acc1);
  338. acc2 = __SMLADX(x3, c0, acc2);
  339. acc3 = __SMLADX(x2, c0, acc3);
  340. }
  341. if(k == 3u)
  342. {
  343. /* Read y[srcBLen - 5], y[srcBLen - 6] */
  344. c0 = _SIMD32_OFFSET(py);
  345. /* Read x[7], x[8] */
  346. x3 = *__SIMD32(px);
  347. /* Read x[9] */
  348. x2 = _SIMD32_OFFSET(px+1);
  349. /* Perform the multiply-accumulates */
  350. acc0 = __SMLADX(x0, c0, acc0);
  351. acc1 = __SMLADX(x1, c0, acc1);
  352. acc2 = __SMLADX(x3, c0, acc2);
  353. acc3 = __SMLADX(x2, c0, acc3);
  354. c0 = *(py-1);
  355. #ifdef ARM_MATH_BIG_ENDIAN
  356. c0 = c0 << 16u;
  357. #else
  358. c0 = c0 & 0x0000FFFF;
  359. #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
  360. /* Read x[10] */
  361. x3 = _SIMD32_OFFSET(px+2);
  362. px += 3u;
  363. /* Perform the multiply-accumulates */
  364. acc0 = __SMLADX(x1, c0, acc0);
  365. acc1 = __SMLAD(x2, c0, acc1);
  366. acc2 = __SMLADX(x2, c0, acc2);
  367. acc3 = __SMLADX(x3, c0, acc3);
  368. }
  369. /* Store the results in the accumulators in the destination buffer. */
  370. #ifndef ARM_MATH_BIG_ENDIAN
  371. *__SIMD32(pOut)++ = __PKHBT(acc0 >> 15, acc1 >> 15, 16);
  372. *__SIMD32(pOut)++ = __PKHBT(acc2 >> 15, acc3 >> 15, 16);
  373. #else
  374. *__SIMD32(pOut)++ = __PKHBT(acc1 >> 15, acc0 >> 15, 16);
  375. *__SIMD32(pOut)++ = __PKHBT(acc3 >> 15, acc2 >> 15, 16);
  376. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  377. /* Increment the pointer pIn1 index, count by 4 */
  378. count += 4u;
  379. /* Update the inputA and inputB pointers for next MAC calculation */
  380. px = pIn1 + count;
  381. py = pSrc2;
  382. /* Decrement the loop counter */
  383. blkCnt--;
  384. }
  385. /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here.
  386. ** No loop unrolling is used. */
  387. blkCnt = (uint32_t) blockSize2 % 0x4u;
  388. while(blkCnt > 0u)
  389. {
  390. /* Accumulator is made zero for every iteration */
  391. sum = 0;
  392. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  393. k = srcBLen >> 2u;
  394. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  395. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  396. while(k > 0u)
  397. {
  398. /* Perform the multiply-accumulates */
  399. sum += ((q31_t) * px++ * *py--);
  400. sum += ((q31_t) * px++ * *py--);
  401. sum += ((q31_t) * px++ * *py--);
  402. sum += ((q31_t) * px++ * *py--);
  403. /* Decrement the loop counter */
  404. k--;
  405. }
  406. /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
  407. ** No loop unrolling is used. */
  408. k = srcBLen % 0x4u;
  409. while(k > 0u)
  410. {
  411. /* Perform the multiply-accumulates */
  412. sum += ((q31_t) * px++ * *py--);
  413. /* Decrement the loop counter */
  414. k--;
  415. }
  416. /* Store the result in the accumulator in the destination buffer. */
  417. *pOut++ = (q15_t) (sum >> 15);
  418. /* Increment the pointer pIn1 index, count by 1 */
  419. count++;
  420. /* Update the inputA and inputB pointers for next MAC calculation */
  421. px = pIn1 + count;
  422. py = pSrc2;
  423. /* Decrement the loop counter */
  424. blkCnt--;
  425. }
  426. }
  427. else
  428. {
  429. /* If the srcBLen is not a multiple of 4,
  430. * the blockSize2 loop cannot be unrolled by 4 */
  431. blkCnt = (uint32_t) blockSize2;
  432. while(blkCnt > 0u)
  433. {
  434. /* Accumulator is made zero for every iteration */
  435. sum = 0;
  436. /* srcBLen number of MACS should be performed */
  437. k = srcBLen;
  438. while(k > 0u)
  439. {
  440. /* Perform the multiply-accumulate */
  441. sum += ((q31_t) * px++ * *py--);
  442. /* Decrement the loop counter */
  443. k--;
  444. }
  445. /* Store the result in the accumulator in the destination buffer. */
  446. *pOut++ = (q15_t) (sum >> 15);
  447. /* Increment the MAC count */
  448. count++;
  449. /* Update the inputA and inputB pointers for next MAC calculation */
  450. px = pIn1 + count;
  451. py = pSrc2;
  452. /* Decrement the loop counter */
  453. blkCnt--;
  454. }
  455. }
  456. /* --------------------------
  457. * Initializations of stage3
  458. * -------------------------*/
  459. /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1]
  460. * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2]
  461. * ....
  462. * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2]
  463. * sum += x[srcALen-1] * y[srcBLen-1]
  464. */
  465. /* In this stage the MAC operations are decreased by 1 for every iteration.
  466. The count variable holds the number of MAC operations performed */
  467. count = srcBLen - 1u;
  468. /* Working pointer of inputA */
  469. pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);
  470. px = pSrc1;
  471. /* Working pointer of inputB */
  472. pSrc2 = pIn2 + (srcBLen - 1u);
  473. pIn2 = pSrc2 - 1u;
  474. py = pIn2;
  475. /* -------------------
  476. * Stage3 process
  477. * ------------------*/
  478. /* For loop unrolling by 4, this stage is divided into two. */
  479. /* First part of this stage computes the MAC operations greater than 4 */
  480. /* Second part of this stage computes the MAC operations less than or equal to 4 */
  481. /* The first part of the stage starts here */
  482. j = count >> 2u;
  483. while((j > 0u) && (blockSize3 > 0))
  484. {
  485. /* Accumulator is made zero for every iteration */
  486. sum = 0;
  487. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  488. k = count >> 2u;
  489. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  490. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  491. while(k > 0u)
  492. {
  493. /* x[srcALen - srcBLen + 1], x[srcALen - srcBLen + 2] are multiplied
  494. * with y[srcBLen - 1], y[srcBLen - 2] respectively */
  495. sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum);
  496. /* x[srcALen - srcBLen + 3], x[srcALen - srcBLen + 4] are multiplied
  497. * with y[srcBLen - 3], y[srcBLen - 4] respectively */
  498. sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum);
  499. /* Decrement the loop counter */
  500. k--;
  501. }
  502. /* For the next MAC operations, the pointer py is used without SIMD
  503. * So, py is incremented by 1 */
  504. py = py + 1u;
  505. /* If the count is not a multiple of 4, compute any remaining MACs here.
  506. ** No loop unrolling is used. */
  507. k = count % 0x4u;
  508. while(k > 0u)
  509. {
  510. /* sum += x[srcALen - srcBLen + 5] * y[srcBLen - 5] */
  511. sum = __SMLAD(*px++, *py--, sum);
  512. /* Decrement the loop counter */
  513. k--;
  514. }
  515. /* Store the result in the accumulator in the destination buffer. */
  516. *pOut++ = (q15_t) (sum >> 15);
  517. /* Update the inputA and inputB pointers for next MAC calculation */
  518. px = ++pSrc1;
  519. py = pIn2;
  520. /* Decrement the MAC count */
  521. count--;
  522. /* Decrement the loop counter */
  523. blockSize3--;
  524. j--;
  525. }
  526. /* The second part of the stage starts here */
  527. /* SIMD is not used for the next MAC operations,
  528. * so pointer py is updated to read only one sample at a time */
  529. py = py + 1u;
  530. while(blockSize3 > 0)
  531. {
  532. /* Accumulator is made zero for every iteration */
  533. sum = 0;
  534. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  535. k = count;
  536. while(k > 0u)
  537. {
  538. /* Perform the multiply-accumulates */
  539. /* sum += x[srcALen-1] * y[srcBLen-1] */
  540. sum = __SMLAD(*px++, *py--, sum);
  541. /* Decrement the loop counter */
  542. k--;
  543. }
  544. /* Store the result in the accumulator in the destination buffer. */
  545. *pOut++ = (q15_t) (sum >> 15);
  546. /* Update the inputA and inputB pointers for next MAC calculation */
  547. px = ++pSrc1;
  548. py = pSrc2;
  549. /* Decrement the MAC count */
  550. count--;
  551. /* Decrement the loop counter */
  552. blockSize3--;
  553. }
  554. /* set status as ARM_MATH_SUCCESS */
  555. status = ARM_MATH_SUCCESS;
  556. }
  557. /* Return to application */
  558. return (status);
  559. #else
  560. q15_t *pIn1; /* inputA pointer */
  561. q15_t *pIn2; /* inputB pointer */
  562. q15_t *pOut = pDst; /* output pointer */
  563. q31_t sum, acc0, acc1, acc2, acc3; /* Accumulator */
  564. q15_t *px; /* Intermediate inputA pointer */
  565. q15_t *py; /* Intermediate inputB pointer */
  566. q15_t *pSrc1, *pSrc2; /* Intermediate pointers */
  567. q31_t x0, x1, x2, x3, c0;
  568. uint32_t j, k, count, check, blkCnt;
  569. int32_t blockSize1, blockSize2, blockSize3; /* loop counters */
  570. arm_status status; /* status of Partial convolution */
  571. q15_t a, b;
  572. /* Check for range of output samples to be calculated */
  573. if((firstIndex + numPoints) > ((srcALen + (srcBLen - 1u))))
  574. {
  575. /* Set status as ARM_MATH_ARGUMENT_ERROR */
  576. status = ARM_MATH_ARGUMENT_ERROR;
  577. }
  578. else
  579. {
  580. /* The algorithm implementation is based on the lengths of the inputs. */
  581. /* srcB is always made to slide across srcA. */
  582. /* So srcBLen is always considered as shorter or equal to srcALen */
  583. if(srcALen >=srcBLen)
  584. {
  585. /* Initialization of inputA pointer */
  586. pIn1 = pSrcA;
  587. /* Initialization of inputB pointer */
  588. pIn2 = pSrcB;
  589. }
  590. else
  591. {
  592. /* Initialization of inputA pointer */
  593. pIn1 = pSrcB;
  594. /* Initialization of inputB pointer */
  595. pIn2 = pSrcA;
  596. /* srcBLen is always considered as shorter or equal to srcALen */
  597. j = srcBLen;
  598. srcBLen = srcALen;
  599. srcALen = j;
  600. }
  601. /* Conditions to check which loopCounter holds
  602. * the first and last indices of the output samples to be calculated. */
  603. check = firstIndex + numPoints;
  604. blockSize3 = ((int32_t) check - (int32_t) srcALen);
  605. blockSize3 = (blockSize3 > 0) ? blockSize3 : 0;
  606. blockSize1 = (((int32_t) srcBLen - 1) - (int32_t) firstIndex);
  607. blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1u)) ? blockSize1 :
  608. (int32_t) numPoints) : 0;
  609. blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) +
  610. (int32_t) firstIndex);
  611. blockSize2 = (blockSize2 > 0) ? blockSize2 : 0;
  612. /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */
  613. /* The function is internally
  614. * divided into three stages according to the number of multiplications that has to be
  615. * taken place between inputA samples and inputB samples. In the first stage of the
  616. * algorithm, the multiplications increase by one for every iteration.
  617. * In the second stage of the algorithm, srcBLen number of multiplications are done.
  618. * In the third stage of the algorithm, the multiplications decrease by one
  619. * for every iteration. */
  620. /* Set the output pointer to point to the firstIndex
  621. * of the output sample to be calculated. */
  622. pOut = pDst + firstIndex;
  623. /* --------------------------
  624. * Initializations of stage1
  625. * -------------------------*/
  626. /* sum = x[0] * y[0]
  627. * sum = x[0] * y[1] + x[1] * y[0]
  628. * ....
  629. * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0]
  630. */
  631. /* In this stage the MAC operations are increased by 1 for every iteration.
  632. The count variable holds the number of MAC operations performed.
  633. Since the partial convolution starts from firstIndex
  634. Number of Macs to be performed is firstIndex + 1 */
  635. count = 1u + firstIndex;
  636. /* Working pointer of inputA */
  637. px = pIn1;
  638. /* Working pointer of inputB */
  639. pSrc2 = pIn2 + firstIndex;
  640. py = pSrc2;
  641. /* ------------------------
  642. * Stage1 process
  643. * ----------------------*/
  644. /* For loop unrolling by 4, this stage is divided into two. */
  645. /* First part of this stage computes the MAC operations less than 4 */
  646. /* Second part of this stage computes the MAC operations greater than or equal to 4 */
  647. /* The first part of the stage starts here */
  648. while((count < 4u) && (blockSize1 > 0u))
  649. {
  650. /* Accumulator is made zero for every iteration */
  651. sum = 0;
  652. /* Loop over number of MAC operations between
  653. * inputA samples and inputB samples */
  654. k = count;
  655. while(k > 0u)
  656. {
  657. /* Perform the multiply-accumulates */
  658. sum += ((q31_t) * px++ * *py--);
  659. /* Decrement the loop counter */
  660. k--;
  661. }
  662. /* Store the result in the accumulator in the destination buffer. */
  663. *pOut++ = (q15_t) (sum >> 15);
  664. /* Update the inputA and inputB pointers for next MAC calculation */
  665. py = ++pSrc2;
  666. px = pIn1;
  667. /* Increment the MAC count */
  668. count++;
  669. /* Decrement the loop counter */
  670. blockSize1--;
  671. }
  672. /* The second part of the stage starts here */
  673. /* The internal loop, over count, is unrolled by 4 */
  674. /* To, read the last two inputB samples using SIMD:
  675. * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */
  676. py = py - 1;
  677. while(blockSize1 > 0u)
  678. {
  679. /* Accumulator is made zero for every iteration */
  680. sum = 0;
  681. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  682. k = count >> 2u;
  683. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  684. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  685. py++;
  686. while(k > 0u)
  687. {
  688. /* Perform the multiply-accumulates */
  689. sum += ((q31_t) * px++ * *py--);
  690. sum += ((q31_t) * px++ * *py--);
  691. sum += ((q31_t) * px++ * *py--);
  692. sum += ((q31_t) * px++ * *py--);
  693. /* Decrement the loop counter */
  694. k--;
  695. }
  696. /* If the count is not a multiple of 4, compute any remaining MACs here.
  697. ** No loop unrolling is used. */
  698. k = count % 0x4u;
  699. while(k > 0u)
  700. {
  701. /* Perform the multiply-accumulates */
  702. sum += ((q31_t) * px++ * *py--);
  703. /* Decrement the loop counter */
  704. k--;
  705. }
  706. /* Store the result in the accumulator in the destination buffer. */
  707. *pOut++ = (q15_t) (sum >> 15);
  708. /* Update the inputA and inputB pointers for next MAC calculation */
  709. py = ++pSrc2 - 1u;
  710. px = pIn1;
  711. /* Increment the MAC count */
  712. count++;
  713. /* Decrement the loop counter */
  714. blockSize1--;
  715. }
  716. /* --------------------------
  717. * Initializations of stage2
  718. * ------------------------*/
  719. /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0]
  720. * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0]
  721. * ....
  722. * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0]
  723. */
  724. /* Working pointer of inputA */
  725. px = pIn1;
  726. /* Working pointer of inputB */
  727. pSrc2 = pIn2 + (srcBLen - 1u);
  728. py = pSrc2;
  729. /* count is the index by which the pointer pIn1 to be incremented */
  730. count = 0u;
  731. /* --------------------
  732. * Stage2 process
  733. * -------------------*/
  734. /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed.
  735. * So, to loop unroll over blockSize2,
  736. * srcBLen should be greater than or equal to 4 */
  737. if(srcBLen >= 4u)
  738. {
  739. /* Loop unroll over blockSize2, by 4 */
  740. blkCnt = ((uint32_t) blockSize2 >> 2u);
  741. while(blkCnt > 0u)
  742. {
  743. py = py - 1u;
  744. /* Set all accumulators to zero */
  745. acc0 = 0;
  746. acc1 = 0;
  747. acc2 = 0;
  748. acc3 = 0;
  749. /* read x[0], x[1] samples */
  750. a = *px++;
  751. b = *px++;
  752. #ifndef ARM_MATH_BIG_ENDIAN
  753. x0 = __PKHBT(a, b, 16);
  754. a = *px;
  755. x1 = __PKHBT(b, a, 16);
  756. #else
  757. x0 = __PKHBT(b, a, 16);
  758. a = *px;
  759. x1 = __PKHBT(a, b, 16);
  760. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  761. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  762. k = srcBLen >> 2u;
  763. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  764. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  765. do
  766. {
  767. /* Read the last two inputB samples using SIMD:
  768. * y[srcBLen - 1] and y[srcBLen - 2] */
  769. a = *py;
  770. b = *(py+1);
  771. py -= 2;
  772. #ifndef ARM_MATH_BIG_ENDIAN
  773. c0 = __PKHBT(a, b, 16);
  774. #else
  775. c0 = __PKHBT(b, a, 16);;
  776. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  777. /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */
  778. acc0 = __SMLADX(x0, c0, acc0);
  779. /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */
  780. acc1 = __SMLADX(x1, c0, acc1);
  781. a = *px;
  782. b = *(px + 1);
  783. #ifndef ARM_MATH_BIG_ENDIAN
  784. x2 = __PKHBT(a, b, 16);
  785. a = *(px + 2);
  786. x3 = __PKHBT(b, a, 16);
  787. #else
  788. x2 = __PKHBT(b, a, 16);
  789. a = *(px + 2);
  790. x3 = __PKHBT(a, b, 16);
  791. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  792. /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */
  793. acc2 = __SMLADX(x2, c0, acc2);
  794. /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */
  795. acc3 = __SMLADX(x3, c0, acc3);
  796. /* Read y[srcBLen - 3] and y[srcBLen - 4] */
  797. a = *py;
  798. b = *(py+1);
  799. py -= 2;
  800. #ifndef ARM_MATH_BIG_ENDIAN
  801. c0 = __PKHBT(a, b, 16);
  802. #else
  803. c0 = __PKHBT(b, a, 16);;
  804. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  805. /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */
  806. acc0 = __SMLADX(x2, c0, acc0);
  807. /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */
  808. acc1 = __SMLADX(x3, c0, acc1);
  809. /* Read x[4], x[5], x[6] */
  810. a = *(px + 2);
  811. b = *(px + 3);
  812. #ifndef ARM_MATH_BIG_ENDIAN
  813. x0 = __PKHBT(a, b, 16);
  814. a = *(px + 4);
  815. x1 = __PKHBT(b, a, 16);
  816. #else
  817. x0 = __PKHBT(b, a, 16);
  818. a = *(px + 4);
  819. x1 = __PKHBT(a, b, 16);
  820. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  821. px += 4u;
  822. /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */
  823. acc2 = __SMLADX(x0, c0, acc2);
  824. /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */
  825. acc3 = __SMLADX(x1, c0, acc3);
  826. } while(--k);
  827. /* For the next MAC operations, SIMD is not used
  828. * So, the 16 bit pointer if inputB, py is updated */
  829. /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
  830. ** No loop unrolling is used. */
  831. k = srcBLen % 0x4u;
  832. if(k == 1u)
  833. {
  834. /* Read y[srcBLen - 5] */
  835. c0 = *(py+1);
  836. #ifdef ARM_MATH_BIG_ENDIAN
  837. c0 = c0 << 16u;
  838. #else
  839. c0 = c0 & 0x0000FFFF;
  840. #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
  841. /* Read x[7] */
  842. a = *px;
  843. b = *(px+1);
  844. px++;
  845. #ifndef ARM_MATH_BIG_ENDIAN
  846. x3 = __PKHBT(a, b, 16);
  847. #else
  848. x3 = __PKHBT(b, a, 16);;
  849. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  850. /* Perform the multiply-accumulates */
  851. acc0 = __SMLAD(x0, c0, acc0);
  852. acc1 = __SMLAD(x1, c0, acc1);
  853. acc2 = __SMLADX(x1, c0, acc2);
  854. acc3 = __SMLADX(x3, c0, acc3);
  855. }
  856. if(k == 2u)
  857. {
  858. /* Read y[srcBLen - 5], y[srcBLen - 6] */
  859. a = *py;
  860. b = *(py+1);
  861. #ifndef ARM_MATH_BIG_ENDIAN
  862. c0 = __PKHBT(a, b, 16);
  863. #else
  864. c0 = __PKHBT(b, a, 16);;
  865. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  866. /* Read x[7], x[8], x[9] */
  867. a = *px;
  868. b = *(px + 1);
  869. #ifndef ARM_MATH_BIG_ENDIAN
  870. x3 = __PKHBT(a, b, 16);
  871. a = *(px + 2);
  872. x2 = __PKHBT(b, a, 16);
  873. #else
  874. x3 = __PKHBT(b, a, 16);
  875. a = *(px + 2);
  876. x2 = __PKHBT(a, b, 16);
  877. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  878. px += 2u;
  879. /* Perform the multiply-accumulates */
  880. acc0 = __SMLADX(x0, c0, acc0);
  881. acc1 = __SMLADX(x1, c0, acc1);
  882. acc2 = __SMLADX(x3, c0, acc2);
  883. acc3 = __SMLADX(x2, c0, acc3);
  884. }
  885. if(k == 3u)
  886. {
  887. /* Read y[srcBLen - 5], y[srcBLen - 6] */
  888. a = *py;
  889. b = *(py+1);
  890. #ifndef ARM_MATH_BIG_ENDIAN
  891. c0 = __PKHBT(a, b, 16);
  892. #else
  893. c0 = __PKHBT(b, a, 16);;
  894. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  895. /* Read x[7], x[8], x[9] */
  896. a = *px;
  897. b = *(px + 1);
  898. #ifndef ARM_MATH_BIG_ENDIAN
  899. x3 = __PKHBT(a, b, 16);
  900. a = *(px + 2);
  901. x2 = __PKHBT(b, a, 16);
  902. #else
  903. x3 = __PKHBT(b, a, 16);
  904. a = *(px + 2);
  905. x2 = __PKHBT(a, b, 16);
  906. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  907. /* Perform the multiply-accumulates */
  908. acc0 = __SMLADX(x0, c0, acc0);
  909. acc1 = __SMLADX(x1, c0, acc1);
  910. acc2 = __SMLADX(x3, c0, acc2);
  911. acc3 = __SMLADX(x2, c0, acc3);
  912. /* Read y[srcBLen - 7] */
  913. c0 = *(py-1);
  914. #ifdef ARM_MATH_BIG_ENDIAN
  915. c0 = c0 << 16u;
  916. #else
  917. c0 = c0 & 0x0000FFFF;
  918. #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
  919. /* Read x[10] */
  920. a = *(px+2);
  921. b = *(px+3);
  922. #ifndef ARM_MATH_BIG_ENDIAN
  923. x3 = __PKHBT(a, b, 16);
  924. #else
  925. x3 = __PKHBT(b, a, 16);;
  926. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  927. px += 3u;
  928. /* Perform the multiply-accumulates */
  929. acc0 = __SMLADX(x1, c0, acc0);
  930. acc1 = __SMLAD(x2, c0, acc1);
  931. acc2 = __SMLADX(x2, c0, acc2);
  932. acc3 = __SMLADX(x3, c0, acc3);
  933. }
  934. /* Store the results in the accumulators in the destination buffer. */
  935. *pOut++ = (q15_t)(acc0 >> 15);
  936. *pOut++ = (q15_t)(acc1 >> 15);
  937. *pOut++ = (q15_t)(acc2 >> 15);
  938. *pOut++ = (q15_t)(acc3 >> 15);
  939. /* Increment the pointer pIn1 index, count by 4 */
  940. count += 4u;
  941. /* Update the inputA and inputB pointers for next MAC calculation */
  942. px = pIn1 + count;
  943. py = pSrc2;
  944. /* Decrement the loop counter */
  945. blkCnt--;
  946. }
  947. /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here.
  948. ** No loop unrolling is used. */
  949. blkCnt = (uint32_t) blockSize2 % 0x4u;
  950. while(blkCnt > 0u)
  951. {
  952. /* Accumulator is made zero for every iteration */
  953. sum = 0;
  954. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  955. k = srcBLen >> 2u;
  956. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  957. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  958. while(k > 0u)
  959. {
  960. /* Perform the multiply-accumulates */
  961. sum += ((q31_t) * px++ * *py--);
  962. sum += ((q31_t) * px++ * *py--);
  963. sum += ((q31_t) * px++ * *py--);
  964. sum += ((q31_t) * px++ * *py--);
  965. /* Decrement the loop counter */
  966. k--;
  967. }
  968. /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
  969. ** No loop unrolling is used. */
  970. k = srcBLen % 0x4u;
  971. while(k > 0u)
  972. {
  973. /* Perform the multiply-accumulates */
  974. sum += ((q31_t) * px++ * *py--);
  975. /* Decrement the loop counter */
  976. k--;
  977. }
  978. /* Store the result in the accumulator in the destination buffer. */
  979. *pOut++ = (q15_t) (sum >> 15);
  980. /* Increment the pointer pIn1 index, count by 1 */
  981. count++;
  982. /* Update the inputA and inputB pointers for next MAC calculation */
  983. px = pIn1 + count;
  984. py = pSrc2;
  985. /* Decrement the loop counter */
  986. blkCnt--;
  987. }
  988. }
  989. else
  990. {
  991. /* If the srcBLen is not a multiple of 4,
  992. * the blockSize2 loop cannot be unrolled by 4 */
  993. blkCnt = (uint32_t) blockSize2;
  994. while(blkCnt > 0u)
  995. {
  996. /* Accumulator is made zero for every iteration */
  997. sum = 0;
  998. /* srcBLen number of MACS should be performed */
  999. k = srcBLen;
  1000. while(k > 0u)
  1001. {
  1002. /* Perform the multiply-accumulate */
  1003. sum += ((q31_t) * px++ * *py--);
  1004. /* Decrement the loop counter */
  1005. k--;
  1006. }
  1007. /* Store the result in the accumulator in the destination buffer. */
  1008. *pOut++ = (q15_t) (sum >> 15);
  1009. /* Increment the MAC count */
  1010. count++;
  1011. /* Update the inputA and inputB pointers for next MAC calculation */
  1012. px = pIn1 + count;
  1013. py = pSrc2;
  1014. /* Decrement the loop counter */
  1015. blkCnt--;
  1016. }
  1017. }
  1018. /* --------------------------
  1019. * Initializations of stage3
  1020. * -------------------------*/
  1021. /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1]
  1022. * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2]
  1023. * ....
  1024. * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2]
  1025. * sum += x[srcALen-1] * y[srcBLen-1]
  1026. */
  1027. /* In this stage the MAC operations are decreased by 1 for every iteration.
  1028. The count variable holds the number of MAC operations performed */
  1029. count = srcBLen - 1u;
  1030. /* Working pointer of inputA */
  1031. pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);
  1032. px = pSrc1;
  1033. /* Working pointer of inputB */
  1034. pSrc2 = pIn2 + (srcBLen - 1u);
  1035. pIn2 = pSrc2 - 1u;
  1036. py = pIn2;
  1037. /* -------------------
  1038. * Stage3 process
  1039. * ------------------*/
  1040. /* For loop unrolling by 4, this stage is divided into two. */
  1041. /* First part of this stage computes the MAC operations greater than 4 */
  1042. /* Second part of this stage computes the MAC operations less than or equal to 4 */
  1043. /* The first part of the stage starts here */
  1044. j = count >> 2u;
  1045. while((j > 0u) && (blockSize3 > 0))
  1046. {
  1047. /* Accumulator is made zero for every iteration */
  1048. sum = 0;
  1049. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  1050. k = count >> 2u;
  1051. /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
  1052. ** a second loop below computes MACs for the remaining 1 to 3 samples. */
  1053. py++;
  1054. while(k > 0u)
  1055. {
  1056. /* Perform the multiply-accumulates */
  1057. sum += ((q31_t) * px++ * *py--);
  1058. sum += ((q31_t) * px++ * *py--);
  1059. sum += ((q31_t) * px++ * *py--);
  1060. sum += ((q31_t) * px++ * *py--);
  1061. /* Decrement the loop counter */
  1062. k--;
  1063. }
  1064. /* If the count is not a multiple of 4, compute any remaining MACs here.
  1065. ** No loop unrolling is used. */
  1066. k = count % 0x4u;
  1067. while(k > 0u)
  1068. {
  1069. /* Perform the multiply-accumulates */
  1070. sum += ((q31_t) * px++ * *py--);
  1071. /* Decrement the loop counter */
  1072. k--;
  1073. }
  1074. /* Store the result in the accumulator in the destination buffer. */
  1075. *pOut++ = (q15_t) (sum >> 15);
  1076. /* Update the inputA and inputB pointers for next MAC calculation */
  1077. px = ++pSrc1;
  1078. py = pIn2;
  1079. /* Decrement the MAC count */
  1080. count--;
  1081. /* Decrement the loop counter */
  1082. blockSize3--;
  1083. j--;
  1084. }
  1085. /* The second part of the stage starts here */
  1086. /* SIMD is not used for the next MAC operations,
  1087. * so pointer py is updated to read only one sample at a time */
  1088. py = py + 1u;
  1089. while(blockSize3 > 0u)
  1090. {
  1091. /* Accumulator is made zero for every iteration */
  1092. sum = 0;
  1093. /* Apply loop unrolling and compute 4 MACs simultaneously. */
  1094. k = count;
  1095. while(k > 0u)
  1096. {
  1097. /* Perform the multiply-accumulates */
  1098. /* sum += x[srcALen-1] * y[srcBLen-1] */
  1099. sum += ((q31_t) * px++ * *py--);
  1100. /* Decrement the loop counter */
  1101. k--;
  1102. }
  1103. /* Store the result in the accumulator in the destination buffer. */
  1104. *pOut++ = (q15_t) (sum >> 15);
  1105. /* Update the inputA and inputB pointers for next MAC calculation */
  1106. px = ++pSrc1;
  1107. py = pSrc2;
  1108. /* Decrement the MAC count */
  1109. count--;
  1110. /* Decrement the loop counter */
  1111. blockSize3--;
  1112. }
  1113. /* set status as ARM_MATH_SUCCESS */
  1114. status = ARM_MATH_SUCCESS;
  1115. }
  1116. /* Return to application */
  1117. return (status);
  1118. #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
  1119. }
  1120. /**
  1121. * @} end of PartialConv group
  1122. */