V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.
Dependents: MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more
FilteringFunctions/arm_conv_partial_q15.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- Committer:
- emh203
- Date:
- Mon Jul 28 15:03:15 2014 +0000
- Revision:
- 0:3d9c67d97d6f
1st working commit. Had to remove arm_bitreversal2.s arm_cfft_f32.c and arm_rfft_fast_f32.c. The .s will not assemble. For now I removed these functions so we could at least have a library for the other functions.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emh203 | 0:3d9c67d97d6f | 1 | /* ---------------------------------------------------------------------- |
emh203 | 0:3d9c67d97d6f | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
emh203 | 0:3d9c67d97d6f | 3 | * |
emh203 | 0:3d9c67d97d6f | 4 | * $Date: 12. March 2014 |
emh203 | 0:3d9c67d97d6f | 5 | * $Revision: V1.4.3 |
emh203 | 0:3d9c67d97d6f | 6 | * |
emh203 | 0:3d9c67d97d6f | 7 | * Project: CMSIS DSP Library |
emh203 | 0:3d9c67d97d6f | 8 | * Title: arm_conv_partial_q15.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Partial convolution of Q15 sequences. |
emh203 | 0:3d9c67d97d6f | 11 | * |
emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emh203 | 0:3d9c67d97d6f | 13 | * |
emh203 | 0:3d9c67d97d6f | 14 | * Redistribution and use in source and binary forms, with or without |
emh203 | 0:3d9c67d97d6f | 15 | * modification, are permitted provided that the following conditions |
emh203 | 0:3d9c67d97d6f | 16 | * are met: |
emh203 | 0:3d9c67d97d6f | 17 | * - Redistributions of source code must retain the above copyright |
emh203 | 0:3d9c67d97d6f | 18 | * notice, this list of conditions and the following disclaimer. |
emh203 | 0:3d9c67d97d6f | 19 | * - Redistributions in binary form must reproduce the above copyright |
emh203 | 0:3d9c67d97d6f | 20 | * notice, this list of conditions and the following disclaimer in |
emh203 | 0:3d9c67d97d6f | 21 | * the documentation and/or other materials provided with the |
emh203 | 0:3d9c67d97d6f | 22 | * distribution. |
emh203 | 0:3d9c67d97d6f | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
emh203 | 0:3d9c67d97d6f | 24 | * may be used to endorse or promote products derived from this |
emh203 | 0:3d9c67d97d6f | 25 | * software without specific prior written permission. |
emh203 | 0:3d9c67d97d6f | 26 | * |
emh203 | 0:3d9c67d97d6f | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
emh203 | 0:3d9c67d97d6f | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
emh203 | 0:3d9c67d97d6f | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
emh203 | 0:3d9c67d97d6f | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
emh203 | 0:3d9c67d97d6f | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
emh203 | 0:3d9c67d97d6f | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
emh203 | 0:3d9c67d97d6f | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
emh203 | 0:3d9c67d97d6f | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
emh203 | 0:3d9c67d97d6f | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
emh203 | 0:3d9c67d97d6f | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
emh203 | 0:3d9c67d97d6f | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
emh203 | 0:3d9c67d97d6f | 38 | * POSSIBILITY OF SUCH DAMAGE. |
emh203 | 0:3d9c67d97d6f | 39 | * -------------------------------------------------------------------- */ |
emh203 | 0:3d9c67d97d6f | 40 | |
emh203 | 0:3d9c67d97d6f | 41 | #include "arm_math.h" |
emh203 | 0:3d9c67d97d6f | 42 | |
emh203 | 0:3d9c67d97d6f | 43 | /** |
emh203 | 0:3d9c67d97d6f | 44 | * @ingroup groupFilters |
emh203 | 0:3d9c67d97d6f | 45 | */ |
emh203 | 0:3d9c67d97d6f | 46 | |
emh203 | 0:3d9c67d97d6f | 47 | /** |
emh203 | 0:3d9c67d97d6f | 48 | * @addtogroup PartialConv |
emh203 | 0:3d9c67d97d6f | 49 | * @{ |
emh203 | 0:3d9c67d97d6f | 50 | */ |
emh203 | 0:3d9c67d97d6f | 51 | |
emh203 | 0:3d9c67d97d6f | 52 | /** |
emh203 | 0:3d9c67d97d6f | 53 | * @brief Partial convolution of Q15 sequences. |
emh203 | 0:3d9c67d97d6f | 54 | * @param[in] *pSrcA points to the first input sequence. |
emh203 | 0:3d9c67d97d6f | 55 | * @param[in] srcALen length of the first input sequence. |
emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *pSrcB points to the second input sequence. |
emh203 | 0:3d9c67d97d6f | 57 | * @param[in] srcBLen length of the second input sequence. |
emh203 | 0:3d9c67d97d6f | 58 | * @param[out] *pDst points to the location where the output result is written. |
emh203 | 0:3d9c67d97d6f | 59 | * @param[in] firstIndex is the first output sample to start with. |
emh203 | 0:3d9c67d97d6f | 60 | * @param[in] numPoints is the number of output points to be computed. |
emh203 | 0:3d9c67d97d6f | 61 | * @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]. |
emh203 | 0:3d9c67d97d6f | 62 | * |
emh203 | 0:3d9c67d97d6f | 63 | * 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. |
emh203 | 0:3d9c67d97d6f | 64 | * |
emh203 | 0:3d9c67d97d6f | 65 | * \par |
emh203 | 0:3d9c67d97d6f | 66 | * Refer the function <code>arm_conv_partial_opt_q15()</code> for a faster implementation of this function using scratch buffers. |
emh203 | 0:3d9c67d97d6f | 67 | * |
emh203 | 0:3d9c67d97d6f | 68 | */ |
emh203 | 0:3d9c67d97d6f | 69 | |
emh203 | 0:3d9c67d97d6f | 70 | |
emh203 | 0:3d9c67d97d6f | 71 | arm_status arm_conv_partial_q15( |
emh203 | 0:3d9c67d97d6f | 72 | q15_t * pSrcA, |
emh203 | 0:3d9c67d97d6f | 73 | uint32_t srcALen, |
emh203 | 0:3d9c67d97d6f | 74 | q15_t * pSrcB, |
emh203 | 0:3d9c67d97d6f | 75 | uint32_t srcBLen, |
emh203 | 0:3d9c67d97d6f | 76 | q15_t * pDst, |
emh203 | 0:3d9c67d97d6f | 77 | uint32_t firstIndex, |
emh203 | 0:3d9c67d97d6f | 78 | uint32_t numPoints) |
emh203 | 0:3d9c67d97d6f | 79 | { |
emh203 | 0:3d9c67d97d6f | 80 | |
emh203 | 0:3d9c67d97d6f | 81 | #if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE) |
emh203 | 0:3d9c67d97d6f | 82 | |
emh203 | 0:3d9c67d97d6f | 83 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emh203 | 0:3d9c67d97d6f | 84 | |
emh203 | 0:3d9c67d97d6f | 85 | q15_t *pIn1; /* inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 86 | q15_t *pIn2; /* inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 87 | q15_t *pOut = pDst; /* output pointer */ |
emh203 | 0:3d9c67d97d6f | 88 | q63_t sum, acc0, acc1, acc2, acc3; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 89 | q15_t *px; /* Intermediate inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 90 | q15_t *py; /* Intermediate inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 91 | q15_t *pSrc1, *pSrc2; /* Intermediate pointers */ |
emh203 | 0:3d9c67d97d6f | 92 | q31_t x0, x1, x2, x3, c0; /* Temporary input variables */ |
emh203 | 0:3d9c67d97d6f | 93 | uint32_t j, k, count, check, blkCnt; |
emh203 | 0:3d9c67d97d6f | 94 | int32_t blockSize1, blockSize2, blockSize3; /* loop counter */ |
emh203 | 0:3d9c67d97d6f | 95 | arm_status status; /* status of Partial convolution */ |
emh203 | 0:3d9c67d97d6f | 96 | |
emh203 | 0:3d9c67d97d6f | 97 | /* Check for range of output samples to be calculated */ |
emh203 | 0:3d9c67d97d6f | 98 | if((firstIndex + numPoints) > ((srcALen + (srcBLen - 1u)))) |
emh203 | 0:3d9c67d97d6f | 99 | { |
emh203 | 0:3d9c67d97d6f | 100 | /* Set status as ARM_MATH_ARGUMENT_ERROR */ |
emh203 | 0:3d9c67d97d6f | 101 | status = ARM_MATH_ARGUMENT_ERROR; |
emh203 | 0:3d9c67d97d6f | 102 | } |
emh203 | 0:3d9c67d97d6f | 103 | else |
emh203 | 0:3d9c67d97d6f | 104 | { |
emh203 | 0:3d9c67d97d6f | 105 | |
emh203 | 0:3d9c67d97d6f | 106 | /* The algorithm implementation is based on the lengths of the inputs. */ |
emh203 | 0:3d9c67d97d6f | 107 | /* srcB is always made to slide across srcA. */ |
emh203 | 0:3d9c67d97d6f | 108 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 109 | if(srcALen >= srcBLen) |
emh203 | 0:3d9c67d97d6f | 110 | { |
emh203 | 0:3d9c67d97d6f | 111 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 112 | pIn1 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 113 | |
emh203 | 0:3d9c67d97d6f | 114 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 115 | pIn2 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 116 | } |
emh203 | 0:3d9c67d97d6f | 117 | else |
emh203 | 0:3d9c67d97d6f | 118 | { |
emh203 | 0:3d9c67d97d6f | 119 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 120 | pIn1 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 121 | |
emh203 | 0:3d9c67d97d6f | 122 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 123 | pIn2 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 124 | |
emh203 | 0:3d9c67d97d6f | 125 | /* srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 126 | j = srcBLen; |
emh203 | 0:3d9c67d97d6f | 127 | srcBLen = srcALen; |
emh203 | 0:3d9c67d97d6f | 128 | srcALen = j; |
emh203 | 0:3d9c67d97d6f | 129 | } |
emh203 | 0:3d9c67d97d6f | 130 | |
emh203 | 0:3d9c67d97d6f | 131 | /* Conditions to check which loopCounter holds |
emh203 | 0:3d9c67d97d6f | 132 | * the first and last indices of the output samples to be calculated. */ |
emh203 | 0:3d9c67d97d6f | 133 | check = firstIndex + numPoints; |
emh203 | 0:3d9c67d97d6f | 134 | blockSize3 = ((int32_t)check > (int32_t)srcALen) ? (int32_t)check - (int32_t)srcALen : 0; |
emh203 | 0:3d9c67d97d6f | 135 | blockSize3 = ((int32_t)firstIndex > (int32_t)srcALen - 1) ? blockSize3 - (int32_t)firstIndex + (int32_t)srcALen : blockSize3; |
emh203 | 0:3d9c67d97d6f | 136 | blockSize1 = (((int32_t) srcBLen - 1) - (int32_t) firstIndex); |
emh203 | 0:3d9c67d97d6f | 137 | blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1u)) ? blockSize1 : |
emh203 | 0:3d9c67d97d6f | 138 | (int32_t) numPoints) : 0; |
emh203 | 0:3d9c67d97d6f | 139 | blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) + |
emh203 | 0:3d9c67d97d6f | 140 | (int32_t) firstIndex); |
emh203 | 0:3d9c67d97d6f | 141 | blockSize2 = (blockSize2 > 0) ? blockSize2 : 0; |
emh203 | 0:3d9c67d97d6f | 142 | |
emh203 | 0:3d9c67d97d6f | 143 | /* 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] */ |
emh203 | 0:3d9c67d97d6f | 144 | /* The function is internally |
emh203 | 0:3d9c67d97d6f | 145 | * divided into three stages according to the number of multiplications that has to be |
emh203 | 0:3d9c67d97d6f | 146 | * taken place between inputA samples and inputB samples. In the first stage of the |
emh203 | 0:3d9c67d97d6f | 147 | * algorithm, the multiplications increase by one for every iteration. |
emh203 | 0:3d9c67d97d6f | 148 | * In the second stage of the algorithm, srcBLen number of multiplications are done. |
emh203 | 0:3d9c67d97d6f | 149 | * In the third stage of the algorithm, the multiplications decrease by one |
emh203 | 0:3d9c67d97d6f | 150 | * for every iteration. */ |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | /* Set the output pointer to point to the firstIndex |
emh203 | 0:3d9c67d97d6f | 153 | * of the output sample to be calculated. */ |
emh203 | 0:3d9c67d97d6f | 154 | pOut = pDst + firstIndex; |
emh203 | 0:3d9c67d97d6f | 155 | |
emh203 | 0:3d9c67d97d6f | 156 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 157 | * Initializations of stage1 |
emh203 | 0:3d9c67d97d6f | 158 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 159 | |
emh203 | 0:3d9c67d97d6f | 160 | /* sum = x[0] * y[0] |
emh203 | 0:3d9c67d97d6f | 161 | * sum = x[0] * y[1] + x[1] * y[0] |
emh203 | 0:3d9c67d97d6f | 162 | * .... |
emh203 | 0:3d9c67d97d6f | 163 | * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] |
emh203 | 0:3d9c67d97d6f | 164 | */ |
emh203 | 0:3d9c67d97d6f | 165 | |
emh203 | 0:3d9c67d97d6f | 166 | /* In this stage the MAC operations are increased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 167 | The count variable holds the number of MAC operations performed. |
emh203 | 0:3d9c67d97d6f | 168 | Since the partial convolution starts from firstIndex |
emh203 | 0:3d9c67d97d6f | 169 | Number of Macs to be performed is firstIndex + 1 */ |
emh203 | 0:3d9c67d97d6f | 170 | count = 1u + firstIndex; |
emh203 | 0:3d9c67d97d6f | 171 | |
emh203 | 0:3d9c67d97d6f | 172 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 173 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 174 | |
emh203 | 0:3d9c67d97d6f | 175 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 176 | pSrc2 = pIn2 + firstIndex; |
emh203 | 0:3d9c67d97d6f | 177 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 178 | |
emh203 | 0:3d9c67d97d6f | 179 | /* ------------------------ |
emh203 | 0:3d9c67d97d6f | 180 | * Stage1 process |
emh203 | 0:3d9c67d97d6f | 181 | * ----------------------*/ |
emh203 | 0:3d9c67d97d6f | 182 | |
emh203 | 0:3d9c67d97d6f | 183 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 184 | /* First part of this stage computes the MAC operations less than 4 */ |
emh203 | 0:3d9c67d97d6f | 185 | /* Second part of this stage computes the MAC operations greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 186 | |
emh203 | 0:3d9c67d97d6f | 187 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 188 | while((count < 4u) && (blockSize1 > 0)) |
emh203 | 0:3d9c67d97d6f | 189 | { |
emh203 | 0:3d9c67d97d6f | 190 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 191 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | /* Loop over number of MAC operations between |
emh203 | 0:3d9c67d97d6f | 194 | * inputA samples and inputB samples */ |
emh203 | 0:3d9c67d97d6f | 195 | k = count; |
emh203 | 0:3d9c67d97d6f | 196 | |
emh203 | 0:3d9c67d97d6f | 197 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 198 | { |
emh203 | 0:3d9c67d97d6f | 199 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 200 | sum = __SMLALD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 201 | |
emh203 | 0:3d9c67d97d6f | 202 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 203 | k--; |
emh203 | 0:3d9c67d97d6f | 204 | } |
emh203 | 0:3d9c67d97d6f | 205 | |
emh203 | 0:3d9c67d97d6f | 206 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 207 | *pOut++ = (q15_t) (__SSAT((sum >> 15), 16)); |
emh203 | 0:3d9c67d97d6f | 208 | |
emh203 | 0:3d9c67d97d6f | 209 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 210 | py = ++pSrc2; |
emh203 | 0:3d9c67d97d6f | 211 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 212 | |
emh203 | 0:3d9c67d97d6f | 213 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 214 | count++; |
emh203 | 0:3d9c67d97d6f | 215 | |
emh203 | 0:3d9c67d97d6f | 216 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 217 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 218 | } |
emh203 | 0:3d9c67d97d6f | 219 | |
emh203 | 0:3d9c67d97d6f | 220 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 221 | /* The internal loop, over count, is unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 222 | /* To, read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 223 | * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 224 | py = py - 1; |
emh203 | 0:3d9c67d97d6f | 225 | |
emh203 | 0:3d9c67d97d6f | 226 | while(blockSize1 > 0) |
emh203 | 0:3d9c67d97d6f | 227 | { |
emh203 | 0:3d9c67d97d6f | 228 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 229 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 230 | |
emh203 | 0:3d9c67d97d6f | 231 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 232 | k = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 235 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 236 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 237 | { |
emh203 | 0:3d9c67d97d6f | 238 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 239 | /* x[0], x[1] are multiplied with y[srcBLen - 1], y[srcBLen - 2] respectively */ |
emh203 | 0:3d9c67d97d6f | 240 | sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 241 | /* x[2], x[3] are multiplied with y[srcBLen - 3], y[srcBLen - 4] respectively */ |
emh203 | 0:3d9c67d97d6f | 242 | sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 243 | |
emh203 | 0:3d9c67d97d6f | 244 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 245 | k--; |
emh203 | 0:3d9c67d97d6f | 246 | } |
emh203 | 0:3d9c67d97d6f | 247 | |
emh203 | 0:3d9c67d97d6f | 248 | /* For the next MAC operations, the pointer py is used without SIMD |
emh203 | 0:3d9c67d97d6f | 249 | * So, py is incremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 250 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 251 | |
emh203 | 0:3d9c67d97d6f | 252 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 253 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 254 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 255 | |
emh203 | 0:3d9c67d97d6f | 256 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 257 | { |
emh203 | 0:3d9c67d97d6f | 258 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 259 | sum = __SMLALD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 260 | |
emh203 | 0:3d9c67d97d6f | 261 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 262 | k--; |
emh203 | 0:3d9c67d97d6f | 263 | } |
emh203 | 0:3d9c67d97d6f | 264 | |
emh203 | 0:3d9c67d97d6f | 265 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 266 | *pOut++ = (q15_t) (__SSAT((sum >> 15), 16)); |
emh203 | 0:3d9c67d97d6f | 267 | |
emh203 | 0:3d9c67d97d6f | 268 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 269 | py = ++pSrc2 - 1u; |
emh203 | 0:3d9c67d97d6f | 270 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 271 | |
emh203 | 0:3d9c67d97d6f | 272 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 273 | count++; |
emh203 | 0:3d9c67d97d6f | 274 | |
emh203 | 0:3d9c67d97d6f | 275 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 276 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 277 | } |
emh203 | 0:3d9c67d97d6f | 278 | |
emh203 | 0:3d9c67d97d6f | 279 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 280 | * Initializations of stage2 |
emh203 | 0:3d9c67d97d6f | 281 | * ------------------------*/ |
emh203 | 0:3d9c67d97d6f | 282 | |
emh203 | 0:3d9c67d97d6f | 283 | /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 284 | * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] |
emh203 | 0:3d9c67d97d6f | 285 | * .... |
emh203 | 0:3d9c67d97d6f | 286 | * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 287 | */ |
emh203 | 0:3d9c67d97d6f | 288 | |
emh203 | 0:3d9c67d97d6f | 289 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 290 | if((int32_t)firstIndex - (int32_t)srcBLen + 1 > 0) |
emh203 | 0:3d9c67d97d6f | 291 | { |
emh203 | 0:3d9c67d97d6f | 292 | px = pIn1 + firstIndex - srcBLen + 1; |
emh203 | 0:3d9c67d97d6f | 293 | } |
emh203 | 0:3d9c67d97d6f | 294 | else |
emh203 | 0:3d9c67d97d6f | 295 | { |
emh203 | 0:3d9c67d97d6f | 296 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 297 | } |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 300 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 301 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 302 | |
emh203 | 0:3d9c67d97d6f | 303 | /* count is the index by which the pointer pIn1 to be incremented */ |
emh203 | 0:3d9c67d97d6f | 304 | count = 0u; |
emh203 | 0:3d9c67d97d6f | 305 | |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | /* -------------------- |
emh203 | 0:3d9c67d97d6f | 308 | * Stage2 process |
emh203 | 0:3d9c67d97d6f | 309 | * -------------------*/ |
emh203 | 0:3d9c67d97d6f | 310 | |
emh203 | 0:3d9c67d97d6f | 311 | /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. |
emh203 | 0:3d9c67d97d6f | 312 | * So, to loop unroll over blockSize2, |
emh203 | 0:3d9c67d97d6f | 313 | * srcBLen should be greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 314 | if(srcBLen >= 4u) |
emh203 | 0:3d9c67d97d6f | 315 | { |
emh203 | 0:3d9c67d97d6f | 316 | /* Loop unroll over blockSize2, by 4 */ |
emh203 | 0:3d9c67d97d6f | 317 | blkCnt = blockSize2 >> 2u; |
emh203 | 0:3d9c67d97d6f | 318 | |
emh203 | 0:3d9c67d97d6f | 319 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 320 | { |
emh203 | 0:3d9c67d97d6f | 321 | py = py - 1u; |
emh203 | 0:3d9c67d97d6f | 322 | |
emh203 | 0:3d9c67d97d6f | 323 | /* Set all accumulators to zero */ |
emh203 | 0:3d9c67d97d6f | 324 | acc0 = 0; |
emh203 | 0:3d9c67d97d6f | 325 | acc1 = 0; |
emh203 | 0:3d9c67d97d6f | 326 | acc2 = 0; |
emh203 | 0:3d9c67d97d6f | 327 | acc3 = 0; |
emh203 | 0:3d9c67d97d6f | 328 | |
emh203 | 0:3d9c67d97d6f | 329 | |
emh203 | 0:3d9c67d97d6f | 330 | /* read x[0], x[1] samples */ |
emh203 | 0:3d9c67d97d6f | 331 | x0 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 332 | /* read x[1], x[2] samples */ |
emh203 | 0:3d9c67d97d6f | 333 | x1 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 334 | px+= 2u; |
emh203 | 0:3d9c67d97d6f | 335 | |
emh203 | 0:3d9c67d97d6f | 336 | |
emh203 | 0:3d9c67d97d6f | 337 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 338 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 339 | |
emh203 | 0:3d9c67d97d6f | 340 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 341 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 342 | do |
emh203 | 0:3d9c67d97d6f | 343 | { |
emh203 | 0:3d9c67d97d6f | 344 | /* Read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 345 | * y[srcBLen - 1] and y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 346 | c0 = *__SIMD32(py)--; |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 349 | acc0 = __SMLALDX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 350 | |
emh203 | 0:3d9c67d97d6f | 351 | /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 352 | acc1 = __SMLALDX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 353 | |
emh203 | 0:3d9c67d97d6f | 354 | /* Read x[2], x[3] */ |
emh203 | 0:3d9c67d97d6f | 355 | x2 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 356 | |
emh203 | 0:3d9c67d97d6f | 357 | /* Read x[3], x[4] */ |
emh203 | 0:3d9c67d97d6f | 358 | x3 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 359 | |
emh203 | 0:3d9c67d97d6f | 360 | /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 361 | acc2 = __SMLALDX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 362 | |
emh203 | 0:3d9c67d97d6f | 363 | /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 364 | acc3 = __SMLALDX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 365 | |
emh203 | 0:3d9c67d97d6f | 366 | /* Read y[srcBLen - 3] and y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 367 | c0 = *__SIMD32(py)--; |
emh203 | 0:3d9c67d97d6f | 368 | |
emh203 | 0:3d9c67d97d6f | 369 | /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 370 | acc0 = __SMLALDX(x2, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 371 | |
emh203 | 0:3d9c67d97d6f | 372 | /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 373 | acc1 = __SMLALDX(x3, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 374 | |
emh203 | 0:3d9c67d97d6f | 375 | /* Read x[4], x[5] */ |
emh203 | 0:3d9c67d97d6f | 376 | x0 = _SIMD32_OFFSET(px+2); |
emh203 | 0:3d9c67d97d6f | 377 | |
emh203 | 0:3d9c67d97d6f | 378 | /* Read x[5], x[6] */ |
emh203 | 0:3d9c67d97d6f | 379 | x1 = _SIMD32_OFFSET(px+3); |
emh203 | 0:3d9c67d97d6f | 380 | px += 4u; |
emh203 | 0:3d9c67d97d6f | 381 | |
emh203 | 0:3d9c67d97d6f | 382 | /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 383 | acc2 = __SMLALDX(x0, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 384 | |
emh203 | 0:3d9c67d97d6f | 385 | /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 386 | acc3 = __SMLALDX(x1, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 387 | |
emh203 | 0:3d9c67d97d6f | 388 | } while(--k); |
emh203 | 0:3d9c67d97d6f | 389 | |
emh203 | 0:3d9c67d97d6f | 390 | /* For the next MAC operations, SIMD is not used |
emh203 | 0:3d9c67d97d6f | 391 | * So, the 16 bit pointer if inputB, py is updated */ |
emh203 | 0:3d9c67d97d6f | 392 | |
emh203 | 0:3d9c67d97d6f | 393 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 394 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 395 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 396 | |
emh203 | 0:3d9c67d97d6f | 397 | if(k == 1u) |
emh203 | 0:3d9c67d97d6f | 398 | { |
emh203 | 0:3d9c67d97d6f | 399 | /* Read y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 400 | c0 = *(py+1); |
emh203 | 0:3d9c67d97d6f | 401 | |
emh203 | 0:3d9c67d97d6f | 402 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 403 | |
emh203 | 0:3d9c67d97d6f | 404 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 405 | |
emh203 | 0:3d9c67d97d6f | 406 | #else |
emh203 | 0:3d9c67d97d6f | 407 | |
emh203 | 0:3d9c67d97d6f | 408 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 409 | |
emh203 | 0:3d9c67d97d6f | 410 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 411 | |
emh203 | 0:3d9c67d97d6f | 412 | /* Read x[7] */ |
emh203 | 0:3d9c67d97d6f | 413 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 414 | px++; |
emh203 | 0:3d9c67d97d6f | 415 | |
emh203 | 0:3d9c67d97d6f | 416 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 417 | acc0 = __SMLALD(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 418 | acc1 = __SMLALD(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 419 | acc2 = __SMLALDX(x1, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 420 | acc3 = __SMLALDX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 421 | } |
emh203 | 0:3d9c67d97d6f | 422 | |
emh203 | 0:3d9c67d97d6f | 423 | if(k == 2u) |
emh203 | 0:3d9c67d97d6f | 424 | { |
emh203 | 0:3d9c67d97d6f | 425 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 426 | c0 = _SIMD32_OFFSET(py); |
emh203 | 0:3d9c67d97d6f | 427 | |
emh203 | 0:3d9c67d97d6f | 428 | /* Read x[7], x[8] */ |
emh203 | 0:3d9c67d97d6f | 429 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 430 | |
emh203 | 0:3d9c67d97d6f | 431 | /* Read x[9] */ |
emh203 | 0:3d9c67d97d6f | 432 | x2 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 433 | px += 2u; |
emh203 | 0:3d9c67d97d6f | 434 | |
emh203 | 0:3d9c67d97d6f | 435 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 436 | acc0 = __SMLALDX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 437 | acc1 = __SMLALDX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 438 | acc2 = __SMLALDX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 439 | acc3 = __SMLALDX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 440 | } |
emh203 | 0:3d9c67d97d6f | 441 | |
emh203 | 0:3d9c67d97d6f | 442 | if(k == 3u) |
emh203 | 0:3d9c67d97d6f | 443 | { |
emh203 | 0:3d9c67d97d6f | 444 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 445 | c0 = _SIMD32_OFFSET(py); |
emh203 | 0:3d9c67d97d6f | 446 | |
emh203 | 0:3d9c67d97d6f | 447 | /* Read x[7], x[8] */ |
emh203 | 0:3d9c67d97d6f | 448 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 449 | |
emh203 | 0:3d9c67d97d6f | 450 | /* Read x[9] */ |
emh203 | 0:3d9c67d97d6f | 451 | x2 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 452 | |
emh203 | 0:3d9c67d97d6f | 453 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 454 | acc0 = __SMLALDX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 455 | acc1 = __SMLALDX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 456 | acc2 = __SMLALDX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 457 | acc3 = __SMLALDX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 458 | |
emh203 | 0:3d9c67d97d6f | 459 | c0 = *(py-1); |
emh203 | 0:3d9c67d97d6f | 460 | |
emh203 | 0:3d9c67d97d6f | 461 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 462 | |
emh203 | 0:3d9c67d97d6f | 463 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 464 | #else |
emh203 | 0:3d9c67d97d6f | 465 | |
emh203 | 0:3d9c67d97d6f | 466 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 467 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 468 | |
emh203 | 0:3d9c67d97d6f | 469 | /* Read x[10] */ |
emh203 | 0:3d9c67d97d6f | 470 | x3 = _SIMD32_OFFSET(px+2); |
emh203 | 0:3d9c67d97d6f | 471 | px += 3u; |
emh203 | 0:3d9c67d97d6f | 472 | |
emh203 | 0:3d9c67d97d6f | 473 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 474 | acc0 = __SMLALDX(x1, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 475 | acc1 = __SMLALD(x2, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 476 | acc2 = __SMLALDX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 477 | acc3 = __SMLALDX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 478 | } |
emh203 | 0:3d9c67d97d6f | 479 | |
emh203 | 0:3d9c67d97d6f | 480 | |
emh203 | 0:3d9c67d97d6f | 481 | /* Store the results in the accumulators in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 482 | |
emh203 | 0:3d9c67d97d6f | 483 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 484 | |
emh203 | 0:3d9c67d97d6f | 485 | *__SIMD32(pOut)++ = |
emh203 | 0:3d9c67d97d6f | 486 | __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16); |
emh203 | 0:3d9c67d97d6f | 487 | *__SIMD32(pOut)++ = |
emh203 | 0:3d9c67d97d6f | 488 | __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16); |
emh203 | 0:3d9c67d97d6f | 489 | |
emh203 | 0:3d9c67d97d6f | 490 | #else |
emh203 | 0:3d9c67d97d6f | 491 | |
emh203 | 0:3d9c67d97d6f | 492 | *__SIMD32(pOut)++ = |
emh203 | 0:3d9c67d97d6f | 493 | __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16); |
emh203 | 0:3d9c67d97d6f | 494 | *__SIMD32(pOut)++ = |
emh203 | 0:3d9c67d97d6f | 495 | __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16); |
emh203 | 0:3d9c67d97d6f | 496 | |
emh203 | 0:3d9c67d97d6f | 497 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 498 | |
emh203 | 0:3d9c67d97d6f | 499 | /* Increment the pointer pIn1 index, count by 4 */ |
emh203 | 0:3d9c67d97d6f | 500 | count += 4u; |
emh203 | 0:3d9c67d97d6f | 501 | |
emh203 | 0:3d9c67d97d6f | 502 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 503 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 504 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 505 | |
emh203 | 0:3d9c67d97d6f | 506 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 507 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 508 | } |
emh203 | 0:3d9c67d97d6f | 509 | |
emh203 | 0:3d9c67d97d6f | 510 | /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 511 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 512 | blkCnt = (uint32_t) blockSize2 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 513 | |
emh203 | 0:3d9c67d97d6f | 514 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 515 | { |
emh203 | 0:3d9c67d97d6f | 516 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 517 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 518 | |
emh203 | 0:3d9c67d97d6f | 519 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 520 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 521 | |
emh203 | 0:3d9c67d97d6f | 522 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 523 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 524 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 525 | { |
emh203 | 0:3d9c67d97d6f | 526 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 527 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 528 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 529 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 530 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 531 | |
emh203 | 0:3d9c67d97d6f | 532 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 533 | k--; |
emh203 | 0:3d9c67d97d6f | 534 | } |
emh203 | 0:3d9c67d97d6f | 535 | |
emh203 | 0:3d9c67d97d6f | 536 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 537 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 538 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 539 | |
emh203 | 0:3d9c67d97d6f | 540 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 541 | { |
emh203 | 0:3d9c67d97d6f | 542 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 543 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 544 | |
emh203 | 0:3d9c67d97d6f | 545 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 546 | k--; |
emh203 | 0:3d9c67d97d6f | 547 | } |
emh203 | 0:3d9c67d97d6f | 548 | |
emh203 | 0:3d9c67d97d6f | 549 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 550 | *pOut++ = (q15_t) (__SSAT(sum >> 15, 16)); |
emh203 | 0:3d9c67d97d6f | 551 | |
emh203 | 0:3d9c67d97d6f | 552 | /* Increment the pointer pIn1 index, count by 1 */ |
emh203 | 0:3d9c67d97d6f | 553 | count++; |
emh203 | 0:3d9c67d97d6f | 554 | |
emh203 | 0:3d9c67d97d6f | 555 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 556 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 557 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 558 | |
emh203 | 0:3d9c67d97d6f | 559 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 560 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 561 | } |
emh203 | 0:3d9c67d97d6f | 562 | } |
emh203 | 0:3d9c67d97d6f | 563 | else |
emh203 | 0:3d9c67d97d6f | 564 | { |
emh203 | 0:3d9c67d97d6f | 565 | /* If the srcBLen is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 566 | * the blockSize2 loop cannot be unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 567 | blkCnt = (uint32_t) blockSize2; |
emh203 | 0:3d9c67d97d6f | 568 | |
emh203 | 0:3d9c67d97d6f | 569 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 570 | { |
emh203 | 0:3d9c67d97d6f | 571 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 572 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 573 | |
emh203 | 0:3d9c67d97d6f | 574 | /* srcBLen number of MACS should be performed */ |
emh203 | 0:3d9c67d97d6f | 575 | k = srcBLen; |
emh203 | 0:3d9c67d97d6f | 576 | |
emh203 | 0:3d9c67d97d6f | 577 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 578 | { |
emh203 | 0:3d9c67d97d6f | 579 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 580 | sum += (q63_t) ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 581 | |
emh203 | 0:3d9c67d97d6f | 582 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 583 | k--; |
emh203 | 0:3d9c67d97d6f | 584 | } |
emh203 | 0:3d9c67d97d6f | 585 | |
emh203 | 0:3d9c67d97d6f | 586 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 587 | *pOut++ = (q15_t) (__SSAT(sum >> 15, 16)); |
emh203 | 0:3d9c67d97d6f | 588 | |
emh203 | 0:3d9c67d97d6f | 589 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 590 | count++; |
emh203 | 0:3d9c67d97d6f | 591 | |
emh203 | 0:3d9c67d97d6f | 592 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 593 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 594 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 595 | |
emh203 | 0:3d9c67d97d6f | 596 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 597 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 598 | } |
emh203 | 0:3d9c67d97d6f | 599 | } |
emh203 | 0:3d9c67d97d6f | 600 | |
emh203 | 0:3d9c67d97d6f | 601 | |
emh203 | 0:3d9c67d97d6f | 602 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 603 | * Initializations of stage3 |
emh203 | 0:3d9c67d97d6f | 604 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 605 | |
emh203 | 0:3d9c67d97d6f | 606 | /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] |
emh203 | 0:3d9c67d97d6f | 607 | * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] |
emh203 | 0:3d9c67d97d6f | 608 | * .... |
emh203 | 0:3d9c67d97d6f | 609 | * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] |
emh203 | 0:3d9c67d97d6f | 610 | * sum += x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 611 | */ |
emh203 | 0:3d9c67d97d6f | 612 | |
emh203 | 0:3d9c67d97d6f | 613 | /* In this stage the MAC operations are decreased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 614 | The count variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 615 | count = srcBLen - 1u; |
emh203 | 0:3d9c67d97d6f | 616 | |
emh203 | 0:3d9c67d97d6f | 617 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 618 | pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 619 | px = pSrc1; |
emh203 | 0:3d9c67d97d6f | 620 | |
emh203 | 0:3d9c67d97d6f | 621 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 622 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 623 | pIn2 = pSrc2 - 1u; |
emh203 | 0:3d9c67d97d6f | 624 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 625 | |
emh203 | 0:3d9c67d97d6f | 626 | /* ------------------- |
emh203 | 0:3d9c67d97d6f | 627 | * Stage3 process |
emh203 | 0:3d9c67d97d6f | 628 | * ------------------*/ |
emh203 | 0:3d9c67d97d6f | 629 | |
emh203 | 0:3d9c67d97d6f | 630 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 631 | /* First part of this stage computes the MAC operations greater than 4 */ |
emh203 | 0:3d9c67d97d6f | 632 | /* Second part of this stage computes the MAC operations less than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 633 | |
emh203 | 0:3d9c67d97d6f | 634 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 635 | j = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 636 | |
emh203 | 0:3d9c67d97d6f | 637 | while((j > 0u) && (blockSize3 > 0)) |
emh203 | 0:3d9c67d97d6f | 638 | { |
emh203 | 0:3d9c67d97d6f | 639 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 640 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 641 | |
emh203 | 0:3d9c67d97d6f | 642 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 643 | k = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 644 | |
emh203 | 0:3d9c67d97d6f | 645 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 646 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 647 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 648 | { |
emh203 | 0:3d9c67d97d6f | 649 | /* x[srcALen - srcBLen + 1], x[srcALen - srcBLen + 2] are multiplied |
emh203 | 0:3d9c67d97d6f | 650 | * with y[srcBLen - 1], y[srcBLen - 2] respectively */ |
emh203 | 0:3d9c67d97d6f | 651 | sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 652 | /* x[srcALen - srcBLen + 3], x[srcALen - srcBLen + 4] are multiplied |
emh203 | 0:3d9c67d97d6f | 653 | * with y[srcBLen - 3], y[srcBLen - 4] respectively */ |
emh203 | 0:3d9c67d97d6f | 654 | sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 655 | |
emh203 | 0:3d9c67d97d6f | 656 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 657 | k--; |
emh203 | 0:3d9c67d97d6f | 658 | } |
emh203 | 0:3d9c67d97d6f | 659 | |
emh203 | 0:3d9c67d97d6f | 660 | /* For the next MAC operations, the pointer py is used without SIMD |
emh203 | 0:3d9c67d97d6f | 661 | * So, py is incremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 662 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 663 | |
emh203 | 0:3d9c67d97d6f | 664 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 665 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 666 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 667 | |
emh203 | 0:3d9c67d97d6f | 668 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 669 | { |
emh203 | 0:3d9c67d97d6f | 670 | /* sum += x[srcALen - srcBLen + 5] * y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 671 | sum = __SMLALD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 672 | |
emh203 | 0:3d9c67d97d6f | 673 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 674 | k--; |
emh203 | 0:3d9c67d97d6f | 675 | } |
emh203 | 0:3d9c67d97d6f | 676 | |
emh203 | 0:3d9c67d97d6f | 677 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 678 | *pOut++ = (q15_t) (__SSAT((sum >> 15), 16)); |
emh203 | 0:3d9c67d97d6f | 679 | |
emh203 | 0:3d9c67d97d6f | 680 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 681 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 682 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 683 | |
emh203 | 0:3d9c67d97d6f | 684 | /* Decrement the MAC count */ |
emh203 | 0:3d9c67d97d6f | 685 | count--; |
emh203 | 0:3d9c67d97d6f | 686 | |
emh203 | 0:3d9c67d97d6f | 687 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 688 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 689 | |
emh203 | 0:3d9c67d97d6f | 690 | j--; |
emh203 | 0:3d9c67d97d6f | 691 | } |
emh203 | 0:3d9c67d97d6f | 692 | |
emh203 | 0:3d9c67d97d6f | 693 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 694 | /* SIMD is not used for the next MAC operations, |
emh203 | 0:3d9c67d97d6f | 695 | * so pointer py is updated to read only one sample at a time */ |
emh203 | 0:3d9c67d97d6f | 696 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 697 | |
emh203 | 0:3d9c67d97d6f | 698 | while(blockSize3 > 0) |
emh203 | 0:3d9c67d97d6f | 699 | { |
emh203 | 0:3d9c67d97d6f | 700 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 701 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 702 | |
emh203 | 0:3d9c67d97d6f | 703 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 704 | k = count; |
emh203 | 0:3d9c67d97d6f | 705 | |
emh203 | 0:3d9c67d97d6f | 706 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 707 | { |
emh203 | 0:3d9c67d97d6f | 708 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 709 | /* sum += x[srcALen-1] * y[srcBLen-1] */ |
emh203 | 0:3d9c67d97d6f | 710 | sum = __SMLALD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 711 | |
emh203 | 0:3d9c67d97d6f | 712 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 713 | k--; |
emh203 | 0:3d9c67d97d6f | 714 | } |
emh203 | 0:3d9c67d97d6f | 715 | |
emh203 | 0:3d9c67d97d6f | 716 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 717 | *pOut++ = (q15_t) (__SSAT((sum >> 15), 16)); |
emh203 | 0:3d9c67d97d6f | 718 | |
emh203 | 0:3d9c67d97d6f | 719 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 720 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 721 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 722 | |
emh203 | 0:3d9c67d97d6f | 723 | /* Decrement the MAC count */ |
emh203 | 0:3d9c67d97d6f | 724 | count--; |
emh203 | 0:3d9c67d97d6f | 725 | |
emh203 | 0:3d9c67d97d6f | 726 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 727 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 728 | } |
emh203 | 0:3d9c67d97d6f | 729 | |
emh203 | 0:3d9c67d97d6f | 730 | /* set status as ARM_MATH_SUCCESS */ |
emh203 | 0:3d9c67d97d6f | 731 | status = ARM_MATH_SUCCESS; |
emh203 | 0:3d9c67d97d6f | 732 | } |
emh203 | 0:3d9c67d97d6f | 733 | |
emh203 | 0:3d9c67d97d6f | 734 | /* Return to application */ |
emh203 | 0:3d9c67d97d6f | 735 | return (status); |
emh203 | 0:3d9c67d97d6f | 736 | |
emh203 | 0:3d9c67d97d6f | 737 | #else |
emh203 | 0:3d9c67d97d6f | 738 | |
emh203 | 0:3d9c67d97d6f | 739 | /* Run the below code for Cortex-M0 */ |
emh203 | 0:3d9c67d97d6f | 740 | |
emh203 | 0:3d9c67d97d6f | 741 | q15_t *pIn1 = pSrcA; /* inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 742 | q15_t *pIn2 = pSrcB; /* inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 743 | q63_t sum; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 744 | uint32_t i, j; /* loop counters */ |
emh203 | 0:3d9c67d97d6f | 745 | arm_status status; /* status of Partial convolution */ |
emh203 | 0:3d9c67d97d6f | 746 | |
emh203 | 0:3d9c67d97d6f | 747 | /* Check for range of output samples to be calculated */ |
emh203 | 0:3d9c67d97d6f | 748 | if((firstIndex + numPoints) > ((srcALen + (srcBLen - 1u)))) |
emh203 | 0:3d9c67d97d6f | 749 | { |
emh203 | 0:3d9c67d97d6f | 750 | /* Set status as ARM_ARGUMENT_ERROR */ |
emh203 | 0:3d9c67d97d6f | 751 | status = ARM_MATH_ARGUMENT_ERROR; |
emh203 | 0:3d9c67d97d6f | 752 | } |
emh203 | 0:3d9c67d97d6f | 753 | else |
emh203 | 0:3d9c67d97d6f | 754 | { |
emh203 | 0:3d9c67d97d6f | 755 | /* Loop to calculate convolution for output length number of values */ |
emh203 | 0:3d9c67d97d6f | 756 | for (i = firstIndex; i <= (firstIndex + numPoints - 1); i++) |
emh203 | 0:3d9c67d97d6f | 757 | { |
emh203 | 0:3d9c67d97d6f | 758 | /* Initialize sum with zero to carry on MAC operations */ |
emh203 | 0:3d9c67d97d6f | 759 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 760 | |
emh203 | 0:3d9c67d97d6f | 761 | /* Loop to perform MAC operations according to convolution equation */ |
emh203 | 0:3d9c67d97d6f | 762 | for (j = 0; j <= i; j++) |
emh203 | 0:3d9c67d97d6f | 763 | { |
emh203 | 0:3d9c67d97d6f | 764 | /* Check the array limitations */ |
emh203 | 0:3d9c67d97d6f | 765 | if(((i - j) < srcBLen) && (j < srcALen)) |
emh203 | 0:3d9c67d97d6f | 766 | { |
emh203 | 0:3d9c67d97d6f | 767 | /* z[i] += x[i-j] * y[j] */ |
emh203 | 0:3d9c67d97d6f | 768 | sum += ((q31_t) pIn1[j] * (pIn2[i - j])); |
emh203 | 0:3d9c67d97d6f | 769 | } |
emh203 | 0:3d9c67d97d6f | 770 | } |
emh203 | 0:3d9c67d97d6f | 771 | |
emh203 | 0:3d9c67d97d6f | 772 | /* Store the output in the destination buffer */ |
emh203 | 0:3d9c67d97d6f | 773 | pDst[i] = (q15_t) __SSAT((sum >> 15u), 16u); |
emh203 | 0:3d9c67d97d6f | 774 | } |
emh203 | 0:3d9c67d97d6f | 775 | /* set status as ARM_SUCCESS as there are no argument errors */ |
emh203 | 0:3d9c67d97d6f | 776 | status = ARM_MATH_SUCCESS; |
emh203 | 0:3d9c67d97d6f | 777 | } |
emh203 | 0:3d9c67d97d6f | 778 | return (status); |
emh203 | 0:3d9c67d97d6f | 779 | |
emh203 | 0:3d9c67d97d6f | 780 | #endif /* #if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE) */ |
emh203 | 0:3d9c67d97d6f | 781 | |
emh203 | 0:3d9c67d97d6f | 782 | } |
emh203 | 0:3d9c67d97d6f | 783 | |
emh203 | 0:3d9c67d97d6f | 784 | /** |
emh203 | 0:3d9c67d97d6f | 785 | * @} end of PartialConv group |
emh203 | 0:3d9c67d97d6f | 786 | */ |