Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dsp by
arm_cmplx_dot_prod_q31.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010-2013 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 17. January 2013 00005 * $Revision: V1.4.1 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_cmplx_dot_prod_q31.c 00009 * 00010 * Description: Q31 complex dot product 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * - Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in 00021 * the documentation and/or other materials provided with the 00022 * distribution. 00023 * - Neither the name of ARM LIMITED nor the names of its contributors 00024 * may be used to endorse or promote products derived from this 00025 * software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00028 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00029 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00030 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00031 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00033 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00037 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * -------------------------------------------------------------------- */ 00040 00041 #include "arm_math.h" 00042 00043 /** 00044 * @ingroup groupCmplxMath 00045 */ 00046 00047 /** 00048 * @addtogroup cmplx_dot_prod 00049 * @{ 00050 */ 00051 00052 /** 00053 * @brief Q31 complex dot product 00054 * @param *pSrcA points to the first input vector 00055 * @param *pSrcB points to the second input vector 00056 * @param numSamples number of complex samples in each vector 00057 * @param *realResult real part of the result returned here 00058 * @param *imagResult imaginary part of the result returned here 00059 * @return none. 00060 * 00061 * <b>Scaling and Overflow Behavior:</b> 00062 * \par 00063 * The function is implemented using an internal 64-bit accumulator. 00064 * The intermediate 1.31 by 1.31 multiplications are performed with 64-bit precision and then shifted to 16.48 format. 00065 * The internal real and imaginary accumulators are in 16.48 format and provide 15 guard bits. 00066 * Additions are nonsaturating and no overflow will occur as long as <code>numSamples</code> is less than 32768. 00067 * The return results <code>realResult</code> and <code>imagResult</code> are in 16.48 format. 00068 * Input down scaling is not required. 00069 */ 00070 00071 void arm_cmplx_dot_prod_q31( 00072 q31_t * pSrcA, 00073 q31_t * pSrcB, 00074 uint32_t numSamples, 00075 q63_t * realResult, 00076 q63_t * imagResult) 00077 { 00078 q63_t real_sum = 0, imag_sum = 0; /* Temporary result storage */ 00079 00080 #ifndef ARM_MATH_CM0_FAMILY 00081 00082 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00083 uint32_t blkCnt; /* loop counter */ 00084 00085 00086 /*loop Unrolling */ 00087 blkCnt = numSamples >> 2u; 00088 00089 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00090 ** a second loop below computes the remaining 1 to 3 samples. */ 00091 while(blkCnt > 0u) 00092 { 00093 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ 00094 /* Convert real data in 2.62 to 16.48 by 14 right shifts */ 00095 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00096 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ 00097 /* Convert imag data in 2.62 to 16.48 by 14 right shifts */ 00098 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00099 00100 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00101 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00102 00103 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00104 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00105 00106 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00107 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00108 00109 00110 /* Decrement the loop counter */ 00111 blkCnt--; 00112 } 00113 00114 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00115 ** No loop unrolling is used. */ 00116 blkCnt = numSamples % 0x4u; 00117 00118 while(blkCnt > 0u) 00119 { 00120 /* CReal = A[0]* B[0] + A[2]* B[2] + A[4]* B[4] + .....+ A[numSamples-2]* B[numSamples-2] */ 00121 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00122 /* CImag = A[1]* B[1] + A[3]* B[3] + A[5]* B[5] + .....+ A[numSamples-1]* B[numSamples-1] */ 00123 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00124 00125 /* Decrement the loop counter */ 00126 blkCnt--; 00127 } 00128 00129 #else 00130 00131 /* Run the below code for Cortex-M0 */ 00132 00133 while(numSamples > 0u) 00134 { 00135 /* outReal = realA[0]* realB[0] + realA[2]* realB[2] + realA[4]* realB[4] + .....+ realA[numSamples-2]* realB[numSamples-2] */ 00136 real_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00137 /* outImag = imagA[1]* imagB[1] + imagA[3]* imagB[3] + imagA[5]* imagB[5] + .....+ imagA[numSamples-1]* imagB[numSamples-1] */ 00138 imag_sum += (q63_t) * pSrcA++ * (*pSrcB++) >> 14; 00139 00140 /* Decrement the loop counter */ 00141 numSamples--; 00142 } 00143 00144 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00145 00146 /* Store the real and imaginary results in 16.48 format */ 00147 *realResult = real_sum; 00148 *imagResult = imag_sum; 00149 } 00150 00151 /** 00152 * @} end of cmplx_dot_prod group 00153 */
Generated on Tue Jul 12 2022 18:44:08 by
1.7.2
