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