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_fast_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_fast_q15.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Fast Q15 Convolution. |
emh203 | 0:3d9c67d97d6f | 11 | * |
emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3 |
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 Conv |
emh203 | 0:3d9c67d97d6f | 49 | * @{ |
emh203 | 0:3d9c67d97d6f | 50 | */ |
emh203 | 0:3d9c67d97d6f | 51 | |
emh203 | 0:3d9c67d97d6f | 52 | /** |
emh203 | 0:3d9c67d97d6f | 53 | * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4. |
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. Length srcALen+srcBLen-1. |
emh203 | 0:3d9c67d97d6f | 59 | * @return none. |
emh203 | 0:3d9c67d97d6f | 60 | * |
emh203 | 0:3d9c67d97d6f | 61 | * <b>Scaling and Overflow Behavior:</b> |
emh203 | 0:3d9c67d97d6f | 62 | * |
emh203 | 0:3d9c67d97d6f | 63 | * \par |
emh203 | 0:3d9c67d97d6f | 64 | * This fast version uses a 32-bit accumulator with 2.30 format. |
emh203 | 0:3d9c67d97d6f | 65 | * The accumulator maintains full precision of the intermediate multiplication results |
emh203 | 0:3d9c67d97d6f | 66 | * but provides only a single guard bit. There is no saturation on intermediate additions. |
emh203 | 0:3d9c67d97d6f | 67 | * Thus, if the accumulator overflows it wraps around and distorts the result. |
emh203 | 0:3d9c67d97d6f | 68 | * The input signals should be scaled down to avoid intermediate overflows. |
emh203 | 0:3d9c67d97d6f | 69 | * Scale down the inputs by log2(min(srcALen, srcBLen)) (log2 is read as log to the base 2) times to avoid overflows, |
emh203 | 0:3d9c67d97d6f | 70 | * as maximum of min(srcALen, srcBLen) number of additions are carried internally. |
emh203 | 0:3d9c67d97d6f | 71 | * The 2.30 accumulator is right shifted by 15 bits and then saturated to 1.15 format to yield the final result. |
emh203 | 0:3d9c67d97d6f | 72 | * |
emh203 | 0:3d9c67d97d6f | 73 | * \par |
emh203 | 0:3d9c67d97d6f | 74 | * See <code>arm_conv_q15()</code> for a slower implementation of this function which uses 64-bit accumulation to avoid wrap around distortion. |
emh203 | 0:3d9c67d97d6f | 75 | */ |
emh203 | 0:3d9c67d97d6f | 76 | |
emh203 | 0:3d9c67d97d6f | 77 | void arm_conv_fast_q15( |
emh203 | 0:3d9c67d97d6f | 78 | q15_t * pSrcA, |
emh203 | 0:3d9c67d97d6f | 79 | uint32_t srcALen, |
emh203 | 0:3d9c67d97d6f | 80 | q15_t * pSrcB, |
emh203 | 0:3d9c67d97d6f | 81 | uint32_t srcBLen, |
emh203 | 0:3d9c67d97d6f | 82 | q15_t * pDst) |
emh203 | 0:3d9c67d97d6f | 83 | { |
emh203 | 0:3d9c67d97d6f | 84 | #ifndef UNALIGNED_SUPPORT_DISABLE |
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 | q31_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 variables to hold state and coefficient values */ |
emh203 | 0:3d9c67d97d6f | 93 | uint32_t blockSize1, blockSize2, blockSize3, j, k, count, blkCnt; /* loop counter */ |
emh203 | 0:3d9c67d97d6f | 94 | |
emh203 | 0:3d9c67d97d6f | 95 | /* The algorithm implementation is based on the lengths of the inputs. */ |
emh203 | 0:3d9c67d97d6f | 96 | /* srcB is always made to slide across srcA. */ |
emh203 | 0:3d9c67d97d6f | 97 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 98 | if(srcALen >= srcBLen) |
emh203 | 0:3d9c67d97d6f | 99 | { |
emh203 | 0:3d9c67d97d6f | 100 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 101 | pIn1 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 102 | |
emh203 | 0:3d9c67d97d6f | 103 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 104 | pIn2 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 105 | } |
emh203 | 0:3d9c67d97d6f | 106 | else |
emh203 | 0:3d9c67d97d6f | 107 | { |
emh203 | 0:3d9c67d97d6f | 108 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 109 | pIn1 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 110 | |
emh203 | 0:3d9c67d97d6f | 111 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 112 | pIn2 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 113 | |
emh203 | 0:3d9c67d97d6f | 114 | /* srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 115 | j = srcBLen; |
emh203 | 0:3d9c67d97d6f | 116 | srcBLen = srcALen; |
emh203 | 0:3d9c67d97d6f | 117 | srcALen = j; |
emh203 | 0:3d9c67d97d6f | 118 | } |
emh203 | 0:3d9c67d97d6f | 119 | |
emh203 | 0:3d9c67d97d6f | 120 | /* 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 | 121 | /* The function is internally |
emh203 | 0:3d9c67d97d6f | 122 | * divided into three stages according to the number of multiplications that has to be |
emh203 | 0:3d9c67d97d6f | 123 | * taken place between inputA samples and inputB samples. In the first stage of the |
emh203 | 0:3d9c67d97d6f | 124 | * algorithm, the multiplications increase by one for every iteration. |
emh203 | 0:3d9c67d97d6f | 125 | * In the second stage of the algorithm, srcBLen number of multiplications are done. |
emh203 | 0:3d9c67d97d6f | 126 | * In the third stage of the algorithm, the multiplications decrease by one |
emh203 | 0:3d9c67d97d6f | 127 | * for every iteration. */ |
emh203 | 0:3d9c67d97d6f | 128 | |
emh203 | 0:3d9c67d97d6f | 129 | /* The algorithm is implemented in three stages. |
emh203 | 0:3d9c67d97d6f | 130 | The loop counters of each stage is initiated here. */ |
emh203 | 0:3d9c67d97d6f | 131 | blockSize1 = srcBLen - 1u; |
emh203 | 0:3d9c67d97d6f | 132 | blockSize2 = srcALen - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 133 | blockSize3 = blockSize1; |
emh203 | 0:3d9c67d97d6f | 134 | |
emh203 | 0:3d9c67d97d6f | 135 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 136 | * Initializations of stage1 |
emh203 | 0:3d9c67d97d6f | 137 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 138 | |
emh203 | 0:3d9c67d97d6f | 139 | /* sum = x[0] * y[0] |
emh203 | 0:3d9c67d97d6f | 140 | * sum = x[0] * y[1] + x[1] * y[0] |
emh203 | 0:3d9c67d97d6f | 141 | * .... |
emh203 | 0:3d9c67d97d6f | 142 | * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] |
emh203 | 0:3d9c67d97d6f | 143 | */ |
emh203 | 0:3d9c67d97d6f | 144 | |
emh203 | 0:3d9c67d97d6f | 145 | /* In this stage the MAC operations are increased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 146 | The count variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 147 | count = 1u; |
emh203 | 0:3d9c67d97d6f | 148 | |
emh203 | 0:3d9c67d97d6f | 149 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 150 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 151 | |
emh203 | 0:3d9c67d97d6f | 152 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 153 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 154 | |
emh203 | 0:3d9c67d97d6f | 155 | |
emh203 | 0:3d9c67d97d6f | 156 | /* ------------------------ |
emh203 | 0:3d9c67d97d6f | 157 | * Stage1 process |
emh203 | 0:3d9c67d97d6f | 158 | * ----------------------*/ |
emh203 | 0:3d9c67d97d6f | 159 | |
emh203 | 0:3d9c67d97d6f | 160 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 161 | /* First part of this stage computes the MAC operations less than 4 */ |
emh203 | 0:3d9c67d97d6f | 162 | /* Second part of this stage computes the MAC operations greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 163 | |
emh203 | 0:3d9c67d97d6f | 164 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 165 | while((count < 4u) && (blockSize1 > 0u)) |
emh203 | 0:3d9c67d97d6f | 166 | { |
emh203 | 0:3d9c67d97d6f | 167 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 168 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 169 | |
emh203 | 0:3d9c67d97d6f | 170 | /* Loop over number of MAC operations between |
emh203 | 0:3d9c67d97d6f | 171 | * inputA samples and inputB samples */ |
emh203 | 0:3d9c67d97d6f | 172 | k = count; |
emh203 | 0:3d9c67d97d6f | 173 | |
emh203 | 0:3d9c67d97d6f | 174 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 175 | { |
emh203 | 0:3d9c67d97d6f | 176 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 177 | sum = __SMLAD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 178 | |
emh203 | 0:3d9c67d97d6f | 179 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 180 | k--; |
emh203 | 0:3d9c67d97d6f | 181 | } |
emh203 | 0:3d9c67d97d6f | 182 | |
emh203 | 0:3d9c67d97d6f | 183 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 184 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 185 | |
emh203 | 0:3d9c67d97d6f | 186 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 187 | py = pIn2 + count; |
emh203 | 0:3d9c67d97d6f | 188 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 191 | count++; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 194 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 195 | } |
emh203 | 0:3d9c67d97d6f | 196 | |
emh203 | 0:3d9c67d97d6f | 197 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 198 | /* The internal loop, over count, is unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 199 | /* To, read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 200 | * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 201 | py = py - 1; |
emh203 | 0:3d9c67d97d6f | 202 | |
emh203 | 0:3d9c67d97d6f | 203 | while(blockSize1 > 0u) |
emh203 | 0:3d9c67d97d6f | 204 | { |
emh203 | 0:3d9c67d97d6f | 205 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 206 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 207 | |
emh203 | 0:3d9c67d97d6f | 208 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 209 | k = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 210 | |
emh203 | 0:3d9c67d97d6f | 211 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 212 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 213 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 214 | { |
emh203 | 0:3d9c67d97d6f | 215 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 216 | /* x[0], x[1] are multiplied with y[srcBLen - 1], y[srcBLen - 2] respectively */ |
emh203 | 0:3d9c67d97d6f | 217 | sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 218 | /* x[2], x[3] are multiplied with y[srcBLen - 3], y[srcBLen - 4] respectively */ |
emh203 | 0:3d9c67d97d6f | 219 | sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 220 | |
emh203 | 0:3d9c67d97d6f | 221 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 222 | k--; |
emh203 | 0:3d9c67d97d6f | 223 | } |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* For the next MAC operations, the pointer py is used without SIMD |
emh203 | 0:3d9c67d97d6f | 226 | * So, py is incremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 227 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 228 | |
emh203 | 0:3d9c67d97d6f | 229 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 230 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 231 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 232 | |
emh203 | 0:3d9c67d97d6f | 233 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 234 | { |
emh203 | 0:3d9c67d97d6f | 235 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 236 | sum = __SMLAD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 237 | |
emh203 | 0:3d9c67d97d6f | 238 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 239 | k--; |
emh203 | 0:3d9c67d97d6f | 240 | } |
emh203 | 0:3d9c67d97d6f | 241 | |
emh203 | 0:3d9c67d97d6f | 242 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 243 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 246 | py = pIn2 + (count - 1u); |
emh203 | 0:3d9c67d97d6f | 247 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 248 | |
emh203 | 0:3d9c67d97d6f | 249 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 250 | count++; |
emh203 | 0:3d9c67d97d6f | 251 | |
emh203 | 0:3d9c67d97d6f | 252 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 253 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 254 | } |
emh203 | 0:3d9c67d97d6f | 255 | |
emh203 | 0:3d9c67d97d6f | 256 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 257 | * Initializations of stage2 |
emh203 | 0:3d9c67d97d6f | 258 | * ------------------------*/ |
emh203 | 0:3d9c67d97d6f | 259 | |
emh203 | 0:3d9c67d97d6f | 260 | /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 261 | * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] |
emh203 | 0:3d9c67d97d6f | 262 | * .... |
emh203 | 0:3d9c67d97d6f | 263 | * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 264 | */ |
emh203 | 0:3d9c67d97d6f | 265 | |
emh203 | 0:3d9c67d97d6f | 266 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 267 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 268 | |
emh203 | 0:3d9c67d97d6f | 269 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 270 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 271 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 272 | |
emh203 | 0:3d9c67d97d6f | 273 | /* count is the index by which the pointer pIn1 to be incremented */ |
emh203 | 0:3d9c67d97d6f | 274 | count = 0u; |
emh203 | 0:3d9c67d97d6f | 275 | |
emh203 | 0:3d9c67d97d6f | 276 | |
emh203 | 0:3d9c67d97d6f | 277 | /* -------------------- |
emh203 | 0:3d9c67d97d6f | 278 | * Stage2 process |
emh203 | 0:3d9c67d97d6f | 279 | * -------------------*/ |
emh203 | 0:3d9c67d97d6f | 280 | |
emh203 | 0:3d9c67d97d6f | 281 | /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. |
emh203 | 0:3d9c67d97d6f | 282 | * So, to loop unroll over blockSize2, |
emh203 | 0:3d9c67d97d6f | 283 | * srcBLen should be greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 284 | if(srcBLen >= 4u) |
emh203 | 0:3d9c67d97d6f | 285 | { |
emh203 | 0:3d9c67d97d6f | 286 | /* Loop unroll over blockSize2, by 4 */ |
emh203 | 0:3d9c67d97d6f | 287 | blkCnt = blockSize2 >> 2u; |
emh203 | 0:3d9c67d97d6f | 288 | |
emh203 | 0:3d9c67d97d6f | 289 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 290 | { |
emh203 | 0:3d9c67d97d6f | 291 | py = py - 1u; |
emh203 | 0:3d9c67d97d6f | 292 | |
emh203 | 0:3d9c67d97d6f | 293 | /* Set all accumulators to zero */ |
emh203 | 0:3d9c67d97d6f | 294 | acc0 = 0; |
emh203 | 0:3d9c67d97d6f | 295 | acc1 = 0; |
emh203 | 0:3d9c67d97d6f | 296 | acc2 = 0; |
emh203 | 0:3d9c67d97d6f | 297 | acc3 = 0; |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | |
emh203 | 0:3d9c67d97d6f | 300 | /* read x[0], x[1] samples */ |
emh203 | 0:3d9c67d97d6f | 301 | x0 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 302 | /* read x[1], x[2] samples */ |
emh203 | 0:3d9c67d97d6f | 303 | x1 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 304 | px+= 2u; |
emh203 | 0:3d9c67d97d6f | 305 | |
emh203 | 0:3d9c67d97d6f | 306 | |
emh203 | 0:3d9c67d97d6f | 307 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 308 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 309 | |
emh203 | 0:3d9c67d97d6f | 310 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 311 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 312 | do |
emh203 | 0:3d9c67d97d6f | 313 | { |
emh203 | 0:3d9c67d97d6f | 314 | /* Read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 315 | * y[srcBLen - 1] and y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 316 | c0 = *__SIMD32(py)--; |
emh203 | 0:3d9c67d97d6f | 317 | |
emh203 | 0:3d9c67d97d6f | 318 | /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 319 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 320 | |
emh203 | 0:3d9c67d97d6f | 321 | /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 322 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 323 | |
emh203 | 0:3d9c67d97d6f | 324 | /* Read x[2], x[3] */ |
emh203 | 0:3d9c67d97d6f | 325 | x2 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 326 | |
emh203 | 0:3d9c67d97d6f | 327 | /* Read x[3], x[4] */ |
emh203 | 0:3d9c67d97d6f | 328 | x3 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 329 | |
emh203 | 0:3d9c67d97d6f | 330 | /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 331 | acc2 = __SMLADX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 332 | |
emh203 | 0:3d9c67d97d6f | 333 | /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 334 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 335 | |
emh203 | 0:3d9c67d97d6f | 336 | /* Read y[srcBLen - 3] and y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 337 | c0 = *__SIMD32(py)--; |
emh203 | 0:3d9c67d97d6f | 338 | |
emh203 | 0:3d9c67d97d6f | 339 | /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 340 | acc0 = __SMLADX(x2, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 341 | |
emh203 | 0:3d9c67d97d6f | 342 | /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 343 | acc1 = __SMLADX(x3, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 344 | |
emh203 | 0:3d9c67d97d6f | 345 | /* Read x[4], x[5] */ |
emh203 | 0:3d9c67d97d6f | 346 | x0 = _SIMD32_OFFSET(px+2); |
emh203 | 0:3d9c67d97d6f | 347 | |
emh203 | 0:3d9c67d97d6f | 348 | /* Read x[5], x[6] */ |
emh203 | 0:3d9c67d97d6f | 349 | x1 = _SIMD32_OFFSET(px+3); |
emh203 | 0:3d9c67d97d6f | 350 | px += 4u; |
emh203 | 0:3d9c67d97d6f | 351 | |
emh203 | 0:3d9c67d97d6f | 352 | /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 353 | acc2 = __SMLADX(x0, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 354 | |
emh203 | 0:3d9c67d97d6f | 355 | /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 356 | acc3 = __SMLADX(x1, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 357 | |
emh203 | 0:3d9c67d97d6f | 358 | } while(--k); |
emh203 | 0:3d9c67d97d6f | 359 | |
emh203 | 0:3d9c67d97d6f | 360 | /* For the next MAC operations, SIMD is not used |
emh203 | 0:3d9c67d97d6f | 361 | * So, the 16 bit pointer if inputB, py is updated */ |
emh203 | 0:3d9c67d97d6f | 362 | |
emh203 | 0:3d9c67d97d6f | 363 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 364 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 365 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 366 | |
emh203 | 0:3d9c67d97d6f | 367 | if(k == 1u) |
emh203 | 0:3d9c67d97d6f | 368 | { |
emh203 | 0:3d9c67d97d6f | 369 | /* Read y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 370 | c0 = *(py+1); |
emh203 | 0:3d9c67d97d6f | 371 | |
emh203 | 0:3d9c67d97d6f | 372 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 373 | |
emh203 | 0:3d9c67d97d6f | 374 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 375 | |
emh203 | 0:3d9c67d97d6f | 376 | #else |
emh203 | 0:3d9c67d97d6f | 377 | |
emh203 | 0:3d9c67d97d6f | 378 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 379 | |
emh203 | 0:3d9c67d97d6f | 380 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 381 | |
emh203 | 0:3d9c67d97d6f | 382 | /* Read x[7] */ |
emh203 | 0:3d9c67d97d6f | 383 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 384 | px++; |
emh203 | 0:3d9c67d97d6f | 385 | |
emh203 | 0:3d9c67d97d6f | 386 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 387 | acc0 = __SMLAD(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 388 | acc1 = __SMLAD(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 389 | acc2 = __SMLADX(x1, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 390 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 391 | } |
emh203 | 0:3d9c67d97d6f | 392 | |
emh203 | 0:3d9c67d97d6f | 393 | if(k == 2u) |
emh203 | 0:3d9c67d97d6f | 394 | { |
emh203 | 0:3d9c67d97d6f | 395 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 396 | c0 = _SIMD32_OFFSET(py); |
emh203 | 0:3d9c67d97d6f | 397 | |
emh203 | 0:3d9c67d97d6f | 398 | /* Read x[7], x[8] */ |
emh203 | 0:3d9c67d97d6f | 399 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 400 | |
emh203 | 0:3d9c67d97d6f | 401 | /* Read x[9] */ |
emh203 | 0:3d9c67d97d6f | 402 | x2 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 403 | px += 2u; |
emh203 | 0:3d9c67d97d6f | 404 | |
emh203 | 0:3d9c67d97d6f | 405 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 406 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 407 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 408 | acc2 = __SMLADX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 409 | acc3 = __SMLADX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 410 | } |
emh203 | 0:3d9c67d97d6f | 411 | |
emh203 | 0:3d9c67d97d6f | 412 | if(k == 3u) |
emh203 | 0:3d9c67d97d6f | 413 | { |
emh203 | 0:3d9c67d97d6f | 414 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 415 | c0 = _SIMD32_OFFSET(py); |
emh203 | 0:3d9c67d97d6f | 416 | |
emh203 | 0:3d9c67d97d6f | 417 | /* Read x[7], x[8] */ |
emh203 | 0:3d9c67d97d6f | 418 | x3 = *__SIMD32(px); |
emh203 | 0:3d9c67d97d6f | 419 | |
emh203 | 0:3d9c67d97d6f | 420 | /* Read x[9] */ |
emh203 | 0:3d9c67d97d6f | 421 | x2 = _SIMD32_OFFSET(px+1); |
emh203 | 0:3d9c67d97d6f | 422 | |
emh203 | 0:3d9c67d97d6f | 423 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 424 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 425 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 426 | acc2 = __SMLADX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 427 | acc3 = __SMLADX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 428 | |
emh203 | 0:3d9c67d97d6f | 429 | /* Read y[srcBLen - 7] */ |
emh203 | 0:3d9c67d97d6f | 430 | c0 = *(py-1); |
emh203 | 0:3d9c67d97d6f | 431 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 432 | |
emh203 | 0:3d9c67d97d6f | 433 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 434 | #else |
emh203 | 0:3d9c67d97d6f | 435 | |
emh203 | 0:3d9c67d97d6f | 436 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 437 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 438 | |
emh203 | 0:3d9c67d97d6f | 439 | /* Read x[10] */ |
emh203 | 0:3d9c67d97d6f | 440 | x3 = _SIMD32_OFFSET(px+2); |
emh203 | 0:3d9c67d97d6f | 441 | px += 3u; |
emh203 | 0:3d9c67d97d6f | 442 | |
emh203 | 0:3d9c67d97d6f | 443 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 444 | acc0 = __SMLADX(x1, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 445 | acc1 = __SMLAD(x2, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 446 | acc2 = __SMLADX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 447 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 448 | } |
emh203 | 0:3d9c67d97d6f | 449 | |
emh203 | 0:3d9c67d97d6f | 450 | /* Store the results in the accumulators in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 451 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 452 | |
emh203 | 0:3d9c67d97d6f | 453 | *__SIMD32(pOut)++ = __PKHBT((acc0 >> 15), (acc1 >> 15), 16); |
emh203 | 0:3d9c67d97d6f | 454 | *__SIMD32(pOut)++ = __PKHBT((acc2 >> 15), (acc3 >> 15), 16); |
emh203 | 0:3d9c67d97d6f | 455 | |
emh203 | 0:3d9c67d97d6f | 456 | #else |
emh203 | 0:3d9c67d97d6f | 457 | |
emh203 | 0:3d9c67d97d6f | 458 | *__SIMD32(pOut)++ = __PKHBT((acc1 >> 15), (acc0 >> 15), 16); |
emh203 | 0:3d9c67d97d6f | 459 | *__SIMD32(pOut)++ = __PKHBT((acc3 >> 15), (acc2 >> 15), 16); |
emh203 | 0:3d9c67d97d6f | 460 | |
emh203 | 0:3d9c67d97d6f | 461 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 462 | |
emh203 | 0:3d9c67d97d6f | 463 | /* Increment the pointer pIn1 index, count by 4 */ |
emh203 | 0:3d9c67d97d6f | 464 | count += 4u; |
emh203 | 0:3d9c67d97d6f | 465 | |
emh203 | 0:3d9c67d97d6f | 466 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 467 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 468 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 469 | |
emh203 | 0:3d9c67d97d6f | 470 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 471 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 472 | } |
emh203 | 0:3d9c67d97d6f | 473 | |
emh203 | 0:3d9c67d97d6f | 474 | /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 475 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 476 | blkCnt = blockSize2 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 477 | |
emh203 | 0:3d9c67d97d6f | 478 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 479 | { |
emh203 | 0:3d9c67d97d6f | 480 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 481 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 482 | |
emh203 | 0:3d9c67d97d6f | 483 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 484 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 485 | |
emh203 | 0:3d9c67d97d6f | 486 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 487 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 488 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 489 | { |
emh203 | 0:3d9c67d97d6f | 490 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 491 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 492 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 493 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 494 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 495 | |
emh203 | 0:3d9c67d97d6f | 496 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 497 | k--; |
emh203 | 0:3d9c67d97d6f | 498 | } |
emh203 | 0:3d9c67d97d6f | 499 | |
emh203 | 0:3d9c67d97d6f | 500 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 501 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 502 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 503 | |
emh203 | 0:3d9c67d97d6f | 504 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 505 | { |
emh203 | 0:3d9c67d97d6f | 506 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 507 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 508 | |
emh203 | 0:3d9c67d97d6f | 509 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 510 | k--; |
emh203 | 0:3d9c67d97d6f | 511 | } |
emh203 | 0:3d9c67d97d6f | 512 | |
emh203 | 0:3d9c67d97d6f | 513 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 514 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 515 | |
emh203 | 0:3d9c67d97d6f | 516 | /* Increment the pointer pIn1 index, count by 1 */ |
emh203 | 0:3d9c67d97d6f | 517 | count++; |
emh203 | 0:3d9c67d97d6f | 518 | |
emh203 | 0:3d9c67d97d6f | 519 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 520 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 521 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 522 | |
emh203 | 0:3d9c67d97d6f | 523 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 524 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 525 | } |
emh203 | 0:3d9c67d97d6f | 526 | } |
emh203 | 0:3d9c67d97d6f | 527 | else |
emh203 | 0:3d9c67d97d6f | 528 | { |
emh203 | 0:3d9c67d97d6f | 529 | /* If the srcBLen is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 530 | * the blockSize2 loop cannot be unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 531 | blkCnt = blockSize2; |
emh203 | 0:3d9c67d97d6f | 532 | |
emh203 | 0:3d9c67d97d6f | 533 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 534 | { |
emh203 | 0:3d9c67d97d6f | 535 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 536 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 537 | |
emh203 | 0:3d9c67d97d6f | 538 | /* srcBLen number of MACS should be performed */ |
emh203 | 0:3d9c67d97d6f | 539 | k = srcBLen; |
emh203 | 0:3d9c67d97d6f | 540 | |
emh203 | 0:3d9c67d97d6f | 541 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 542 | { |
emh203 | 0:3d9c67d97d6f | 543 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 544 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 545 | |
emh203 | 0:3d9c67d97d6f | 546 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 547 | k--; |
emh203 | 0:3d9c67d97d6f | 548 | } |
emh203 | 0:3d9c67d97d6f | 549 | |
emh203 | 0:3d9c67d97d6f | 550 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 551 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 552 | |
emh203 | 0:3d9c67d97d6f | 553 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 554 | count++; |
emh203 | 0:3d9c67d97d6f | 555 | |
emh203 | 0:3d9c67d97d6f | 556 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 557 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 558 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 559 | |
emh203 | 0:3d9c67d97d6f | 560 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 561 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 562 | } |
emh203 | 0:3d9c67d97d6f | 563 | } |
emh203 | 0:3d9c67d97d6f | 564 | |
emh203 | 0:3d9c67d97d6f | 565 | |
emh203 | 0:3d9c67d97d6f | 566 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 567 | * Initializations of stage3 |
emh203 | 0:3d9c67d97d6f | 568 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 569 | |
emh203 | 0:3d9c67d97d6f | 570 | /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] |
emh203 | 0:3d9c67d97d6f | 571 | * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] |
emh203 | 0:3d9c67d97d6f | 572 | * .... |
emh203 | 0:3d9c67d97d6f | 573 | * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] |
emh203 | 0:3d9c67d97d6f | 574 | * sum += x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 575 | */ |
emh203 | 0:3d9c67d97d6f | 576 | |
emh203 | 0:3d9c67d97d6f | 577 | /* In this stage the MAC operations are decreased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 578 | The blockSize3 variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 579 | |
emh203 | 0:3d9c67d97d6f | 580 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 581 | pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 582 | px = pSrc1; |
emh203 | 0:3d9c67d97d6f | 583 | |
emh203 | 0:3d9c67d97d6f | 584 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 585 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 586 | pIn2 = pSrc2 - 1u; |
emh203 | 0:3d9c67d97d6f | 587 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 588 | |
emh203 | 0:3d9c67d97d6f | 589 | /* ------------------- |
emh203 | 0:3d9c67d97d6f | 590 | * Stage3 process |
emh203 | 0:3d9c67d97d6f | 591 | * ------------------*/ |
emh203 | 0:3d9c67d97d6f | 592 | |
emh203 | 0:3d9c67d97d6f | 593 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 594 | /* First part of this stage computes the MAC operations greater than 4 */ |
emh203 | 0:3d9c67d97d6f | 595 | /* Second part of this stage computes the MAC operations less than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 596 | |
emh203 | 0:3d9c67d97d6f | 597 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 598 | j = blockSize3 >> 2u; |
emh203 | 0:3d9c67d97d6f | 599 | |
emh203 | 0:3d9c67d97d6f | 600 | while((j > 0u) && (blockSize3 > 0u)) |
emh203 | 0:3d9c67d97d6f | 601 | { |
emh203 | 0:3d9c67d97d6f | 602 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 603 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 604 | |
emh203 | 0:3d9c67d97d6f | 605 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 606 | k = blockSize3 >> 2u; |
emh203 | 0:3d9c67d97d6f | 607 | |
emh203 | 0:3d9c67d97d6f | 608 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 609 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 610 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 611 | { |
emh203 | 0:3d9c67d97d6f | 612 | /* x[srcALen - srcBLen + 1], x[srcALen - srcBLen + 2] are multiplied |
emh203 | 0:3d9c67d97d6f | 613 | * with y[srcBLen - 1], y[srcBLen - 2] respectively */ |
emh203 | 0:3d9c67d97d6f | 614 | sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 615 | /* x[srcALen - srcBLen + 3], x[srcALen - srcBLen + 4] are multiplied |
emh203 | 0:3d9c67d97d6f | 616 | * with y[srcBLen - 3], y[srcBLen - 4] respectively */ |
emh203 | 0:3d9c67d97d6f | 617 | sum = __SMLADX(*__SIMD32(px)++, *__SIMD32(py)--, sum); |
emh203 | 0:3d9c67d97d6f | 618 | |
emh203 | 0:3d9c67d97d6f | 619 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 620 | k--; |
emh203 | 0:3d9c67d97d6f | 621 | } |
emh203 | 0:3d9c67d97d6f | 622 | |
emh203 | 0:3d9c67d97d6f | 623 | /* For the next MAC operations, the pointer py is used without SIMD |
emh203 | 0:3d9c67d97d6f | 624 | * So, py is incremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 625 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 626 | |
emh203 | 0:3d9c67d97d6f | 627 | /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 628 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 629 | k = blockSize3 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 630 | |
emh203 | 0:3d9c67d97d6f | 631 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 632 | { |
emh203 | 0:3d9c67d97d6f | 633 | /* sum += x[srcALen - srcBLen + 5] * y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 634 | sum = __SMLAD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 635 | |
emh203 | 0:3d9c67d97d6f | 636 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 637 | k--; |
emh203 | 0:3d9c67d97d6f | 638 | } |
emh203 | 0:3d9c67d97d6f | 639 | |
emh203 | 0:3d9c67d97d6f | 640 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 641 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 642 | |
emh203 | 0:3d9c67d97d6f | 643 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 644 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 645 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 646 | |
emh203 | 0:3d9c67d97d6f | 647 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 648 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 649 | |
emh203 | 0:3d9c67d97d6f | 650 | j--; |
emh203 | 0:3d9c67d97d6f | 651 | } |
emh203 | 0:3d9c67d97d6f | 652 | |
emh203 | 0:3d9c67d97d6f | 653 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 654 | /* SIMD is not used for the next MAC operations, |
emh203 | 0:3d9c67d97d6f | 655 | * so pointer py is updated to read only one sample at a time */ |
emh203 | 0:3d9c67d97d6f | 656 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 657 | |
emh203 | 0:3d9c67d97d6f | 658 | while(blockSize3 > 0u) |
emh203 | 0:3d9c67d97d6f | 659 | { |
emh203 | 0:3d9c67d97d6f | 660 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 661 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 662 | |
emh203 | 0:3d9c67d97d6f | 663 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 664 | k = blockSize3; |
emh203 | 0:3d9c67d97d6f | 665 | |
emh203 | 0:3d9c67d97d6f | 666 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 667 | { |
emh203 | 0:3d9c67d97d6f | 668 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 669 | /* sum += x[srcALen-1] * y[srcBLen-1] */ |
emh203 | 0:3d9c67d97d6f | 670 | sum = __SMLAD(*px++, *py--, sum); |
emh203 | 0:3d9c67d97d6f | 671 | |
emh203 | 0:3d9c67d97d6f | 672 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 673 | k--; |
emh203 | 0:3d9c67d97d6f | 674 | } |
emh203 | 0:3d9c67d97d6f | 675 | |
emh203 | 0:3d9c67d97d6f | 676 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 677 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 678 | |
emh203 | 0:3d9c67d97d6f | 679 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 680 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 681 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 682 | |
emh203 | 0:3d9c67d97d6f | 683 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 684 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 685 | } |
emh203 | 0:3d9c67d97d6f | 686 | |
emh203 | 0:3d9c67d97d6f | 687 | #else |
emh203 | 0:3d9c67d97d6f | 688 | q15_t *pIn1; /* inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 689 | q15_t *pIn2; /* inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 690 | q15_t *pOut = pDst; /* output pointer */ |
emh203 | 0:3d9c67d97d6f | 691 | q31_t sum, acc0, acc1, acc2, acc3; /* Accumulator */ |
emh203 | 0:3d9c67d97d6f | 692 | q15_t *px; /* Intermediate inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 693 | q15_t *py; /* Intermediate inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 694 | q15_t *pSrc1, *pSrc2; /* Intermediate pointers */ |
emh203 | 0:3d9c67d97d6f | 695 | q31_t x0, x1, x2, x3, c0; /* Temporary variables to hold state and coefficient values */ |
emh203 | 0:3d9c67d97d6f | 696 | uint32_t blockSize1, blockSize2, blockSize3, j, k, count, blkCnt; /* loop counter */ |
emh203 | 0:3d9c67d97d6f | 697 | q15_t a, b; |
emh203 | 0:3d9c67d97d6f | 698 | |
emh203 | 0:3d9c67d97d6f | 699 | /* The algorithm implementation is based on the lengths of the inputs. */ |
emh203 | 0:3d9c67d97d6f | 700 | /* srcB is always made to slide across srcA. */ |
emh203 | 0:3d9c67d97d6f | 701 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 702 | if(srcALen >= srcBLen) |
emh203 | 0:3d9c67d97d6f | 703 | { |
emh203 | 0:3d9c67d97d6f | 704 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 705 | pIn1 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 706 | |
emh203 | 0:3d9c67d97d6f | 707 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 708 | pIn2 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 709 | } |
emh203 | 0:3d9c67d97d6f | 710 | else |
emh203 | 0:3d9c67d97d6f | 711 | { |
emh203 | 0:3d9c67d97d6f | 712 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 713 | pIn1 = pSrcB; |
emh203 | 0:3d9c67d97d6f | 714 | |
emh203 | 0:3d9c67d97d6f | 715 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 716 | pIn2 = pSrcA; |
emh203 | 0:3d9c67d97d6f | 717 | |
emh203 | 0:3d9c67d97d6f | 718 | /* srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 719 | j = srcBLen; |
emh203 | 0:3d9c67d97d6f | 720 | srcBLen = srcALen; |
emh203 | 0:3d9c67d97d6f | 721 | srcALen = j; |
emh203 | 0:3d9c67d97d6f | 722 | } |
emh203 | 0:3d9c67d97d6f | 723 | |
emh203 | 0:3d9c67d97d6f | 724 | /* 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 | 725 | /* The function is internally |
emh203 | 0:3d9c67d97d6f | 726 | * divided into three stages according to the number of multiplications that has to be |
emh203 | 0:3d9c67d97d6f | 727 | * taken place between inputA samples and inputB samples. In the first stage of the |
emh203 | 0:3d9c67d97d6f | 728 | * algorithm, the multiplications increase by one for every iteration. |
emh203 | 0:3d9c67d97d6f | 729 | * In the second stage of the algorithm, srcBLen number of multiplications are done. |
emh203 | 0:3d9c67d97d6f | 730 | * In the third stage of the algorithm, the multiplications decrease by one |
emh203 | 0:3d9c67d97d6f | 731 | * for every iteration. */ |
emh203 | 0:3d9c67d97d6f | 732 | |
emh203 | 0:3d9c67d97d6f | 733 | /* The algorithm is implemented in three stages. |
emh203 | 0:3d9c67d97d6f | 734 | The loop counters of each stage is initiated here. */ |
emh203 | 0:3d9c67d97d6f | 735 | blockSize1 = srcBLen - 1u; |
emh203 | 0:3d9c67d97d6f | 736 | blockSize2 = srcALen - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 737 | blockSize3 = blockSize1; |
emh203 | 0:3d9c67d97d6f | 738 | |
emh203 | 0:3d9c67d97d6f | 739 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 740 | * Initializations of stage1 |
emh203 | 0:3d9c67d97d6f | 741 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 742 | |
emh203 | 0:3d9c67d97d6f | 743 | /* sum = x[0] * y[0] |
emh203 | 0:3d9c67d97d6f | 744 | * sum = x[0] * y[1] + x[1] * y[0] |
emh203 | 0:3d9c67d97d6f | 745 | * .... |
emh203 | 0:3d9c67d97d6f | 746 | * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] |
emh203 | 0:3d9c67d97d6f | 747 | */ |
emh203 | 0:3d9c67d97d6f | 748 | |
emh203 | 0:3d9c67d97d6f | 749 | /* In this stage the MAC operations are increased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 750 | The count variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 751 | count = 1u; |
emh203 | 0:3d9c67d97d6f | 752 | |
emh203 | 0:3d9c67d97d6f | 753 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 754 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 755 | |
emh203 | 0:3d9c67d97d6f | 756 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 757 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 758 | |
emh203 | 0:3d9c67d97d6f | 759 | |
emh203 | 0:3d9c67d97d6f | 760 | /* ------------------------ |
emh203 | 0:3d9c67d97d6f | 761 | * Stage1 process |
emh203 | 0:3d9c67d97d6f | 762 | * ----------------------*/ |
emh203 | 0:3d9c67d97d6f | 763 | |
emh203 | 0:3d9c67d97d6f | 764 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 765 | /* First part of this stage computes the MAC operations less than 4 */ |
emh203 | 0:3d9c67d97d6f | 766 | /* Second part of this stage computes the MAC operations greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 767 | |
emh203 | 0:3d9c67d97d6f | 768 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 769 | while((count < 4u) && (blockSize1 > 0u)) |
emh203 | 0:3d9c67d97d6f | 770 | { |
emh203 | 0:3d9c67d97d6f | 771 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 772 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 773 | |
emh203 | 0:3d9c67d97d6f | 774 | /* Loop over number of MAC operations between |
emh203 | 0:3d9c67d97d6f | 775 | * inputA samples and inputB samples */ |
emh203 | 0:3d9c67d97d6f | 776 | k = count; |
emh203 | 0:3d9c67d97d6f | 777 | |
emh203 | 0:3d9c67d97d6f | 778 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 779 | { |
emh203 | 0:3d9c67d97d6f | 780 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 781 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 782 | |
emh203 | 0:3d9c67d97d6f | 783 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 784 | k--; |
emh203 | 0:3d9c67d97d6f | 785 | } |
emh203 | 0:3d9c67d97d6f | 786 | |
emh203 | 0:3d9c67d97d6f | 787 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 788 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 789 | |
emh203 | 0:3d9c67d97d6f | 790 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 791 | py = pIn2 + count; |
emh203 | 0:3d9c67d97d6f | 792 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 793 | |
emh203 | 0:3d9c67d97d6f | 794 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 795 | count++; |
emh203 | 0:3d9c67d97d6f | 796 | |
emh203 | 0:3d9c67d97d6f | 797 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 798 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 799 | } |
emh203 | 0:3d9c67d97d6f | 800 | |
emh203 | 0:3d9c67d97d6f | 801 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 802 | /* The internal loop, over count, is unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 803 | /* To, read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 804 | * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */ |
emh203 | 0:3d9c67d97d6f | 805 | py = py - 1; |
emh203 | 0:3d9c67d97d6f | 806 | |
emh203 | 0:3d9c67d97d6f | 807 | while(blockSize1 > 0u) |
emh203 | 0:3d9c67d97d6f | 808 | { |
emh203 | 0:3d9c67d97d6f | 809 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 810 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 811 | |
emh203 | 0:3d9c67d97d6f | 812 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 813 | k = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 814 | |
emh203 | 0:3d9c67d97d6f | 815 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 816 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 817 | py++; |
emh203 | 0:3d9c67d97d6f | 818 | |
emh203 | 0:3d9c67d97d6f | 819 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 820 | { |
emh203 | 0:3d9c67d97d6f | 821 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 822 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 823 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 824 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 825 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 826 | |
emh203 | 0:3d9c67d97d6f | 827 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 828 | k--; |
emh203 | 0:3d9c67d97d6f | 829 | } |
emh203 | 0:3d9c67d97d6f | 830 | |
emh203 | 0:3d9c67d97d6f | 831 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 832 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 833 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 834 | |
emh203 | 0:3d9c67d97d6f | 835 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 836 | { |
emh203 | 0:3d9c67d97d6f | 837 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 838 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 839 | |
emh203 | 0:3d9c67d97d6f | 840 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 841 | k--; |
emh203 | 0:3d9c67d97d6f | 842 | } |
emh203 | 0:3d9c67d97d6f | 843 | |
emh203 | 0:3d9c67d97d6f | 844 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 845 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 846 | |
emh203 | 0:3d9c67d97d6f | 847 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 848 | py = pIn2 + (count - 1u); |
emh203 | 0:3d9c67d97d6f | 849 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 850 | |
emh203 | 0:3d9c67d97d6f | 851 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 852 | count++; |
emh203 | 0:3d9c67d97d6f | 853 | |
emh203 | 0:3d9c67d97d6f | 854 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 855 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 856 | } |
emh203 | 0:3d9c67d97d6f | 857 | |
emh203 | 0:3d9c67d97d6f | 858 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 859 | * Initializations of stage2 |
emh203 | 0:3d9c67d97d6f | 860 | * ------------------------*/ |
emh203 | 0:3d9c67d97d6f | 861 | |
emh203 | 0:3d9c67d97d6f | 862 | /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 863 | * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] |
emh203 | 0:3d9c67d97d6f | 864 | * .... |
emh203 | 0:3d9c67d97d6f | 865 | * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 866 | */ |
emh203 | 0:3d9c67d97d6f | 867 | |
emh203 | 0:3d9c67d97d6f | 868 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 869 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 870 | |
emh203 | 0:3d9c67d97d6f | 871 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 872 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 873 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 874 | |
emh203 | 0:3d9c67d97d6f | 875 | /* count is the index by which the pointer pIn1 to be incremented */ |
emh203 | 0:3d9c67d97d6f | 876 | count = 0u; |
emh203 | 0:3d9c67d97d6f | 877 | |
emh203 | 0:3d9c67d97d6f | 878 | |
emh203 | 0:3d9c67d97d6f | 879 | /* -------------------- |
emh203 | 0:3d9c67d97d6f | 880 | * Stage2 process |
emh203 | 0:3d9c67d97d6f | 881 | * -------------------*/ |
emh203 | 0:3d9c67d97d6f | 882 | |
emh203 | 0:3d9c67d97d6f | 883 | /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. |
emh203 | 0:3d9c67d97d6f | 884 | * So, to loop unroll over blockSize2, |
emh203 | 0:3d9c67d97d6f | 885 | * srcBLen should be greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 886 | if(srcBLen >= 4u) |
emh203 | 0:3d9c67d97d6f | 887 | { |
emh203 | 0:3d9c67d97d6f | 888 | /* Loop unroll over blockSize2, by 4 */ |
emh203 | 0:3d9c67d97d6f | 889 | blkCnt = blockSize2 >> 2u; |
emh203 | 0:3d9c67d97d6f | 890 | |
emh203 | 0:3d9c67d97d6f | 891 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 892 | { |
emh203 | 0:3d9c67d97d6f | 893 | py = py - 1u; |
emh203 | 0:3d9c67d97d6f | 894 | |
emh203 | 0:3d9c67d97d6f | 895 | /* Set all accumulators to zero */ |
emh203 | 0:3d9c67d97d6f | 896 | acc0 = 0; |
emh203 | 0:3d9c67d97d6f | 897 | acc1 = 0; |
emh203 | 0:3d9c67d97d6f | 898 | acc2 = 0; |
emh203 | 0:3d9c67d97d6f | 899 | acc3 = 0; |
emh203 | 0:3d9c67d97d6f | 900 | |
emh203 | 0:3d9c67d97d6f | 901 | /* read x[0], x[1] samples */ |
emh203 | 0:3d9c67d97d6f | 902 | a = *px++; |
emh203 | 0:3d9c67d97d6f | 903 | b = *px++; |
emh203 | 0:3d9c67d97d6f | 904 | |
emh203 | 0:3d9c67d97d6f | 905 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 906 | |
emh203 | 0:3d9c67d97d6f | 907 | x0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 908 | a = *px; |
emh203 | 0:3d9c67d97d6f | 909 | x1 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 910 | |
emh203 | 0:3d9c67d97d6f | 911 | #else |
emh203 | 0:3d9c67d97d6f | 912 | |
emh203 | 0:3d9c67d97d6f | 913 | x0 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 914 | a = *px; |
emh203 | 0:3d9c67d97d6f | 915 | x1 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 916 | |
emh203 | 0:3d9c67d97d6f | 917 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 918 | |
emh203 | 0:3d9c67d97d6f | 919 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 920 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 921 | |
emh203 | 0:3d9c67d97d6f | 922 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 923 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 924 | do |
emh203 | 0:3d9c67d97d6f | 925 | { |
emh203 | 0:3d9c67d97d6f | 926 | /* Read the last two inputB samples using SIMD: |
emh203 | 0:3d9c67d97d6f | 927 | * y[srcBLen - 1] and y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 928 | a = *py; |
emh203 | 0:3d9c67d97d6f | 929 | b = *(py+1); |
emh203 | 0:3d9c67d97d6f | 930 | py -= 2; |
emh203 | 0:3d9c67d97d6f | 931 | |
emh203 | 0:3d9c67d97d6f | 932 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 933 | |
emh203 | 0:3d9c67d97d6f | 934 | c0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 935 | |
emh203 | 0:3d9c67d97d6f | 936 | #else |
emh203 | 0:3d9c67d97d6f | 937 | |
emh203 | 0:3d9c67d97d6f | 938 | c0 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 939 | |
emh203 | 0:3d9c67d97d6f | 940 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 941 | |
emh203 | 0:3d9c67d97d6f | 942 | /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 943 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 944 | |
emh203 | 0:3d9c67d97d6f | 945 | /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 946 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 947 | |
emh203 | 0:3d9c67d97d6f | 948 | a = *px; |
emh203 | 0:3d9c67d97d6f | 949 | b = *(px + 1); |
emh203 | 0:3d9c67d97d6f | 950 | |
emh203 | 0:3d9c67d97d6f | 951 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 952 | |
emh203 | 0:3d9c67d97d6f | 953 | x2 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 954 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 955 | x3 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 956 | |
emh203 | 0:3d9c67d97d6f | 957 | #else |
emh203 | 0:3d9c67d97d6f | 958 | |
emh203 | 0:3d9c67d97d6f | 959 | x2 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 960 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 961 | x3 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 962 | |
emh203 | 0:3d9c67d97d6f | 963 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 964 | |
emh203 | 0:3d9c67d97d6f | 965 | /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 966 | acc2 = __SMLADX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 967 | |
emh203 | 0:3d9c67d97d6f | 968 | /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 969 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 970 | |
emh203 | 0:3d9c67d97d6f | 971 | /* Read y[srcBLen - 3] and y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 972 | a = *py; |
emh203 | 0:3d9c67d97d6f | 973 | b = *(py+1); |
emh203 | 0:3d9c67d97d6f | 974 | py -= 2; |
emh203 | 0:3d9c67d97d6f | 975 | |
emh203 | 0:3d9c67d97d6f | 976 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 977 | |
emh203 | 0:3d9c67d97d6f | 978 | c0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 979 | |
emh203 | 0:3d9c67d97d6f | 980 | #else |
emh203 | 0:3d9c67d97d6f | 981 | |
emh203 | 0:3d9c67d97d6f | 982 | c0 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 983 | |
emh203 | 0:3d9c67d97d6f | 984 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 985 | |
emh203 | 0:3d9c67d97d6f | 986 | /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 987 | acc0 = __SMLADX(x2, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 988 | |
emh203 | 0:3d9c67d97d6f | 989 | /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 990 | acc1 = __SMLADX(x3, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 991 | |
emh203 | 0:3d9c67d97d6f | 992 | /* Read x[4], x[5], x[6] */ |
emh203 | 0:3d9c67d97d6f | 993 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 994 | b = *(px + 3); |
emh203 | 0:3d9c67d97d6f | 995 | |
emh203 | 0:3d9c67d97d6f | 996 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 997 | |
emh203 | 0:3d9c67d97d6f | 998 | x0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 999 | a = *(px + 4); |
emh203 | 0:3d9c67d97d6f | 1000 | x1 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1001 | |
emh203 | 0:3d9c67d97d6f | 1002 | #else |
emh203 | 0:3d9c67d97d6f | 1003 | |
emh203 | 0:3d9c67d97d6f | 1004 | x0 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1005 | a = *(px + 4); |
emh203 | 0:3d9c67d97d6f | 1006 | x1 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1007 | |
emh203 | 0:3d9c67d97d6f | 1008 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1009 | |
emh203 | 0:3d9c67d97d6f | 1010 | px += 4u; |
emh203 | 0:3d9c67d97d6f | 1011 | |
emh203 | 0:3d9c67d97d6f | 1012 | /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 1013 | acc2 = __SMLADX(x0, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 1014 | |
emh203 | 0:3d9c67d97d6f | 1015 | /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 1016 | acc3 = __SMLADX(x1, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 1017 | |
emh203 | 0:3d9c67d97d6f | 1018 | } while(--k); |
emh203 | 0:3d9c67d97d6f | 1019 | |
emh203 | 0:3d9c67d97d6f | 1020 | /* For the next MAC operations, SIMD is not used |
emh203 | 0:3d9c67d97d6f | 1021 | * So, the 16 bit pointer if inputB, py is updated */ |
emh203 | 0:3d9c67d97d6f | 1022 | |
emh203 | 0:3d9c67d97d6f | 1023 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 1024 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 1025 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 1026 | |
emh203 | 0:3d9c67d97d6f | 1027 | if(k == 1u) |
emh203 | 0:3d9c67d97d6f | 1028 | { |
emh203 | 0:3d9c67d97d6f | 1029 | /* Read y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 1030 | c0 = *(py+1); |
emh203 | 0:3d9c67d97d6f | 1031 | |
emh203 | 0:3d9c67d97d6f | 1032 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1033 | |
emh203 | 0:3d9c67d97d6f | 1034 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 1035 | |
emh203 | 0:3d9c67d97d6f | 1036 | #else |
emh203 | 0:3d9c67d97d6f | 1037 | |
emh203 | 0:3d9c67d97d6f | 1038 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 1039 | |
emh203 | 0:3d9c67d97d6f | 1040 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1041 | |
emh203 | 0:3d9c67d97d6f | 1042 | /* Read x[7] */ |
emh203 | 0:3d9c67d97d6f | 1043 | a = *px; |
emh203 | 0:3d9c67d97d6f | 1044 | b = *(px+1); |
emh203 | 0:3d9c67d97d6f | 1045 | px++; |
emh203 | 0:3d9c67d97d6f | 1046 | |
emh203 | 0:3d9c67d97d6f | 1047 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1048 | |
emh203 | 0:3d9c67d97d6f | 1049 | x3 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1050 | |
emh203 | 0:3d9c67d97d6f | 1051 | #else |
emh203 | 0:3d9c67d97d6f | 1052 | |
emh203 | 0:3d9c67d97d6f | 1053 | x3 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 1054 | |
emh203 | 0:3d9c67d97d6f | 1055 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1056 | |
emh203 | 0:3d9c67d97d6f | 1057 | |
emh203 | 0:3d9c67d97d6f | 1058 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1059 | acc0 = __SMLAD(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 1060 | acc1 = __SMLAD(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 1061 | acc2 = __SMLADX(x1, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 1062 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 1063 | } |
emh203 | 0:3d9c67d97d6f | 1064 | |
emh203 | 0:3d9c67d97d6f | 1065 | if(k == 2u) |
emh203 | 0:3d9c67d97d6f | 1066 | { |
emh203 | 0:3d9c67d97d6f | 1067 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 1068 | a = *py; |
emh203 | 0:3d9c67d97d6f | 1069 | b = *(py+1); |
emh203 | 0:3d9c67d97d6f | 1070 | |
emh203 | 0:3d9c67d97d6f | 1071 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1072 | |
emh203 | 0:3d9c67d97d6f | 1073 | c0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1074 | |
emh203 | 0:3d9c67d97d6f | 1075 | #else |
emh203 | 0:3d9c67d97d6f | 1076 | |
emh203 | 0:3d9c67d97d6f | 1077 | c0 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 1078 | |
emh203 | 0:3d9c67d97d6f | 1079 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1080 | |
emh203 | 0:3d9c67d97d6f | 1081 | /* Read x[7], x[8], x[9] */ |
emh203 | 0:3d9c67d97d6f | 1082 | a = *px; |
emh203 | 0:3d9c67d97d6f | 1083 | b = *(px + 1); |
emh203 | 0:3d9c67d97d6f | 1084 | |
emh203 | 0:3d9c67d97d6f | 1085 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1086 | |
emh203 | 0:3d9c67d97d6f | 1087 | x3 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1088 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 1089 | x2 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1090 | |
emh203 | 0:3d9c67d97d6f | 1091 | #else |
emh203 | 0:3d9c67d97d6f | 1092 | |
emh203 | 0:3d9c67d97d6f | 1093 | x3 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1094 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 1095 | x2 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1096 | |
emh203 | 0:3d9c67d97d6f | 1097 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1098 | px += 2u; |
emh203 | 0:3d9c67d97d6f | 1099 | |
emh203 | 0:3d9c67d97d6f | 1100 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1101 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 1102 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 1103 | acc2 = __SMLADX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 1104 | acc3 = __SMLADX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 1105 | } |
emh203 | 0:3d9c67d97d6f | 1106 | |
emh203 | 0:3d9c67d97d6f | 1107 | if(k == 3u) |
emh203 | 0:3d9c67d97d6f | 1108 | { |
emh203 | 0:3d9c67d97d6f | 1109 | /* Read y[srcBLen - 5], y[srcBLen - 6] */ |
emh203 | 0:3d9c67d97d6f | 1110 | a = *py; |
emh203 | 0:3d9c67d97d6f | 1111 | b = *(py+1); |
emh203 | 0:3d9c67d97d6f | 1112 | |
emh203 | 0:3d9c67d97d6f | 1113 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1114 | |
emh203 | 0:3d9c67d97d6f | 1115 | c0 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1116 | |
emh203 | 0:3d9c67d97d6f | 1117 | #else |
emh203 | 0:3d9c67d97d6f | 1118 | |
emh203 | 0:3d9c67d97d6f | 1119 | c0 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 1120 | |
emh203 | 0:3d9c67d97d6f | 1121 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1122 | |
emh203 | 0:3d9c67d97d6f | 1123 | /* Read x[7], x[8], x[9] */ |
emh203 | 0:3d9c67d97d6f | 1124 | a = *px; |
emh203 | 0:3d9c67d97d6f | 1125 | b = *(px + 1); |
emh203 | 0:3d9c67d97d6f | 1126 | |
emh203 | 0:3d9c67d97d6f | 1127 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1128 | |
emh203 | 0:3d9c67d97d6f | 1129 | x3 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1130 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 1131 | x2 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1132 | |
emh203 | 0:3d9c67d97d6f | 1133 | #else |
emh203 | 0:3d9c67d97d6f | 1134 | |
emh203 | 0:3d9c67d97d6f | 1135 | x3 = __PKHBT(b, a, 16); |
emh203 | 0:3d9c67d97d6f | 1136 | a = *(px + 2); |
emh203 | 0:3d9c67d97d6f | 1137 | x2 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1138 | |
emh203 | 0:3d9c67d97d6f | 1139 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1140 | |
emh203 | 0:3d9c67d97d6f | 1141 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1142 | acc0 = __SMLADX(x0, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 1143 | acc1 = __SMLADX(x1, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 1144 | acc2 = __SMLADX(x3, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 1145 | acc3 = __SMLADX(x2, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 1146 | |
emh203 | 0:3d9c67d97d6f | 1147 | /* Read y[srcBLen - 7] */ |
emh203 | 0:3d9c67d97d6f | 1148 | c0 = *(py-1); |
emh203 | 0:3d9c67d97d6f | 1149 | #ifdef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1150 | |
emh203 | 0:3d9c67d97d6f | 1151 | c0 = c0 << 16u; |
emh203 | 0:3d9c67d97d6f | 1152 | #else |
emh203 | 0:3d9c67d97d6f | 1153 | |
emh203 | 0:3d9c67d97d6f | 1154 | c0 = c0 & 0x0000FFFF; |
emh203 | 0:3d9c67d97d6f | 1155 | #endif /* #ifdef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1156 | |
emh203 | 0:3d9c67d97d6f | 1157 | /* Read x[10] */ |
emh203 | 0:3d9c67d97d6f | 1158 | a = *(px+2); |
emh203 | 0:3d9c67d97d6f | 1159 | b = *(px+3); |
emh203 | 0:3d9c67d97d6f | 1160 | |
emh203 | 0:3d9c67d97d6f | 1161 | #ifndef ARM_MATH_BIG_ENDIAN |
emh203 | 0:3d9c67d97d6f | 1162 | |
emh203 | 0:3d9c67d97d6f | 1163 | x3 = __PKHBT(a, b, 16); |
emh203 | 0:3d9c67d97d6f | 1164 | |
emh203 | 0:3d9c67d97d6f | 1165 | #else |
emh203 | 0:3d9c67d97d6f | 1166 | |
emh203 | 0:3d9c67d97d6f | 1167 | x3 = __PKHBT(b, a, 16);; |
emh203 | 0:3d9c67d97d6f | 1168 | |
emh203 | 0:3d9c67d97d6f | 1169 | #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ |
emh203 | 0:3d9c67d97d6f | 1170 | |
emh203 | 0:3d9c67d97d6f | 1171 | px += 3u; |
emh203 | 0:3d9c67d97d6f | 1172 | |
emh203 | 0:3d9c67d97d6f | 1173 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1174 | acc0 = __SMLADX(x1, c0, acc0); |
emh203 | 0:3d9c67d97d6f | 1175 | acc1 = __SMLAD(x2, c0, acc1); |
emh203 | 0:3d9c67d97d6f | 1176 | acc2 = __SMLADX(x2, c0, acc2); |
emh203 | 0:3d9c67d97d6f | 1177 | acc3 = __SMLADX(x3, c0, acc3); |
emh203 | 0:3d9c67d97d6f | 1178 | } |
emh203 | 0:3d9c67d97d6f | 1179 | |
emh203 | 0:3d9c67d97d6f | 1180 | /* Store the results in the accumulators in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 1181 | *pOut++ = (q15_t)(acc0 >> 15); |
emh203 | 0:3d9c67d97d6f | 1182 | *pOut++ = (q15_t)(acc1 >> 15); |
emh203 | 0:3d9c67d97d6f | 1183 | *pOut++ = (q15_t)(acc2 >> 15); |
emh203 | 0:3d9c67d97d6f | 1184 | *pOut++ = (q15_t)(acc3 >> 15); |
emh203 | 0:3d9c67d97d6f | 1185 | |
emh203 | 0:3d9c67d97d6f | 1186 | /* Increment the pointer pIn1 index, count by 4 */ |
emh203 | 0:3d9c67d97d6f | 1187 | count += 4u; |
emh203 | 0:3d9c67d97d6f | 1188 | |
emh203 | 0:3d9c67d97d6f | 1189 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 1190 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 1191 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 1192 | |
emh203 | 0:3d9c67d97d6f | 1193 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1194 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 1195 | } |
emh203 | 0:3d9c67d97d6f | 1196 | |
emh203 | 0:3d9c67d97d6f | 1197 | /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 1198 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 1199 | blkCnt = blockSize2 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 1200 | |
emh203 | 0:3d9c67d97d6f | 1201 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 1202 | { |
emh203 | 0:3d9c67d97d6f | 1203 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 1204 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 1205 | |
emh203 | 0:3d9c67d97d6f | 1206 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 1207 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 1208 | |
emh203 | 0:3d9c67d97d6f | 1209 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 1210 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 1211 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1212 | { |
emh203 | 0:3d9c67d97d6f | 1213 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1214 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1215 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1216 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1217 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1218 | |
emh203 | 0:3d9c67d97d6f | 1219 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1220 | k--; |
emh203 | 0:3d9c67d97d6f | 1221 | } |
emh203 | 0:3d9c67d97d6f | 1222 | |
emh203 | 0:3d9c67d97d6f | 1223 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 1224 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 1225 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 1226 | |
emh203 | 0:3d9c67d97d6f | 1227 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1228 | { |
emh203 | 0:3d9c67d97d6f | 1229 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1230 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1231 | |
emh203 | 0:3d9c67d97d6f | 1232 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1233 | k--; |
emh203 | 0:3d9c67d97d6f | 1234 | } |
emh203 | 0:3d9c67d97d6f | 1235 | |
emh203 | 0:3d9c67d97d6f | 1236 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 1237 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 1238 | |
emh203 | 0:3d9c67d97d6f | 1239 | /* Increment the pointer pIn1 index, count by 1 */ |
emh203 | 0:3d9c67d97d6f | 1240 | count++; |
emh203 | 0:3d9c67d97d6f | 1241 | |
emh203 | 0:3d9c67d97d6f | 1242 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 1243 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 1244 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 1245 | |
emh203 | 0:3d9c67d97d6f | 1246 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1247 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 1248 | } |
emh203 | 0:3d9c67d97d6f | 1249 | } |
emh203 | 0:3d9c67d97d6f | 1250 | else |
emh203 | 0:3d9c67d97d6f | 1251 | { |
emh203 | 0:3d9c67d97d6f | 1252 | /* If the srcBLen is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 1253 | * the blockSize2 loop cannot be unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 1254 | blkCnt = blockSize2; |
emh203 | 0:3d9c67d97d6f | 1255 | |
emh203 | 0:3d9c67d97d6f | 1256 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 1257 | { |
emh203 | 0:3d9c67d97d6f | 1258 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 1259 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 1260 | |
emh203 | 0:3d9c67d97d6f | 1261 | /* srcBLen number of MACS should be performed */ |
emh203 | 0:3d9c67d97d6f | 1262 | k = srcBLen; |
emh203 | 0:3d9c67d97d6f | 1263 | |
emh203 | 0:3d9c67d97d6f | 1264 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1265 | { |
emh203 | 0:3d9c67d97d6f | 1266 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 1267 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1268 | |
emh203 | 0:3d9c67d97d6f | 1269 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1270 | k--; |
emh203 | 0:3d9c67d97d6f | 1271 | } |
emh203 | 0:3d9c67d97d6f | 1272 | |
emh203 | 0:3d9c67d97d6f | 1273 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 1274 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 1275 | |
emh203 | 0:3d9c67d97d6f | 1276 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 1277 | count++; |
emh203 | 0:3d9c67d97d6f | 1278 | |
emh203 | 0:3d9c67d97d6f | 1279 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 1280 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 1281 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 1282 | |
emh203 | 0:3d9c67d97d6f | 1283 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1284 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 1285 | } |
emh203 | 0:3d9c67d97d6f | 1286 | } |
emh203 | 0:3d9c67d97d6f | 1287 | |
emh203 | 0:3d9c67d97d6f | 1288 | |
emh203 | 0:3d9c67d97d6f | 1289 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 1290 | * Initializations of stage3 |
emh203 | 0:3d9c67d97d6f | 1291 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 1292 | |
emh203 | 0:3d9c67d97d6f | 1293 | /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] |
emh203 | 0:3d9c67d97d6f | 1294 | * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] |
emh203 | 0:3d9c67d97d6f | 1295 | * .... |
emh203 | 0:3d9c67d97d6f | 1296 | * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] |
emh203 | 0:3d9c67d97d6f | 1297 | * sum += x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 1298 | */ |
emh203 | 0:3d9c67d97d6f | 1299 | |
emh203 | 0:3d9c67d97d6f | 1300 | /* In this stage the MAC operations are decreased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 1301 | The blockSize3 variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 1302 | |
emh203 | 0:3d9c67d97d6f | 1303 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 1304 | pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 1305 | px = pSrc1; |
emh203 | 0:3d9c67d97d6f | 1306 | |
emh203 | 0:3d9c67d97d6f | 1307 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 1308 | pSrc2 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 1309 | pIn2 = pSrc2 - 1u; |
emh203 | 0:3d9c67d97d6f | 1310 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 1311 | |
emh203 | 0:3d9c67d97d6f | 1312 | /* ------------------- |
emh203 | 0:3d9c67d97d6f | 1313 | * Stage3 process |
emh203 | 0:3d9c67d97d6f | 1314 | * ------------------*/ |
emh203 | 0:3d9c67d97d6f | 1315 | |
emh203 | 0:3d9c67d97d6f | 1316 | /* For loop unrolling by 4, this stage is divided into two. */ |
emh203 | 0:3d9c67d97d6f | 1317 | /* First part of this stage computes the MAC operations greater than 4 */ |
emh203 | 0:3d9c67d97d6f | 1318 | /* Second part of this stage computes the MAC operations less than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 1319 | |
emh203 | 0:3d9c67d97d6f | 1320 | /* The first part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 1321 | j = blockSize3 >> 2u; |
emh203 | 0:3d9c67d97d6f | 1322 | |
emh203 | 0:3d9c67d97d6f | 1323 | while((j > 0u) && (blockSize3 > 0u)) |
emh203 | 0:3d9c67d97d6f | 1324 | { |
emh203 | 0:3d9c67d97d6f | 1325 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 1326 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 1327 | |
emh203 | 0:3d9c67d97d6f | 1328 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 1329 | k = blockSize3 >> 2u; |
emh203 | 0:3d9c67d97d6f | 1330 | |
emh203 | 0:3d9c67d97d6f | 1331 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 1332 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 1333 | py++; |
emh203 | 0:3d9c67d97d6f | 1334 | |
emh203 | 0:3d9c67d97d6f | 1335 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1336 | { |
emh203 | 0:3d9c67d97d6f | 1337 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1338 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1339 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1340 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1341 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1342 | k--; |
emh203 | 0:3d9c67d97d6f | 1343 | } |
emh203 | 0:3d9c67d97d6f | 1344 | |
emh203 | 0:3d9c67d97d6f | 1345 | /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 1346 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 1347 | k = blockSize3 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 1348 | |
emh203 | 0:3d9c67d97d6f | 1349 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1350 | { |
emh203 | 0:3d9c67d97d6f | 1351 | /* sum += x[srcALen - srcBLen + 5] * y[srcBLen - 5] */ |
emh203 | 0:3d9c67d97d6f | 1352 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1353 | |
emh203 | 0:3d9c67d97d6f | 1354 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1355 | k--; |
emh203 | 0:3d9c67d97d6f | 1356 | } |
emh203 | 0:3d9c67d97d6f | 1357 | |
emh203 | 0:3d9c67d97d6f | 1358 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 1359 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 1360 | |
emh203 | 0:3d9c67d97d6f | 1361 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 1362 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 1363 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 1364 | |
emh203 | 0:3d9c67d97d6f | 1365 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1366 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 1367 | |
emh203 | 0:3d9c67d97d6f | 1368 | j--; |
emh203 | 0:3d9c67d97d6f | 1369 | } |
emh203 | 0:3d9c67d97d6f | 1370 | |
emh203 | 0:3d9c67d97d6f | 1371 | /* The second part of the stage starts here */ |
emh203 | 0:3d9c67d97d6f | 1372 | /* SIMD is not used for the next MAC operations, |
emh203 | 0:3d9c67d97d6f | 1373 | * so pointer py is updated to read only one sample at a time */ |
emh203 | 0:3d9c67d97d6f | 1374 | py = py + 1u; |
emh203 | 0:3d9c67d97d6f | 1375 | |
emh203 | 0:3d9c67d97d6f | 1376 | while(blockSize3 > 0u) |
emh203 | 0:3d9c67d97d6f | 1377 | { |
emh203 | 0:3d9c67d97d6f | 1378 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 1379 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 1380 | |
emh203 | 0:3d9c67d97d6f | 1381 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 1382 | k = blockSize3; |
emh203 | 0:3d9c67d97d6f | 1383 | |
emh203 | 0:3d9c67d97d6f | 1384 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 1385 | { |
emh203 | 0:3d9c67d97d6f | 1386 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 1387 | /* sum += x[srcALen-1] * y[srcBLen-1] */ |
emh203 | 0:3d9c67d97d6f | 1388 | sum += ((q31_t) * px++ * *py--); |
emh203 | 0:3d9c67d97d6f | 1389 | |
emh203 | 0:3d9c67d97d6f | 1390 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1391 | k--; |
emh203 | 0:3d9c67d97d6f | 1392 | } |
emh203 | 0:3d9c67d97d6f | 1393 | |
emh203 | 0:3d9c67d97d6f | 1394 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 1395 | *pOut++ = (q15_t) (sum >> 15); |
emh203 | 0:3d9c67d97d6f | 1396 | |
emh203 | 0:3d9c67d97d6f | 1397 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 1398 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 1399 | py = pSrc2; |
emh203 | 0:3d9c67d97d6f | 1400 | |
emh203 | 0:3d9c67d97d6f | 1401 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 1402 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 1403 | } |
emh203 | 0:3d9c67d97d6f | 1404 | |
emh203 | 0:3d9c67d97d6f | 1405 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
emh203 | 0:3d9c67d97d6f | 1406 | } |
emh203 | 0:3d9c67d97d6f | 1407 | |
emh203 | 0:3d9c67d97d6f | 1408 | /** |
emh203 | 0:3d9c67d97d6f | 1409 | * @} end of Conv group |
emh203 | 0:3d9c67d97d6f | 1410 | */ |