]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/FilteringFunctions/arm_conv_partial_opt_q15.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_conv_partial_opt_q15.c
10 * Description: Partial convolution of Q15 sequences.
12 * Target Processor: Cortex-M4/Cortex-M3
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
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
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.
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 * -------------------------------------------------------------------- */
44 * @ingroup groupFilters
48 * @addtogroup PartialConv
53 * @brief Partial convolution of Q15 sequences.
54 * @param[in] *pSrcA points to the first input sequence.
55 * @param[in] srcALen length of the first input sequence.
56 * @param[in] *pSrcB points to the second input sequence.
57 * @param[in] srcBLen length of the second input sequence.
58 * @param[out] *pDst points to the location where the output result is written.
59 * @param[in] firstIndex is the first output sample to start with.
60 * @param[in] numPoints is the number of output points to be computed.
61 * @param[in] *pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
62 * @param[in] *pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
63 * @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].
66 * If the silicon does not support unaligned memory access enable the macro UNALIGNED_SUPPORT_DISABLE
67 * In this case input, output, state buffers should be aligned by 32-bit
69 * Refer to <code>arm_conv_partial_fast_q15()</code> for a faster but less precise version of this function for Cortex-M3 and Cortex-M4.
74 #ifndef UNALIGNED_SUPPORT_DISABLE
76 arm_status
arm_conv_partial_opt_q15 (
88 q15_t
* pOut
= pDst
; /* output pointer */
89 q15_t
* pScr1
= pScratch1
; /* Temporary pointer for scratch1 */
90 q15_t
* pScr2
= pScratch2
; /* Temporary pointer for scratch1 */
91 q63_t acc0
, acc1
, acc2
, acc3
; /* Accumulator */
92 q31_t x1
, x2
, x3
; /* Temporary variables to hold state and coefficient values */
93 q31_t y1
, y2
; /* State variables */
94 q15_t
* pIn1
; /* inputA pointer */
95 q15_t
* pIn2
; /* inputB pointer */
96 q15_t
* px
; /* Intermediate inputA pointer */
97 q15_t
* py
; /* Intermediate inputB pointer */
98 uint32_t j
, k
, blkCnt
; /* loop counter */
99 arm_status status
; /* Status variable */
100 uint32_t tapCnt
; /* loop count */
102 /* Check for range of output samples to be calculated */
103 if (( firstIndex
+ numPoints
) > (( srcALen
+ ( srcBLen
- 1u ))))
105 /* Set status as ARM_MATH_ARGUMENT_ERROR */
106 status
= ARM_MATH_ARGUMENT_ERROR
;
111 /* The algorithm implementation is based on the lengths of the inputs. */
112 /* srcB is always made to slide across srcA. */
113 /* So srcBLen is always considered as shorter or equal to srcALen */
114 if ( srcALen
>= srcBLen
)
116 /* Initialization of inputA pointer */
119 /* Initialization of inputB pointer */
124 /* Initialization of inputA pointer */
127 /* Initialization of inputB pointer */
130 /* srcBLen is always considered as shorter or equal to srcALen */
136 /* Temporary pointer for scratch2 */
139 /* pointer to take end of scratch2 buffer */
140 pScr2
= pScratch2
+ srcBLen
- 1 ;
142 /* points to smaller length sequence */
145 /* Apply loop unrolling and do 4 Copies simultaneously. */
148 /* First part of the processing with loop unrolling copies 4 data points at a time.
149 ** a second loop below copies for the remaining 1 to 3 samples. */
152 /* copy second buffer in reversal manner */
158 /* Decrement the loop counter */
162 /* If the count is not a multiple of 4, copy remaining samples here.
163 ** No loop unrolling is used. */
168 /* copy second buffer in reversal manner for remaining samples */
171 /* Decrement the loop counter */
175 /* Initialze temporary scratch pointer */
178 /* Fill (srcBLen - 1u) zeros in scratch buffer */
179 arm_fill_q15 ( 0 , pScr1
, ( srcBLen
- 1u ));
181 /* Update temporary scratch pointer */
182 pScr1
+= ( srcBLen
- 1u );
184 /* Copy bigger length sequence(srcALen) samples in scratch1 buffer */
186 /* Copy (srcALen) samples in scratch buffer */
187 arm_copy_q15 ( pIn1
, pScr1
, srcALen
);
189 /* Update pointers */
192 /* Fill (srcBLen - 1u) zeros at end of scratch buffer */
193 arm_fill_q15 ( 0 , pScr1
, ( srcBLen
- 1u ));
196 pScr1
+= ( srcBLen
- 1u );
198 /* Initialization of pIn2 pointer */
201 pScratch1
+= firstIndex
;
203 pOut
= pDst
+ firstIndex
;
205 /* Actual convolution process starts here */
206 blkCnt
= ( numPoints
) >> 2 ;
210 /* Initialze temporary scratch pointer as scratch1 */
213 /* Clear Accumlators */
219 /* Read two samples from scratch1 buffer */
220 x1
= * __SIMD32 ( pScr1
)++;
222 /* Read next two samples from scratch1 buffer */
223 x2
= * __SIMD32 ( pScr1
)++;
225 tapCnt
= ( srcBLen
) >> 2u ;
230 /* Read four samples from smaller buffer */
231 y1
= _SIMD32_OFFSET ( pIn2
);
232 y2
= _SIMD32_OFFSET ( pIn2
+ 2u );
234 /* multiply and accumlate */
235 acc0
= __SMLALD ( x1
, y1
, acc0
);
236 acc2
= __SMLALD ( x2
, y1
, acc2
);
238 /* pack input data */
239 #ifndef ARM_MATH_BIG_ENDIAN
240 x3
= __PKHBT ( x2
, x1
, 0 );
242 x3
= __PKHBT ( x1
, x2
, 0 );
245 /* multiply and accumlate */
246 acc1
= __SMLALDX ( x3
, y1
, acc1
);
248 /* Read next two samples from scratch1 buffer */
249 x1
= _SIMD32_OFFSET ( pScr1
);
251 /* multiply and accumlate */
252 acc0
= __SMLALD ( x2
, y2
, acc0
);
253 acc2
= __SMLALD ( x1
, y2
, acc2
);
255 /* pack input data */
256 #ifndef ARM_MATH_BIG_ENDIAN
257 x3
= __PKHBT ( x1
, x2
, 0 );
259 x3
= __PKHBT ( x2
, x1
, 0 );
262 acc3
= __SMLALDX ( x3
, y1
, acc3
);
263 acc1
= __SMLALDX ( x3
, y2
, acc1
);
265 x2
= _SIMD32_OFFSET ( pScr1
+ 2u );
267 #ifndef ARM_MATH_BIG_ENDIAN
268 x3
= __PKHBT ( x2
, x1
, 0 );
270 x3
= __PKHBT ( x1
, x2
, 0 );
273 acc3
= __SMLALDX ( x3
, y2
, acc3
);
275 /* update scratch pointers */
280 /* Decrement the loop counter */
284 /* Update scratch pointer for remaining samples of smaller length sequence */
287 /* apply same above for remaining samples of smaller length sequence */
288 tapCnt
= ( srcBLen
) & 3u ;
292 /* accumlate the results */
293 acc0
+= (* pScr1
++ * * pIn2
);
294 acc1
+= (* pScr1
++ * * pIn2
);
295 acc2
+= (* pScr1
++ * * pIn2
);
296 acc3
+= (* pScr1
++ * * pIn2
++);
300 /* Decrement the loop counter */
307 /* Store the results in the accumulators in the destination buffer. */
309 #ifndef ARM_MATH_BIG_ENDIAN
312 __PKHBT ( __SSAT (( acc0
>> 15 ), 16 ), __SSAT (( acc1
>> 15 ), 16 ), 16 );
314 __PKHBT ( __SSAT (( acc2
>> 15 ), 16 ), __SSAT (( acc3
>> 15 ), 16 ), 16 );
319 __PKHBT ( __SSAT (( acc1
>> 15 ), 16 ), __SSAT (( acc0
>> 15 ), 16 ), 16 );
321 __PKHBT ( __SSAT (( acc3
>> 15 ), 16 ), __SSAT (( acc2
>> 15 ), 16 ), 16 );
323 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
325 /* Initialization of inputB pointer */
333 blkCnt
= numPoints
& 0x3 ;
335 /* Calculate convolution for remaining samples of Bigger length sequence */
338 /* Initialze temporary scratch pointer as scratch1 */
341 /* Clear Accumlators */
344 tapCnt
= ( srcBLen
) >> 1u ;
349 /* Read next two samples from scratch1 buffer */
350 x1
= * __SIMD32 ( pScr1
)++;
352 /* Read two samples from smaller buffer */
353 y1
= * __SIMD32 ( pIn2
)++;
355 acc0
= __SMLALD ( x1
, y1
, acc0
);
357 /* Decrement the loop counter */
361 tapCnt
= ( srcBLen
) & 1u ;
363 /* apply same above for remaining samples of smaller length sequence */
367 /* accumlate the results */
368 acc0
+= (* pScr1
++ * * pIn2
++);
370 /* Decrement the loop counter */
376 /* Store the result in the accumulator in the destination buffer. */
377 * pOut
++ = ( q15_t
) ( __SSAT (( acc0
>> 15 ), 16 ));
379 /* Initialization of inputB pointer */
386 /* set status as ARM_MATH_SUCCESS */
387 status
= ARM_MATH_SUCCESS
;
391 /* Return to application */
397 arm_status
arm_conv_partial_opt_q15 (
409 q15_t
* pOut
= pDst
; /* output pointer */
410 q15_t
* pScr1
= pScratch1
; /* Temporary pointer for scratch1 */
411 q15_t
* pScr2
= pScratch2
; /* Temporary pointer for scratch1 */
412 q63_t acc0
, acc1
, acc2
, acc3
; /* Accumulator */
413 q15_t
* pIn1
; /* inputA pointer */
414 q15_t
* pIn2
; /* inputB pointer */
415 q15_t
* px
; /* Intermediate inputA pointer */
416 q15_t
* py
; /* Intermediate inputB pointer */
417 uint32_t j
, k
, blkCnt
; /* loop counter */
418 arm_status status
; /* Status variable */
419 uint32_t tapCnt
; /* loop count */
420 q15_t x10
, x11
, x20
, x21
; /* Temporary variables to hold srcA buffer */
421 q15_t y10
, y11
; /* Temporary variables to hold srcB buffer */
424 /* Check for range of output samples to be calculated */
425 if (( firstIndex
+ numPoints
) > (( srcALen
+ ( srcBLen
- 1u ))))
427 /* Set status as ARM_MATH_ARGUMENT_ERROR */
428 status
= ARM_MATH_ARGUMENT_ERROR
;
433 /* The algorithm implementation is based on the lengths of the inputs. */
434 /* srcB is always made to slide across srcA. */
435 /* So srcBLen is always considered as shorter or equal to srcALen */
436 if ( srcALen
>= srcBLen
)
438 /* Initialization of inputA pointer */
441 /* Initialization of inputB pointer */
446 /* Initialization of inputA pointer */
449 /* Initialization of inputB pointer */
452 /* srcBLen is always considered as shorter or equal to srcALen */
458 /* Temporary pointer for scratch2 */
461 /* pointer to take end of scratch2 buffer */
462 pScr2
= pScratch2
+ srcBLen
- 1 ;
464 /* points to smaller length sequence */
467 /* Apply loop unrolling and do 4 Copies simultaneously. */
470 /* First part of the processing with loop unrolling copies 4 data points at a time.
471 ** a second loop below copies for the remaining 1 to 3 samples. */
474 /* copy second buffer in reversal manner */
480 /* Decrement the loop counter */
484 /* If the count is not a multiple of 4, copy remaining samples here.
485 ** No loop unrolling is used. */
490 /* copy second buffer in reversal manner for remaining samples */
493 /* Decrement the loop counter */
497 /* Initialze temporary scratch pointer */
500 /* Fill (srcBLen - 1u) zeros in scratch buffer */
501 arm_fill_q15 ( 0 , pScr1
, ( srcBLen
- 1u ));
503 /* Update temporary scratch pointer */
504 pScr1
+= ( srcBLen
- 1u );
506 /* Copy bigger length sequence(srcALen) samples in scratch1 buffer */
509 /* Apply loop unrolling and do 4 Copies simultaneously. */
512 /* First part of the processing with loop unrolling copies 4 data points at a time.
513 ** a second loop below copies for the remaining 1 to 3 samples. */
516 /* copy second buffer in reversal manner */
522 /* Decrement the loop counter */
526 /* If the count is not a multiple of 4, copy remaining samples here.
527 ** No loop unrolling is used. */
532 /* copy second buffer in reversal manner for remaining samples */
535 /* Decrement the loop counter */
540 /* Apply loop unrolling and do 4 Copies simultaneously. */
541 k
= ( srcBLen
- 1u ) >> 2u ;
543 /* First part of the processing with loop unrolling copies 4 data points at a time.
544 ** a second loop below copies for the remaining 1 to 3 samples. */
547 /* copy second buffer in reversal manner */
553 /* Decrement the loop counter */
557 /* If the count is not a multiple of 4, copy remaining samples here.
558 ** No loop unrolling is used. */
559 k
= ( srcBLen
- 1u ) % 0x4 u
;
563 /* copy second buffer in reversal manner for remaining samples */
566 /* Decrement the loop counter */
571 /* Initialization of pIn2 pointer */
574 pScratch1
+= firstIndex
;
576 pOut
= pDst
+ firstIndex
;
578 /* Actual convolution process starts here */
579 blkCnt
= ( numPoints
) >> 2 ;
583 /* Initialze temporary scratch pointer as scratch1 */
586 /* Clear Accumlators */
592 /* Read two samples from scratch1 buffer */
596 /* Read next two samples from scratch1 buffer */
600 tapCnt
= ( srcBLen
) >> 2u ;
605 /* Read two samples from smaller buffer */
609 /* multiply and accumlate */
610 acc0
+= ( q63_t
) x10
* y10
;
611 acc0
+= ( q63_t
) x11
* y11
;
612 acc2
+= ( q63_t
) x20
* y10
;
613 acc2
+= ( q63_t
) x21
* y11
;
615 /* multiply and accumlate */
616 acc1
+= ( q63_t
) x11
* y10
;
617 acc1
+= ( q63_t
) x20
* y11
;
619 /* Read next two samples from scratch1 buffer */
623 /* multiply and accumlate */
624 acc3
+= ( q63_t
) x21
* y10
;
625 acc3
+= ( q63_t
) x10
* y11
;
627 /* Read next two samples from scratch2 buffer */
631 /* multiply and accumlate */
632 acc0
+= ( q63_t
) x20
* y10
;
633 acc0
+= ( q63_t
) x21
* y11
;
634 acc2
+= ( q63_t
) x10
* y10
;
635 acc2
+= ( q63_t
) x11
* y11
;
636 acc1
+= ( q63_t
) x21
* y10
;
637 acc1
+= ( q63_t
) x10
* y11
;
639 /* Read next two samples from scratch1 buffer */
643 /* multiply and accumlate */
644 acc3
+= ( q63_t
) x11
* y10
;
645 acc3
+= ( q63_t
) x20
* y11
;
647 /* update scratch pointers */
651 /* Decrement the loop counter */
655 /* Update scratch pointer for remaining samples of smaller length sequence */
658 /* apply same above for remaining samples of smaller length sequence */
659 tapCnt
= ( srcBLen
) & 3u ;
663 /* accumlate the results */
664 acc0
+= (* pScr1
++ * * pIn2
);
665 acc1
+= (* pScr1
++ * * pIn2
);
666 acc2
+= (* pScr1
++ * * pIn2
);
667 acc3
+= (* pScr1
++ * * pIn2
++);
671 /* Decrement the loop counter */
678 /* Store the results in the accumulators in the destination buffer. */
679 * pOut
++ = __SSAT (( acc0
>> 15 ), 16 );
680 * pOut
++ = __SSAT (( acc1
>> 15 ), 16 );
681 * pOut
++ = __SSAT (( acc2
>> 15 ), 16 );
682 * pOut
++ = __SSAT (( acc3
>> 15 ), 16 );
685 /* Initialization of inputB pointer */
693 blkCnt
= numPoints
& 0x3 ;
695 /* Calculate convolution for remaining samples of Bigger length sequence */
698 /* Initialze temporary scratch pointer as scratch1 */
701 /* Clear Accumlators */
704 tapCnt
= ( srcBLen
) >> 1u ;
709 /* Read next two samples from scratch1 buffer */
713 /* Read two samples from smaller buffer */
717 /* multiply and accumlate */
718 acc0
+= ( q63_t
) x10
* y10
;
719 acc0
+= ( q63_t
) x11
* y11
;
721 /* Decrement the loop counter */
725 tapCnt
= ( srcBLen
) & 1u ;
727 /* apply same above for remaining samples of smaller length sequence */
731 /* accumlate the results */
732 acc0
+= (* pScr1
++ * * pIn2
++);
734 /* Decrement the loop counter */
740 /* Store the result in the accumulator in the destination buffer. */
741 * pOut
++ = ( q15_t
) ( __SSAT (( acc0
>> 15 ), 16 ));
744 /* Initialization of inputB pointer */
751 /* set status as ARM_MATH_SUCCESS */
752 status
= ARM_MATH_SUCCESS
;
756 /* Return to application */
760 #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */
764 * @} end of PartialConv group