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

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?

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