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_correlate_fast_opt_q15.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_correlate_fast_opt_q15.c |
| emh203 | 0:3d9c67d97d6f | 9 | * |
| emh203 | 0:3d9c67d97d6f | 10 | * Description: Fast Q15 Correlation. |
| 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 Corr |
| emh203 | 0:3d9c67d97d6f | 49 | * @{ |
| emh203 | 0:3d9c67d97d6f | 50 | */ |
| emh203 | 0:3d9c67d97d6f | 51 | |
| emh203 | 0:3d9c67d97d6f | 52 | /** |
| emh203 | 0:3d9c67d97d6f | 53 | * @brief Correlation of Q15 sequences (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. Length 2 * max(srcALen, srcBLen) - 1. |
| emh203 | 0:3d9c67d97d6f | 59 | * @param[in] *pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. |
| emh203 | 0:3d9c67d97d6f | 60 | * @return none. |
| emh203 | 0:3d9c67d97d6f | 61 | * |
| emh203 | 0:3d9c67d97d6f | 62 | * |
| emh203 | 0:3d9c67d97d6f | 63 | * \par Restrictions |
| emh203 | 0:3d9c67d97d6f | 64 | * If the silicon does not support unaligned memory access enable the macro UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 65 | * In this case input, output, scratch buffers should be aligned by 32-bit |
| emh203 | 0:3d9c67d97d6f | 66 | * |
| emh203 | 0:3d9c67d97d6f | 67 | * |
| emh203 | 0:3d9c67d97d6f | 68 | * <b>Scaling and Overflow Behavior:</b> |
| emh203 | 0:3d9c67d97d6f | 69 | * |
| emh203 | 0:3d9c67d97d6f | 70 | * \par |
| emh203 | 0:3d9c67d97d6f | 71 | * This fast version uses a 32-bit accumulator with 2.30 format. |
| emh203 | 0:3d9c67d97d6f | 72 | * The accumulator maintains full precision of the intermediate multiplication results but provides only a single guard bit. |
| emh203 | 0:3d9c67d97d6f | 73 | * There is no saturation on intermediate additions. |
| emh203 | 0:3d9c67d97d6f | 74 | * Thus, if the accumulator overflows it wraps around and distorts the result. |
| emh203 | 0:3d9c67d97d6f | 75 | * The input signals should be scaled down to avoid intermediate overflows. |
| emh203 | 0:3d9c67d97d6f | 76 | * Scale down one of the inputs by 1/min(srcALen, srcBLen) to avoid overflow since a |
| emh203 | 0:3d9c67d97d6f | 77 | * maximum of min(srcALen, srcBLen) number of additions is carried internally. |
| emh203 | 0:3d9c67d97d6f | 78 | * The 2.30 accumulator is right shifted by 15 bits and then saturated to 1.15 format to yield the final result. |
| emh203 | 0:3d9c67d97d6f | 79 | * |
| emh203 | 0:3d9c67d97d6f | 80 | * \par |
| emh203 | 0:3d9c67d97d6f | 81 | * See <code>arm_correlate_q15()</code> for a slower implementation of this function which uses a 64-bit accumulator to avoid wrap around distortion. |
| emh203 | 0:3d9c67d97d6f | 82 | */ |
| emh203 | 0:3d9c67d97d6f | 83 | |
| emh203 | 0:3d9c67d97d6f | 84 | void arm_correlate_fast_opt_q15( |
| emh203 | 0:3d9c67d97d6f | 85 | q15_t * pSrcA, |
| emh203 | 0:3d9c67d97d6f | 86 | uint32_t srcALen, |
| emh203 | 0:3d9c67d97d6f | 87 | q15_t * pSrcB, |
| emh203 | 0:3d9c67d97d6f | 88 | uint32_t srcBLen, |
| emh203 | 0:3d9c67d97d6f | 89 | q15_t * pDst, |
| emh203 | 0:3d9c67d97d6f | 90 | q15_t * pScratch) |
| emh203 | 0:3d9c67d97d6f | 91 | { |
| emh203 | 0:3d9c67d97d6f | 92 | q15_t *pIn1; /* inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 93 | q15_t *pIn2; /* inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 94 | q31_t acc0, acc1, acc2, acc3; /* Accumulators */ |
| emh203 | 0:3d9c67d97d6f | 95 | q15_t *py; /* Intermediate inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 96 | q31_t x1, x2, x3; /* temporary variables for holding input and coefficient values */ |
| emh203 | 0:3d9c67d97d6f | 97 | uint32_t j, blkCnt, outBlockSize; /* loop counter */ |
| emh203 | 0:3d9c67d97d6f | 98 | int32_t inc = 1; /* Destination address modifier */ |
| emh203 | 0:3d9c67d97d6f | 99 | uint32_t tapCnt; |
| emh203 | 0:3d9c67d97d6f | 100 | q31_t y1, y2; |
| emh203 | 0:3d9c67d97d6f | 101 | q15_t *pScr; /* Intermediate pointers */ |
| emh203 | 0:3d9c67d97d6f | 102 | q15_t *pOut = pDst; /* output pointer */ |
| emh203 | 0:3d9c67d97d6f | 103 | #ifdef UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 104 | |
| emh203 | 0:3d9c67d97d6f | 105 | q15_t a, b; |
| emh203 | 0:3d9c67d97d6f | 106 | |
| emh203 | 0:3d9c67d97d6f | 107 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
| emh203 | 0:3d9c67d97d6f | 108 | |
| emh203 | 0:3d9c67d97d6f | 109 | /* The algorithm implementation is based on the lengths of the inputs. */ |
| emh203 | 0:3d9c67d97d6f | 110 | /* srcB is always made to slide across srcA. */ |
| emh203 | 0:3d9c67d97d6f | 111 | /* So srcBLen is always considered as shorter or equal to srcALen */ |
| emh203 | 0:3d9c67d97d6f | 112 | /* But CORR(x, y) is reverse of CORR(y, x) */ |
| emh203 | 0:3d9c67d97d6f | 113 | /* So, when srcBLen > srcALen, output pointer is made to point to the end of the output buffer */ |
| emh203 | 0:3d9c67d97d6f | 114 | /* and the destination pointer modifier, inc is set to -1 */ |
| emh203 | 0:3d9c67d97d6f | 115 | /* If srcALen > srcBLen, zero pad has to be done to srcB to make the two inputs of same length */ |
| emh203 | 0:3d9c67d97d6f | 116 | /* But to improve the performance, |
| emh203 | 0:3d9c67d97d6f | 117 | * we include zeroes in the output instead of zero padding either of the the inputs*/ |
| emh203 | 0:3d9c67d97d6f | 118 | /* If srcALen > srcBLen, |
| emh203 | 0:3d9c67d97d6f | 119 | * (srcALen - srcBLen) zeroes has to included in the starting of the output buffer */ |
| emh203 | 0:3d9c67d97d6f | 120 | /* If srcALen < srcBLen, |
| emh203 | 0:3d9c67d97d6f | 121 | * (srcALen - srcBLen) zeroes has to included in the ending of the output buffer */ |
| emh203 | 0:3d9c67d97d6f | 122 | if(srcALen >= srcBLen) |
| emh203 | 0:3d9c67d97d6f | 123 | { |
| emh203 | 0:3d9c67d97d6f | 124 | /* Initialization of inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 125 | pIn1 = (pSrcA); |
| emh203 | 0:3d9c67d97d6f | 126 | |
| emh203 | 0:3d9c67d97d6f | 127 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 128 | pIn2 = (pSrcB); |
| emh203 | 0:3d9c67d97d6f | 129 | |
| emh203 | 0:3d9c67d97d6f | 130 | /* Number of output samples is calculated */ |
| emh203 | 0:3d9c67d97d6f | 131 | outBlockSize = (2u * srcALen) - 1u; |
| emh203 | 0:3d9c67d97d6f | 132 | |
| emh203 | 0:3d9c67d97d6f | 133 | /* When srcALen > srcBLen, zero padding is done to srcB |
| emh203 | 0:3d9c67d97d6f | 134 | * to make their lengths equal. |
| emh203 | 0:3d9c67d97d6f | 135 | * Instead, (outBlockSize - (srcALen + srcBLen - 1)) |
| emh203 | 0:3d9c67d97d6f | 136 | * number of output samples are made zero */ |
| emh203 | 0:3d9c67d97d6f | 137 | j = outBlockSize - (srcALen + (srcBLen - 1u)); |
| emh203 | 0:3d9c67d97d6f | 138 | |
| emh203 | 0:3d9c67d97d6f | 139 | /* Updating the pointer position to non zero value */ |
| emh203 | 0:3d9c67d97d6f | 140 | pOut += j; |
| emh203 | 0:3d9c67d97d6f | 141 | |
| emh203 | 0:3d9c67d97d6f | 142 | } |
| emh203 | 0:3d9c67d97d6f | 143 | else |
| emh203 | 0:3d9c67d97d6f | 144 | { |
| emh203 | 0:3d9c67d97d6f | 145 | /* Initialization of inputA pointer */ |
| emh203 | 0:3d9c67d97d6f | 146 | pIn1 = (pSrcB); |
| emh203 | 0:3d9c67d97d6f | 147 | |
| emh203 | 0:3d9c67d97d6f | 148 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 149 | pIn2 = (pSrcA); |
| emh203 | 0:3d9c67d97d6f | 150 | |
| emh203 | 0:3d9c67d97d6f | 151 | /* srcBLen is always considered as shorter or equal to srcALen */ |
| emh203 | 0:3d9c67d97d6f | 152 | j = srcBLen; |
| emh203 | 0:3d9c67d97d6f | 153 | srcBLen = srcALen; |
| emh203 | 0:3d9c67d97d6f | 154 | srcALen = j; |
| emh203 | 0:3d9c67d97d6f | 155 | |
| emh203 | 0:3d9c67d97d6f | 156 | /* CORR(x, y) = Reverse order(CORR(y, x)) */ |
| emh203 | 0:3d9c67d97d6f | 157 | /* Hence set the destination pointer to point to the last output sample */ |
| emh203 | 0:3d9c67d97d6f | 158 | pOut = pDst + ((srcALen + srcBLen) - 2u); |
| emh203 | 0:3d9c67d97d6f | 159 | |
| emh203 | 0:3d9c67d97d6f | 160 | /* Destination address modifier is set to -1 */ |
| emh203 | 0:3d9c67d97d6f | 161 | inc = -1; |
| emh203 | 0:3d9c67d97d6f | 162 | |
| emh203 | 0:3d9c67d97d6f | 163 | } |
| emh203 | 0:3d9c67d97d6f | 164 | |
| emh203 | 0:3d9c67d97d6f | 165 | pScr = pScratch; |
| emh203 | 0:3d9c67d97d6f | 166 | |
| emh203 | 0:3d9c67d97d6f | 167 | /* Fill (srcBLen - 1u) zeros in scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 168 | arm_fill_q15(0, pScr, (srcBLen - 1u)); |
| emh203 | 0:3d9c67d97d6f | 169 | |
| emh203 | 0:3d9c67d97d6f | 170 | /* Update temporary scratch pointer */ |
| emh203 | 0:3d9c67d97d6f | 171 | pScr += (srcBLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 172 | |
| emh203 | 0:3d9c67d97d6f | 173 | #ifndef UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 174 | |
| emh203 | 0:3d9c67d97d6f | 175 | /* Copy (srcALen) samples in scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 176 | arm_copy_q15(pIn1, pScr, srcALen); |
| emh203 | 0:3d9c67d97d6f | 177 | |
| emh203 | 0:3d9c67d97d6f | 178 | /* Update pointers */ |
| emh203 | 0:3d9c67d97d6f | 179 | pScr += srcALen; |
| emh203 | 0:3d9c67d97d6f | 180 | |
| emh203 | 0:3d9c67d97d6f | 181 | #else |
| emh203 | 0:3d9c67d97d6f | 182 | |
| emh203 | 0:3d9c67d97d6f | 183 | /* Apply loop unrolling and do 4 Copies simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 184 | j = srcALen >> 2u; |
| emh203 | 0:3d9c67d97d6f | 185 | |
| emh203 | 0:3d9c67d97d6f | 186 | /* First part of the processing with loop unrolling copies 4 data points at a time. |
| emh203 | 0:3d9c67d97d6f | 187 | ** a second loop below copies for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 188 | while(j > 0u) |
| emh203 | 0:3d9c67d97d6f | 189 | { |
| emh203 | 0:3d9c67d97d6f | 190 | /* copy second buffer in reversal manner */ |
| emh203 | 0:3d9c67d97d6f | 191 | *pScr++ = *pIn1++; |
| emh203 | 0:3d9c67d97d6f | 192 | *pScr++ = *pIn1++; |
| emh203 | 0:3d9c67d97d6f | 193 | *pScr++ = *pIn1++; |
| emh203 | 0:3d9c67d97d6f | 194 | *pScr++ = *pIn1++; |
| emh203 | 0:3d9c67d97d6f | 195 | |
| emh203 | 0:3d9c67d97d6f | 196 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 197 | j--; |
| emh203 | 0:3d9c67d97d6f | 198 | } |
| emh203 | 0:3d9c67d97d6f | 199 | |
| emh203 | 0:3d9c67d97d6f | 200 | /* If the count is not a multiple of 4, copy remaining samples here. |
| emh203 | 0:3d9c67d97d6f | 201 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 202 | j = srcALen % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 203 | |
| emh203 | 0:3d9c67d97d6f | 204 | while(j > 0u) |
| emh203 | 0:3d9c67d97d6f | 205 | { |
| emh203 | 0:3d9c67d97d6f | 206 | /* copy second buffer in reversal manner for remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 207 | *pScr++ = *pIn1++; |
| emh203 | 0:3d9c67d97d6f | 208 | |
| emh203 | 0:3d9c67d97d6f | 209 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 210 | j--; |
| emh203 | 0:3d9c67d97d6f | 211 | } |
| emh203 | 0:3d9c67d97d6f | 212 | |
| emh203 | 0:3d9c67d97d6f | 213 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
| emh203 | 0:3d9c67d97d6f | 214 | |
| emh203 | 0:3d9c67d97d6f | 215 | #ifndef UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 216 | |
| emh203 | 0:3d9c67d97d6f | 217 | /* Fill (srcBLen - 1u) zeros at end of scratch buffer */ |
| emh203 | 0:3d9c67d97d6f | 218 | arm_fill_q15(0, pScr, (srcBLen - 1u)); |
| emh203 | 0:3d9c67d97d6f | 219 | |
| emh203 | 0:3d9c67d97d6f | 220 | /* Update pointer */ |
| emh203 | 0:3d9c67d97d6f | 221 | pScr += (srcBLen - 1u); |
| emh203 | 0:3d9c67d97d6f | 222 | |
| emh203 | 0:3d9c67d97d6f | 223 | #else |
| emh203 | 0:3d9c67d97d6f | 224 | |
| emh203 | 0:3d9c67d97d6f | 225 | /* Apply loop unrolling and do 4 Copies simultaneously. */ |
| emh203 | 0:3d9c67d97d6f | 226 | j = (srcBLen - 1u) >> 2u; |
| emh203 | 0:3d9c67d97d6f | 227 | |
| emh203 | 0:3d9c67d97d6f | 228 | /* First part of the processing with loop unrolling copies 4 data points at a time. |
| emh203 | 0:3d9c67d97d6f | 229 | ** a second loop below copies for the remaining 1 to 3 samples. */ |
| emh203 | 0:3d9c67d97d6f | 230 | while(j > 0u) |
| emh203 | 0:3d9c67d97d6f | 231 | { |
| emh203 | 0:3d9c67d97d6f | 232 | /* copy second buffer in reversal manner */ |
| emh203 | 0:3d9c67d97d6f | 233 | *pScr++ = 0; |
| emh203 | 0:3d9c67d97d6f | 234 | *pScr++ = 0; |
| emh203 | 0:3d9c67d97d6f | 235 | *pScr++ = 0; |
| emh203 | 0:3d9c67d97d6f | 236 | *pScr++ = 0; |
| emh203 | 0:3d9c67d97d6f | 237 | |
| emh203 | 0:3d9c67d97d6f | 238 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 239 | j--; |
| emh203 | 0:3d9c67d97d6f | 240 | } |
| emh203 | 0:3d9c67d97d6f | 241 | |
| emh203 | 0:3d9c67d97d6f | 242 | /* If the count is not a multiple of 4, copy remaining samples here. |
| emh203 | 0:3d9c67d97d6f | 243 | ** No loop unrolling is used. */ |
| emh203 | 0:3d9c67d97d6f | 244 | j = (srcBLen - 1u) % 0x4u; |
| emh203 | 0:3d9c67d97d6f | 245 | |
| emh203 | 0:3d9c67d97d6f | 246 | while(j > 0u) |
| emh203 | 0:3d9c67d97d6f | 247 | { |
| emh203 | 0:3d9c67d97d6f | 248 | /* copy second buffer in reversal manner for remaining samples */ |
| emh203 | 0:3d9c67d97d6f | 249 | *pScr++ = 0; |
| emh203 | 0:3d9c67d97d6f | 250 | |
| emh203 | 0:3d9c67d97d6f | 251 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 252 | j--; |
| emh203 | 0:3d9c67d97d6f | 253 | } |
| emh203 | 0:3d9c67d97d6f | 254 | |
| emh203 | 0:3d9c67d97d6f | 255 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
| emh203 | 0:3d9c67d97d6f | 256 | |
| emh203 | 0:3d9c67d97d6f | 257 | /* Temporary pointer for scratch2 */ |
| emh203 | 0:3d9c67d97d6f | 258 | py = pIn2; |
| emh203 | 0:3d9c67d97d6f | 259 | |
| emh203 | 0:3d9c67d97d6f | 260 | |
| emh203 | 0:3d9c67d97d6f | 261 | /* Actual correlation process starts here */ |
| emh203 | 0:3d9c67d97d6f | 262 | blkCnt = (srcALen + srcBLen - 1u) >> 2; |
| emh203 | 0:3d9c67d97d6f | 263 | |
| emh203 | 0:3d9c67d97d6f | 264 | while(blkCnt > 0) |
| emh203 | 0:3d9c67d97d6f | 265 | { |
| emh203 | 0:3d9c67d97d6f | 266 | /* Initialze temporary scratch pointer as scratch1 */ |
| emh203 | 0:3d9c67d97d6f | 267 | pScr = pScratch; |
| emh203 | 0:3d9c67d97d6f | 268 | |
| emh203 | 0:3d9c67d97d6f | 269 | /* Clear Accumlators */ |
| emh203 | 0:3d9c67d97d6f | 270 | acc0 = 0; |
| emh203 | 0:3d9c67d97d6f | 271 | acc1 = 0; |
| emh203 | 0:3d9c67d97d6f | 272 | acc2 = 0; |
| emh203 | 0:3d9c67d97d6f | 273 | acc3 = 0; |
| emh203 | 0:3d9c67d97d6f | 274 | |
| emh203 | 0:3d9c67d97d6f | 275 | /* Read four samples from scratch1 buffer */ |
| emh203 | 0:3d9c67d97d6f | 276 | x1 = *__SIMD32(pScr)++; |
| emh203 | 0:3d9c67d97d6f | 277 | |
| emh203 | 0:3d9c67d97d6f | 278 | /* Read next four samples from scratch1 buffer */ |
| emh203 | 0:3d9c67d97d6f | 279 | x2 = *__SIMD32(pScr)++; |
| emh203 | 0:3d9c67d97d6f | 280 | |
| emh203 | 0:3d9c67d97d6f | 281 | tapCnt = (srcBLen) >> 2u; |
| emh203 | 0:3d9c67d97d6f | 282 | |
| emh203 | 0:3d9c67d97d6f | 283 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 284 | { |
| emh203 | 0:3d9c67d97d6f | 285 | |
| emh203 | 0:3d9c67d97d6f | 286 | #ifndef UNALIGNED_SUPPORT_DISABLE |
| emh203 | 0:3d9c67d97d6f | 287 | |
| emh203 | 0:3d9c67d97d6f | 288 | /* Read four samples from smaller buffer */ |
| emh203 | 0:3d9c67d97d6f | 289 | y1 = _SIMD32_OFFSET(pIn2); |
| emh203 | 0:3d9c67d97d6f | 290 | y2 = _SIMD32_OFFSET(pIn2 + 2u); |
| emh203 | 0:3d9c67d97d6f | 291 | |
| emh203 | 0:3d9c67d97d6f | 292 | acc0 = __SMLAD(x1, y1, acc0); |
| emh203 | 0:3d9c67d97d6f | 293 | |
| emh203 | 0:3d9c67d97d6f | 294 | acc2 = __SMLAD(x2, y1, acc2); |
| emh203 | 0:3d9c67d97d6f | 295 | |
| emh203 | 0:3d9c67d97d6f | 296 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 297 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 298 | #else |
| emh203 | 0:3d9c67d97d6f | 299 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 300 | #endif |
| emh203 | 0:3d9c67d97d6f | 301 | |
| emh203 | 0:3d9c67d97d6f | 302 | acc1 = __SMLADX(x3, y1, acc1); |
| emh203 | 0:3d9c67d97d6f | 303 | |
| emh203 | 0:3d9c67d97d6f | 304 | x1 = _SIMD32_OFFSET(pScr); |
| emh203 | 0:3d9c67d97d6f | 305 | |
| emh203 | 0:3d9c67d97d6f | 306 | acc0 = __SMLAD(x2, y2, acc0); |
| emh203 | 0:3d9c67d97d6f | 307 | |
| emh203 | 0:3d9c67d97d6f | 308 | acc2 = __SMLAD(x1, y2, acc2); |
| emh203 | 0:3d9c67d97d6f | 309 | |
| emh203 | 0:3d9c67d97d6f | 310 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 311 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 312 | #else |
| emh203 | 0:3d9c67d97d6f | 313 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 314 | #endif |
| emh203 | 0:3d9c67d97d6f | 315 | |
| emh203 | 0:3d9c67d97d6f | 316 | acc3 = __SMLADX(x3, y1, acc3); |
| emh203 | 0:3d9c67d97d6f | 317 | |
| emh203 | 0:3d9c67d97d6f | 318 | acc1 = __SMLADX(x3, y2, acc1); |
| emh203 | 0:3d9c67d97d6f | 319 | |
| emh203 | 0:3d9c67d97d6f | 320 | x2 = _SIMD32_OFFSET(pScr + 2u); |
| emh203 | 0:3d9c67d97d6f | 321 | |
| emh203 | 0:3d9c67d97d6f | 322 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 323 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 324 | #else |
| emh203 | 0:3d9c67d97d6f | 325 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 326 | #endif |
| emh203 | 0:3d9c67d97d6f | 327 | |
| emh203 | 0:3d9c67d97d6f | 328 | acc3 = __SMLADX(x3, y2, acc3); |
| emh203 | 0:3d9c67d97d6f | 329 | #else |
| emh203 | 0:3d9c67d97d6f | 330 | |
| emh203 | 0:3d9c67d97d6f | 331 | /* Read four samples from smaller buffer */ |
| emh203 | 0:3d9c67d97d6f | 332 | a = *pIn2; |
| emh203 | 0:3d9c67d97d6f | 333 | b = *(pIn2 + 1); |
| emh203 | 0:3d9c67d97d6f | 334 | |
| emh203 | 0:3d9c67d97d6f | 335 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 336 | y1 = __PKHBT(a, b, 16); |
| emh203 | 0:3d9c67d97d6f | 337 | #else |
| emh203 | 0:3d9c67d97d6f | 338 | y1 = __PKHBT(b, a, 16); |
| emh203 | 0:3d9c67d97d6f | 339 | #endif |
| emh203 | 0:3d9c67d97d6f | 340 | |
| emh203 | 0:3d9c67d97d6f | 341 | a = *(pIn2 + 2); |
| emh203 | 0:3d9c67d97d6f | 342 | b = *(pIn2 + 3); |
| emh203 | 0:3d9c67d97d6f | 343 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 344 | y2 = __PKHBT(a, b, 16); |
| emh203 | 0:3d9c67d97d6f | 345 | #else |
| emh203 | 0:3d9c67d97d6f | 346 | y2 = __PKHBT(b, a, 16); |
| emh203 | 0:3d9c67d97d6f | 347 | #endif |
| emh203 | 0:3d9c67d97d6f | 348 | |
| emh203 | 0:3d9c67d97d6f | 349 | acc0 = __SMLAD(x1, y1, acc0); |
| emh203 | 0:3d9c67d97d6f | 350 | |
| emh203 | 0:3d9c67d97d6f | 351 | acc2 = __SMLAD(x2, y1, acc2); |
| emh203 | 0:3d9c67d97d6f | 352 | |
| emh203 | 0:3d9c67d97d6f | 353 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 354 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 355 | #else |
| emh203 | 0:3d9c67d97d6f | 356 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 357 | #endif |
| emh203 | 0:3d9c67d97d6f | 358 | |
| emh203 | 0:3d9c67d97d6f | 359 | acc1 = __SMLADX(x3, y1, acc1); |
| emh203 | 0:3d9c67d97d6f | 360 | |
| emh203 | 0:3d9c67d97d6f | 361 | a = *pScr; |
| emh203 | 0:3d9c67d97d6f | 362 | b = *(pScr + 1); |
| emh203 | 0:3d9c67d97d6f | 363 | |
| emh203 | 0:3d9c67d97d6f | 364 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 365 | x1 = __PKHBT(a, b, 16); |
| emh203 | 0:3d9c67d97d6f | 366 | #else |
| emh203 | 0:3d9c67d97d6f | 367 | x1 = __PKHBT(b, a, 16); |
| emh203 | 0:3d9c67d97d6f | 368 | #endif |
| emh203 | 0:3d9c67d97d6f | 369 | |
| emh203 | 0:3d9c67d97d6f | 370 | acc0 = __SMLAD(x2, y2, acc0); |
| emh203 | 0:3d9c67d97d6f | 371 | |
| emh203 | 0:3d9c67d97d6f | 372 | acc2 = __SMLAD(x1, y2, acc2); |
| emh203 | 0:3d9c67d97d6f | 373 | |
| emh203 | 0:3d9c67d97d6f | 374 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 375 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 376 | #else |
| emh203 | 0:3d9c67d97d6f | 377 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 378 | #endif |
| emh203 | 0:3d9c67d97d6f | 379 | |
| emh203 | 0:3d9c67d97d6f | 380 | acc3 = __SMLADX(x3, y1, acc3); |
| emh203 | 0:3d9c67d97d6f | 381 | |
| emh203 | 0:3d9c67d97d6f | 382 | acc1 = __SMLADX(x3, y2, acc1); |
| emh203 | 0:3d9c67d97d6f | 383 | |
| emh203 | 0:3d9c67d97d6f | 384 | a = *(pScr + 2); |
| emh203 | 0:3d9c67d97d6f | 385 | b = *(pScr + 3); |
| emh203 | 0:3d9c67d97d6f | 386 | |
| emh203 | 0:3d9c67d97d6f | 387 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 388 | x2 = __PKHBT(a, b, 16); |
| emh203 | 0:3d9c67d97d6f | 389 | #else |
| emh203 | 0:3d9c67d97d6f | 390 | x2 = __PKHBT(b, a, 16); |
| emh203 | 0:3d9c67d97d6f | 391 | #endif |
| emh203 | 0:3d9c67d97d6f | 392 | |
| emh203 | 0:3d9c67d97d6f | 393 | #ifndef ARM_MATH_BIG_ENDIAN |
| emh203 | 0:3d9c67d97d6f | 394 | x3 = __PKHBT(x2, x1, 0); |
| emh203 | 0:3d9c67d97d6f | 395 | #else |
| emh203 | 0:3d9c67d97d6f | 396 | x3 = __PKHBT(x1, x2, 0); |
| emh203 | 0:3d9c67d97d6f | 397 | #endif |
| emh203 | 0:3d9c67d97d6f | 398 | |
| emh203 | 0:3d9c67d97d6f | 399 | acc3 = __SMLADX(x3, y2, acc3); |
| emh203 | 0:3d9c67d97d6f | 400 | |
| emh203 | 0:3d9c67d97d6f | 401 | #endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */ |
| emh203 | 0:3d9c67d97d6f | 402 | |
| emh203 | 0:3d9c67d97d6f | 403 | pIn2 += 4u; |
| emh203 | 0:3d9c67d97d6f | 404 | |
| emh203 | 0:3d9c67d97d6f | 405 | pScr += 4u; |
| emh203 | 0:3d9c67d97d6f | 406 | |
| emh203 | 0:3d9c67d97d6f | 407 | |
| emh203 | 0:3d9c67d97d6f | 408 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 409 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 410 | } |
| emh203 | 0:3d9c67d97d6f | 411 | |
| emh203 | 0:3d9c67d97d6f | 412 | |
| emh203 | 0:3d9c67d97d6f | 413 | |
| emh203 | 0:3d9c67d97d6f | 414 | /* Update scratch pointer for remaining samples of smaller length sequence */ |
| emh203 | 0:3d9c67d97d6f | 415 | pScr -= 4u; |
| emh203 | 0:3d9c67d97d6f | 416 | |
| emh203 | 0:3d9c67d97d6f | 417 | |
| emh203 | 0:3d9c67d97d6f | 418 | /* apply same above for remaining samples of smaller length sequence */ |
| emh203 | 0:3d9c67d97d6f | 419 | tapCnt = (srcBLen) & 3u; |
| emh203 | 0:3d9c67d97d6f | 420 | |
| emh203 | 0:3d9c67d97d6f | 421 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 422 | { |
| emh203 | 0:3d9c67d97d6f | 423 | |
| emh203 | 0:3d9c67d97d6f | 424 | /* accumlate the results */ |
| emh203 | 0:3d9c67d97d6f | 425 | acc0 += (*pScr++ * *pIn2); |
| emh203 | 0:3d9c67d97d6f | 426 | acc1 += (*pScr++ * *pIn2); |
| emh203 | 0:3d9c67d97d6f | 427 | acc2 += (*pScr++ * *pIn2); |
| emh203 | 0:3d9c67d97d6f | 428 | acc3 += (*pScr++ * *pIn2++); |
| emh203 | 0:3d9c67d97d6f | 429 | |
| emh203 | 0:3d9c67d97d6f | 430 | pScr -= 3u; |
| emh203 | 0:3d9c67d97d6f | 431 | |
| emh203 | 0:3d9c67d97d6f | 432 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 433 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 434 | } |
| emh203 | 0:3d9c67d97d6f | 435 | |
| emh203 | 0:3d9c67d97d6f | 436 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 437 | |
| emh203 | 0:3d9c67d97d6f | 438 | |
| emh203 | 0:3d9c67d97d6f | 439 | /* Store the results in the accumulators in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 440 | *pOut = (__SSAT(acc0 >> 15u, 16)); |
| emh203 | 0:3d9c67d97d6f | 441 | pOut += inc; |
| emh203 | 0:3d9c67d97d6f | 442 | *pOut = (__SSAT(acc1 >> 15u, 16)); |
| emh203 | 0:3d9c67d97d6f | 443 | pOut += inc; |
| emh203 | 0:3d9c67d97d6f | 444 | *pOut = (__SSAT(acc2 >> 15u, 16)); |
| emh203 | 0:3d9c67d97d6f | 445 | pOut += inc; |
| emh203 | 0:3d9c67d97d6f | 446 | *pOut = (__SSAT(acc3 >> 15u, 16)); |
| emh203 | 0:3d9c67d97d6f | 447 | pOut += inc; |
| emh203 | 0:3d9c67d97d6f | 448 | |
| emh203 | 0:3d9c67d97d6f | 449 | |
| emh203 | 0:3d9c67d97d6f | 450 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 451 | pIn2 = py; |
| emh203 | 0:3d9c67d97d6f | 452 | |
| emh203 | 0:3d9c67d97d6f | 453 | pScratch += 4u; |
| emh203 | 0:3d9c67d97d6f | 454 | |
| emh203 | 0:3d9c67d97d6f | 455 | } |
| emh203 | 0:3d9c67d97d6f | 456 | |
| emh203 | 0:3d9c67d97d6f | 457 | |
| emh203 | 0:3d9c67d97d6f | 458 | blkCnt = (srcALen + srcBLen - 1u) & 0x3; |
| emh203 | 0:3d9c67d97d6f | 459 | |
| emh203 | 0:3d9c67d97d6f | 460 | /* Calculate correlation for remaining samples of Bigger length sequence */ |
| emh203 | 0:3d9c67d97d6f | 461 | while(blkCnt > 0) |
| emh203 | 0:3d9c67d97d6f | 462 | { |
| emh203 | 0:3d9c67d97d6f | 463 | /* Initialze temporary scratch pointer as scratch1 */ |
| emh203 | 0:3d9c67d97d6f | 464 | pScr = pScratch; |
| emh203 | 0:3d9c67d97d6f | 465 | |
| emh203 | 0:3d9c67d97d6f | 466 | /* Clear Accumlators */ |
| emh203 | 0:3d9c67d97d6f | 467 | acc0 = 0; |
| emh203 | 0:3d9c67d97d6f | 468 | |
| emh203 | 0:3d9c67d97d6f | 469 | tapCnt = (srcBLen) >> 1u; |
| emh203 | 0:3d9c67d97d6f | 470 | |
| emh203 | 0:3d9c67d97d6f | 471 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 472 | { |
| emh203 | 0:3d9c67d97d6f | 473 | |
| emh203 | 0:3d9c67d97d6f | 474 | acc0 += (*pScr++ * *pIn2++); |
| emh203 | 0:3d9c67d97d6f | 475 | acc0 += (*pScr++ * *pIn2++); |
| emh203 | 0:3d9c67d97d6f | 476 | |
| emh203 | 0:3d9c67d97d6f | 477 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 478 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 479 | } |
| emh203 | 0:3d9c67d97d6f | 480 | |
| emh203 | 0:3d9c67d97d6f | 481 | tapCnt = (srcBLen) & 1u; |
| emh203 | 0:3d9c67d97d6f | 482 | |
| emh203 | 0:3d9c67d97d6f | 483 | /* apply same above for remaining samples of smaller length sequence */ |
| emh203 | 0:3d9c67d97d6f | 484 | while(tapCnt > 0u) |
| emh203 | 0:3d9c67d97d6f | 485 | { |
| emh203 | 0:3d9c67d97d6f | 486 | |
| emh203 | 0:3d9c67d97d6f | 487 | /* accumlate the results */ |
| emh203 | 0:3d9c67d97d6f | 488 | acc0 += (*pScr++ * *pIn2++); |
| emh203 | 0:3d9c67d97d6f | 489 | |
| emh203 | 0:3d9c67d97d6f | 490 | /* Decrement the loop counter */ |
| emh203 | 0:3d9c67d97d6f | 491 | tapCnt--; |
| emh203 | 0:3d9c67d97d6f | 492 | } |
| emh203 | 0:3d9c67d97d6f | 493 | |
| emh203 | 0:3d9c67d97d6f | 494 | blkCnt--; |
| emh203 | 0:3d9c67d97d6f | 495 | |
| emh203 | 0:3d9c67d97d6f | 496 | /* Store the result in the accumulator in the destination buffer. */ |
| emh203 | 0:3d9c67d97d6f | 497 | |
| emh203 | 0:3d9c67d97d6f | 498 | *pOut = (q15_t) (__SSAT((acc0 >> 15), 16)); |
| emh203 | 0:3d9c67d97d6f | 499 | |
| emh203 | 0:3d9c67d97d6f | 500 | pOut += inc; |
| emh203 | 0:3d9c67d97d6f | 501 | |
| emh203 | 0:3d9c67d97d6f | 502 | /* Initialization of inputB pointer */ |
| emh203 | 0:3d9c67d97d6f | 503 | pIn2 = py; |
| emh203 | 0:3d9c67d97d6f | 504 | |
| emh203 | 0:3d9c67d97d6f | 505 | pScratch += 1u; |
| emh203 | 0:3d9c67d97d6f | 506 | |
| emh203 | 0:3d9c67d97d6f | 507 | } |
| emh203 | 0:3d9c67d97d6f | 508 | } |
| emh203 | 0:3d9c67d97d6f | 509 | |
| emh203 | 0:3d9c67d97d6f | 510 | /** |
| emh203 | 0:3d9c67d97d6f | 511 | * @} end of Corr group |
| emh203 | 0:3d9c67d97d6f | 512 | */ |
Eli Hughes