00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. July 2011 00005 * $Revision: V1.0.10 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 * Version 1.0.10 2011/7/15 00015 * Big Endian support added and Merged M0 and M3/M4 Source code. 00016 * 00017 * Version 1.0.3 2010/11/29 00018 * Re-organized the CMSIS folders and updated documentation. 00019 * 00020 * Version 1.0.2 2010/11/11 00021 * Documentation updated. 00022 * 00023 * Version 1.0.1 2010/10/05 00024 * Production release and review comments incorporated. 00025 * 00026 * Version 1.0.0 2010/09/20 00027 * Production release and review comments incorporated. 00028 * -------------------------------------------------------------------- */ 00029 00030 #include "arm_math.h" 00031 00054 void arm_cmplx_mult_cmplx_q15( 00055 q15_t * pSrcA, 00056 q15_t * pSrcB, 00057 q15_t * pDst, 00058 uint32_t numSamples) 00059 { 00060 q15_t a, b, c, d; /* Temporary variables to store real and imaginary values */ 00061 00062 #ifndef ARM_MATH_CM0 00063 00064 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00065 uint32_t blkCnt; /* loop counters */ 00066 00067 /* loop Unrolling */ 00068 blkCnt = numSamples >> 2u; 00069 00070 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00071 ** a second loop below computes the remaining 1 to 3 samples. */ 00072 while(blkCnt > 0u) 00073 { 00074 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00075 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00076 a = *pSrcA++; 00077 b = *pSrcA++; 00078 c = *pSrcB++; 00079 d = *pSrcB++; 00080 00081 /* store the result in 3.13 format in the destination buffer. */ 00082 *pDst++ = 00083 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00084 /* store the result in 3.13 format in the destination buffer. */ 00085 *pDst++ = 00086 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00087 00088 a = *pSrcA++; 00089 b = *pSrcA++; 00090 c = *pSrcB++; 00091 d = *pSrcB++; 00092 00093 /* store the result in 3.13 format in the destination buffer. */ 00094 *pDst++ = 00095 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00096 /* store the result in 3.13 format in the destination buffer. */ 00097 *pDst++ = 00098 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00099 00100 a = *pSrcA++; 00101 b = *pSrcA++; 00102 c = *pSrcB++; 00103 d = *pSrcB++; 00104 00105 /* store the result in 3.13 format in the destination buffer. */ 00106 *pDst++ = 00107 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00108 /* store the result in 3.13 format in the destination buffer. */ 00109 *pDst++ = 00110 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00111 00112 a = *pSrcA++; 00113 b = *pSrcA++; 00114 c = *pSrcB++; 00115 d = *pSrcB++; 00116 00117 /* store the result in 3.13 format in the destination buffer. */ 00118 *pDst++ = 00119 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00120 /* store the result in 3.13 format in the destination buffer. */ 00121 *pDst++ = 00122 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00123 00124 /* Decrement the blockSize loop counter */ 00125 blkCnt--; 00126 } 00127 00128 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00129 ** No loop unrolling is used. */ 00130 blkCnt = numSamples % 0x4u; 00131 00132 while(blkCnt > 0u) 00133 { 00134 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00135 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00136 a = *pSrcA++; 00137 b = *pSrcA++; 00138 c = *pSrcB++; 00139 d = *pSrcB++; 00140 00141 /* store the result in 3.13 format in the destination buffer. */ 00142 *pDst++ = 00143 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00144 /* store the result in 3.13 format in the destination buffer. */ 00145 *pDst++ = 00146 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00147 00148 /* Decrement the blockSize loop counter */ 00149 blkCnt--; 00150 } 00151 00152 #else 00153 00154 /* Run the below code for Cortex-M0 */ 00155 00156 while(numSamples > 0u) 00157 { 00158 /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1]. */ 00159 /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i]. */ 00160 a = *pSrcA++; 00161 b = *pSrcA++; 00162 c = *pSrcB++; 00163 d = *pSrcB++; 00164 00165 /* store the result in 3.13 format in the destination buffer. */ 00166 *pDst++ = 00167 (q15_t) (q31_t) (((q31_t) a * c) >> 17) - (((q31_t) b * d) >> 17); 00168 /* store the result in 3.13 format in the destination buffer. */ 00169 *pDst++ = 00170 (q15_t) (q31_t) (((q31_t) a * d) >> 17) + (((q31_t) b * c) >> 17); 00171 00172 /* Decrement the blockSize loop counter */ 00173 numSamples--; 00174 } 00175 00176 #endif /* #ifndef ARM_MATH_CM0 */ 00177 00178 } 00179