CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
mbed_official
Date:
Fri Nov 20 08:45:18 2015 +0000
Revision:
5:3762170b6d4d
Parent:
3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b

Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/

Added option to build rpc library. closes #1426

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 5:3762170b6d4d 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 5:3762170b6d4d 4 * $Date: 19. March 2015
mbed_official 5:3762170b6d4d 5 * $Revision: V.1.4.5
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_fir_sparse_q31.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Q31 sparse FIR filter processing function.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * ------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @addtogroup FIR_Sparse
emilmont 1:fdd22bb7aa52 45 * @{
emilmont 1:fdd22bb7aa52 46 */
emilmont 1:fdd22bb7aa52 47
emilmont 1:fdd22bb7aa52 48 /**
emilmont 1:fdd22bb7aa52 49 * @brief Processing function for the Q31 sparse FIR filter.
emilmont 1:fdd22bb7aa52 50 * @param[in] *S points to an instance of the Q31 sparse FIR structure.
emilmont 1:fdd22bb7aa52 51 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 52 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 53 * @param[in] *pScratchIn points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 54 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 55 * @return none.
emilmont 1:fdd22bb7aa52 56 *
emilmont 1:fdd22bb7aa52 57 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 58 * \par
emilmont 1:fdd22bb7aa52 59 * The function is implemented using an internal 32-bit accumulator.
emilmont 1:fdd22bb7aa52 60 * The 1.31 x 1.31 multiplications are truncated to 2.30 format.
emilmont 1:fdd22bb7aa52 61 * This leads to loss of precision on the intermediate multiplications and provides only a single guard bit.
emilmont 1:fdd22bb7aa52 62 * If the accumulator result overflows, it wraps around rather than saturate.
emilmont 1:fdd22bb7aa52 63 * In order to avoid overflows the input signal or coefficients must be scaled down by log2(numTaps) bits.
emilmont 1:fdd22bb7aa52 64 */
emilmont 1:fdd22bb7aa52 65
emilmont 1:fdd22bb7aa52 66 void arm_fir_sparse_q31(
emilmont 1:fdd22bb7aa52 67 arm_fir_sparse_instance_q31 * S,
emilmont 1:fdd22bb7aa52 68 q31_t * pSrc,
emilmont 1:fdd22bb7aa52 69 q31_t * pDst,
emilmont 1:fdd22bb7aa52 70 q31_t * pScratchIn,
emilmont 1:fdd22bb7aa52 71 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 72 {
emilmont 1:fdd22bb7aa52 73
emilmont 1:fdd22bb7aa52 74 q31_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 75 q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 76 q31_t *px; /* Scratch buffer pointer */
emilmont 1:fdd22bb7aa52 77 q31_t *py = pState; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 78 q31_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */
emilmont 1:fdd22bb7aa52 79 q31_t *pOut; /* Destination pointer */
emilmont 1:fdd22bb7aa52 80 q63_t out; /* Temporary output variable */
emilmont 1:fdd22bb7aa52 81 int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */
emilmont 1:fdd22bb7aa52 82 uint32_t delaySize = S->maxDelay + blockSize; /* state length */
emilmont 1:fdd22bb7aa52 83 uint16_t numTaps = S->numTaps; /* Filter order */
emilmont 1:fdd22bb7aa52 84 int32_t readIndex; /* Read index of the state buffer */
emilmont 1:fdd22bb7aa52 85 uint32_t tapCnt, blkCnt; /* loop counters */
emilmont 1:fdd22bb7aa52 86 q31_t coeff = *pCoeffs++; /* Read the first coefficient value */
emilmont 1:fdd22bb7aa52 87 q31_t in;
emilmont 1:fdd22bb7aa52 88
emilmont 1:fdd22bb7aa52 89
emilmont 1:fdd22bb7aa52 90 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 91 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 92 arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1,
emilmont 1:fdd22bb7aa52 93 (int32_t *) pSrc, 1, blockSize);
emilmont 1:fdd22bb7aa52 94
emilmont 1:fdd22bb7aa52 95 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 96 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 97
emilmont 1:fdd22bb7aa52 98 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 99 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 100 {
emilmont 1:fdd22bb7aa52 101 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 102 }
emilmont 1:fdd22bb7aa52 103
emilmont 1:fdd22bb7aa52 104 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 105 py = pState;
emilmont 1:fdd22bb7aa52 106
emilmont 1:fdd22bb7aa52 107 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 108 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 109 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 110 blockSize);
emilmont 1:fdd22bb7aa52 111
emilmont 1:fdd22bb7aa52 112 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 113 px = pb;
emilmont 1:fdd22bb7aa52 114
emilmont 1:fdd22bb7aa52 115 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 116 pOut = pDst;
emilmont 1:fdd22bb7aa52 117
emilmont 1:fdd22bb7aa52 118
mbed_official 3:7a284390b0ce 119 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 122
emilmont 1:fdd22bb7aa52 123 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 124 * Compute 4 Multiplications at a time. */
emilmont 1:fdd22bb7aa52 125 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 126
emilmont 1:fdd22bb7aa52 127 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 128 {
emilmont 1:fdd22bb7aa52 129 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 130 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 131 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 132 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 133 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 134
emilmont 1:fdd22bb7aa52 135 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 136 blkCnt--;
emilmont 1:fdd22bb7aa52 137 }
emilmont 1:fdd22bb7aa52 138
emilmont 1:fdd22bb7aa52 139 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 140 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 141 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 142
emilmont 1:fdd22bb7aa52 143 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 144 {
emilmont 1:fdd22bb7aa52 145 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 146 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 147
emilmont 1:fdd22bb7aa52 148 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 149 blkCnt--;
emilmont 1:fdd22bb7aa52 150 }
emilmont 1:fdd22bb7aa52 151
emilmont 1:fdd22bb7aa52 152 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 153 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 154 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 155
emilmont 1:fdd22bb7aa52 156 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 157 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 160 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 161 {
emilmont 1:fdd22bb7aa52 162 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 163 }
emilmont 1:fdd22bb7aa52 164
emilmont 1:fdd22bb7aa52 165 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 166 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 167
emilmont 1:fdd22bb7aa52 168 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 169 {
emilmont 1:fdd22bb7aa52 170 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 171 py = pState;
emilmont 1:fdd22bb7aa52 172
emilmont 1:fdd22bb7aa52 173 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 174 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 175 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 176 blockSize);
emilmont 1:fdd22bb7aa52 177
emilmont 1:fdd22bb7aa52 178 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 179 px = pb;
emilmont 1:fdd22bb7aa52 180
emilmont 1:fdd22bb7aa52 181 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 182 pOut = pDst;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 185 * Compute 4 MACS at a time. */
emilmont 1:fdd22bb7aa52 186 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 189 {
emilmont 1:fdd22bb7aa52 190 out = *pOut;
emilmont 1:fdd22bb7aa52 191 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 192 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 out = *pOut;
emilmont 1:fdd22bb7aa52 195 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 196 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 out = *pOut;
emilmont 1:fdd22bb7aa52 199 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 200 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 201
emilmont 1:fdd22bb7aa52 202 out = *pOut;
emilmont 1:fdd22bb7aa52 203 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 204 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 205
emilmont 1:fdd22bb7aa52 206 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 207 blkCnt--;
emilmont 1:fdd22bb7aa52 208 }
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 211 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 212 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 215 {
emilmont 1:fdd22bb7aa52 216 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 217 out = *pOut;
emilmont 1:fdd22bb7aa52 218 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 219 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 220
emilmont 1:fdd22bb7aa52 221 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 222 blkCnt--;
emilmont 1:fdd22bb7aa52 223 }
emilmont 1:fdd22bb7aa52 224
emilmont 1:fdd22bb7aa52 225 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 226 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 227 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 228
emilmont 1:fdd22bb7aa52 229 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 230 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 233 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 234 {
emilmont 1:fdd22bb7aa52 235 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 236 }
emilmont 1:fdd22bb7aa52 237
emilmont 1:fdd22bb7aa52 238 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 239 tapCnt--;
emilmont 1:fdd22bb7aa52 240 }
mbed_official 5:3762170b6d4d 241
mbed_official 5:3762170b6d4d 242 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 243
mbed_official 5:3762170b6d4d 244 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 245 py = pState;
mbed_official 5:3762170b6d4d 246
mbed_official 5:3762170b6d4d 247 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 248 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
mbed_official 5:3762170b6d4d 249 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
mbed_official 5:3762170b6d4d 250 blockSize);
mbed_official 5:3762170b6d4d 251
mbed_official 5:3762170b6d4d 252 /* Working pointer for the scratch buffer of state values */
mbed_official 5:3762170b6d4d 253 px = pb;
mbed_official 5:3762170b6d4d 254
mbed_official 5:3762170b6d4d 255 /* Working pointer for scratch buffer of output values */
mbed_official 5:3762170b6d4d 256 pOut = pDst;
mbed_official 5:3762170b6d4d 257
mbed_official 5:3762170b6d4d 258 /* Loop over the blockSize. Unroll by a factor of 4.
mbed_official 5:3762170b6d4d 259 * Compute 4 MACS at a time. */
mbed_official 5:3762170b6d4d 260 blkCnt = blockSize >> 2;
mbed_official 5:3762170b6d4d 261
mbed_official 5:3762170b6d4d 262 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 263 {
mbed_official 5:3762170b6d4d 264 out = *pOut;
mbed_official 5:3762170b6d4d 265 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 266 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 267
mbed_official 5:3762170b6d4d 268 out = *pOut;
mbed_official 5:3762170b6d4d 269 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 270 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 271
mbed_official 5:3762170b6d4d 272 out = *pOut;
mbed_official 5:3762170b6d4d 273 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 274 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 275
mbed_official 5:3762170b6d4d 276 out = *pOut;
mbed_official 5:3762170b6d4d 277 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 278 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 279
mbed_official 5:3762170b6d4d 280 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 281 blkCnt--;
mbed_official 5:3762170b6d4d 282 }
mbed_official 5:3762170b6d4d 283
mbed_official 5:3762170b6d4d 284 /* If the blockSize is not a multiple of 4,
mbed_official 5:3762170b6d4d 285 * compute the remaining samples */
mbed_official 5:3762170b6d4d 286 blkCnt = blockSize % 0x4u;
mbed_official 5:3762170b6d4d 287
mbed_official 5:3762170b6d4d 288 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 289 {
mbed_official 5:3762170b6d4d 290 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 291 out = *pOut;
mbed_official 5:3762170b6d4d 292 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 293 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 294
mbed_official 5:3762170b6d4d 295 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 296 blkCnt--;
mbed_official 5:3762170b6d4d 297 }
emilmont 1:fdd22bb7aa52 298
emilmont 1:fdd22bb7aa52 299 /* Working output pointer is updated */
emilmont 1:fdd22bb7aa52 300 pOut = pDst;
emilmont 1:fdd22bb7aa52 301
emilmont 1:fdd22bb7aa52 302 /* Output is converted into 1.31 format. */
emilmont 1:fdd22bb7aa52 303 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 304 * process 4 output samples at a time. */
emilmont 1:fdd22bb7aa52 305 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 308 {
emilmont 1:fdd22bb7aa52 309 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 310 *pOut++ = in;
emilmont 1:fdd22bb7aa52 311 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 312 *pOut++ = in;
emilmont 1:fdd22bb7aa52 313 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 314 *pOut++ = in;
emilmont 1:fdd22bb7aa52 315 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 316 *pOut++ = in;
emilmont 1:fdd22bb7aa52 317
emilmont 1:fdd22bb7aa52 318 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 319 blkCnt--;
emilmont 1:fdd22bb7aa52 320 }
emilmont 1:fdd22bb7aa52 321
emilmont 1:fdd22bb7aa52 322 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 323 * process the remaining output samples */
emilmont 1:fdd22bb7aa52 324 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 325
emilmont 1:fdd22bb7aa52 326 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 327 {
emilmont 1:fdd22bb7aa52 328 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 329 *pOut++ = in;
emilmont 1:fdd22bb7aa52 330
emilmont 1:fdd22bb7aa52 331 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 332 blkCnt--;
emilmont 1:fdd22bb7aa52 333 }
emilmont 1:fdd22bb7aa52 334
emilmont 1:fdd22bb7aa52 335 #else
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 338 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 341 {
emilmont 1:fdd22bb7aa52 342 /* Perform Multiplications and store in the destination buffer */
emilmont 1:fdd22bb7aa52 343 *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32);
emilmont 1:fdd22bb7aa52 344
emilmont 1:fdd22bb7aa52 345 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 346 blkCnt--;
emilmont 1:fdd22bb7aa52 347 }
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 350 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 351 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 354 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 355
emilmont 1:fdd22bb7aa52 356 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 357 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 358 {
emilmont 1:fdd22bb7aa52 359 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 360 }
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 363 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 364
emilmont 1:fdd22bb7aa52 365 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 366 {
emilmont 1:fdd22bb7aa52 367 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 368 py = pState;
emilmont 1:fdd22bb7aa52 369
emilmont 1:fdd22bb7aa52 370 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 371 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
emilmont 1:fdd22bb7aa52 372 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
emilmont 1:fdd22bb7aa52 373 blockSize);
emilmont 1:fdd22bb7aa52 374
emilmont 1:fdd22bb7aa52 375 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 376 px = pb;
emilmont 1:fdd22bb7aa52 377
emilmont 1:fdd22bb7aa52 378 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 379 pOut = pDst;
emilmont 1:fdd22bb7aa52 380
emilmont 1:fdd22bb7aa52 381 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 382
emilmont 1:fdd22bb7aa52 383 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 384 {
emilmont 1:fdd22bb7aa52 385 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 386 out = *pOut;
emilmont 1:fdd22bb7aa52 387 out += ((q63_t) * px++ * coeff) >> 32;
emilmont 1:fdd22bb7aa52 388 *pOut++ = (q31_t) (out);
emilmont 1:fdd22bb7aa52 389
emilmont 1:fdd22bb7aa52 390 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 391 blkCnt--;
emilmont 1:fdd22bb7aa52 392 }
emilmont 1:fdd22bb7aa52 393
emilmont 1:fdd22bb7aa52 394 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 395 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 396 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 397
emilmont 1:fdd22bb7aa52 398 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 399 readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 400
emilmont 1:fdd22bb7aa52 401 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 402 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 403 {
emilmont 1:fdd22bb7aa52 404 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 405 }
emilmont 1:fdd22bb7aa52 406
emilmont 1:fdd22bb7aa52 407 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 408 tapCnt--;
emilmont 1:fdd22bb7aa52 409 }
mbed_official 5:3762170b6d4d 410
mbed_official 5:3762170b6d4d 411 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 412
mbed_official 5:3762170b6d4d 413 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 414 py = pState;
mbed_official 5:3762170b6d4d 415
mbed_official 5:3762170b6d4d 416 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 417 arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1,
mbed_official 5:3762170b6d4d 418 (int32_t *) pb, (int32_t *) pb, blockSize, 1,
mbed_official 5:3762170b6d4d 419 blockSize);
mbed_official 5:3762170b6d4d 420
mbed_official 5:3762170b6d4d 421 /* Working pointer for the scratch buffer of state values */
mbed_official 5:3762170b6d4d 422 px = pb;
mbed_official 5:3762170b6d4d 423
mbed_official 5:3762170b6d4d 424 /* Working pointer for scratch buffer of output values */
mbed_official 5:3762170b6d4d 425 pOut = pDst;
mbed_official 5:3762170b6d4d 426
mbed_official 5:3762170b6d4d 427 blkCnt = blockSize;
mbed_official 5:3762170b6d4d 428
mbed_official 5:3762170b6d4d 429 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 430 {
mbed_official 5:3762170b6d4d 431 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 432 out = *pOut;
mbed_official 5:3762170b6d4d 433 out += ((q63_t) * px++ * coeff) >> 32;
mbed_official 5:3762170b6d4d 434 *pOut++ = (q31_t) (out);
mbed_official 5:3762170b6d4d 435
mbed_official 5:3762170b6d4d 436 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 437 blkCnt--;
mbed_official 5:3762170b6d4d 438 }
emilmont 1:fdd22bb7aa52 439
emilmont 1:fdd22bb7aa52 440 /* Working output pointer is updated */
emilmont 1:fdd22bb7aa52 441 pOut = pDst;
emilmont 1:fdd22bb7aa52 442
emilmont 1:fdd22bb7aa52 443 /* Output is converted into 1.31 format. */
emilmont 1:fdd22bb7aa52 444 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 445
emilmont 1:fdd22bb7aa52 446 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 447 {
emilmont 1:fdd22bb7aa52 448 in = *pOut << 1;
emilmont 1:fdd22bb7aa52 449 *pOut++ = in;
emilmont 1:fdd22bb7aa52 450
emilmont 1:fdd22bb7aa52 451 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 452 blkCnt--;
emilmont 1:fdd22bb7aa52 453 }
emilmont 1:fdd22bb7aa52 454
mbed_official 3:7a284390b0ce 455 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 456
emilmont 1:fdd22bb7aa52 457 }
emilmont 1:fdd22bb7aa52 458
emilmont 1:fdd22bb7aa52 459 /**
emilmont 1:fdd22bb7aa52 460 * @} end of FIR_Sparse group
emilmont 1:fdd22bb7aa52 461 */