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