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_q15.c
emh203 0:3d9c67d97d6f 9 *
emh203 0:3d9c67d97d6f 10 * Description: Correlation of Q15 sequences.
emh203 0:3d9c67d97d6f 11 *
emh203 0:3d9c67d97d6f 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emh203 0:3d9c67d97d6f 13 *
emh203 0:3d9c67d97d6f 14 * Redistribution and use in source and binary forms, with or without
emh203 0:3d9c67d97d6f 15 * modification, are permitted provided that the following conditions
emh203 0:3d9c67d97d6f 16 * are met:
emh203 0:3d9c67d97d6f 17 * - Redistributions of source code must retain the above copyright
emh203 0:3d9c67d97d6f 18 * notice, this list of conditions and the following disclaimer.
emh203 0:3d9c67d97d6f 19 * - Redistributions in binary form must reproduce the above copyright
emh203 0:3d9c67d97d6f 20 * notice, this list of conditions and the following disclaimer in
emh203 0:3d9c67d97d6f 21 * the documentation and/or other materials provided with the
emh203 0:3d9c67d97d6f 22 * distribution.
emh203 0:3d9c67d97d6f 23 * - Neither the name of ARM LIMITED nor the names of its contributors
emh203 0:3d9c67d97d6f 24 * may be used to endorse or promote products derived from this
emh203 0:3d9c67d97d6f 25 * software without specific prior written permission.
emh203 0:3d9c67d97d6f 26 *
emh203 0:3d9c67d97d6f 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
emh203 0:3d9c67d97d6f 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
emh203 0:3d9c67d97d6f 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
emh203 0:3d9c67d97d6f 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
emh203 0:3d9c67d97d6f 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
emh203 0:3d9c67d97d6f 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
emh203 0:3d9c67d97d6f 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
emh203 0:3d9c67d97d6f 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
emh203 0:3d9c67d97d6f 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
emh203 0:3d9c67d97d6f 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
emh203 0:3d9c67d97d6f 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
emh203 0:3d9c67d97d6f 38 * POSSIBILITY OF SUCH DAMAGE.
emh203 0:3d9c67d97d6f 39 * -------------------------------------------------------------------- */
emh203 0:3d9c67d97d6f 40
emh203 0:3d9c67d97d6f 41 #include "arm_math.h"
emh203 0:3d9c67d97d6f 42
emh203 0:3d9c67d97d6f 43 /**
emh203 0:3d9c67d97d6f 44 * @ingroup groupFilters
emh203 0:3d9c67d97d6f 45 */
emh203 0:3d9c67d97d6f 46
emh203 0:3d9c67d97d6f 47 /**
emh203 0:3d9c67d97d6f 48 * @addtogroup Corr
emh203 0:3d9c67d97d6f 49 * @{
emh203 0:3d9c67d97d6f 50 */
emh203 0:3d9c67d97d6f 51
emh203 0:3d9c67d97d6f 52 /**
emh203 0:3d9c67d97d6f 53 * @brief Correlation of Q15 sequences.
emh203 0:3d9c67d97d6f 54 * @param[in] *pSrcA points to the first input sequence.
emh203 0:3d9c67d97d6f 55 * @param[in] srcALen length of the first input sequence.
emh203 0:3d9c67d97d6f 56 * @param[in] *pSrcB points to the second input sequence.
emh203 0:3d9c67d97d6f 57 * @param[in] srcBLen length of the second input sequence.
emh203 0:3d9c67d97d6f 58 * @param[out] *pDst points to the location where the output result is written. 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 64-bit internal accumulator.
emh203 0:3d9c67d97d6f 66 * Both inputs are in 1.15 format and multiplications yield a 2.30 result.
emh203 0:3d9c67d97d6f 67 * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format.
emh203 0:3d9c67d97d6f 68 * This approach provides 33 guard bits and there is no risk of overflow.
emh203 0:3d9c67d97d6f 69 * The 34.30 result is then truncated to 34.15 format by discarding the low 15 bits and then saturated to 1.15 format.
emh203 0:3d9c67d97d6f 70 *
emh203 0:3d9c67d97d6f 71 * \par
emh203 0:3d9c67d97d6f 72 * Refer to <code>arm_correlate_fast_q15()</code> for a faster but less precise version of this function for Cortex-M3 and Cortex-M4.
emh203 0:3d9c67d97d6f 73 *
emh203 0:3d9c67d97d6f 74 * \par
emh203 0:3d9c67d97d6f 75 * Refer the function <code>arm_correlate_opt_q15()</code> for a faster implementation of this function using scratch buffers.
emh203 0:3d9c67d97d6f 76 *
emh203 0:3d9c67d97d6f 77 */
emh203 0:3d9c67d97d6f 78
emh203 0:3d9c67d97d6f 79 void arm_correlate_q15(
emh203 0:3d9c67d97d6f 80 q15_t * pSrcA,
emh203 0:3d9c67d97d6f 81 uint32_t srcALen,
emh203 0:3d9c67d97d6f 82 q15_t * pSrcB,
emh203 0:3d9c67d97d6f 83 uint32_t srcBLen,
emh203 0:3d9c67d97d6f 84 q15_t * pDst)
emh203 0:3d9c67d97d6f 85 {
emh203 0:3d9c67d97d6f 86
emh203 0:3d9c67d97d6f 87 #if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE)
emh203 0:3d9c67d97d6f 88
emh203 0:3d9c67d97d6f 89 /* Run the below code for Cortex-M4 and Cortex-M3 */
emh203 0:3d9c67d97d6f 90
emh203 0:3d9c67d97d6f 91 q15_t *pIn1; /* inputA pointer */
emh203 0:3d9c67d97d6f 92 q15_t *pIn2; /* inputB pointer */
emh203 0:3d9c67d97d6f 93 q15_t *pOut = pDst; /* output pointer */
emh203 0:3d9c67d97d6f 94 q63_t sum, acc0, acc1, acc2, acc3; /* Accumulators */
emh203 0:3d9c67d97d6f 95 q15_t *px; /* Intermediate inputA pointer */
emh203 0:3d9c67d97d6f 96 q15_t *py; /* Intermediate inputB pointer */
emh203 0:3d9c67d97d6f 97 q15_t *pSrc1; /* Intermediate pointers */
emh203 0:3d9c67d97d6f 98 q31_t x0, x1, x2, x3, c0; /* 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; /* Destination address modifier */
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 loop 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] * y[srcBLen - 4] , x[1] * y[srcBLen - 3] */
emh203 0:3d9c67d97d6f 211 sum = __SMLALD(*__SIMD32(px)++, *__SIMD32(py)++, sum);
emh203 0:3d9c67d97d6f 212 /* x[3] * y[srcBLen - 1] , x[2] * y[srcBLen - 2] */
emh203 0:3d9c67d97d6f 213 sum = __SMLALD(*__SIMD32(px)++, *__SIMD32(py)++, sum);
emh203 0:3d9c67d97d6f 214
emh203 0:3d9c67d97d6f 215 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 216 k--;
emh203 0:3d9c67d97d6f 217 }
emh203 0:3d9c67d97d6f 218
emh203 0:3d9c67d97d6f 219 /* If the count is not a multiple of 4, compute any remaining MACs here.
emh203 0:3d9c67d97d6f 220 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 221 k = count % 0x4u;
emh203 0:3d9c67d97d6f 222
emh203 0:3d9c67d97d6f 223 while(k > 0u)
emh203 0:3d9c67d97d6f 224 {
emh203 0:3d9c67d97d6f 225 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 226 /* x[0] * y[srcBLen - 1] */
emh203 0:3d9c67d97d6f 227 sum = __SMLALD(*px++, *py++, sum);
emh203 0:3d9c67d97d6f 228
emh203 0:3d9c67d97d6f 229 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 230 k--;
emh203 0:3d9c67d97d6f 231 }
emh203 0:3d9c67d97d6f 232
emh203 0:3d9c67d97d6f 233 /* Store the result in the accumulator in the destination buffer. */
emh203 0:3d9c67d97d6f 234 *pOut = (q15_t) (__SSAT((sum >> 15), 16));
emh203 0:3d9c67d97d6f 235 /* Destination pointer is updated according to the address modifier, inc */
emh203 0:3d9c67d97d6f 236 pOut += inc;
emh203 0:3d9c67d97d6f 237
emh203 0:3d9c67d97d6f 238 /* Update the inputA and inputB pointers for next MAC calculation */
emh203 0:3d9c67d97d6f 239 py = pSrc1 - count;
emh203 0:3d9c67d97d6f 240 px = pIn1;
emh203 0:3d9c67d97d6f 241
emh203 0:3d9c67d97d6f 242 /* Increment the MAC count */
emh203 0:3d9c67d97d6f 243 count++;
emh203 0:3d9c67d97d6f 244
emh203 0:3d9c67d97d6f 245 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 246 blockSize1--;
emh203 0:3d9c67d97d6f 247 }
emh203 0:3d9c67d97d6f 248
emh203 0:3d9c67d97d6f 249 /* --------------------------
emh203 0:3d9c67d97d6f 250 * Initializations of stage2
emh203 0:3d9c67d97d6f 251 * ------------------------*/
emh203 0:3d9c67d97d6f 252
emh203 0:3d9c67d97d6f 253 /* sum = x[0] * y[0] + x[1] * y[1] +...+ x[srcBLen-1] * y[srcBLen-1]
emh203 0:3d9c67d97d6f 254 * sum = x[1] * y[0] + x[2] * y[1] +...+ x[srcBLen] * y[srcBLen-1]
emh203 0:3d9c67d97d6f 255 * ....
emh203 0:3d9c67d97d6f 256 * sum = x[srcALen-srcBLen-2] * y[0] + x[srcALen-srcBLen-1] * y[1] +...+ x[srcALen-1] * y[srcBLen-1]
emh203 0:3d9c67d97d6f 257 */
emh203 0:3d9c67d97d6f 258
emh203 0:3d9c67d97d6f 259 /* Working pointer of inputA */
emh203 0:3d9c67d97d6f 260 px = pIn1;
emh203 0:3d9c67d97d6f 261
emh203 0:3d9c67d97d6f 262 /* Working pointer of inputB */
emh203 0:3d9c67d97d6f 263 py = pIn2;
emh203 0:3d9c67d97d6f 264
emh203 0:3d9c67d97d6f 265 /* count is index by which the pointer pIn1 to be incremented */
emh203 0:3d9c67d97d6f 266 count = 0u;
emh203 0:3d9c67d97d6f 267
emh203 0:3d9c67d97d6f 268 /* -------------------
emh203 0:3d9c67d97d6f 269 * Stage2 process
emh203 0:3d9c67d97d6f 270 * ------------------*/
emh203 0:3d9c67d97d6f 271
emh203 0:3d9c67d97d6f 272 /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed.
emh203 0:3d9c67d97d6f 273 * So, to loop unroll over blockSize2,
emh203 0:3d9c67d97d6f 274 * srcBLen should be greater than or equal to 4, to loop unroll the srcBLen loop */
emh203 0:3d9c67d97d6f 275 if(srcBLen >= 4u)
emh203 0:3d9c67d97d6f 276 {
emh203 0:3d9c67d97d6f 277 /* Loop unroll over blockSize2, by 4 */
emh203 0:3d9c67d97d6f 278 blkCnt = blockSize2 >> 2u;
emh203 0:3d9c67d97d6f 279
emh203 0:3d9c67d97d6f 280 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 281 {
emh203 0:3d9c67d97d6f 282 /* Set all accumulators to zero */
emh203 0:3d9c67d97d6f 283 acc0 = 0;
emh203 0:3d9c67d97d6f 284 acc1 = 0;
emh203 0:3d9c67d97d6f 285 acc2 = 0;
emh203 0:3d9c67d97d6f 286 acc3 = 0;
emh203 0:3d9c67d97d6f 287
emh203 0:3d9c67d97d6f 288 /* read x[0], x[1] samples */
emh203 0:3d9c67d97d6f 289 x0 = *__SIMD32(px);
emh203 0:3d9c67d97d6f 290 /* read x[1], x[2] samples */
emh203 0:3d9c67d97d6f 291 x1 = _SIMD32_OFFSET(px + 1);
emh203 0:3d9c67d97d6f 292 px += 2u;
emh203 0:3d9c67d97d6f 293
emh203 0:3d9c67d97d6f 294 /* Apply loop unrolling and compute 4 MACs simultaneously. */
emh203 0:3d9c67d97d6f 295 k = srcBLen >> 2u;
emh203 0:3d9c67d97d6f 296
emh203 0:3d9c67d97d6f 297 /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
emh203 0:3d9c67d97d6f 298 ** a second loop below computes MACs for the remaining 1 to 3 samples. */
emh203 0:3d9c67d97d6f 299 do
emh203 0:3d9c67d97d6f 300 {
emh203 0:3d9c67d97d6f 301 /* Read the first two inputB samples using SIMD:
emh203 0:3d9c67d97d6f 302 * y[0] and y[1] */
emh203 0:3d9c67d97d6f 303 c0 = *__SIMD32(py)++;
emh203 0:3d9c67d97d6f 304
emh203 0:3d9c67d97d6f 305 /* acc0 += x[0] * y[0] + x[1] * y[1] */
emh203 0:3d9c67d97d6f 306 acc0 = __SMLALD(x0, c0, acc0);
emh203 0:3d9c67d97d6f 307
emh203 0:3d9c67d97d6f 308 /* acc1 += x[1] * y[0] + x[2] * y[1] */
emh203 0:3d9c67d97d6f 309 acc1 = __SMLALD(x1, c0, acc1);
emh203 0:3d9c67d97d6f 310
emh203 0:3d9c67d97d6f 311 /* Read x[2], x[3] */
emh203 0:3d9c67d97d6f 312 x2 = *__SIMD32(px);
emh203 0:3d9c67d97d6f 313
emh203 0:3d9c67d97d6f 314 /* Read x[3], x[4] */
emh203 0:3d9c67d97d6f 315 x3 = _SIMD32_OFFSET(px + 1);
emh203 0:3d9c67d97d6f 316
emh203 0:3d9c67d97d6f 317 /* acc2 += x[2] * y[0] + x[3] * y[1] */
emh203 0:3d9c67d97d6f 318 acc2 = __SMLALD(x2, c0, acc2);
emh203 0:3d9c67d97d6f 319
emh203 0:3d9c67d97d6f 320 /* acc3 += x[3] * y[0] + x[4] * y[1] */
emh203 0:3d9c67d97d6f 321 acc3 = __SMLALD(x3, c0, acc3);
emh203 0:3d9c67d97d6f 322
emh203 0:3d9c67d97d6f 323 /* Read y[2] and y[3] */
emh203 0:3d9c67d97d6f 324 c0 = *__SIMD32(py)++;
emh203 0:3d9c67d97d6f 325
emh203 0:3d9c67d97d6f 326 /* acc0 += x[2] * y[2] + x[3] * y[3] */
emh203 0:3d9c67d97d6f 327 acc0 = __SMLALD(x2, c0, acc0);
emh203 0:3d9c67d97d6f 328
emh203 0:3d9c67d97d6f 329 /* acc1 += x[3] * y[2] + x[4] * y[3] */
emh203 0:3d9c67d97d6f 330 acc1 = __SMLALD(x3, c0, acc1);
emh203 0:3d9c67d97d6f 331
emh203 0:3d9c67d97d6f 332 /* Read x[4], x[5] */
emh203 0:3d9c67d97d6f 333 x0 = _SIMD32_OFFSET(px + 2);
emh203 0:3d9c67d97d6f 334
emh203 0:3d9c67d97d6f 335 /* Read x[5], x[6] */
emh203 0:3d9c67d97d6f 336 x1 = _SIMD32_OFFSET(px + 3);
emh203 0:3d9c67d97d6f 337
emh203 0:3d9c67d97d6f 338 px += 4u;
emh203 0:3d9c67d97d6f 339
emh203 0:3d9c67d97d6f 340 /* acc2 += x[4] * y[2] + x[5] * y[3] */
emh203 0:3d9c67d97d6f 341 acc2 = __SMLALD(x0, c0, acc2);
emh203 0:3d9c67d97d6f 342
emh203 0:3d9c67d97d6f 343 /* acc3 += x[5] * y[2] + x[6] * y[3] */
emh203 0:3d9c67d97d6f 344 acc3 = __SMLALD(x1, c0, acc3);
emh203 0:3d9c67d97d6f 345
emh203 0:3d9c67d97d6f 346 } while(--k);
emh203 0:3d9c67d97d6f 347
emh203 0:3d9c67d97d6f 348 /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
emh203 0:3d9c67d97d6f 349 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 350 k = srcBLen % 0x4u;
emh203 0:3d9c67d97d6f 351
emh203 0:3d9c67d97d6f 352 if(k == 1u)
emh203 0:3d9c67d97d6f 353 {
emh203 0:3d9c67d97d6f 354 /* Read y[4] */
emh203 0:3d9c67d97d6f 355 c0 = *py;
emh203 0:3d9c67d97d6f 356 #ifdef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 357
emh203 0:3d9c67d97d6f 358 c0 = c0 << 16u;
emh203 0:3d9c67d97d6f 359
emh203 0:3d9c67d97d6f 360 #else
emh203 0:3d9c67d97d6f 361
emh203 0:3d9c67d97d6f 362 c0 = c0 & 0x0000FFFF;
emh203 0:3d9c67d97d6f 363
emh203 0:3d9c67d97d6f 364 #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 365 /* Read x[7] */
emh203 0:3d9c67d97d6f 366 x3 = *__SIMD32(px);
emh203 0:3d9c67d97d6f 367 px++;
emh203 0:3d9c67d97d6f 368
emh203 0:3d9c67d97d6f 369 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 370 acc0 = __SMLALD(x0, c0, acc0);
emh203 0:3d9c67d97d6f 371 acc1 = __SMLALD(x1, c0, acc1);
emh203 0:3d9c67d97d6f 372 acc2 = __SMLALDX(x1, c0, acc2);
emh203 0:3d9c67d97d6f 373 acc3 = __SMLALDX(x3, c0, acc3);
emh203 0:3d9c67d97d6f 374 }
emh203 0:3d9c67d97d6f 375
emh203 0:3d9c67d97d6f 376 if(k == 2u)
emh203 0:3d9c67d97d6f 377 {
emh203 0:3d9c67d97d6f 378 /* Read y[4], y[5] */
emh203 0:3d9c67d97d6f 379 c0 = *__SIMD32(py);
emh203 0:3d9c67d97d6f 380
emh203 0:3d9c67d97d6f 381 /* Read x[7], x[8] */
emh203 0:3d9c67d97d6f 382 x3 = *__SIMD32(px);
emh203 0:3d9c67d97d6f 383
emh203 0:3d9c67d97d6f 384 /* Read x[9] */
emh203 0:3d9c67d97d6f 385 x2 = _SIMD32_OFFSET(px + 1);
emh203 0:3d9c67d97d6f 386 px += 2u;
emh203 0:3d9c67d97d6f 387
emh203 0:3d9c67d97d6f 388 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 389 acc0 = __SMLALD(x0, c0, acc0);
emh203 0:3d9c67d97d6f 390 acc1 = __SMLALD(x1, c0, acc1);
emh203 0:3d9c67d97d6f 391 acc2 = __SMLALD(x3, c0, acc2);
emh203 0:3d9c67d97d6f 392 acc3 = __SMLALD(x2, c0, acc3);
emh203 0:3d9c67d97d6f 393 }
emh203 0:3d9c67d97d6f 394
emh203 0:3d9c67d97d6f 395 if(k == 3u)
emh203 0:3d9c67d97d6f 396 {
emh203 0:3d9c67d97d6f 397 /* Read y[4], y[5] */
emh203 0:3d9c67d97d6f 398 c0 = *__SIMD32(py)++;
emh203 0:3d9c67d97d6f 399
emh203 0:3d9c67d97d6f 400 /* Read x[7], x[8] */
emh203 0:3d9c67d97d6f 401 x3 = *__SIMD32(px);
emh203 0:3d9c67d97d6f 402
emh203 0:3d9c67d97d6f 403 /* Read x[9] */
emh203 0:3d9c67d97d6f 404 x2 = _SIMD32_OFFSET(px + 1);
emh203 0:3d9c67d97d6f 405
emh203 0:3d9c67d97d6f 406 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 407 acc0 = __SMLALD(x0, c0, acc0);
emh203 0:3d9c67d97d6f 408 acc1 = __SMLALD(x1, c0, acc1);
emh203 0:3d9c67d97d6f 409 acc2 = __SMLALD(x3, c0, acc2);
emh203 0:3d9c67d97d6f 410 acc3 = __SMLALD(x2, c0, acc3);
emh203 0:3d9c67d97d6f 411
emh203 0:3d9c67d97d6f 412 c0 = (*py);
emh203 0:3d9c67d97d6f 413
emh203 0:3d9c67d97d6f 414 /* Read y[6] */
emh203 0:3d9c67d97d6f 415 #ifdef ARM_MATH_BIG_ENDIAN
emh203 0:3d9c67d97d6f 416
emh203 0:3d9c67d97d6f 417 c0 = c0 << 16u;
emh203 0:3d9c67d97d6f 418 #else
emh203 0:3d9c67d97d6f 419
emh203 0:3d9c67d97d6f 420 c0 = c0 & 0x0000FFFF;
emh203 0:3d9c67d97d6f 421 #endif /* #ifdef ARM_MATH_BIG_ENDIAN */
emh203 0:3d9c67d97d6f 422 /* Read x[10] */
emh203 0:3d9c67d97d6f 423 x3 = _SIMD32_OFFSET(px + 2);
emh203 0:3d9c67d97d6f 424 px += 3u;
emh203 0:3d9c67d97d6f 425
emh203 0:3d9c67d97d6f 426 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 427 acc0 = __SMLALDX(x1, c0, acc0);
emh203 0:3d9c67d97d6f 428 acc1 = __SMLALD(x2, c0, acc1);
emh203 0:3d9c67d97d6f 429 acc2 = __SMLALDX(x2, c0, acc2);
emh203 0:3d9c67d97d6f 430 acc3 = __SMLALDX(x3, c0, acc3);
emh203 0:3d9c67d97d6f 431 }
emh203 0:3d9c67d97d6f 432
emh203 0:3d9c67d97d6f 433 /* Store the result in the accumulator in the destination buffer. */
emh203 0:3d9c67d97d6f 434 *pOut = (q15_t) (__SSAT(acc0 >> 15, 16));
emh203 0:3d9c67d97d6f 435 /* Destination pointer is updated according to the address modifier, inc */
emh203 0:3d9c67d97d6f 436 pOut += inc;
emh203 0:3d9c67d97d6f 437
emh203 0:3d9c67d97d6f 438 *pOut = (q15_t) (__SSAT(acc1 >> 15, 16));
emh203 0:3d9c67d97d6f 439 pOut += inc;
emh203 0:3d9c67d97d6f 440
emh203 0:3d9c67d97d6f 441 *pOut = (q15_t) (__SSAT(acc2 >> 15, 16));
emh203 0:3d9c67d97d6f 442 pOut += inc;
emh203 0:3d9c67d97d6f 443
emh203 0:3d9c67d97d6f 444 *pOut = (q15_t) (__SSAT(acc3 >> 15, 16));
emh203 0:3d9c67d97d6f 445 pOut += inc;
emh203 0:3d9c67d97d6f 446
emh203 0:3d9c67d97d6f 447 /* Increment the count by 4 as 4 output values are computed */
emh203 0:3d9c67d97d6f 448 count += 4u;
emh203 0:3d9c67d97d6f 449
emh203 0:3d9c67d97d6f 450 /* Update the inputA and inputB pointers for next MAC calculation */
emh203 0:3d9c67d97d6f 451 px = pIn1 + count;
emh203 0:3d9c67d97d6f 452 py = pIn2;
emh203 0:3d9c67d97d6f 453
emh203 0:3d9c67d97d6f 454 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 455 blkCnt--;
emh203 0:3d9c67d97d6f 456 }
emh203 0:3d9c67d97d6f 457
emh203 0:3d9c67d97d6f 458 /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here.
emh203 0:3d9c67d97d6f 459 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 460 blkCnt = blockSize2 % 0x4u;
emh203 0:3d9c67d97d6f 461
emh203 0:3d9c67d97d6f 462 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 463 {
emh203 0:3d9c67d97d6f 464 /* Accumulator is made zero for every iteration */
emh203 0:3d9c67d97d6f 465 sum = 0;
emh203 0:3d9c67d97d6f 466
emh203 0:3d9c67d97d6f 467 /* Apply loop unrolling and compute 4 MACs simultaneously. */
emh203 0:3d9c67d97d6f 468 k = srcBLen >> 2u;
emh203 0:3d9c67d97d6f 469
emh203 0:3d9c67d97d6f 470 /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
emh203 0:3d9c67d97d6f 471 ** a second loop below computes MACs for the remaining 1 to 3 samples. */
emh203 0:3d9c67d97d6f 472 while(k > 0u)
emh203 0:3d9c67d97d6f 473 {
emh203 0:3d9c67d97d6f 474 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 475 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 476 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 477 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 478 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 479
emh203 0:3d9c67d97d6f 480 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 481 k--;
emh203 0:3d9c67d97d6f 482 }
emh203 0:3d9c67d97d6f 483
emh203 0:3d9c67d97d6f 484 /* If the srcBLen is not a multiple of 4, compute any remaining MACs here.
emh203 0:3d9c67d97d6f 485 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 486 k = srcBLen % 0x4u;
emh203 0:3d9c67d97d6f 487
emh203 0:3d9c67d97d6f 488 while(k > 0u)
emh203 0:3d9c67d97d6f 489 {
emh203 0:3d9c67d97d6f 490 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 491 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 492
emh203 0:3d9c67d97d6f 493 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 494 k--;
emh203 0:3d9c67d97d6f 495 }
emh203 0:3d9c67d97d6f 496
emh203 0:3d9c67d97d6f 497 /* Store the result in the accumulator in the destination buffer. */
emh203 0:3d9c67d97d6f 498 *pOut = (q15_t) (__SSAT(sum >> 15, 16));
emh203 0:3d9c67d97d6f 499 /* Destination pointer is updated according to the address modifier, inc */
emh203 0:3d9c67d97d6f 500 pOut += inc;
emh203 0:3d9c67d97d6f 501
emh203 0:3d9c67d97d6f 502 /* Increment count by 1, as one output value is computed */
emh203 0:3d9c67d97d6f 503 count++;
emh203 0:3d9c67d97d6f 504
emh203 0:3d9c67d97d6f 505 /* Update the inputA and inputB pointers for next MAC calculation */
emh203 0:3d9c67d97d6f 506 px = pIn1 + count;
emh203 0:3d9c67d97d6f 507 py = pIn2;
emh203 0:3d9c67d97d6f 508
emh203 0:3d9c67d97d6f 509 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 510 blkCnt--;
emh203 0:3d9c67d97d6f 511 }
emh203 0:3d9c67d97d6f 512 }
emh203 0:3d9c67d97d6f 513 else
emh203 0:3d9c67d97d6f 514 {
emh203 0:3d9c67d97d6f 515 /* If the srcBLen is not a multiple of 4,
emh203 0:3d9c67d97d6f 516 * the blockSize2 loop cannot be unrolled by 4 */
emh203 0:3d9c67d97d6f 517 blkCnt = blockSize2;
emh203 0:3d9c67d97d6f 518
emh203 0:3d9c67d97d6f 519 while(blkCnt > 0u)
emh203 0:3d9c67d97d6f 520 {
emh203 0:3d9c67d97d6f 521 /* Accumulator is made zero for every iteration */
emh203 0:3d9c67d97d6f 522 sum = 0;
emh203 0:3d9c67d97d6f 523
emh203 0:3d9c67d97d6f 524 /* Loop over srcBLen */
emh203 0:3d9c67d97d6f 525 k = srcBLen;
emh203 0:3d9c67d97d6f 526
emh203 0:3d9c67d97d6f 527 while(k > 0u)
emh203 0:3d9c67d97d6f 528 {
emh203 0:3d9c67d97d6f 529 /* Perform the multiply-accumulate */
emh203 0:3d9c67d97d6f 530 sum += ((q63_t) * px++ * *py++);
emh203 0:3d9c67d97d6f 531
emh203 0:3d9c67d97d6f 532 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 533 k--;
emh203 0:3d9c67d97d6f 534 }
emh203 0:3d9c67d97d6f 535
emh203 0:3d9c67d97d6f 536 /* Store the result in the accumulator in the destination buffer. */
emh203 0:3d9c67d97d6f 537 *pOut = (q15_t) (__SSAT(sum >> 15, 16));
emh203 0:3d9c67d97d6f 538 /* Destination pointer is updated according to the address modifier, inc */
emh203 0:3d9c67d97d6f 539 pOut += inc;
emh203 0:3d9c67d97d6f 540
emh203 0:3d9c67d97d6f 541 /* Increment the MAC count */
emh203 0:3d9c67d97d6f 542 count++;
emh203 0:3d9c67d97d6f 543
emh203 0:3d9c67d97d6f 544 /* Update the inputA and inputB pointers for next MAC calculation */
emh203 0:3d9c67d97d6f 545 px = pIn1 + count;
emh203 0:3d9c67d97d6f 546 py = pIn2;
emh203 0:3d9c67d97d6f 547
emh203 0:3d9c67d97d6f 548 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 549 blkCnt--;
emh203 0:3d9c67d97d6f 550 }
emh203 0:3d9c67d97d6f 551 }
emh203 0:3d9c67d97d6f 552
emh203 0:3d9c67d97d6f 553 /* --------------------------
emh203 0:3d9c67d97d6f 554 * Initializations of stage3
emh203 0:3d9c67d97d6f 555 * -------------------------*/
emh203 0:3d9c67d97d6f 556
emh203 0:3d9c67d97d6f 557 /* sum += x[srcALen-srcBLen+1] * y[0] + x[srcALen-srcBLen+2] * y[1] +...+ x[srcALen-1] * y[srcBLen-1]
emh203 0:3d9c67d97d6f 558 * sum += x[srcALen-srcBLen+2] * y[0] + x[srcALen-srcBLen+3] * y[1] +...+ x[srcALen-1] * y[srcBLen-1]
emh203 0:3d9c67d97d6f 559 * ....
emh203 0:3d9c67d97d6f 560 * sum += x[srcALen-2] * y[0] + x[srcALen-1] * y[1]
emh203 0:3d9c67d97d6f 561 * sum += x[srcALen-1] * y[0]
emh203 0:3d9c67d97d6f 562 */
emh203 0:3d9c67d97d6f 563
emh203 0:3d9c67d97d6f 564 /* In this stage the MAC operations are decreased by 1 for every iteration.
emh203 0:3d9c67d97d6f 565 The count variable holds the number of MAC operations performed */
emh203 0:3d9c67d97d6f 566 count = srcBLen - 1u;
emh203 0:3d9c67d97d6f 567
emh203 0:3d9c67d97d6f 568 /* Working pointer of inputA */
emh203 0:3d9c67d97d6f 569 pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);
emh203 0:3d9c67d97d6f 570 px = pSrc1;
emh203 0:3d9c67d97d6f 571
emh203 0:3d9c67d97d6f 572 /* Working pointer of inputB */
emh203 0:3d9c67d97d6f 573 py = pIn2;
emh203 0:3d9c67d97d6f 574
emh203 0:3d9c67d97d6f 575 /* -------------------
emh203 0:3d9c67d97d6f 576 * Stage3 process
emh203 0:3d9c67d97d6f 577 * ------------------*/
emh203 0:3d9c67d97d6f 578
emh203 0:3d9c67d97d6f 579 while(blockSize3 > 0u)
emh203 0:3d9c67d97d6f 580 {
emh203 0:3d9c67d97d6f 581 /* Accumulator is made zero for every iteration */
emh203 0:3d9c67d97d6f 582 sum = 0;
emh203 0:3d9c67d97d6f 583
emh203 0:3d9c67d97d6f 584 /* Apply loop unrolling and compute 4 MACs simultaneously. */
emh203 0:3d9c67d97d6f 585 k = count >> 2u;
emh203 0:3d9c67d97d6f 586
emh203 0:3d9c67d97d6f 587 /* First part of the processing with loop unrolling. Compute 4 MACs at a time.
emh203 0:3d9c67d97d6f 588 ** a second loop below computes MACs for the remaining 1 to 3 samples. */
emh203 0:3d9c67d97d6f 589 while(k > 0u)
emh203 0:3d9c67d97d6f 590 {
emh203 0:3d9c67d97d6f 591 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 592 /* sum += x[srcALen - srcBLen + 4] * y[3] , sum += x[srcALen - srcBLen + 3] * y[2] */
emh203 0:3d9c67d97d6f 593 sum = __SMLALD(*__SIMD32(px)++, *__SIMD32(py)++, sum);
emh203 0:3d9c67d97d6f 594 /* sum += x[srcALen - srcBLen + 2] * y[1] , sum += x[srcALen - srcBLen + 1] * y[0] */
emh203 0:3d9c67d97d6f 595 sum = __SMLALD(*__SIMD32(px)++, *__SIMD32(py)++, sum);
emh203 0:3d9c67d97d6f 596
emh203 0:3d9c67d97d6f 597 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 598 k--;
emh203 0:3d9c67d97d6f 599 }
emh203 0:3d9c67d97d6f 600
emh203 0:3d9c67d97d6f 601 /* If the count is not a multiple of 4, compute any remaining MACs here.
emh203 0:3d9c67d97d6f 602 ** No loop unrolling is used. */
emh203 0:3d9c67d97d6f 603 k = count % 0x4u;
emh203 0:3d9c67d97d6f 604
emh203 0:3d9c67d97d6f 605 while(k > 0u)
emh203 0:3d9c67d97d6f 606 {
emh203 0:3d9c67d97d6f 607 /* Perform the multiply-accumulates */
emh203 0:3d9c67d97d6f 608 sum = __SMLALD(*px++, *py++, sum);
emh203 0:3d9c67d97d6f 609
emh203 0:3d9c67d97d6f 610 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 611 k--;
emh203 0:3d9c67d97d6f 612 }
emh203 0:3d9c67d97d6f 613
emh203 0:3d9c67d97d6f 614 /* Store the result in the accumulator in the destination buffer. */
emh203 0:3d9c67d97d6f 615 *pOut = (q15_t) (__SSAT((sum >> 15), 16));
emh203 0:3d9c67d97d6f 616 /* Destination pointer is updated according to the address modifier, inc */
emh203 0:3d9c67d97d6f 617 pOut += inc;
emh203 0:3d9c67d97d6f 618
emh203 0:3d9c67d97d6f 619 /* Update the inputA and inputB pointers for next MAC calculation */
emh203 0:3d9c67d97d6f 620 px = ++pSrc1;
emh203 0:3d9c67d97d6f 621 py = pIn2;
emh203 0:3d9c67d97d6f 622
emh203 0:3d9c67d97d6f 623 /* Decrement the MAC count */
emh203 0:3d9c67d97d6f 624 count--;
emh203 0:3d9c67d97d6f 625
emh203 0:3d9c67d97d6f 626 /* Decrement the loop counter */
emh203 0:3d9c67d97d6f 627 blockSize3--;
emh203 0:3d9c67d97d6f 628 }
emh203 0:3d9c67d97d6f 629
emh203 0:3d9c67d97d6f 630 #else
emh203 0:3d9c67d97d6f 631
emh203 0:3d9c67d97d6f 632 /* Run the below code for Cortex-M0 */
emh203 0:3d9c67d97d6f 633
emh203 0:3d9c67d97d6f 634 q15_t *pIn1 = pSrcA; /* inputA pointer */
emh203 0:3d9c67d97d6f 635 q15_t *pIn2 = pSrcB + (srcBLen - 1u); /* inputB pointer */
emh203 0:3d9c67d97d6f 636 q63_t sum; /* Accumulators */
emh203 0:3d9c67d97d6f 637 uint32_t i = 0u, j; /* loop counters */
emh203 0:3d9c67d97d6f 638 uint32_t inv = 0u; /* Reverse order flag */
emh203 0:3d9c67d97d6f 639 uint32_t tot = 0u; /* Length */
emh203 0:3d9c67d97d6f 640
emh203 0:3d9c67d97d6f 641 /* The algorithm implementation is based on the lengths of the inputs. */
emh203 0:3d9c67d97d6f 642 /* srcB is always made to slide across srcA. */
emh203 0:3d9c67d97d6f 643 /* So srcBLen is always considered as shorter or equal to srcALen */
emh203 0:3d9c67d97d6f 644 /* But CORR(x, y) is reverse of CORR(y, x) */
emh203 0:3d9c67d97d6f 645 /* So, when srcBLen > srcALen, output pointer is made to point to the end of the output buffer */
emh203 0:3d9c67d97d6f 646 /* and a varaible, inv is set to 1 */
emh203 0:3d9c67d97d6f 647 /* If lengths are not equal then zero pad has to be done to make the two
emh203 0:3d9c67d97d6f 648 * inputs of same length. But to improve the performance, we include zeroes
emh203 0:3d9c67d97d6f 649 * in the output instead of zero padding either of the the inputs*/
emh203 0:3d9c67d97d6f 650 /* If srcALen > srcBLen, (srcALen - srcBLen) zeroes has to included in the
emh203 0:3d9c67d97d6f 651 * starting of the output buffer */
emh203 0:3d9c67d97d6f 652 /* If srcALen < srcBLen, (srcALen - srcBLen) zeroes has to included in the
emh203 0:3d9c67d97d6f 653 * ending of the output buffer */
emh203 0:3d9c67d97d6f 654 /* Once the zero padding is done the remaining of the output is calcualted
emh203 0:3d9c67d97d6f 655 * using convolution but with the shorter signal time shifted. */
emh203 0:3d9c67d97d6f 656
emh203 0:3d9c67d97d6f 657 /* Calculate the length of the remaining sequence */
emh203 0:3d9c67d97d6f 658 tot = ((srcALen + srcBLen) - 2u);
emh203 0:3d9c67d97d6f 659
emh203 0:3d9c67d97d6f 660 if(srcALen > srcBLen)
emh203 0:3d9c67d97d6f 661 {
emh203 0:3d9c67d97d6f 662 /* Calculating the number of zeros to be padded to the output */
emh203 0:3d9c67d97d6f 663 j = srcALen - srcBLen;
emh203 0:3d9c67d97d6f 664
emh203 0:3d9c67d97d6f 665 /* Initialise the pointer after zero padding */
emh203 0:3d9c67d97d6f 666 pDst += j;
emh203 0:3d9c67d97d6f 667 }
emh203 0:3d9c67d97d6f 668
emh203 0:3d9c67d97d6f 669 else if(srcALen < srcBLen)
emh203 0:3d9c67d97d6f 670 {
emh203 0:3d9c67d97d6f 671 /* Initialization to inputB pointer */
emh203 0:3d9c67d97d6f 672 pIn1 = pSrcB;
emh203 0:3d9c67d97d6f 673
emh203 0:3d9c67d97d6f 674 /* Initialization to the end of inputA pointer */
emh203 0:3d9c67d97d6f 675 pIn2 = pSrcA + (srcALen - 1u);
emh203 0:3d9c67d97d6f 676
emh203 0:3d9c67d97d6f 677 /* Initialisation of the pointer after zero padding */
emh203 0:3d9c67d97d6f 678 pDst = pDst + tot;
emh203 0:3d9c67d97d6f 679
emh203 0:3d9c67d97d6f 680 /* Swapping the lengths */
emh203 0:3d9c67d97d6f 681 j = srcALen;
emh203 0:3d9c67d97d6f 682 srcALen = srcBLen;
emh203 0:3d9c67d97d6f 683 srcBLen = j;
emh203 0:3d9c67d97d6f 684
emh203 0:3d9c67d97d6f 685 /* Setting the reverse flag */
emh203 0:3d9c67d97d6f 686 inv = 1;
emh203 0:3d9c67d97d6f 687
emh203 0:3d9c67d97d6f 688 }
emh203 0:3d9c67d97d6f 689
emh203 0:3d9c67d97d6f 690 /* Loop to calculate convolution for output length number of times */
emh203 0:3d9c67d97d6f 691 for (i = 0u; i <= tot; i++)
emh203 0:3d9c67d97d6f 692 {
emh203 0:3d9c67d97d6f 693 /* Initialize sum with zero to carry on MAC operations */
emh203 0:3d9c67d97d6f 694 sum = 0;
emh203 0:3d9c67d97d6f 695
emh203 0:3d9c67d97d6f 696 /* Loop to perform MAC operations according to convolution equation */
emh203 0:3d9c67d97d6f 697 for (j = 0u; j <= i; j++)
emh203 0:3d9c67d97d6f 698 {
emh203 0:3d9c67d97d6f 699 /* Check the array limitations */
emh203 0:3d9c67d97d6f 700 if((((i - j) < srcBLen) && (j < srcALen)))
emh203 0:3d9c67d97d6f 701 {
emh203 0:3d9c67d97d6f 702 /* z[i] += x[i-j] * y[j] */
emh203 0:3d9c67d97d6f 703 sum += ((q31_t) pIn1[j] * pIn2[-((int32_t) i - j)]);
emh203 0:3d9c67d97d6f 704 }
emh203 0:3d9c67d97d6f 705 }
emh203 0:3d9c67d97d6f 706 /* Store the output in the destination buffer */
emh203 0:3d9c67d97d6f 707 if(inv == 1)
emh203 0:3d9c67d97d6f 708 *pDst-- = (q15_t) __SSAT((sum >> 15u), 16u);
emh203 0:3d9c67d97d6f 709 else
emh203 0:3d9c67d97d6f 710 *pDst++ = (q15_t) __SSAT((sum >> 15u), 16u);
emh203 0:3d9c67d97d6f 711 }
emh203 0:3d9c67d97d6f 712
emh203 0:3d9c67d97d6f 713 #endif /*#if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE) */
emh203 0:3d9c67d97d6f 714
emh203 0:3d9c67d97d6f 715 }
emh203 0:3d9c67d97d6f 716
emh203 0:3d9c67d97d6f 717 /**
emh203 0:3d9c67d97d6f 718 * @} end of Corr group
emh203 0:3d9c67d97d6f 719 */