Fork of mbed-dsp. CMSIS-DSP library of supporting NEON
Dependents: mbed-os-example-cmsis_dsp_neon
Fork of mbed-dsp by
Information
Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.
CMSIS-DSP of supporting NEON
What is this ?
A library for CMSIS-DSP of supporting NEON.
We supported the NEON to CMSIS-DSP Ver1.4.3(CMSIS V4.1) that ARM supplied, has achieved the processing speed improvement.
If you use the mbed-dsp library, you can use to replace this library.
CMSIS-DSP of supporting NEON is provied as a library.
Library Creation environment
CMSIS-DSP library of supporting NEON was created by the following environment.
- Compiler
ARMCC Version 5.03 - Compile option switch[C Compiler]
-DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -O3 -Otime --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp --vectorize --asm
- Compile option switch[Assembler]
--cpreproc --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp
Effects of NEON support
In the data which passes to each function, large size will be expected more effective than small size.
Also if the data is a multiple of 16, effect will be expected in every function in the CMSIS-DSP.
NEON対応CMSIS-DSP
概要
NEON対応したCMSIS-DSPのライブラリです。
ARM社提供のCMSIS-DSP Ver1.4.3(CMSIS V4.1)をターゲットにNEON対応を行ない、処理速度向上を実現しております。
mbed-dspライブラリを使用している場合は、本ライブラリに置き換えて使用することができます。
NEON対応したCMSIS-DSPはライブラリで提供します。
ライブラリ作成環境
NEON対応CMSIS-DSPライブラリは、以下の環境で作成しています。
- コンパイラ
ARMCC Version 5.03 - コンパイルオプションスイッチ[C Compiler]
-DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -O3 -Otime --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp --vectorize --asm
- コンパイルオプションスイッチ[Assembler]
--cpreproc --cpu=Cortex-A9 --littleend --arm --apcs=/interwork --no_unaligned_access --fpu=vfpv3_fp16 --fpmode=fast --apcs=/hardfp
NEON対応による効果について
CMSIS-DSP内の各関数へ渡すデータは、小さいサイズよりも大きいサイズの方が効果が見込めます。
また、16の倍数のデータであれば、CMSIS-DSP内のどの関数でも効果が見込めます。
cmsis_dsp/TransformFunctions/arm_dct4_q15.c@3:7a284390b0ce, 2013-11-08 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Nov 08 13:45:10 2013 +0000
- Revision:
- 3:7a284390b0ce
- Parent:
- 2:da51fb522205
Synchronized with git revision e69956aba2f68a2a26ac26b051f8d349deaa1ce8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:fdd22bb7aa52 | 1 | /* ---------------------------------------------------------------------- |
mbed_official | 3:7a284390b0ce | 2 | * Copyright (C) 2010-2013 ARM Limited. All rights reserved. |
emilmont | 1:fdd22bb7aa52 | 3 | * |
mbed_official | 3:7a284390b0ce | 4 | * $Date: 17. January 2013 |
mbed_official | 3:7a284390b0ce | 5 | * $Revision: V1.4.1 |
emilmont | 1:fdd22bb7aa52 | 6 | * |
emilmont | 2:da51fb522205 | 7 | * Project: CMSIS DSP Library |
emilmont | 2:da51fb522205 | 8 | * Title: arm_dct4_q15.c |
emilmont | 1:fdd22bb7aa52 | 9 | * |
emilmont | 2:da51fb522205 | 10 | * Description: Processing function of DCT4 & IDCT4 Q15. |
emilmont | 1:fdd22bb7aa52 | 11 | * |
emilmont | 1:fdd22bb7aa52 | 12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 |
emilmont | 1:fdd22bb7aa52 | 13 | * |
mbed_official | 3:7a284390b0ce | 14 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 3:7a284390b0ce | 15 | * modification, are permitted provided that the following conditions |
mbed_official | 3:7a284390b0ce | 16 | * are met: |
mbed_official | 3:7a284390b0ce | 17 | * - Redistributions of source code must retain the above copyright |
mbed_official | 3:7a284390b0ce | 18 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 3:7a284390b0ce | 19 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 3:7a284390b0ce | 20 | * notice, this list of conditions and the following disclaimer in |
mbed_official | 3:7a284390b0ce | 21 | * the documentation and/or other materials provided with the |
mbed_official | 3:7a284390b0ce | 22 | * distribution. |
mbed_official | 3:7a284390b0ce | 23 | * - Neither the name of ARM LIMITED nor the names of its contributors |
mbed_official | 3:7a284390b0ce | 24 | * may be used to endorse or promote products derived from this |
mbed_official | 3:7a284390b0ce | 25 | * software without specific prior written permission. |
mbed_official | 3:7a284390b0ce | 26 | * |
mbed_official | 3:7a284390b0ce | 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
mbed_official | 3:7a284390b0ce | 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
mbed_official | 3:7a284390b0ce | 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
mbed_official | 3:7a284390b0ce | 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
mbed_official | 3:7a284390b0ce | 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
mbed_official | 3:7a284390b0ce | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
mbed_official | 3:7a284390b0ce | 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mbed_official | 3:7a284390b0ce | 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 3:7a284390b0ce | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
mbed_official | 3:7a284390b0ce | 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
mbed_official | 3:7a284390b0ce | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 3:7a284390b0ce | 38 | * POSSIBILITY OF SUCH DAMAGE. |
emilmont | 1:fdd22bb7aa52 | 39 | * -------------------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 40 | |
emilmont | 1:fdd22bb7aa52 | 41 | #include "arm_math.h" |
emilmont | 1:fdd22bb7aa52 | 42 | |
emilmont | 1:fdd22bb7aa52 | 43 | /** |
emilmont | 1:fdd22bb7aa52 | 44 | * @addtogroup DCT4_IDCT4 |
emilmont | 1:fdd22bb7aa52 | 45 | * @{ |
emilmont | 1:fdd22bb7aa52 | 46 | */ |
emilmont | 1:fdd22bb7aa52 | 47 | |
emilmont | 1:fdd22bb7aa52 | 48 | /** |
emilmont | 1:fdd22bb7aa52 | 49 | * @brief Processing function for the Q15 DCT4/IDCT4. |
emilmont | 1:fdd22bb7aa52 | 50 | * @param[in] *S points to an instance of the Q15 DCT4 structure. |
emilmont | 1:fdd22bb7aa52 | 51 | * @param[in] *pState points to state buffer. |
emilmont | 1:fdd22bb7aa52 | 52 | * @param[in,out] *pInlineBuffer points to the in-place input and output buffer. |
emilmont | 1:fdd22bb7aa52 | 53 | * @return none. |
emilmont | 1:fdd22bb7aa52 | 54 | * |
emilmont | 1:fdd22bb7aa52 | 55 | * \par Input an output formats: |
emilmont | 1:fdd22bb7aa52 | 56 | * Internally inputs are downscaled in the RFFT process function to avoid overflows. |
emilmont | 1:fdd22bb7aa52 | 57 | * Number of bits downscaled, depends on the size of the transform. |
emilmont | 1:fdd22bb7aa52 | 58 | * The input and output formats for different DCT sizes and number of bits to upscale are mentioned in the table below: |
emilmont | 1:fdd22bb7aa52 | 59 | * |
emilmont | 1:fdd22bb7aa52 | 60 | * \image html dct4FormatsQ15Table.gif |
emilmont | 1:fdd22bb7aa52 | 61 | */ |
emilmont | 1:fdd22bb7aa52 | 62 | |
emilmont | 1:fdd22bb7aa52 | 63 | void arm_dct4_q15( |
emilmont | 1:fdd22bb7aa52 | 64 | const arm_dct4_instance_q15 * S, |
emilmont | 1:fdd22bb7aa52 | 65 | q15_t * pState, |
emilmont | 1:fdd22bb7aa52 | 66 | q15_t * pInlineBuffer) |
emilmont | 1:fdd22bb7aa52 | 67 | { |
emilmont | 1:fdd22bb7aa52 | 68 | uint32_t i; /* Loop counter */ |
emilmont | 1:fdd22bb7aa52 | 69 | q15_t *weights = S->pTwiddle; /* Pointer to the Weights table */ |
emilmont | 1:fdd22bb7aa52 | 70 | q15_t *cosFact = S->pCosFactor; /* Pointer to the cos factors table */ |
emilmont | 1:fdd22bb7aa52 | 71 | q15_t *pS1, *pS2, *pbuff; /* Temporary pointers for input buffer and pState buffer */ |
emilmont | 1:fdd22bb7aa52 | 72 | q15_t in; /* Temporary variable */ |
emilmont | 1:fdd22bb7aa52 | 73 | |
emilmont | 1:fdd22bb7aa52 | 74 | |
emilmont | 1:fdd22bb7aa52 | 75 | /* DCT4 computation involves DCT2 (which is calculated using RFFT) |
emilmont | 1:fdd22bb7aa52 | 76 | * along with some pre-processing and post-processing. |
emilmont | 1:fdd22bb7aa52 | 77 | * Computational procedure is explained as follows: |
emilmont | 1:fdd22bb7aa52 | 78 | * (a) Pre-processing involves multiplying input with cos factor, |
emilmont | 1:fdd22bb7aa52 | 79 | * r(n) = 2 * u(n) * cos(pi*(2*n+1)/(4*n)) |
emilmont | 1:fdd22bb7aa52 | 80 | * where, |
emilmont | 1:fdd22bb7aa52 | 81 | * r(n) -- output of preprocessing |
emilmont | 1:fdd22bb7aa52 | 82 | * u(n) -- input to preprocessing(actual Source buffer) |
emilmont | 1:fdd22bb7aa52 | 83 | * (b) Calculation of DCT2 using FFT is divided into three steps: |
emilmont | 1:fdd22bb7aa52 | 84 | * Step1: Re-ordering of even and odd elements of input. |
emilmont | 1:fdd22bb7aa52 | 85 | * Step2: Calculating FFT of the re-ordered input. |
emilmont | 1:fdd22bb7aa52 | 86 | * Step3: Taking the real part of the product of FFT output and weights. |
emilmont | 1:fdd22bb7aa52 | 87 | * (c) Post-processing - DCT4 can be obtained from DCT2 output using the following equation: |
emilmont | 1:fdd22bb7aa52 | 88 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emilmont | 1:fdd22bb7aa52 | 89 | * where, |
emilmont | 1:fdd22bb7aa52 | 90 | * Y4 -- DCT4 output, Y2 -- DCT2 output |
emilmont | 1:fdd22bb7aa52 | 91 | * (d) Multiplying the output with the normalizing factor sqrt(2/N). |
emilmont | 1:fdd22bb7aa52 | 92 | */ |
emilmont | 1:fdd22bb7aa52 | 93 | |
emilmont | 1:fdd22bb7aa52 | 94 | /*-------- Pre-processing ------------*/ |
emilmont | 1:fdd22bb7aa52 | 95 | /* Multiplying input with cos factor i.e. r(n) = 2 * x(n) * cos(pi*(2*n+1)/(4*n)) */ |
emilmont | 1:fdd22bb7aa52 | 96 | arm_mult_q15(pInlineBuffer, cosFact, pInlineBuffer, S->N); |
emilmont | 1:fdd22bb7aa52 | 97 | arm_shift_q15(pInlineBuffer, 1, pInlineBuffer, S->N); |
emilmont | 1:fdd22bb7aa52 | 98 | |
emilmont | 1:fdd22bb7aa52 | 99 | /* ---------------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 100 | * Step1: Re-ordering of even and odd elements as |
emilmont | 1:fdd22bb7aa52 | 101 | * pState[i] = pInlineBuffer[2*i] and |
emilmont | 1:fdd22bb7aa52 | 102 | * pState[N-i-1] = pInlineBuffer[2*i+1] where i = 0 to N/2 |
emilmont | 1:fdd22bb7aa52 | 103 | ---------------------------------------------------------------------*/ |
emilmont | 1:fdd22bb7aa52 | 104 | |
emilmont | 1:fdd22bb7aa52 | 105 | /* pS1 initialized to pState */ |
emilmont | 1:fdd22bb7aa52 | 106 | pS1 = pState; |
emilmont | 1:fdd22bb7aa52 | 107 | |
emilmont | 1:fdd22bb7aa52 | 108 | /* pS2 initialized to pState+N-1, so that it points to the end of the state buffer */ |
emilmont | 1:fdd22bb7aa52 | 109 | pS2 = pState + (S->N - 1u); |
emilmont | 1:fdd22bb7aa52 | 110 | |
emilmont | 1:fdd22bb7aa52 | 111 | /* pbuff initialized to input buffer */ |
emilmont | 1:fdd22bb7aa52 | 112 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 113 | |
emilmont | 1:fdd22bb7aa52 | 114 | |
mbed_official | 3:7a284390b0ce | 115 | #ifndef ARM_MATH_CM0_FAMILY |
emilmont | 1:fdd22bb7aa52 | 116 | |
emilmont | 1:fdd22bb7aa52 | 117 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
emilmont | 1:fdd22bb7aa52 | 118 | |
emilmont | 1:fdd22bb7aa52 | 119 | /* Initializing the loop counter to N/2 >> 2 for loop unrolling by 4 */ |
emilmont | 1:fdd22bb7aa52 | 120 | i = (uint32_t) S->Nby2 >> 2u; |
emilmont | 1:fdd22bb7aa52 | 121 | |
emilmont | 1:fdd22bb7aa52 | 122 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
emilmont | 1:fdd22bb7aa52 | 123 | ** a second loop below computes the remaining 1 to 3 samples. */ |
emilmont | 1:fdd22bb7aa52 | 124 | do |
emilmont | 1:fdd22bb7aa52 | 125 | { |
emilmont | 1:fdd22bb7aa52 | 126 | /* Re-ordering of even and odd elements */ |
emilmont | 1:fdd22bb7aa52 | 127 | /* pState[i] = pInlineBuffer[2*i] */ |
emilmont | 1:fdd22bb7aa52 | 128 | *pS1++ = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 129 | /* pState[N-i-1] = pInlineBuffer[2*i+1] */ |
emilmont | 1:fdd22bb7aa52 | 130 | *pS2-- = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 131 | |
emilmont | 1:fdd22bb7aa52 | 132 | *pS1++ = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 133 | *pS2-- = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 134 | |
emilmont | 1:fdd22bb7aa52 | 135 | *pS1++ = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 136 | *pS2-- = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 137 | |
emilmont | 1:fdd22bb7aa52 | 138 | *pS1++ = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 139 | *pS2-- = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 140 | |
emilmont | 1:fdd22bb7aa52 | 141 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 142 | i--; |
emilmont | 1:fdd22bb7aa52 | 143 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 144 | |
emilmont | 1:fdd22bb7aa52 | 145 | /* pbuff initialized to input buffer */ |
emilmont | 1:fdd22bb7aa52 | 146 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 147 | |
emilmont | 1:fdd22bb7aa52 | 148 | /* pS1 initialized to pState */ |
emilmont | 1:fdd22bb7aa52 | 149 | pS1 = pState; |
emilmont | 1:fdd22bb7aa52 | 150 | |
emilmont | 1:fdd22bb7aa52 | 151 | /* Initializing the loop counter to N/4 instead of N for loop unrolling */ |
emilmont | 1:fdd22bb7aa52 | 152 | i = (uint32_t) S->N >> 2u; |
emilmont | 1:fdd22bb7aa52 | 153 | |
emilmont | 1:fdd22bb7aa52 | 154 | /* Processing with loop unrolling 4 times as N is always multiple of 4. |
emilmont | 1:fdd22bb7aa52 | 155 | * Compute 4 outputs at a time */ |
emilmont | 1:fdd22bb7aa52 | 156 | do |
emilmont | 1:fdd22bb7aa52 | 157 | { |
emilmont | 1:fdd22bb7aa52 | 158 | /* Writing the re-ordered output back to inplace input buffer */ |
emilmont | 1:fdd22bb7aa52 | 159 | *pbuff++ = *pS1++; |
emilmont | 1:fdd22bb7aa52 | 160 | *pbuff++ = *pS1++; |
emilmont | 1:fdd22bb7aa52 | 161 | *pbuff++ = *pS1++; |
emilmont | 1:fdd22bb7aa52 | 162 | *pbuff++ = *pS1++; |
emilmont | 1:fdd22bb7aa52 | 163 | |
emilmont | 1:fdd22bb7aa52 | 164 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 165 | i--; |
emilmont | 1:fdd22bb7aa52 | 166 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 167 | |
emilmont | 1:fdd22bb7aa52 | 168 | |
emilmont | 1:fdd22bb7aa52 | 169 | /* --------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 170 | * Step2: Calculate RFFT for N-point input |
emilmont | 1:fdd22bb7aa52 | 171 | * ---------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 172 | /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */ |
emilmont | 1:fdd22bb7aa52 | 173 | arm_rfft_q15(S->pRfft, pInlineBuffer, pState); |
emilmont | 1:fdd22bb7aa52 | 174 | |
emilmont | 1:fdd22bb7aa52 | 175 | /*---------------------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 176 | * Step3: Multiply the FFT output with the weights. |
emilmont | 1:fdd22bb7aa52 | 177 | *----------------------------------------------------------------------*/ |
emilmont | 1:fdd22bb7aa52 | 178 | arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N); |
emilmont | 1:fdd22bb7aa52 | 179 | |
emilmont | 1:fdd22bb7aa52 | 180 | /* The output of complex multiplication is in 3.13 format. |
emilmont | 1:fdd22bb7aa52 | 181 | * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */ |
emilmont | 1:fdd22bb7aa52 | 182 | arm_shift_q15(pState, 2, pState, S->N * 2); |
emilmont | 1:fdd22bb7aa52 | 183 | |
emilmont | 1:fdd22bb7aa52 | 184 | /* ----------- Post-processing ---------- */ |
emilmont | 1:fdd22bb7aa52 | 185 | /* DCT-IV can be obtained from DCT-II by the equation, |
emilmont | 1:fdd22bb7aa52 | 186 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emilmont | 1:fdd22bb7aa52 | 187 | * Hence, Y4(0) = Y2(0)/2 */ |
emilmont | 1:fdd22bb7aa52 | 188 | /* Getting only real part from the output and Converting to DCT-IV */ |
emilmont | 1:fdd22bb7aa52 | 189 | |
emilmont | 1:fdd22bb7aa52 | 190 | /* Initializing the loop counter to N >> 2 for loop unrolling by 4 */ |
emilmont | 1:fdd22bb7aa52 | 191 | i = ((uint32_t) S->N - 1u) >> 2u; |
emilmont | 1:fdd22bb7aa52 | 192 | |
emilmont | 1:fdd22bb7aa52 | 193 | /* pbuff initialized to input buffer. */ |
emilmont | 1:fdd22bb7aa52 | 194 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 195 | |
emilmont | 1:fdd22bb7aa52 | 196 | /* pS1 initialized to pState */ |
emilmont | 1:fdd22bb7aa52 | 197 | pS1 = pState; |
emilmont | 1:fdd22bb7aa52 | 198 | |
emilmont | 1:fdd22bb7aa52 | 199 | /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */ |
emilmont | 1:fdd22bb7aa52 | 200 | in = *pS1++ >> 1u; |
emilmont | 1:fdd22bb7aa52 | 201 | /* input buffer acts as inplace, so output values are stored in the input itself. */ |
emilmont | 1:fdd22bb7aa52 | 202 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 203 | |
emilmont | 1:fdd22bb7aa52 | 204 | /* pState pointer is incremented twice as the real values are located alternatively in the array */ |
emilmont | 1:fdd22bb7aa52 | 205 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 206 | |
emilmont | 1:fdd22bb7aa52 | 207 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
emilmont | 1:fdd22bb7aa52 | 208 | ** a second loop below computes the remaining 1 to 3 samples. */ |
emilmont | 1:fdd22bb7aa52 | 209 | do |
emilmont | 1:fdd22bb7aa52 | 210 | { |
emilmont | 1:fdd22bb7aa52 | 211 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emilmont | 1:fdd22bb7aa52 | 212 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emilmont | 1:fdd22bb7aa52 | 213 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 214 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 215 | /* points to the next real value */ |
emilmont | 1:fdd22bb7aa52 | 216 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 217 | |
emilmont | 1:fdd22bb7aa52 | 218 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 219 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 220 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 221 | |
emilmont | 1:fdd22bb7aa52 | 222 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 223 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 224 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 225 | |
emilmont | 1:fdd22bb7aa52 | 226 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 227 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 228 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 229 | |
emilmont | 1:fdd22bb7aa52 | 230 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 231 | i--; |
emilmont | 1:fdd22bb7aa52 | 232 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 233 | |
emilmont | 1:fdd22bb7aa52 | 234 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
emilmont | 1:fdd22bb7aa52 | 235 | ** No loop unrolling is used. */ |
emilmont | 1:fdd22bb7aa52 | 236 | i = ((uint32_t) S->N - 1u) % 0x4u; |
emilmont | 1:fdd22bb7aa52 | 237 | |
emilmont | 1:fdd22bb7aa52 | 238 | while(i > 0u) |
emilmont | 1:fdd22bb7aa52 | 239 | { |
emilmont | 1:fdd22bb7aa52 | 240 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emilmont | 1:fdd22bb7aa52 | 241 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emilmont | 1:fdd22bb7aa52 | 242 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 243 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 244 | /* points to the next real value */ |
emilmont | 1:fdd22bb7aa52 | 245 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 246 | |
emilmont | 1:fdd22bb7aa52 | 247 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 248 | i--; |
emilmont | 1:fdd22bb7aa52 | 249 | } |
emilmont | 1:fdd22bb7aa52 | 250 | |
emilmont | 1:fdd22bb7aa52 | 251 | |
emilmont | 1:fdd22bb7aa52 | 252 | /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/ |
emilmont | 1:fdd22bb7aa52 | 253 | |
emilmont | 1:fdd22bb7aa52 | 254 | /* Initializing the loop counter to N/4 instead of N for loop unrolling */ |
emilmont | 1:fdd22bb7aa52 | 255 | i = (uint32_t) S->N >> 2u; |
emilmont | 1:fdd22bb7aa52 | 256 | |
emilmont | 1:fdd22bb7aa52 | 257 | /* pbuff initialized to the pInlineBuffer(now contains the output values) */ |
emilmont | 1:fdd22bb7aa52 | 258 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 259 | |
emilmont | 1:fdd22bb7aa52 | 260 | /* Processing with loop unrolling 4 times as N is always multiple of 4. Compute 4 outputs at a time */ |
emilmont | 1:fdd22bb7aa52 | 261 | do |
emilmont | 1:fdd22bb7aa52 | 262 | { |
emilmont | 1:fdd22bb7aa52 | 263 | /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */ |
emilmont | 1:fdd22bb7aa52 | 264 | in = *pbuff; |
emilmont | 1:fdd22bb7aa52 | 265 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emilmont | 1:fdd22bb7aa52 | 266 | |
emilmont | 1:fdd22bb7aa52 | 267 | in = *pbuff; |
emilmont | 1:fdd22bb7aa52 | 268 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emilmont | 1:fdd22bb7aa52 | 269 | |
emilmont | 1:fdd22bb7aa52 | 270 | in = *pbuff; |
emilmont | 1:fdd22bb7aa52 | 271 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emilmont | 1:fdd22bb7aa52 | 272 | |
emilmont | 1:fdd22bb7aa52 | 273 | in = *pbuff; |
emilmont | 1:fdd22bb7aa52 | 274 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emilmont | 1:fdd22bb7aa52 | 275 | |
emilmont | 1:fdd22bb7aa52 | 276 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 277 | i--; |
emilmont | 1:fdd22bb7aa52 | 278 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 279 | |
emilmont | 1:fdd22bb7aa52 | 280 | |
emilmont | 1:fdd22bb7aa52 | 281 | #else |
emilmont | 1:fdd22bb7aa52 | 282 | |
emilmont | 1:fdd22bb7aa52 | 283 | /* Run the below code for Cortex-M0 */ |
emilmont | 1:fdd22bb7aa52 | 284 | |
emilmont | 1:fdd22bb7aa52 | 285 | /* Initializing the loop counter to N/2 */ |
emilmont | 1:fdd22bb7aa52 | 286 | i = (uint32_t) S->Nby2; |
emilmont | 1:fdd22bb7aa52 | 287 | |
emilmont | 1:fdd22bb7aa52 | 288 | do |
emilmont | 1:fdd22bb7aa52 | 289 | { |
emilmont | 1:fdd22bb7aa52 | 290 | /* Re-ordering of even and odd elements */ |
emilmont | 1:fdd22bb7aa52 | 291 | /* pState[i] = pInlineBuffer[2*i] */ |
emilmont | 1:fdd22bb7aa52 | 292 | *pS1++ = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 293 | /* pState[N-i-1] = pInlineBuffer[2*i+1] */ |
emilmont | 1:fdd22bb7aa52 | 294 | *pS2-- = *pbuff++; |
emilmont | 1:fdd22bb7aa52 | 295 | |
emilmont | 1:fdd22bb7aa52 | 296 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 297 | i--; |
emilmont | 1:fdd22bb7aa52 | 298 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 299 | |
emilmont | 1:fdd22bb7aa52 | 300 | /* pbuff initialized to input buffer */ |
emilmont | 1:fdd22bb7aa52 | 301 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 302 | |
emilmont | 1:fdd22bb7aa52 | 303 | /* pS1 initialized to pState */ |
emilmont | 1:fdd22bb7aa52 | 304 | pS1 = pState; |
emilmont | 1:fdd22bb7aa52 | 305 | |
emilmont | 1:fdd22bb7aa52 | 306 | /* Initializing the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 307 | i = (uint32_t) S->N; |
emilmont | 1:fdd22bb7aa52 | 308 | |
emilmont | 1:fdd22bb7aa52 | 309 | do |
emilmont | 1:fdd22bb7aa52 | 310 | { |
emilmont | 1:fdd22bb7aa52 | 311 | /* Writing the re-ordered output back to inplace input buffer */ |
emilmont | 1:fdd22bb7aa52 | 312 | *pbuff++ = *pS1++; |
emilmont | 1:fdd22bb7aa52 | 313 | |
emilmont | 1:fdd22bb7aa52 | 314 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 315 | i--; |
emilmont | 1:fdd22bb7aa52 | 316 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 317 | |
emilmont | 1:fdd22bb7aa52 | 318 | |
emilmont | 1:fdd22bb7aa52 | 319 | /* --------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 320 | * Step2: Calculate RFFT for N-point input |
emilmont | 1:fdd22bb7aa52 | 321 | * ---------------------------------------------------------- */ |
emilmont | 1:fdd22bb7aa52 | 322 | /* pInlineBuffer is real input of length N , pState is the complex output of length 2N */ |
emilmont | 1:fdd22bb7aa52 | 323 | arm_rfft_q15(S->pRfft, pInlineBuffer, pState); |
emilmont | 1:fdd22bb7aa52 | 324 | |
emilmont | 1:fdd22bb7aa52 | 325 | /*---------------------------------------------------------------------- |
emilmont | 1:fdd22bb7aa52 | 326 | * Step3: Multiply the FFT output with the weights. |
emilmont | 1:fdd22bb7aa52 | 327 | *----------------------------------------------------------------------*/ |
emilmont | 1:fdd22bb7aa52 | 328 | arm_cmplx_mult_cmplx_q15(pState, weights, pState, S->N); |
emilmont | 1:fdd22bb7aa52 | 329 | |
emilmont | 1:fdd22bb7aa52 | 330 | /* The output of complex multiplication is in 3.13 format. |
emilmont | 1:fdd22bb7aa52 | 331 | * Hence changing the format of N (i.e. 2*N elements) complex numbers to 1.15 format by shifting left by 2 bits. */ |
emilmont | 1:fdd22bb7aa52 | 332 | arm_shift_q15(pState, 2, pState, S->N * 2); |
emilmont | 1:fdd22bb7aa52 | 333 | |
emilmont | 1:fdd22bb7aa52 | 334 | /* ----------- Post-processing ---------- */ |
emilmont | 1:fdd22bb7aa52 | 335 | /* DCT-IV can be obtained from DCT-II by the equation, |
emilmont | 1:fdd22bb7aa52 | 336 | * Y4(k) = Y2(k) - Y4(k-1) and Y4(-1) = Y4(0) |
emilmont | 1:fdd22bb7aa52 | 337 | * Hence, Y4(0) = Y2(0)/2 */ |
emilmont | 1:fdd22bb7aa52 | 338 | /* Getting only real part from the output and Converting to DCT-IV */ |
emilmont | 1:fdd22bb7aa52 | 339 | |
emilmont | 1:fdd22bb7aa52 | 340 | /* Initializing the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 341 | i = ((uint32_t) S->N - 1u); |
emilmont | 1:fdd22bb7aa52 | 342 | |
emilmont | 1:fdd22bb7aa52 | 343 | /* pbuff initialized to input buffer. */ |
emilmont | 1:fdd22bb7aa52 | 344 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 345 | |
emilmont | 1:fdd22bb7aa52 | 346 | /* pS1 initialized to pState */ |
emilmont | 1:fdd22bb7aa52 | 347 | pS1 = pState; |
emilmont | 1:fdd22bb7aa52 | 348 | |
emilmont | 1:fdd22bb7aa52 | 349 | /* Calculating Y4(0) from Y2(0) using Y4(0) = Y2(0)/2 */ |
emilmont | 1:fdd22bb7aa52 | 350 | in = *pS1++ >> 1u; |
emilmont | 1:fdd22bb7aa52 | 351 | /* input buffer acts as inplace, so output values are stored in the input itself. */ |
emilmont | 1:fdd22bb7aa52 | 352 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 353 | |
emilmont | 1:fdd22bb7aa52 | 354 | /* pState pointer is incremented twice as the real values are located alternatively in the array */ |
emilmont | 1:fdd22bb7aa52 | 355 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 356 | |
emilmont | 1:fdd22bb7aa52 | 357 | do |
emilmont | 1:fdd22bb7aa52 | 358 | { |
emilmont | 1:fdd22bb7aa52 | 359 | /* Calculating Y4(1) to Y4(N-1) from Y2 using equation Y4(k) = Y2(k) - Y4(k-1) */ |
emilmont | 1:fdd22bb7aa52 | 360 | /* pState pointer (pS1) is incremented twice as the real values are located alternatively in the array */ |
emilmont | 1:fdd22bb7aa52 | 361 | in = *pS1++ - in; |
emilmont | 1:fdd22bb7aa52 | 362 | *pbuff++ = in; |
emilmont | 1:fdd22bb7aa52 | 363 | /* points to the next real value */ |
emilmont | 1:fdd22bb7aa52 | 364 | pS1++; |
emilmont | 1:fdd22bb7aa52 | 365 | |
emilmont | 1:fdd22bb7aa52 | 366 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 367 | i--; |
emilmont | 1:fdd22bb7aa52 | 368 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 369 | |
emilmont | 1:fdd22bb7aa52 | 370 | /*------------ Normalizing the output by multiplying with the normalizing factor ----------*/ |
emilmont | 1:fdd22bb7aa52 | 371 | |
emilmont | 1:fdd22bb7aa52 | 372 | /* Initializing the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 373 | i = (uint32_t) S->N; |
emilmont | 1:fdd22bb7aa52 | 374 | |
emilmont | 1:fdd22bb7aa52 | 375 | /* pbuff initialized to the pInlineBuffer(now contains the output values) */ |
emilmont | 1:fdd22bb7aa52 | 376 | pbuff = pInlineBuffer; |
emilmont | 1:fdd22bb7aa52 | 377 | |
emilmont | 1:fdd22bb7aa52 | 378 | do |
emilmont | 1:fdd22bb7aa52 | 379 | { |
emilmont | 1:fdd22bb7aa52 | 380 | /* Multiplying pInlineBuffer with the normalizing factor sqrt(2/N) */ |
emilmont | 1:fdd22bb7aa52 | 381 | in = *pbuff; |
emilmont | 1:fdd22bb7aa52 | 382 | *pbuff++ = ((q15_t) (((q31_t) in * S->normalize) >> 15)); |
emilmont | 1:fdd22bb7aa52 | 383 | |
emilmont | 1:fdd22bb7aa52 | 384 | /* Decrement the loop counter */ |
emilmont | 1:fdd22bb7aa52 | 385 | i--; |
emilmont | 1:fdd22bb7aa52 | 386 | } while(i > 0u); |
emilmont | 1:fdd22bb7aa52 | 387 | |
mbed_official | 3:7a284390b0ce | 388 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */ |
emilmont | 1:fdd22bb7aa52 | 389 | |
emilmont | 1:fdd22bb7aa52 | 390 | } |
emilmont | 1:fdd22bb7aa52 | 391 | |
emilmont | 1:fdd22bb7aa52 | 392 | /** |
emilmont | 1:fdd22bb7aa52 | 393 | * @} end of DCT4_IDCT4 group |
emilmont | 1:fdd22bb7aa52 | 394 | */ |