V4.0.1 of the ARM CMSIS DSP libraries. Note that arm_bitreversal2.s, arm_cfft_f32.c and arm_rfft_fast_f32.c had to be removed. arm_bitreversal2.s will not assemble with the online tools. So, the fast f32 FFT functions are not yet available. All the other FFT functions are available.
Dependents: MPU9150_Example fir_f32 fir_f32 MPU9150_nucleo_noni2cdev ... more
FilteringFunctions/arm_conv_partial_fast_q31.c@0:3d9c67d97d6f, 2014-07-28 (annotated)
- Committer:
- emh203
- Date:
- Mon Jul 28 15:03:15 2014 +0000
- Revision:
- 0:3d9c67d97d6f
1st working commit. Had to remove arm_bitreversal2.s arm_cfft_f32.c and arm_rfft_fast_f32.c. The .s will not assemble. For now I removed these functions so we could at least have a library for the other functions.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emh203 | 0:3d9c67d97d6f | 1 | /* ---------------------------------------------------------------------- |
| emh203 | 0:3d9c67d97d6f | 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. |
| emh203 | 0:3d9c67d97d6f | 3 | * |
| emh203 | 0:3d9c67d97d6f | 4 | * $Date: 12. March 2014 |
| emh203 | 0:3d9c67d97d6f | 5 | * $Revision: V1.4.3 |
| emh203 | 0:3d9c67d97d6f | 6 | * |
| emh203 | 0:3d9c67d97d6f | 7 | * Project: CMSIS DSP Library |
| emh203 | 0:3d9c67d97d6f | 8 | * Title: arm_conv_partial_fast_q31.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Fast Q31 Partial convolution. |
| emh203 | 0:3d9c67d97d6f | 11 | * |
| emh203 | 0:3d9c67d97d6f | 12 | * Target Processor: Cortex-M4/Cortex-M3 |
| emh203 | 0:3d9c67d97d6f | 13 | * |
| emh203 | 0:3d9c67d97d6f | 14 | * Redistribution and use in source and binary forms, with or without |
| emh203 | 0:3d9c67d97d6f | 15 | * modification, are permitted provided that the following conditions |
| emh203 | 0:3d9c67d97d6f | 16 | * are met: |
| emh203 | 0:3d9c67d97d6f | 17 | * - Redistributions of source code must retain the above copyright |
| emh203 | 0:3d9c67d97d6f | 18 | * notice, this list of conditions and the following disclaimer. |
| emh203 | 0:3d9c67d97d6f | 19 | * - Redistributions in binary form must reproduce the above copyright |
| emh203 | 0:3d9c67d97d6f | 20 | * notice, this list of conditions and the following disclaimer in |
| emh203 | 0:3d9c67d97d6f | 21 | * the documentation and/or other materials provided with the |
| emh203 | 0:3d9c67d97d6f | 22 | * distribution. |
| emh203 | 0:3d9c67d97d6f | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
| emh203 | 0:3d9c67d97d6f | 24 | * may be used to endorse or promote products derived from this |
| emh203 | 0:3d9c67d97d6f | 25 | * software without specific prior written permission. |
| emh203 | 0:3d9c67d97d6f | 26 | * |
| emh203 | 0:3d9c67d97d6f | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| emh203 | 0:3d9c67d97d6f | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| emh203 | 0:3d9c67d97d6f | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| emh203 | 0:3d9c67d97d6f | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| emh203 | 0:3d9c67d97d6f | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| emh203 | 0:3d9c67d97d6f | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| emh203 | 0:3d9c67d97d6f | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| emh203 | 0:3d9c67d97d6f | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| emh203 | 0:3d9c67d97d6f | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| emh203 | 0:3d9c67d97d6f | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| emh203 | 0:3d9c67d97d6f | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| emh203 | 0:3d9c67d97d6f | 38 | * POSSIBILITY OF SUCH DAMAGE. |
| emh203 | 0:3d9c67d97d6f | 39 | * -------------------------------------------------------------------- */ |
| emh203 | 0:3d9c67d97d6f | 40 | |
| emh203 | 0:3d9c67d97d6f | 41 | #include "arm_math.h" |
| emh203 | 0:3d9c67d97d6f | 42 | |
| emh203 | 0:3d9c67d97d6f | 43 | /** |
| emh203 | 0:3d9c67d97d6f | 44 | * @ingroup groupFilters |
| emh203 | 0:3d9c67d97d6f | 45 | */ |
| emh203 | 0:3d9c67d97d6f | 46 | |
| emh203 | 0:3d9c67d97d6f | 47 | /** |
| emh203 | 0:3d9c67d97d6f | 48 | * @addtogroup PartialConv |
| emh203 | 0:3d9c67d97d6f | 49 | * @{ |
| emh203 | 0:3d9c67d97d6f | 50 | */ |
| emh203 | 0:3d9c67d97d6f | 51 | |
| emh203 | 0:3d9c67d97d6f | 52 | /** |
| emh203 | 0:3d9c67d97d6f | 53 | * @brief Partial convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4. |
| emh203 | 0:3d9c67d97d6f | 54 | * @param[in] *pSrcA points to the first input sequence. |
| emh203 | 0:3d9c67d97d6f | 55 | * @param[in] srcALen length of the first input sequence. |
| emh203 | 0:3d9c67d97d6f | 56 | * @param[in] *pSrcB points to the second input sequence. |
| emh203 | 0:3d9c67d97d6f | 57 | * @param[in] srcBLen length of the second input sequence. |
| emh203 | 0:3d9c67d97d6f | 58 | * @param[out] *pDst points to the location where the output result is written. |
| emh203 | 0:3d9c67d97d6f | 59 | * @param[in] firstIndex is the first output sample to start with. |
| emh203 | 0:3d9c67d97d6f | 60 | * @param[in] numPoints is the number of output points to be computed. |
| emh203 | 0:3d9c67d97d6f | 61 | * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. |
| emh203 | 0:3d9c67d97d6f | 62 | * |
| emh203 | 0:3d9c67d97d6f | 63 | * \par |
| emh203 | 0:3d9c67d97d6f | 64 | * See <code>arm_conv_partial_q31()</code> for a slower implementation of this function which uses a 64-bit accumulator to provide higher precision. |
| emh203 | 0:3d9c67d97d6f | 65 | */ |
| emh203 | 0:3d9c67d97d6f | 66 | |
| emh203 | 0:3d9c67d97d6f | 67 | arm_status arm_conv_partial_fast_q31( |
| emh203 | 0:3d9c67d97d6f | 68 | q31_t * pSrcA, |
| emh203 | 0:3d9c67d97d6f | 69 | uint32_t srcALen, |
| emh203 | 0:3d9c67d97d6f | 70 | q31_t * pSrcB, |
| emh203 | 0:3d9c67d97d6f | 71 | uint32_t srcBLen, |
| emh203 | 0:3d9c67d97d6f | 72 | q31_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 73 | uint32_t firstIndex, |
| emh203 | 0:3d9c67d97d6f | 74 | uint32_t numPoints) |
| emh203 | 0:3d9c67d97d6f | 75 | { |
| emh203 | 0:3d9c67d97d6f | 76 | q31_t *pIn1; /* inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 77 | q31_t *pIn2; /* inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 78 | q31_t *pOut = pDst; /* output pointer */ |
| emh203 | 0:3d9c67d97d6f | 79 | q31_t *px; /* Intermediate inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 80 | q31_t *py; /* Intermediate inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 81 | q31_t *pSrc1, *pSrc2; /* Intermediate pointers */ |
| emh203 | 0:3d9c67d97d6f | 82 | q31_t sum, acc0, acc1, acc2, acc3; /* Accumulators */ |
| emh203 | 0:3d9c67d97d6f | 83 | q31_t x0, x1, x2, x3, c0; |
| emh203 | 0:3d9c67d97d6f | 84 | uint32_t j, k, count, check, blkCnt; |
| emh203 | 0:3d9c67d97d6f | 85 | int32_t blockSize1, blockSize2, blockSize3; /* loop counters */ |
| emh203 | 0:3d9c67d97d6f | 86 | arm_status status; /* status of Partial convolution */ |
| emh203 | 0:3d9c67d97d6f | 87 | |
| emh203 | 0:3d9c67d97d6f | 88 | |
| emh203 | 0:3d9c67d97d6f | 89 | /* Check for range of output samples to be calculated */ |
| emh203 | 0:3d9c67d97d6f | 90 | if((firstIndex + numPoints) > ((srcALen + (srcBLen - 1u)))) |
| emh203 | 0:3d9c67d97d6f | 91 | { |
| emh203 | 0:3d9c67d97d6f | 92 | /* Set status as ARM_MATH_ARGUMENT_ERROR */ |
| emh203 | 0:3d9c67d97d6f | 93 | status = ARM_MATH_ARGUMENT_ERROR; |
| emh203 | 0:3d9c67d97d6f | 94 | } |
| emh203 | 0:3d9c67d97d6f | 95 | else |
| emh203 | 0:3d9c67d97d6f | 96 | { |
| emh203 | 0:3d9c67d97d6f | 97 | |
| emh203 | 0:3d9c67d97d6f | 98 | /* The algorithm implementation is based on the lengths of the inputs. */ |
| emh203 | 0:3d9c67d97d6f | 99 | /* srcB is always made to slide across srcA. */ |
| emh203 | 0:3d9c67d97d6f | 100 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
| emh203 | 0:3d9c67d97d6f | 101 | if(srcALen >= srcBLen) |
| emh203 | 0:3d9c67d97d6f | 102 | { |
| emh203 | 0:3d9c67d97d6f | 103 | /* Initialization of inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 104 | pIn1 = pSrcA; |
| emh203 | 0:3d9c67d97d6f | 105 | |
| emh203 | 0:3d9c67d97d6f | 106 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 107 | pIn2 = pSrcB; |
| emh203 | 0:3d9c67d97d6f | 108 | } |
| emh203 | 0:3d9c67d97d6f | 109 | else |
| emh203 | 0:3d9c67d97d6f | 110 | { |
| emh203 | 0:3d9c67d97d6f | 111 | /* Initialization of inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 112 | pIn1 = pSrcB; |
| emh203 | 0:3d9c67d97d6f | 113 | |
| emh203 | 0:3d9c67d97d6f | 114 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 115 | pIn2 = pSrcA; |
| emh203 | 0:3d9c67d97d6f | 116 | |
| emh203 | 0:3d9c67d97d6f | 117 | /* srcBLen is always considered as shorter or equal to srcALen */ |
| emh203 | 0:3d9c67d97d6f | 118 | j = srcBLen; |
| emh203 | 0:3d9c67d97d6f | 119 | srcBLen = srcALen; |
| emh203 | 0:3d9c67d97d6f | 120 | srcALen = j; |
| emh203 | 0:3d9c67d97d6f | 121 | } |
| emh203 | 0:3d9c67d97d6f | 122 | |
| emh203 | 0:3d9c67d97d6f | 123 | /* Conditions to check which loopCounter holds |
| emh203 | 0:3d9c67d97d6f | 124 | * the first and last indices of the output samples to be calculated. */ |
| emh203 | 0:3d9c67d97d6f | 125 | check = firstIndex + numPoints; |
| emh203 | 0:3d9c67d97d6f | 126 | blockSize3 = ((int32_t)check > (int32_t)srcALen) ? (int32_t)check - (int32_t)srcALen : 0; |
| emh203 | 0:3d9c67d97d6f | 127 | blockSize3 = ((int32_t)firstIndex > (int32_t)srcALen - 1) ? blockSize3 - (int32_t)firstIndex + (int32_t)srcALen : blockSize3; |
| emh203 | 0:3d9c67d97d6f | 128 | blockSize1 = (((int32_t) srcBLen - 1) - (int32_t) firstIndex); |
| emh203 | 0:3d9c67d97d6f | 129 | blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1u)) ? blockSize1 : |
| emh203 | 0:3d9c67d97d6f | 130 | (int32_t) numPoints) : 0; |
| emh203 | 0:3d9c67d97d6f | 131 | blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) + |
| emh203 | 0:3d9c67d97d6f | 132 | (int32_t) firstIndex); |
| emh203 | 0:3d9c67d97d6f | 133 | blockSize2 = (blockSize2 > 0) ? blockSize2 : 0; |
| emh203 | 0:3d9c67d97d6f | 134 | |
| emh203 | 0:3d9c67d97d6f | 135 | /* 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 | 136 | /* The function is internally |
| emh203 | 0:3d9c67d97d6f | 137 | * divided into three stages according to the number of multiplications that has to be |
| emh203 | 0:3d9c67d97d6f | 138 | * taken place between inputA samples and inputB samples. In the first stage of the |
| emh203 | 0:3d9c67d97d6f | 139 | * algorithm, the multiplications increase by one for every iteration. |
| emh203 | 0:3d9c67d97d6f | 140 | * In the second stage of the algorithm, srcBLen number of multiplications are done. |
| emh203 | 0:3d9c67d97d6f | 141 | * In the third stage of the algorithm, the multiplications decrease by one |
| emh203 | 0:3d9c67d97d6f | 142 | * for every iteration. */ |
| emh203 | 0:3d9c67d97d6f | 143 | |
| emh203 | 0:3d9c67d97d6f | 144 | /* Set the output pointer to point to the firstIndex |
| emh203 | 0:3d9c67d97d6f | 145 | * of the output sample to be calculated. */ |
| emh203 | 0:3d9c67d97d6f | 146 | pOut = pDst + firstIndex; |
| emh203 | 0:3d9c67d97d6f | 147 | |
| emh203 | 0:3d9c67d97d6f | 148 | /* -------------------------- |
| emh203 | 0:3d9c67d97d6f | 149 | * Initializations of stage1 |
| emh203 | 0:3d9c67d97d6f | 150 | * -------------------------*/ |
| emh203 | 0:3d9c67d97d6f | 151 | |
| emh203 | 0:3d9c67d97d6f | 152 | /* sum = x[0] * y[0] |
| emh203 | 0:3d9c67d97d6f | 153 | * sum = x[0] * y[1] + x[1] * y[0] |
| emh203 | 0:3d9c67d97d6f | 154 | * .... |
| emh203 | 0:3d9c67d97d6f | 155 | * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] |
| emh203 | 0:3d9c67d97d6f | 156 | */ |
| emh203 | 0:3d9c67d97d6f | 157 | |
| emh203 | 0:3d9c67d97d6f | 158 | /* In this stage the MAC operations are increased by 1 for every iteration. |
| emh203 | 0:3d9c67d97d6f | 159 | The count variable holds the number of MAC operations performed. |
| emh203 | 0:3d9c67d97d6f | 160 | Since the partial convolution starts from firstIndex |
| emh203 | 0:3d9c67d97d6f | 161 | Number of Macs to be performed is firstIndex + 1 */ |
| emh203 | 0:3d9c67d97d6f | 162 | count = 1u + firstIndex; |
| emh203 | 0:3d9c67d97d6f | 163 | |
| emh203 | 0:3d9c67d97d6f | 164 | /* Working pointer of inputA */ |
| emh203 | 0:3d9c67d97d6f | 165 | px = pIn1; |
| emh203 | 0:3d9c67d97d6f | 166 | |
| emh203 | 0:3d9c67d97d6f | 167 | /* Working pointer of inputB */ |
| emh203 | 0:3d9c67d97d6f | 168 | pSrc2 = pIn2 + firstIndex; |
| emh203 | 0:3d9c67d97d6f | 169 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 170 | |
| emh203 | 0:3d9c67d97d6f | 171 | /* ------------------------ |
| emh203 | 0:3d9c67d97d6f | 172 | * Stage1 process |
| emh203 | 0:3d9c67d97d6f | 173 | * ----------------------*/ |
| emh203 | 0:3d9c67d97d6f | 174 | |
| emh203 | 0:3d9c67d97d6f | 175 | /* The first loop starts here */ |
| emh203 | 0:3d9c67d97d6f | 176 | while(blockSize1 > 0) |
| emh203 | 0:3d9c67d97d6f | 177 | { |
| emh203 | 0:3d9c67d97d6f | 178 | /* Accumulator is made zero for every iteration */ |
| emh203 | 0:3d9c67d97d6f | 179 | sum = 0; |
| emh203 | 0:3d9c67d97d6f | 180 | |
| emh203 | 0:3d9c67d97d6f | 181 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 182 | k = count >> 2u; |
| emh203 | 0:3d9c67d97d6f | 183 | |
| emh203 | 0:3d9c67d97d6f | 184 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
| emh203 | 0:3d9c67d97d6f | 185 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 186 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 187 | { |
| emh203 | 0:3d9c67d97d6f | 188 | /* x[0] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 189 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 190 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 191 | |
| emh203 | 0:3d9c67d97d6f | 192 | /* x[1] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 193 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 194 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 195 | |
| emh203 | 0:3d9c67d97d6f | 196 | /* x[2] * y[srcBLen - 3] */ |
| emh203 | 0:3d9c67d97d6f | 197 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 198 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 199 | |
| emh203 | 0:3d9c67d97d6f | 200 | /* x[3] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 201 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 202 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 203 | |
| emh203 | 0:3d9c67d97d6f | 204 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 205 | k--; |
| emh203 | 0:3d9c67d97d6f | 206 | } |
| emh203 | 0:3d9c67d97d6f | 207 | |
| emh203 | 0:3d9c67d97d6f | 208 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
| emh203 | 0:3d9c67d97d6f | 209 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 210 | k = count % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 211 | |
| emh203 | 0:3d9c67d97d6f | 212 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 213 | { |
| emh203 | 0:3d9c67d97d6f | 214 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 215 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 216 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 217 | |
| emh203 | 0:3d9c67d97d6f | 218 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 219 | k--; |
| emh203 | 0:3d9c67d97d6f | 220 | } |
| emh203 | 0:3d9c67d97d6f | 221 | |
| emh203 | 0:3d9c67d97d6f | 222 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 223 | *pOut++ = sum << 1; |
| emh203 | 0:3d9c67d97d6f | 224 | |
| emh203 | 0:3d9c67d97d6f | 225 | /* Update the inputA and inputB pointers for next MAC calculation */ |
| emh203 | 0:3d9c67d97d6f | 226 | py = ++pSrc2; |
| emh203 | 0:3d9c67d97d6f | 227 | px = pIn1; |
| emh203 | 0:3d9c67d97d6f | 228 | |
| emh203 | 0:3d9c67d97d6f | 229 | /* Increment the MAC count */ |
| emh203 | 0:3d9c67d97d6f | 230 | count++; |
| emh203 | 0:3d9c67d97d6f | 231 | |
| emh203 | 0:3d9c67d97d6f | 232 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 233 | blockSize1--; |
| emh203 | 0:3d9c67d97d6f | 234 | } |
| emh203 | 0:3d9c67d97d6f | 235 | |
| emh203 | 0:3d9c67d97d6f | 236 | /* -------------------------- |
| emh203 | 0:3d9c67d97d6f | 237 | * Initializations of stage2 |
| emh203 | 0:3d9c67d97d6f | 238 | * ------------------------*/ |
| emh203 | 0:3d9c67d97d6f | 239 | |
| emh203 | 0:3d9c67d97d6f | 240 | /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] |
| emh203 | 0:3d9c67d97d6f | 241 | * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] |
| emh203 | 0:3d9c67d97d6f | 242 | * .... |
| emh203 | 0:3d9c67d97d6f | 243 | * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] |
| emh203 | 0:3d9c67d97d6f | 244 | */ |
| emh203 | 0:3d9c67d97d6f | 245 | |
| emh203 | 0:3d9c67d97d6f | 246 | /* Working pointer of inputA */ |
| emh203 | 0:3d9c67d97d6f | 247 | if((int32_t)firstIndex - (int32_t)srcBLen + 1 > 0) |
| emh203 | 0:3d9c67d97d6f | 248 | { |
| emh203 | 0:3d9c67d97d6f | 249 | px = pIn1 + firstIndex - srcBLen + 1; |
| emh203 | 0:3d9c67d97d6f | 250 | } |
| emh203 | 0:3d9c67d97d6f | 251 | else |
| emh203 | 0:3d9c67d97d6f | 252 | { |
| emh203 | 0:3d9c67d97d6f | 253 | px = pIn1; |
| emh203 | 0:3d9c67d97d6f | 254 | } |
| emh203 | 0:3d9c67d97d6f | 255 | |
| emh203 | 0:3d9c67d97d6f | 256 | /* Working pointer of inputB */ |
| emh203 | 0:3d9c67d97d6f | 257 | pSrc2 = pIn2 + (srcBLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 258 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 259 | |
| emh203 | 0:3d9c67d97d6f | 260 | /* count is index by which the pointer pIn1 to be incremented */ |
| emh203 | 0:3d9c67d97d6f | 261 | count = 0u; |
| emh203 | 0:3d9c67d97d6f | 262 | |
| emh203 | 0:3d9c67d97d6f | 263 | /* ------------------- |
| emh203 | 0:3d9c67d97d6f | 264 | * Stage2 process |
| emh203 | 0:3d9c67d97d6f | 265 | * ------------------*/ |
| emh203 | 0:3d9c67d97d6f | 266 | |
| emh203 | 0:3d9c67d97d6f | 267 | /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. |
| emh203 | 0:3d9c67d97d6f | 268 | * So, to loop unroll over blockSize2, |
| emh203 | 0:3d9c67d97d6f | 269 | * srcBLen should be greater than or equal to 4 */ |
| emh203 | 0:3d9c67d97d6f | 270 | if(srcBLen >= 4u) |
| emh203 | 0:3d9c67d97d6f | 271 | { |
| emh203 | 0:3d9c67d97d6f | 272 | /* Loop unroll over blockSize2 */ |
| emh203 | 0:3d9c67d97d6f | 273 | blkCnt = ((uint32_t) blockSize2 >> 2u); |
| emh203 | 0:3d9c67d97d6f | 274 | |
| emh203 | 0:3d9c67d97d6f | 275 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 276 | { |
| emh203 | 0:3d9c67d97d6f | 277 | /* Set all accumulators to zero */ |
| emh203 | 0:3d9c67d97d6f | 278 | acc0 = 0; |
| emh203 | 0:3d9c67d97d6f | 279 | acc1 = 0; |
| emh203 | 0:3d9c67d97d6f | 280 | acc2 = 0; |
| emh203 | 0:3d9c67d97d6f | 281 | acc3 = 0; |
| emh203 | 0:3d9c67d97d6f | 282 | |
| emh203 | 0:3d9c67d97d6f | 283 | /* read x[0], x[1], x[2] samples */ |
| emh203 | 0:3d9c67d97d6f | 284 | x0 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 285 | x1 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 286 | x2 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 287 | |
| emh203 | 0:3d9c67d97d6f | 288 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 289 | k = srcBLen >> 2u; |
| emh203 | 0:3d9c67d97d6f | 290 | |
| emh203 | 0:3d9c67d97d6f | 291 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
| emh203 | 0:3d9c67d97d6f | 292 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 293 | do |
| emh203 | 0:3d9c67d97d6f | 294 | { |
| emh203 | 0:3d9c67d97d6f | 295 | /* Read y[srcBLen - 1] sample */ |
| emh203 | 0:3d9c67d97d6f | 296 | c0 = *(py--); |
| emh203 | 0:3d9c67d97d6f | 297 | |
| emh203 | 0:3d9c67d97d6f | 298 | /* Read x[3] sample */ |
| emh203 | 0:3d9c67d97d6f | 299 | x3 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 300 | |
| emh203 | 0:3d9c67d97d6f | 301 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 302 | /* acc0 += x[0] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 303 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 304 | |
| emh203 | 0:3d9c67d97d6f | 305 | /* acc1 += x[1] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 306 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 307 | |
| emh203 | 0:3d9c67d97d6f | 308 | /* acc2 += x[2] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 309 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 310 | |
| emh203 | 0:3d9c67d97d6f | 311 | /* acc3 += x[3] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 312 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 313 | |
| emh203 | 0:3d9c67d97d6f | 314 | /* Read y[srcBLen - 2] sample */ |
| emh203 | 0:3d9c67d97d6f | 315 | c0 = *(py--); |
| emh203 | 0:3d9c67d97d6f | 316 | |
| emh203 | 0:3d9c67d97d6f | 317 | /* Read x[4] sample */ |
| emh203 | 0:3d9c67d97d6f | 318 | x0 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 319 | |
| emh203 | 0:3d9c67d97d6f | 320 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 321 | /* acc0 += x[1] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 322 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x1 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 323 | /* acc1 += x[2] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 324 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x2 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 325 | /* acc2 += x[3] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 326 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x3 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 327 | /* acc3 += x[4] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 328 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x0 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 329 | |
| emh203 | 0:3d9c67d97d6f | 330 | /* Read y[srcBLen - 3] sample */ |
| emh203 | 0:3d9c67d97d6f | 331 | c0 = *(py--); |
| emh203 | 0:3d9c67d97d6f | 332 | |
| emh203 | 0:3d9c67d97d6f | 333 | /* Read x[5] sample */ |
| emh203 | 0:3d9c67d97d6f | 334 | x1 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 335 | |
| emh203 | 0:3d9c67d97d6f | 336 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 337 | /* acc0 += x[2] * y[srcBLen - 3] */ |
| emh203 | 0:3d9c67d97d6f | 338 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x2 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 339 | /* acc1 += x[3] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 340 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x3 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 341 | /* acc2 += x[4] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 342 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x0 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 343 | /* acc3 += x[5] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 344 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x1 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 345 | |
| emh203 | 0:3d9c67d97d6f | 346 | /* Read y[srcBLen - 4] sample */ |
| emh203 | 0:3d9c67d97d6f | 347 | c0 = *(py--); |
| emh203 | 0:3d9c67d97d6f | 348 | |
| emh203 | 0:3d9c67d97d6f | 349 | /* Read x[6] sample */ |
| emh203 | 0:3d9c67d97d6f | 350 | x2 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 351 | |
| emh203 | 0:3d9c67d97d6f | 352 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 353 | /* acc0 += x[3] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 354 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x3 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 355 | /* acc1 += x[4] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 356 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x0 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 357 | /* acc2 += x[5] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 358 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x1 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 359 | /* acc3 += x[6] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 360 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x2 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 361 | |
| emh203 | 0:3d9c67d97d6f | 362 | |
| emh203 | 0:3d9c67d97d6f | 363 | } while(--k); |
| emh203 | 0:3d9c67d97d6f | 364 | |
| emh203 | 0:3d9c67d97d6f | 365 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
| emh203 | 0:3d9c67d97d6f | 366 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 367 | k = srcBLen % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 368 | |
| emh203 | 0:3d9c67d97d6f | 369 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 370 | { |
| emh203 | 0:3d9c67d97d6f | 371 | /* Read y[srcBLen - 5] sample */ |
| emh203 | 0:3d9c67d97d6f | 372 | c0 = *(py--); |
| emh203 | 0:3d9c67d97d6f | 373 | |
| emh203 | 0:3d9c67d97d6f | 374 | /* Read x[7] sample */ |
| emh203 | 0:3d9c67d97d6f | 375 | x3 = *(px++); |
| emh203 | 0:3d9c67d97d6f | 376 | |
| emh203 | 0:3d9c67d97d6f | 377 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 378 | /* acc0 += x[4] * y[srcBLen - 5] */ |
| emh203 | 0:3d9c67d97d6f | 379 | acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 380 | /* acc1 += x[5] * y[srcBLen - 5] */ |
| emh203 | 0:3d9c67d97d6f | 381 | acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 382 | /* acc2 += x[6] * y[srcBLen - 5] */ |
| emh203 | 0:3d9c67d97d6f | 383 | acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 384 | /* acc3 += x[7] * y[srcBLen - 5] */ |
| emh203 | 0:3d9c67d97d6f | 385 | acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); |
| emh203 | 0:3d9c67d97d6f | 386 | |
| emh203 | 0:3d9c67d97d6f | 387 | /* Reuse the present samples for the next MAC */ |
| emh203 | 0:3d9c67d97d6f | 388 | x0 = x1; |
| emh203 | 0:3d9c67d97d6f | 389 | x1 = x2; |
| emh203 | 0:3d9c67d97d6f | 390 | x2 = x3; |
| emh203 | 0:3d9c67d97d6f | 391 | |
| emh203 | 0:3d9c67d97d6f | 392 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 393 | k--; |
| emh203 | 0:3d9c67d97d6f | 394 | } |
| emh203 | 0:3d9c67d97d6f | 395 | |
| emh203 | 0:3d9c67d97d6f | 396 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 397 | *pOut++ = (q31_t) (acc0 << 1); |
| emh203 | 0:3d9c67d97d6f | 398 | *pOut++ = (q31_t) (acc1 << 1); |
| emh203 | 0:3d9c67d97d6f | 399 | *pOut++ = (q31_t) (acc2 << 1); |
| emh203 | 0:3d9c67d97d6f | 400 | *pOut++ = (q31_t) (acc3 << 1); |
| emh203 | 0:3d9c67d97d6f | 401 | |
| emh203 | 0:3d9c67d97d6f | 402 | /* Increment the pointer pIn1 index, count by 4 */ |
| emh203 | 0:3d9c67d97d6f | 403 | count += 4u; |
| emh203 | 0:3d9c67d97d6f | 404 | |
| emh203 | 0:3d9c67d97d6f | 405 | /* Update the inputA and inputB pointers for next MAC calculation */ |
| emh203 | 0:3d9c67d97d6f | 406 | px = pIn1 + count; |
| emh203 | 0:3d9c67d97d6f | 407 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 408 | |
| emh203 | 0:3d9c67d97d6f | 409 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 410 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 411 | } |
| emh203 | 0:3d9c67d97d6f | 412 | |
| emh203 | 0:3d9c67d97d6f | 413 | /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. |
| emh203 | 0:3d9c67d97d6f | 414 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 415 | blkCnt = (uint32_t) blockSize2 % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 416 | |
| emh203 | 0:3d9c67d97d6f | 417 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 418 | { |
| emh203 | 0:3d9c67d97d6f | 419 | /* Accumulator is made zero for every iteration */ |
| emh203 | 0:3d9c67d97d6f | 420 | sum = 0; |
| emh203 | 0:3d9c67d97d6f | 421 | |
| emh203 | 0:3d9c67d97d6f | 422 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 423 | k = srcBLen >> 2u; |
| emh203 | 0:3d9c67d97d6f | 424 | |
| emh203 | 0:3d9c67d97d6f | 425 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
| emh203 | 0:3d9c67d97d6f | 426 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 427 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 428 | { |
| emh203 | 0:3d9c67d97d6f | 429 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 430 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 431 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 432 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 433 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 434 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 435 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 436 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 437 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 438 | |
| emh203 | 0:3d9c67d97d6f | 439 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 440 | k--; |
| emh203 | 0:3d9c67d97d6f | 441 | } |
| emh203 | 0:3d9c67d97d6f | 442 | |
| emh203 | 0:3d9c67d97d6f | 443 | /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. |
| emh203 | 0:3d9c67d97d6f | 444 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 445 | k = srcBLen % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 446 | |
| emh203 | 0:3d9c67d97d6f | 447 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 448 | { |
| emh203 | 0:3d9c67d97d6f | 449 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 450 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 451 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 452 | |
| emh203 | 0:3d9c67d97d6f | 453 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 454 | k--; |
| emh203 | 0:3d9c67d97d6f | 455 | } |
| emh203 | 0:3d9c67d97d6f | 456 | |
| emh203 | 0:3d9c67d97d6f | 457 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 458 | *pOut++ = sum << 1; |
| emh203 | 0:3d9c67d97d6f | 459 | |
| emh203 | 0:3d9c67d97d6f | 460 | /* Increment the MAC count */ |
| emh203 | 0:3d9c67d97d6f | 461 | count++; |
| emh203 | 0:3d9c67d97d6f | 462 | |
| emh203 | 0:3d9c67d97d6f | 463 | /* Update the inputA and inputB pointers for next MAC calculation */ |
| emh203 | 0:3d9c67d97d6f | 464 | px = pIn1 + count; |
| emh203 | 0:3d9c67d97d6f | 465 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 466 | |
| emh203 | 0:3d9c67d97d6f | 467 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 468 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 469 | } |
| emh203 | 0:3d9c67d97d6f | 470 | } |
| emh203 | 0:3d9c67d97d6f | 471 | else |
| emh203 | 0:3d9c67d97d6f | 472 | { |
| emh203 | 0:3d9c67d97d6f | 473 | /* If the srcBLen is not a multiple of 4, |
| emh203 | 0:3d9c67d97d6f | 474 | * the blockSize2 loop cannot be unrolled by 4 */ |
| emh203 | 0:3d9c67d97d6f | 475 | blkCnt = (uint32_t) blockSize2; |
| emh203 | 0:3d9c67d97d6f | 476 | |
| emh203 | 0:3d9c67d97d6f | 477 | while(blkCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 478 | { |
| emh203 | 0:3d9c67d97d6f | 479 | /* Accumulator is made zero for every iteration */ |
| emh203 | 0:3d9c67d97d6f | 480 | sum = 0; |
| emh203 | 0:3d9c67d97d6f | 481 | |
| emh203 | 0:3d9c67d97d6f | 482 | /* srcBLen number of MACS should be performed */ |
| emh203 | 0:3d9c67d97d6f | 483 | k = srcBLen; |
| emh203 | 0:3d9c67d97d6f | 484 | |
| emh203 | 0:3d9c67d97d6f | 485 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 486 | { |
| emh203 | 0:3d9c67d97d6f | 487 | /* Perform the multiply-accumulate */ |
| emh203 | 0:3d9c67d97d6f | 488 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 489 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 490 | |
| emh203 | 0:3d9c67d97d6f | 491 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 492 | k--; |
| emh203 | 0:3d9c67d97d6f | 493 | } |
| emh203 | 0:3d9c67d97d6f | 494 | |
| emh203 | 0:3d9c67d97d6f | 495 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 496 | *pOut++ = sum << 1; |
| emh203 | 0:3d9c67d97d6f | 497 | |
| emh203 | 0:3d9c67d97d6f | 498 | /* Increment the MAC count */ |
| emh203 | 0:3d9c67d97d6f | 499 | count++; |
| emh203 | 0:3d9c67d97d6f | 500 | |
| emh203 | 0:3d9c67d97d6f | 501 | /* Update the inputA and inputB pointers for next MAC calculation */ |
| emh203 | 0:3d9c67d97d6f | 502 | px = pIn1 + count; |
| emh203 | 0:3d9c67d97d6f | 503 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 504 | |
| emh203 | 0:3d9c67d97d6f | 505 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 506 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 507 | } |
| emh203 | 0:3d9c67d97d6f | 508 | } |
| emh203 | 0:3d9c67d97d6f | 509 | |
| emh203 | 0:3d9c67d97d6f | 510 | |
| emh203 | 0:3d9c67d97d6f | 511 | /* -------------------------- |
| emh203 | 0:3d9c67d97d6f | 512 | * Initializations of stage3 |
| emh203 | 0:3d9c67d97d6f | 513 | * -------------------------*/ |
| emh203 | 0:3d9c67d97d6f | 514 | |
| emh203 | 0:3d9c67d97d6f | 515 | /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] |
| emh203 | 0:3d9c67d97d6f | 516 | * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] |
| emh203 | 0:3d9c67d97d6f | 517 | * .... |
| emh203 | 0:3d9c67d97d6f | 518 | * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] |
| emh203 | 0:3d9c67d97d6f | 519 | * sum += x[srcALen-1] * y[srcBLen-1] |
| emh203 | 0:3d9c67d97d6f | 520 | */ |
| emh203 | 0:3d9c67d97d6f | 521 | |
| emh203 | 0:3d9c67d97d6f | 522 | /* In this stage the MAC operations are decreased by 1 for every iteration. |
| emh203 | 0:3d9c67d97d6f | 523 | The count variable holds the number of MAC operations performed */ |
| emh203 | 0:3d9c67d97d6f | 524 | count = srcBLen - 1u; |
| emh203 | 0:3d9c67d97d6f | 525 | |
| emh203 | 0:3d9c67d97d6f | 526 | /* Working pointer of inputA */ |
| emh203 | 0:3d9c67d97d6f | 527 | pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 528 | px = pSrc1; |
| emh203 | 0:3d9c67d97d6f | 529 | |
| emh203 | 0:3d9c67d97d6f | 530 | /* Working pointer of inputB */ |
| emh203 | 0:3d9c67d97d6f | 531 | pSrc2 = pIn2 + (srcBLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 532 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 533 | |
| emh203 | 0:3d9c67d97d6f | 534 | /* ------------------- |
| emh203 | 0:3d9c67d97d6f | 535 | * Stage3 process |
| emh203 | 0:3d9c67d97d6f | 536 | * ------------------*/ |
| emh203 | 0:3d9c67d97d6f | 537 | |
| emh203 | 0:3d9c67d97d6f | 538 | while(blockSize3 > 0) |
| emh203 | 0:3d9c67d97d6f | 539 | { |
| emh203 | 0:3d9c67d97d6f | 540 | /* Accumulator is made zero for every iteration */ |
| emh203 | 0:3d9c67d97d6f | 541 | sum = 0; |
| emh203 | 0:3d9c67d97d6f | 542 | |
| emh203 | 0:3d9c67d97d6f | 543 | /* Apply loop unrolling and compute 4 MACs simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 544 | k = count >> 2u; |
| emh203 | 0:3d9c67d97d6f | 545 | |
| emh203 | 0:3d9c67d97d6f | 546 | /* First part of the processing with loop unrolling. Compute 4 MACs at a time. |
| emh203 | 0:3d9c67d97d6f | 547 | ** a second loop below computes MACs for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 548 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 549 | { |
| emh203 | 0:3d9c67d97d6f | 550 | /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */ |
| emh203 | 0:3d9c67d97d6f | 551 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 552 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 553 | |
| emh203 | 0:3d9c67d97d6f | 554 | /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */ |
| emh203 | 0:3d9c67d97d6f | 555 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 556 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 557 | |
| emh203 | 0:3d9c67d97d6f | 558 | /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */ |
| emh203 | 0:3d9c67d97d6f | 559 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 560 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 561 | |
| emh203 | 0:3d9c67d97d6f | 562 | /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */ |
| emh203 | 0:3d9c67d97d6f | 563 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 564 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 565 | |
| emh203 | 0:3d9c67d97d6f | 566 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 567 | k--; |
| emh203 | 0:3d9c67d97d6f | 568 | } |
| emh203 | 0:3d9c67d97d6f | 569 | |
| emh203 | 0:3d9c67d97d6f | 570 | /* If the count is not a multiple of 4, compute any remaining MACs here. |
| emh203 | 0:3d9c67d97d6f | 571 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 572 | k = count % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 573 | |
| emh203 | 0:3d9c67d97d6f | 574 | while(k > 0u) |
| emh203 | 0:3d9c67d97d6f | 575 | { |
| emh203 | 0:3d9c67d97d6f | 576 | /* Perform the multiply-accumulates */ |
| emh203 | 0:3d9c67d97d6f | 577 | /* sum += x[srcALen-1] * y[srcBLen-1] */ |
| emh203 | 0:3d9c67d97d6f | 578 | sum = (q31_t) ((((q63_t) sum << 32) + |
| emh203 | 0:3d9c67d97d6f | 579 | ((q63_t) * px++ * (*py--))) >> 32); |
| emh203 | 0:3d9c67d97d6f | 580 | |
| emh203 | 0:3d9c67d97d6f | 581 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 582 | k--; |
| emh203 | 0:3d9c67d97d6f | 583 | } |
| emh203 | 0:3d9c67d97d6f | 584 | |
| emh203 | 0:3d9c67d97d6f | 585 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 586 | *pOut++ = sum << 1; |
| emh203 | 0:3d9c67d97d6f | 587 | |
| emh203 | 0:3d9c67d97d6f | 588 | /* Update the inputA and inputB pointers for next MAC calculation */ |
| emh203 | 0:3d9c67d97d6f | 589 | px = ++pSrc1; |
| emh203 | 0:3d9c67d97d6f | 590 | py = pSrc2; |
| emh203 | 0:3d9c67d97d6f | 591 | |
| emh203 | 0:3d9c67d97d6f | 592 | /* Decrement the MAC count */ |
| emh203 | 0:3d9c67d97d6f | 593 | count--; |
| emh203 | 0:3d9c67d97d6f | 594 | |
| emh203 | 0:3d9c67d97d6f | 595 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 596 | blockSize3--; |
| emh203 | 0:3d9c67d97d6f | 597 | |
| emh203 | 0:3d9c67d97d6f | 598 | } |
| emh203 | 0:3d9c67d97d6f | 599 | |
| emh203 | 0:3d9c67d97d6f | 600 | /* set status as ARM_MATH_SUCCESS */ |
| emh203 | 0:3d9c67d97d6f | 601 | status = ARM_MATH_SUCCESS; |
| emh203 | 0:3d9c67d97d6f | 602 | } |
| emh203 | 0:3d9c67d97d6f | 603 | |
| emh203 | 0:3d9c67d97d6f | 604 | /* Return to application */ |
| emh203 | 0:3d9c67d97d6f | 605 | return (status); |
| emh203 | 0:3d9c67d97d6f | 606 | |
| emh203 | 0:3d9c67d97d6f | 607 | } |
| emh203 | 0:3d9c67d97d6f | 608 | |
| emh203 | 0:3d9c67d97d6f | 609 | /** |
| emh203 | 0:3d9c67d97d6f | 610 | * @} end of PartialConv group |
| emh203 | 0:3d9c67d97d6f | 611 | */ |
Eli Hughes