CMSIS DSP library
Dependents: performance_timer Surfboard_ gps2rtty Capstone ... more
arm_cmplx_mult_cmplx_q15.c
00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 19. March 2015 00005 * $Revision: V.1.4.5 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_cmplx_mult_cmplx_q15.c 00009 * 00010 * Description: Q15 complex-by-complex multiplication 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 CmplxByCmplxMult 00049 * @{ 00050 */ 00051 00052 /** 00053 * @brief Q15 complex-by-complex multiplication 00054 * @param[in] *pSrcA points to the first input vector 00055 * @param[in] *pSrcB points to the second input vector 00056 * @param[out] *pDst points to the output vector 00057 * @param[in] numSamples number of complex samples in each vector 00058 * @return none. 00059 * 00060 * <b>Scaling and Overflow Behavior:</b> 00061 * \par 00062 * The function implements 1.15 by 1.15 multiplications and finally output is converted into 3.13 format. 00063 */ 00064 00065 void arm_cmplx_mult_cmplx_q15( 00066 q15_t * pSrcA, 00067 q15_t * pSrcB, 00068 q15_t * pDst, 00069 uint32_t numSamples) 00070 { 00071 q15_t a, b, c, d; /* Temporary variables to store real and imaginary values */ 00072 00073 #ifndef ARM_MATH_CM0_FAMILY 00074 00075 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00076 uint32_t blkCnt; /* loop counters */ 00077 00078 /* loop Unrolling */ 00079 blkCnt = numSamples >> 2u; 00080 00081 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00082 ** a second loop below computes the remaining 1 to 3 samples. */ 00083 while(blkCnt > 0u) 00084 { 00085 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00086 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00087 a = *pSrcA++; 00088 b = *pSrcA++; 00089 c = *pSrcB++; 00090 d = *pSrcB++; 00091 00092 /* store the result in 3.13 format in the destination buffer. */ 00093 *pDst++ = 00094 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00095 /* store the result in 3.13 format in the destination buffer. */ 00096 *pDst++ = 00097 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00098 00099 a = *pSrcA++; 00100 b = *pSrcA++; 00101 c = *pSrcB++; 00102 d = *pSrcB++; 00103 00104 /* store the result in 3.13 format in the destination buffer. */ 00105 *pDst++ = 00106 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00107 /* store the result in 3.13 format in the destination buffer. */ 00108 *pDst++ = 00109 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00110 00111 a = *pSrcA++; 00112 b = *pSrcA++; 00113 c = *pSrcB++; 00114 d = *pSrcB++; 00115 00116 /* store the result in 3.13 format in the destination buffer. */ 00117 *pDst++ = 00118 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00119 /* store the result in 3.13 format in the destination buffer. */ 00120 *pDst++ = 00121 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00122 00123 a = *pSrcA++; 00124 b = *pSrcA++; 00125 c = *pSrcB++; 00126 d = *pSrcB++; 00127 00128 /* store the result in 3.13 format in the destination buffer. */ 00129 *pDst++ = 00130 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00131 /* store the result in 3.13 format in the destination buffer. */ 00132 *pDst++ = 00133 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00134 00135 /* Decrement the blockSize loop counter */ 00136 blkCnt--; 00137 } 00138 00139 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00140 ** No loop unrolling is used. */ 00141 blkCnt = numSamples % 0x4u; 00142 00143 while(blkCnt > 0u) 00144 { 00145 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00146 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00147 a = *pSrcA++; 00148 b = *pSrcA++; 00149 c = *pSrcB++; 00150 d = *pSrcB++; 00151 00152 /* store the result in 3.13 format in the destination buffer. */ 00153 *pDst++ = 00154 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00155 /* store the result in 3.13 format in the destination buffer. */ 00156 *pDst++ = 00157 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00158 00159 /* Decrement the blockSize loop counter */ 00160 blkCnt--; 00161 } 00162 00163 #else 00164 00165 /* Run the below code for Cortex-M0 */ 00166 00167 while(numSamples > 0u) 00168 { 00169 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00170 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00171 a = *pSrcA++; 00172 b = *pSrcA++; 00173 c = *pSrcB++; 00174 d = *pSrcB++; 00175 00176 /* store the result in 3.13 format in the destination buffer. */ 00177 *pDst++ = 00178 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00179 /* store the result in 3.13 format in the destination buffer. */ 00180 *pDst++ = 00181 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00182 00183 /* Decrement the blockSize loop counter */ 00184 numSamples--; 00185 } 00186 00187 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00188 00189 } 00190 00191 /** 00192 * @} end of CmplxByCmplxMult group 00193 */
Generated on Tue Jul 12 2022 11:59:15 by 1.7.2