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_correlate_fast_q31.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_correlate_fast_q31.c |
emh203 | 0:3d9c67d97d6f | 9 | * |
emh203 | 0:3d9c67d97d6f | 10 | * Description: Fast Q31 Correlation. |
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 Corr |
emh203 | 0:3d9c67d97d6f | 49 | * @{ |
emh203 | 0:3d9c67d97d6f | 50 | */ |
emh203 | 0:3d9c67d97d6f | 51 | |
emh203 | 0:3d9c67d97d6f | 52 | /** |
emh203 | 0:3d9c67d97d6f | 53 | * @brief Correlation of Q31 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 2 * max(srcALen, srcBLen) - 1. |
emh203 | 0:3d9c67d97d6f | 59 | * @return none. |
emh203 | 0:3d9c67d97d6f | 60 | * |
emh203 | 0:3d9c67d97d6f | 61 | * @details |
emh203 | 0:3d9c67d97d6f | 62 | * <b>Scaling and Overflow Behavior:</b> |
emh203 | 0:3d9c67d97d6f | 63 | * |
emh203 | 0:3d9c67d97d6f | 64 | * \par |
emh203 | 0:3d9c67d97d6f | 65 | * This function is optimized for speed at the expense of fixed-point precision and overflow protection. |
emh203 | 0:3d9c67d97d6f | 66 | * The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format. |
emh203 | 0:3d9c67d97d6f | 67 | * These intermediate results are accumulated in a 32-bit register in 2.30 format. |
emh203 | 0:3d9c67d97d6f | 68 | * Finally, the accumulator is saturated and converted to a 1.31 result. |
emh203 | 0:3d9c67d97d6f | 69 | * |
emh203 | 0:3d9c67d97d6f | 70 | * \par |
emh203 | 0:3d9c67d97d6f | 71 | * The fast version has the same overflow behavior as the standard version but provides less precision since it discards the low 32 bits of each multiplication result. |
emh203 | 0:3d9c67d97d6f | 72 | * In order to avoid overflows completely the input signals must be scaled down. |
emh203 | 0:3d9c67d97d6f | 73 | * The input signals should be scaled down to avoid intermediate overflows. |
emh203 | 0:3d9c67d97d6f | 74 | * Scale down one of the inputs by 1/min(srcALen, srcBLen)to avoid overflows since a |
emh203 | 0:3d9c67d97d6f | 75 | * maximum of min(srcALen, srcBLen) number of additions is carried internally. |
emh203 | 0:3d9c67d97d6f | 76 | * |
emh203 | 0:3d9c67d97d6f | 77 | * \par |
emh203 | 0:3d9c67d97d6f | 78 | * See <code>arm_correlate_q31()</code> for a slower implementation of this function which uses 64-bit accumulation to provide higher precision. |
emh203 | 0:3d9c67d97d6f | 79 | */ |
emh203 | 0:3d9c67d97d6f | 80 | |
emh203 | 0:3d9c67d97d6f | 81 | void arm_correlate_fast_q31( |
emh203 | 0:3d9c67d97d6f | 82 | q31_t * pSrcA, |
emh203 | 0:3d9c67d97d6f | 83 | uint32_t srcALen, |
emh203 | 0:3d9c67d97d6f | 84 | q31_t * pSrcB, |
emh203 | 0:3d9c67d97d6f | 85 | uint32_t srcBLen, |
emh203 | 0:3d9c67d97d6f | 86 | q31_t * pDst) |
emh203 | 0:3d9c67d97d6f | 87 | { |
emh203 | 0:3d9c67d97d6f | 88 | q31_t *pIn1; /* inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 89 | q31_t *pIn2; /* inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 90 | q31_t *pOut = pDst; /* output pointer */ |
emh203 | 0:3d9c67d97d6f | 91 | q31_t *px; /* Intermediate inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 92 | q31_t *py; /* Intermediate inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 93 | q31_t *pSrc1; /* Intermediate pointers */ |
emh203 | 0:3d9c67d97d6f | 94 | q31_t sum, acc0, acc1, acc2, acc3; /* Accumulators */ |
emh203 | 0:3d9c67d97d6f | 95 | q31_t x0, x1, x2, x3, c0; /* temporary variables for holding input and coefficient values */ |
emh203 | 0:3d9c67d97d6f | 96 | uint32_t j, k = 0u, count, blkCnt, outBlockSize, blockSize1, blockSize2, blockSize3; /* loop counter */ |
emh203 | 0:3d9c67d97d6f | 97 | int32_t inc = 1; /* Destination address modifier */ |
emh203 | 0:3d9c67d97d6f | 98 | |
emh203 | 0:3d9c67d97d6f | 99 | |
emh203 | 0:3d9c67d97d6f | 100 | /* The algorithm implementation is based on the lengths of the inputs. */ |
emh203 | 0:3d9c67d97d6f | 101 | /* srcB is always made to slide across srcA. */ |
emh203 | 0:3d9c67d97d6f | 102 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 103 | if(srcALen >= srcBLen) |
emh203 | 0:3d9c67d97d6f | 104 | { |
emh203 | 0:3d9c67d97d6f | 105 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 106 | pIn1 = (pSrcA); |
emh203 | 0:3d9c67d97d6f | 107 | |
emh203 | 0:3d9c67d97d6f | 108 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 109 | pIn2 = (pSrcB); |
emh203 | 0:3d9c67d97d6f | 110 | |
emh203 | 0:3d9c67d97d6f | 111 | /* Number of output samples is calculated */ |
emh203 | 0:3d9c67d97d6f | 112 | outBlockSize = (2u * srcALen) - 1u; |
emh203 | 0:3d9c67d97d6f | 113 | |
emh203 | 0:3d9c67d97d6f | 114 | /* When srcALen > srcBLen, zero padding is done to srcB |
emh203 | 0:3d9c67d97d6f | 115 | * to make their lengths equal. |
emh203 | 0:3d9c67d97d6f | 116 | * Instead, (outBlockSize - (srcALen + srcBLen - 1)) |
emh203 | 0:3d9c67d97d6f | 117 | * number of output samples are made zero */ |
emh203 | 0:3d9c67d97d6f | 118 | j = outBlockSize - (srcALen + (srcBLen - 1u)); |
emh203 | 0:3d9c67d97d6f | 119 | |
emh203 | 0:3d9c67d97d6f | 120 | /* Updating the pointer position to non zero value */ |
emh203 | 0:3d9c67d97d6f | 121 | pOut += j; |
emh203 | 0:3d9c67d97d6f | 122 | |
emh203 | 0:3d9c67d97d6f | 123 | } |
emh203 | 0:3d9c67d97d6f | 124 | else |
emh203 | 0:3d9c67d97d6f | 125 | { |
emh203 | 0:3d9c67d97d6f | 126 | /* Initialization of inputA pointer */ |
emh203 | 0:3d9c67d97d6f | 127 | pIn1 = (pSrcB); |
emh203 | 0:3d9c67d97d6f | 128 | |
emh203 | 0:3d9c67d97d6f | 129 | /* Initialization of inputB pointer */ |
emh203 | 0:3d9c67d97d6f | 130 | pIn2 = (pSrcA); |
emh203 | 0:3d9c67d97d6f | 131 | |
emh203 | 0:3d9c67d97d6f | 132 | /* srcBLen is always considered as shorter or equal to srcALen */ |
emh203 | 0:3d9c67d97d6f | 133 | j = srcBLen; |
emh203 | 0:3d9c67d97d6f | 134 | srcBLen = srcALen; |
emh203 | 0:3d9c67d97d6f | 135 | srcALen = j; |
emh203 | 0:3d9c67d97d6f | 136 | |
emh203 | 0:3d9c67d97d6f | 137 | /* CORR(x, y) = Reverse order(CORR(y, x)) */ |
emh203 | 0:3d9c67d97d6f | 138 | /* Hence set the destination pointer to point to the last output sample */ |
emh203 | 0:3d9c67d97d6f | 139 | pOut = pDst + ((srcALen + srcBLen) - 2u); |
emh203 | 0:3d9c67d97d6f | 140 | |
emh203 | 0:3d9c67d97d6f | 141 | /* Destination address modifier is set to -1 */ |
emh203 | 0:3d9c67d97d6f | 142 | inc = -1; |
emh203 | 0:3d9c67d97d6f | 143 | |
emh203 | 0:3d9c67d97d6f | 144 | } |
emh203 | 0:3d9c67d97d6f | 145 | |
emh203 | 0:3d9c67d97d6f | 146 | /* The function is internally |
emh203 | 0:3d9c67d97d6f | 147 | * divided into three parts according to the number of multiplications that has to be |
emh203 | 0:3d9c67d97d6f | 148 | * taken place between inputA samples and inputB samples. In the first part of the |
emh203 | 0:3d9c67d97d6f | 149 | * algorithm, the multiplications increase by one for every iteration. |
emh203 | 0:3d9c67d97d6f | 150 | * In the second part of the algorithm, srcBLen number of multiplications are done. |
emh203 | 0:3d9c67d97d6f | 151 | * In the third part of the algorithm, the multiplications decrease by one |
emh203 | 0:3d9c67d97d6f | 152 | * for every iteration.*/ |
emh203 | 0:3d9c67d97d6f | 153 | /* The algorithm is implemented in three stages. |
emh203 | 0:3d9c67d97d6f | 154 | * The loop counters of each stage is initiated here. */ |
emh203 | 0:3d9c67d97d6f | 155 | blockSize1 = srcBLen - 1u; |
emh203 | 0:3d9c67d97d6f | 156 | blockSize2 = srcALen - (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 157 | blockSize3 = blockSize1; |
emh203 | 0:3d9c67d97d6f | 158 | |
emh203 | 0:3d9c67d97d6f | 159 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 160 | * Initializations of stage1 |
emh203 | 0:3d9c67d97d6f | 161 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 162 | |
emh203 | 0:3d9c67d97d6f | 163 | /* sum = x[0] * y[srcBlen - 1] |
emh203 | 0:3d9c67d97d6f | 164 | * sum = x[0] * y[srcBlen - 2] + x[1] * y[srcBlen - 1] |
emh203 | 0:3d9c67d97d6f | 165 | * .... |
emh203 | 0:3d9c67d97d6f | 166 | * sum = x[0] * y[0] + x[1] * y[1] +...+ x[srcBLen - 1] * y[srcBLen - 1] |
emh203 | 0:3d9c67d97d6f | 167 | */ |
emh203 | 0:3d9c67d97d6f | 168 | |
emh203 | 0:3d9c67d97d6f | 169 | /* In this stage the MAC operations are increased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 170 | The count variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 171 | count = 1u; |
emh203 | 0:3d9c67d97d6f | 172 | |
emh203 | 0:3d9c67d97d6f | 173 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 174 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 175 | |
emh203 | 0:3d9c67d97d6f | 176 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 177 | pSrc1 = pIn2 + (srcBLen - 1u); |
emh203 | 0:3d9c67d97d6f | 178 | py = pSrc1; |
emh203 | 0:3d9c67d97d6f | 179 | |
emh203 | 0:3d9c67d97d6f | 180 | /* ------------------------ |
emh203 | 0:3d9c67d97d6f | 181 | * Stage1 process |
emh203 | 0:3d9c67d97d6f | 182 | * ----------------------*/ |
emh203 | 0:3d9c67d97d6f | 183 | |
emh203 | 0:3d9c67d97d6f | 184 | /* The first stage starts here */ |
emh203 | 0:3d9c67d97d6f | 185 | while(blockSize1 > 0u) |
emh203 | 0:3d9c67d97d6f | 186 | { |
emh203 | 0:3d9c67d97d6f | 187 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 188 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 189 | |
emh203 | 0:3d9c67d97d6f | 190 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 191 | k = count >> 2; |
emh203 | 0:3d9c67d97d6f | 192 | |
emh203 | 0:3d9c67d97d6f | 193 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 194 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 195 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 196 | { |
emh203 | 0:3d9c67d97d6f | 197 | /* x[0] * y[srcBLen - 4] */ |
emh203 | 0:3d9c67d97d6f | 198 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 199 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 200 | /* x[1] * y[srcBLen - 3] */ |
emh203 | 0:3d9c67d97d6f | 201 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 202 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 203 | /* x[2] * y[srcBLen - 2] */ |
emh203 | 0:3d9c67d97d6f | 204 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 205 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 206 | /* x[3] * y[srcBLen - 1] */ |
emh203 | 0:3d9c67d97d6f | 207 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 208 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 209 | |
emh203 | 0:3d9c67d97d6f | 210 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 211 | k--; |
emh203 | 0:3d9c67d97d6f | 212 | } |
emh203 | 0:3d9c67d97d6f | 213 | |
emh203 | 0:3d9c67d97d6f | 214 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 215 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 216 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 217 | |
emh203 | 0:3d9c67d97d6f | 218 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 219 | { |
emh203 | 0:3d9c67d97d6f | 220 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 221 | /* x[0] * y[srcBLen - 1] */ |
emh203 | 0:3d9c67d97d6f | 222 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 223 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 224 | |
emh203 | 0:3d9c67d97d6f | 225 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 226 | k--; |
emh203 | 0:3d9c67d97d6f | 227 | } |
emh203 | 0:3d9c67d97d6f | 228 | |
emh203 | 0:3d9c67d97d6f | 229 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 230 | *pOut = sum << 1; |
emh203 | 0:3d9c67d97d6f | 231 | /* Destination pointer is updated according to the address modifier, inc */ |
emh203 | 0:3d9c67d97d6f | 232 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 233 | |
emh203 | 0:3d9c67d97d6f | 234 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 235 | py = pSrc1 - count; |
emh203 | 0:3d9c67d97d6f | 236 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 237 | |
emh203 | 0:3d9c67d97d6f | 238 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 239 | count++; |
emh203 | 0:3d9c67d97d6f | 240 | |
emh203 | 0:3d9c67d97d6f | 241 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 242 | blockSize1--; |
emh203 | 0:3d9c67d97d6f | 243 | } |
emh203 | 0:3d9c67d97d6f | 244 | |
emh203 | 0:3d9c67d97d6f | 245 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 246 | * Initializations of stage2 |
emh203 | 0:3d9c67d97d6f | 247 | * ------------------------*/ |
emh203 | 0:3d9c67d97d6f | 248 | |
emh203 | 0:3d9c67d97d6f | 249 | /* sum = x[0] * y[0] + x[1] * y[1] +...+ x[srcBLen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 250 | * sum = x[1] * y[0] + x[2] * y[1] +...+ x[srcBLen] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 251 | * .... |
emh203 | 0:3d9c67d97d6f | 252 | * sum = x[srcALen-srcBLen-2] * y[0] + x[srcALen-srcBLen-1] * y[1] +...+ x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 253 | */ |
emh203 | 0:3d9c67d97d6f | 254 | |
emh203 | 0:3d9c67d97d6f | 255 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 256 | px = pIn1; |
emh203 | 0:3d9c67d97d6f | 257 | |
emh203 | 0:3d9c67d97d6f | 258 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 259 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 260 | |
emh203 | 0:3d9c67d97d6f | 261 | /* count is index by which the pointer pIn1 to be incremented */ |
emh203 | 0:3d9c67d97d6f | 262 | count = 0u; |
emh203 | 0:3d9c67d97d6f | 263 | |
emh203 | 0:3d9c67d97d6f | 264 | /* ------------------- |
emh203 | 0:3d9c67d97d6f | 265 | * Stage2 process |
emh203 | 0:3d9c67d97d6f | 266 | * ------------------*/ |
emh203 | 0:3d9c67d97d6f | 267 | |
emh203 | 0:3d9c67d97d6f | 268 | /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. |
emh203 | 0:3d9c67d97d6f | 269 | * So, to loop unroll over blockSize2, |
emh203 | 0:3d9c67d97d6f | 270 | * srcBLen should be greater than or equal to 4 */ |
emh203 | 0:3d9c67d97d6f | 271 | if(srcBLen >= 4u) |
emh203 | 0:3d9c67d97d6f | 272 | { |
emh203 | 0:3d9c67d97d6f | 273 | /* Loop unroll over blockSize2, by 4 */ |
emh203 | 0:3d9c67d97d6f | 274 | blkCnt = blockSize2 >> 2u; |
emh203 | 0:3d9c67d97d6f | 275 | |
emh203 | 0:3d9c67d97d6f | 276 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 277 | { |
emh203 | 0:3d9c67d97d6f | 278 | /* Set all accumulators to zero */ |
emh203 | 0:3d9c67d97d6f | 279 | acc0 = 0; |
emh203 | 0:3d9c67d97d6f | 280 | acc1 = 0; |
emh203 | 0:3d9c67d97d6f | 281 | acc2 = 0; |
emh203 | 0:3d9c67d97d6f | 282 | acc3 = 0; |
emh203 | 0:3d9c67d97d6f | 283 | |
emh203 | 0:3d9c67d97d6f | 284 | /* read x[0], x[1], x[2] samples */ |
emh203 | 0:3d9c67d97d6f | 285 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 286 | x1 = *(px++); |
emh203 | 0:3d9c67d97d6f | 287 | x2 = *(px++); |
emh203 | 0:3d9c67d97d6f | 288 | |
emh203 | 0:3d9c67d97d6f | 289 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 290 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 291 | |
emh203 | 0:3d9c67d97d6f | 292 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 293 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 294 | do |
emh203 | 0:3d9c67d97d6f | 295 | { |
emh203 | 0:3d9c67d97d6f | 296 | /* Read y[0] sample */ |
emh203 | 0:3d9c67d97d6f | 297 | c0 = *(py++); |
emh203 | 0:3d9c67d97d6f | 298 | |
emh203 | 0:3d9c67d97d6f | 299 | /* Read x[3] sample */ |
emh203 | 0:3d9c67d97d6f | 300 | x3 = *(px++); |
emh203 | 0:3d9c67d97d6f | 301 | |
emh203 | 0:3d9c67d97d6f | 302 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 303 | /* acc0 += x[0] * y[0] */ |
emh203 | 0:3d9c67d97d6f | 304 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 305 | /* acc1 += x[1] * y[0] */ |
emh203 | 0:3d9c67d97d6f | 306 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 307 | /* acc2 += x[2] * y[0] */ |
emh203 | 0:3d9c67d97d6f | 308 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 309 | /* acc3 += x[3] * y[0] */ |
emh203 | 0:3d9c67d97d6f | 310 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 311 | |
emh203 | 0:3d9c67d97d6f | 312 | /* Read y[1] sample */ |
emh203 | 0:3d9c67d97d6f | 313 | c0 = *(py++); |
emh203 | 0:3d9c67d97d6f | 314 | |
emh203 | 0:3d9c67d97d6f | 315 | /* Read x[4] sample */ |
emh203 | 0:3d9c67d97d6f | 316 | x0 = *(px++); |
emh203 | 0:3d9c67d97d6f | 317 | |
emh203 | 0:3d9c67d97d6f | 318 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 319 | /* acc0 += x[1] * y[1] */ |
emh203 | 0:3d9c67d97d6f | 320 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 321 | /* acc1 += x[2] * y[1] */ |
emh203 | 0:3d9c67d97d6f | 322 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x2 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 323 | /* acc2 += x[3] * y[1] */ |
emh203 | 0:3d9c67d97d6f | 324 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x3 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 325 | /* acc3 += x[4] * y[1] */ |
emh203 | 0:3d9c67d97d6f | 326 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 327 | |
emh203 | 0:3d9c67d97d6f | 328 | /* Read y[2] sample */ |
emh203 | 0:3d9c67d97d6f | 329 | c0 = *(py++); |
emh203 | 0:3d9c67d97d6f | 330 | |
emh203 | 0:3d9c67d97d6f | 331 | /* Read x[5] sample */ |
emh203 | 0:3d9c67d97d6f | 332 | x1 = *(px++); |
emh203 | 0:3d9c67d97d6f | 333 | |
emh203 | 0:3d9c67d97d6f | 334 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 335 | /* acc0 += x[2] * y[2] */ |
emh203 | 0:3d9c67d97d6f | 336 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x2 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 337 | /* acc1 += x[3] * y[2] */ |
emh203 | 0:3d9c67d97d6f | 338 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x3 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 339 | /* acc2 += x[4] * y[2] */ |
emh203 | 0:3d9c67d97d6f | 340 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 341 | /* acc3 += x[5] * y[2] */ |
emh203 | 0:3d9c67d97d6f | 342 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 343 | |
emh203 | 0:3d9c67d97d6f | 344 | /* Read y[3] sample */ |
emh203 | 0:3d9c67d97d6f | 345 | c0 = *(py++); |
emh203 | 0:3d9c67d97d6f | 346 | |
emh203 | 0:3d9c67d97d6f | 347 | /* Read x[6] sample */ |
emh203 | 0:3d9c67d97d6f | 348 | x2 = *(px++); |
emh203 | 0:3d9c67d97d6f | 349 | |
emh203 | 0:3d9c67d97d6f | 350 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 351 | /* acc0 += x[3] * y[3] */ |
emh203 | 0:3d9c67d97d6f | 352 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x3 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 353 | /* acc1 += x[4] * y[3] */ |
emh203 | 0:3d9c67d97d6f | 354 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 355 | /* acc2 += x[5] * y[3] */ |
emh203 | 0:3d9c67d97d6f | 356 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 357 | /* acc3 += x[6] * y[3] */ |
emh203 | 0:3d9c67d97d6f | 358 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x2 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 359 | |
emh203 | 0:3d9c67d97d6f | 360 | |
emh203 | 0:3d9c67d97d6f | 361 | } while(--k); |
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 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 368 | { |
emh203 | 0:3d9c67d97d6f | 369 | /* Read y[4] sample */ |
emh203 | 0:3d9c67d97d6f | 370 | c0 = *(py++); |
emh203 | 0:3d9c67d97d6f | 371 | |
emh203 | 0:3d9c67d97d6f | 372 | /* Read x[7] sample */ |
emh203 | 0:3d9c67d97d6f | 373 | x3 = *(px++); |
emh203 | 0:3d9c67d97d6f | 374 | |
emh203 | 0:3d9c67d97d6f | 375 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 376 | /* acc0 += x[4] * y[4] */ |
emh203 | 0:3d9c67d97d6f | 377 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 378 | /* acc1 += x[5] * y[4] */ |
emh203 | 0:3d9c67d97d6f | 379 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 380 | /* acc2 += x[6] * y[4] */ |
emh203 | 0:3d9c67d97d6f | 381 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 382 | /* acc3 += x[7] * y[4] */ |
emh203 | 0:3d9c67d97d6f | 383 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); |
emh203 | 0:3d9c67d97d6f | 384 | |
emh203 | 0:3d9c67d97d6f | 385 | /* Reuse the present samples for the next MAC */ |
emh203 | 0:3d9c67d97d6f | 386 | x0 = x1; |
emh203 | 0:3d9c67d97d6f | 387 | x1 = x2; |
emh203 | 0:3d9c67d97d6f | 388 | x2 = x3; |
emh203 | 0:3d9c67d97d6f | 389 | |
emh203 | 0:3d9c67d97d6f | 390 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 391 | k--; |
emh203 | 0:3d9c67d97d6f | 392 | } |
emh203 | 0:3d9c67d97d6f | 393 | |
emh203 | 0:3d9c67d97d6f | 394 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 395 | *pOut = (q31_t) (acc0 << 1); |
emh203 | 0:3d9c67d97d6f | 396 | /* Destination pointer is updated according to the address modifier, inc */ |
emh203 | 0:3d9c67d97d6f | 397 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 398 | |
emh203 | 0:3d9c67d97d6f | 399 | *pOut = (q31_t) (acc1 << 1); |
emh203 | 0:3d9c67d97d6f | 400 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 401 | |
emh203 | 0:3d9c67d97d6f | 402 | *pOut = (q31_t) (acc2 << 1); |
emh203 | 0:3d9c67d97d6f | 403 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 404 | |
emh203 | 0:3d9c67d97d6f | 405 | *pOut = (q31_t) (acc3 << 1); |
emh203 | 0:3d9c67d97d6f | 406 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 407 | |
emh203 | 0:3d9c67d97d6f | 408 | /* Increment the pointer pIn1 index, count by 4 */ |
emh203 | 0:3d9c67d97d6f | 409 | count += 4u; |
emh203 | 0:3d9c67d97d6f | 410 | |
emh203 | 0:3d9c67d97d6f | 411 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 412 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 413 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 414 | |
emh203 | 0:3d9c67d97d6f | 415 | |
emh203 | 0:3d9c67d97d6f | 416 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 417 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 418 | } |
emh203 | 0:3d9c67d97d6f | 419 | |
emh203 | 0:3d9c67d97d6f | 420 | /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. |
emh203 | 0:3d9c67d97d6f | 421 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 422 | blkCnt = blockSize2 % 0x4u; |
emh203 | 0:3d9c67d97d6f | 423 | |
emh203 | 0:3d9c67d97d6f | 424 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 425 | { |
emh203 | 0:3d9c67d97d6f | 426 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 427 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 428 | |
emh203 | 0:3d9c67d97d6f | 429 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 430 | k = srcBLen >> 2u; |
emh203 | 0:3d9c67d97d6f | 431 | |
emh203 | 0:3d9c67d97d6f | 432 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 433 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 434 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 435 | { |
emh203 | 0:3d9c67d97d6f | 436 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 437 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 438 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 439 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 440 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 441 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 442 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 443 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 444 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 445 | |
emh203 | 0:3d9c67d97d6f | 446 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 447 | k--; |
emh203 | 0:3d9c67d97d6f | 448 | } |
emh203 | 0:3d9c67d97d6f | 449 | |
emh203 | 0:3d9c67d97d6f | 450 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 451 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 452 | k = srcBLen % 0x4u; |
emh203 | 0:3d9c67d97d6f | 453 | |
emh203 | 0:3d9c67d97d6f | 454 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 455 | { |
emh203 | 0:3d9c67d97d6f | 456 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 457 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 458 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 459 | |
emh203 | 0:3d9c67d97d6f | 460 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 461 | k--; |
emh203 | 0:3d9c67d97d6f | 462 | } |
emh203 | 0:3d9c67d97d6f | 463 | |
emh203 | 0:3d9c67d97d6f | 464 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 465 | *pOut = sum << 1; |
emh203 | 0:3d9c67d97d6f | 466 | /* Destination pointer is updated according to the address modifier, inc */ |
emh203 | 0:3d9c67d97d6f | 467 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 468 | |
emh203 | 0:3d9c67d97d6f | 469 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 470 | count++; |
emh203 | 0:3d9c67d97d6f | 471 | |
emh203 | 0:3d9c67d97d6f | 472 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 473 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 474 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 475 | |
emh203 | 0:3d9c67d97d6f | 476 | |
emh203 | 0:3d9c67d97d6f | 477 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 478 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 479 | } |
emh203 | 0:3d9c67d97d6f | 480 | } |
emh203 | 0:3d9c67d97d6f | 481 | else |
emh203 | 0:3d9c67d97d6f | 482 | { |
emh203 | 0:3d9c67d97d6f | 483 | /* If the srcBLen is not a multiple of 4, |
emh203 | 0:3d9c67d97d6f | 484 | * the blockSize2 loop cannot be unrolled by 4 */ |
emh203 | 0:3d9c67d97d6f | 485 | blkCnt = blockSize2; |
emh203 | 0:3d9c67d97d6f | 486 | |
emh203 | 0:3d9c67d97d6f | 487 | while(blkCnt > 0u) |
emh203 | 0:3d9c67d97d6f | 488 | { |
emh203 | 0:3d9c67d97d6f | 489 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 490 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 491 | |
emh203 | 0:3d9c67d97d6f | 492 | /* Loop over srcBLen */ |
emh203 | 0:3d9c67d97d6f | 493 | k = srcBLen; |
emh203 | 0:3d9c67d97d6f | 494 | |
emh203 | 0:3d9c67d97d6f | 495 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 496 | { |
emh203 | 0:3d9c67d97d6f | 497 | /* Perform the multiply-accumulate */ |
emh203 | 0:3d9c67d97d6f | 498 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 499 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 500 | |
emh203 | 0:3d9c67d97d6f | 501 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 502 | k--; |
emh203 | 0:3d9c67d97d6f | 503 | } |
emh203 | 0:3d9c67d97d6f | 504 | |
emh203 | 0:3d9c67d97d6f | 505 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 506 | *pOut = sum << 1; |
emh203 | 0:3d9c67d97d6f | 507 | /* Destination pointer is updated according to the address modifier, inc */ |
emh203 | 0:3d9c67d97d6f | 508 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 509 | |
emh203 | 0:3d9c67d97d6f | 510 | /* Increment the MAC count */ |
emh203 | 0:3d9c67d97d6f | 511 | count++; |
emh203 | 0:3d9c67d97d6f | 512 | |
emh203 | 0:3d9c67d97d6f | 513 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 514 | px = pIn1 + count; |
emh203 | 0:3d9c67d97d6f | 515 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 516 | |
emh203 | 0:3d9c67d97d6f | 517 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 518 | blkCnt--; |
emh203 | 0:3d9c67d97d6f | 519 | } |
emh203 | 0:3d9c67d97d6f | 520 | } |
emh203 | 0:3d9c67d97d6f | 521 | |
emh203 | 0:3d9c67d97d6f | 522 | /* -------------------------- |
emh203 | 0:3d9c67d97d6f | 523 | * Initializations of stage3 |
emh203 | 0:3d9c67d97d6f | 524 | * -------------------------*/ |
emh203 | 0:3d9c67d97d6f | 525 | |
emh203 | 0:3d9c67d97d6f | 526 | /* sum += x[srcALen-srcBLen+1] * y[0] + x[srcALen-srcBLen+2] * y[1] +...+ x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 527 | * sum += x[srcALen-srcBLen+2] * y[0] + x[srcALen-srcBLen+3] * y[1] +...+ x[srcALen-1] * y[srcBLen-1] |
emh203 | 0:3d9c67d97d6f | 528 | * .... |
emh203 | 0:3d9c67d97d6f | 529 | * sum += x[srcALen-2] * y[0] + x[srcALen-1] * y[1] |
emh203 | 0:3d9c67d97d6f | 530 | * sum += x[srcALen-1] * y[0] |
emh203 | 0:3d9c67d97d6f | 531 | */ |
emh203 | 0:3d9c67d97d6f | 532 | |
emh203 | 0:3d9c67d97d6f | 533 | /* In this stage the MAC operations are decreased by 1 for every iteration. |
emh203 | 0:3d9c67d97d6f | 534 | The count variable holds the number of MAC operations performed */ |
emh203 | 0:3d9c67d97d6f | 535 | count = srcBLen - 1u; |
emh203 | 0:3d9c67d97d6f | 536 | |
emh203 | 0:3d9c67d97d6f | 537 | /* Working pointer of inputA */ |
emh203 | 0:3d9c67d97d6f | 538 | pSrc1 = ((pIn1 + srcALen) - srcBLen) + 1u; |
emh203 | 0:3d9c67d97d6f | 539 | px = pSrc1; |
emh203 | 0:3d9c67d97d6f | 540 | |
emh203 | 0:3d9c67d97d6f | 541 | /* Working pointer of inputB */ |
emh203 | 0:3d9c67d97d6f | 542 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 543 | |
emh203 | 0:3d9c67d97d6f | 544 | /* ------------------- |
emh203 | 0:3d9c67d97d6f | 545 | * Stage3 process |
emh203 | 0:3d9c67d97d6f | 546 | * ------------------*/ |
emh203 | 0:3d9c67d97d6f | 547 | |
emh203 | 0:3d9c67d97d6f | 548 | while(blockSize3 > 0u) |
emh203 | 0:3d9c67d97d6f | 549 | { |
emh203 | 0:3d9c67d97d6f | 550 | /* Accumulator is made zero for every iteration */ |
emh203 | 0:3d9c67d97d6f | 551 | sum = 0; |
emh203 | 0:3d9c67d97d6f | 552 | |
emh203 | 0:3d9c67d97d6f | 553 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
emh203 | 0:3d9c67d97d6f | 554 | k = count >> 2u; |
emh203 | 0:3d9c67d97d6f | 555 | |
emh203 | 0:3d9c67d97d6f | 556 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
emh203 | 0:3d9c67d97d6f | 557 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
emh203 | 0:3d9c67d97d6f | 558 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 559 | { |
emh203 | 0:3d9c67d97d6f | 560 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 561 | /* sum += x[srcALen - srcBLen + 4] * y[3] */ |
emh203 | 0:3d9c67d97d6f | 562 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 563 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 564 | /* sum += x[srcALen - srcBLen + 3] * y[2] */ |
emh203 | 0:3d9c67d97d6f | 565 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 566 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 567 | /* sum += x[srcALen - srcBLen + 2] * y[1] */ |
emh203 | 0:3d9c67d97d6f | 568 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 569 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 570 | /* sum += x[srcALen - srcBLen + 1] * y[0] */ |
emh203 | 0:3d9c67d97d6f | 571 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 572 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 573 | |
emh203 | 0:3d9c67d97d6f | 574 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 575 | k--; |
emh203 | 0:3d9c67d97d6f | 576 | } |
emh203 | 0:3d9c67d97d6f | 577 | |
emh203 | 0:3d9c67d97d6f | 578 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
emh203 | 0:3d9c67d97d6f | 579 | ** No loop unrolling is used. */ |
emh203 | 0:3d9c67d97d6f | 580 | k = count % 0x4u; |
emh203 | 0:3d9c67d97d6f | 581 | |
emh203 | 0:3d9c67d97d6f | 582 | while(k > 0u) |
emh203 | 0:3d9c67d97d6f | 583 | { |
emh203 | 0:3d9c67d97d6f | 584 | /* Perform the multiply-accumulates */ |
emh203 | 0:3d9c67d97d6f | 585 | sum = (q31_t) ((((q63_t) sum << 32) + |
emh203 | 0:3d9c67d97d6f | 586 | ((q63_t) * px++ * (*py++))) >> 32); |
emh203 | 0:3d9c67d97d6f | 587 | |
emh203 | 0:3d9c67d97d6f | 588 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 589 | k--; |
emh203 | 0:3d9c67d97d6f | 590 | } |
emh203 | 0:3d9c67d97d6f | 591 | |
emh203 | 0:3d9c67d97d6f | 592 | /* Store the result in the accumulator in the destination buffer. */ |
emh203 | 0:3d9c67d97d6f | 593 | *pOut = sum << 1; |
emh203 | 0:3d9c67d97d6f | 594 | /* Destination pointer is updated according to the address modifier, inc */ |
emh203 | 0:3d9c67d97d6f | 595 | pOut += inc; |
emh203 | 0:3d9c67d97d6f | 596 | |
emh203 | 0:3d9c67d97d6f | 597 | /* Update the inputA and inputB pointers for next MAC calculation */ |
emh203 | 0:3d9c67d97d6f | 598 | px = ++pSrc1; |
emh203 | 0:3d9c67d97d6f | 599 | py = pIn2; |
emh203 | 0:3d9c67d97d6f | 600 | |
emh203 | 0:3d9c67d97d6f | 601 | /* Decrement the MAC count */ |
emh203 | 0:3d9c67d97d6f | 602 | count--; |
emh203 | 0:3d9c67d97d6f | 603 | |
emh203 | 0:3d9c67d97d6f | 604 | /* Decrement the loop counter */ |
emh203 | 0:3d9c67d97d6f | 605 | blockSize3--; |
emh203 | 0:3d9c67d97d6f | 606 | } |
emh203 | 0:3d9c67d97d6f | 607 | |
emh203 | 0:3d9c67d97d6f | 608 | } |
emh203 | 0:3d9c67d97d6f | 609 | |
emh203 | 0:3d9c67d97d6f | 610 | /** |
emh203 | 0:3d9c67d97d6f | 611 | * @} end of Corr group |
emh203 | 0:3d9c67d97d6f | 612 | */ |