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.
arm_cmplx_mult_real_q15.c
00001 /* ---------------------------------------------------------------------- 00002 * Project: CMSIS DSP Library 00003 * Title: arm_cmplx_mult_real_q15.c 00004 * Description: Q15 complex by real multiplication 00005 * 00006 * $Date: 27. January 2017 00007 * $Revision: V.1.5.1 00008 * 00009 * Target Processor: Cortex-M cores 00010 * -------------------------------------------------------------------- */ 00011 /* 00012 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 00013 * 00014 * SPDX-License-Identifier: Apache-2.0 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the License); you may 00017 * not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * www.apache.org/licenses/LICENSE-2.0 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00024 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 */ 00028 00029 #include "arm_math.h" 00030 00031 /** 00032 * @ingroup groupCmplxMath 00033 */ 00034 00035 /** 00036 * @addtogroup CmplxByRealMult 00037 * @{ 00038 */ 00039 00040 00041 /** 00042 * @brief Q15 complex-by-real multiplication 00043 * @param[in] *pSrcCmplx points to the complex input vector 00044 * @param[in] *pSrcReal points to the real input vector 00045 * @param[out] *pCmplxDst points to the complex output vector 00046 * @param[in] numSamples number of samples in each vector 00047 * @return none. 00048 * 00049 * <b>Scaling and Overflow Behavior:</b> 00050 * \par 00051 * The function uses saturating arithmetic. 00052 * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated. 00053 */ 00054 00055 void arm_cmplx_mult_real_q15( 00056 q15_t * pSrcCmplx, 00057 q15_t * pSrcReal, 00058 q15_t * pCmplxDst, 00059 uint32_t numSamples) 00060 { 00061 q15_t in; /* Temporary variable to store input value */ 00062 00063 #if defined (ARM_MATH_DSP) 00064 00065 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00066 uint32_t blkCnt; /* loop counters */ 00067 q31_t inA1, inA2; /* Temporary variables to hold input data */ 00068 q31_t inB1; /* Temporary variables to hold input data */ 00069 q15_t out1, out2, out3, out4; /* Temporary variables to hold output data */ 00070 q31_t mul1, mul2, mul3, mul4; /* Temporary variables to hold intermediate data */ 00071 00072 /* loop Unrolling */ 00073 blkCnt = numSamples >> 2U; 00074 00075 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00076 ** a second loop below computes the remaining 1 to 3 samples. */ 00077 while (blkCnt > 0U) 00078 { 00079 /* C[2 * i] = A[2 * i] * B[i]. */ 00080 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */ 00081 /* read complex number both real and imaginary from complex input buffer */ 00082 inA1 = *__SIMD32(pSrcCmplx)++; 00083 /* read two real values at a time from real input buffer */ 00084 inB1 = *__SIMD32(pSrcReal)++; 00085 /* read complex number both real and imaginary from complex input buffer */ 00086 inA2 = *__SIMD32(pSrcCmplx)++; 00087 00088 /* multiply complex number with real numbers */ 00089 #ifndef ARM_MATH_BIG_ENDIAN 00090 00091 mul1 = (q31_t) ((q15_t) (inA1) * (q15_t) (inB1)); 00092 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1)); 00093 mul3 = (q31_t) ((q15_t) (inA2) * (q15_t) (inB1 >> 16)); 00094 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) (inB1 >> 16)); 00095 00096 #else 00097 00098 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1 >> 16)); 00099 mul1 = (q31_t) ((q15_t) inA1 * (q15_t) (inB1 >> 16)); 00100 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) inB1); 00101 mul3 = (q31_t) ((q15_t) inA2 * (q15_t) inB1); 00102 00103 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ 00104 00105 /* saturate the result */ 00106 out1 = (q15_t) __SSAT(mul1 >> 15U, 16); 00107 out2 = (q15_t) __SSAT(mul2 >> 15U, 16); 00108 out3 = (q15_t) __SSAT(mul3 >> 15U, 16); 00109 out4 = (q15_t) __SSAT(mul4 >> 15U, 16); 00110 00111 /* pack real and imaginary outputs and store them to destination */ 00112 *__SIMD32(pCmplxDst)++ = __PKHBT(out1, out2, 16); 00113 *__SIMD32(pCmplxDst)++ = __PKHBT(out3, out4, 16); 00114 00115 inA1 = *__SIMD32(pSrcCmplx)++; 00116 inB1 = *__SIMD32(pSrcReal)++; 00117 inA2 = *__SIMD32(pSrcCmplx)++; 00118 00119 #ifndef ARM_MATH_BIG_ENDIAN 00120 00121 mul1 = (q31_t) ((q15_t) (inA1) * (q15_t) (inB1)); 00122 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1)); 00123 mul3 = (q31_t) ((q15_t) (inA2) * (q15_t) (inB1 >> 16)); 00124 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) (inB1 >> 16)); 00125 00126 #else 00127 00128 mul2 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1 >> 16)); 00129 mul1 = (q31_t) ((q15_t) inA1 * (q15_t) (inB1 >> 16)); 00130 mul4 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) inB1); 00131 mul3 = (q31_t) ((q15_t) inA2 * (q15_t) inB1); 00132 00133 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ 00134 00135 out1 = (q15_t) __SSAT(mul1 >> 15U, 16); 00136 out2 = (q15_t) __SSAT(mul2 >> 15U, 16); 00137 out3 = (q15_t) __SSAT(mul3 >> 15U, 16); 00138 out4 = (q15_t) __SSAT(mul4 >> 15U, 16); 00139 00140 *__SIMD32(pCmplxDst)++ = __PKHBT(out1, out2, 16); 00141 *__SIMD32(pCmplxDst)++ = __PKHBT(out3, out4, 16); 00142 00143 /* Decrement the numSamples loop counter */ 00144 blkCnt--; 00145 } 00146 00147 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00148 ** No loop unrolling is used. */ 00149 blkCnt = numSamples % 0x4U; 00150 00151 while (blkCnt > 0U) 00152 { 00153 /* C[2 * i] = A[2 * i] * B[i]. */ 00154 /* C[2 * i + 1] = A[2 * i + 1] * B[i]. */ 00155 in = *pSrcReal++; 00156 /* store the result in the destination buffer. */ 00157 *pCmplxDst++ = 00158 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16); 00159 *pCmplxDst++ = 00160 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16); 00161 00162 /* Decrement the numSamples loop counter */ 00163 blkCnt--; 00164 } 00165 00166 #else 00167 00168 /* Run the below code for Cortex-M0 */ 00169 00170 while (numSamples > 0U) 00171 { 00172 /* realOut = realA * realB. */ 00173 /* imagOut = imagA * realB. */ 00174 in = *pSrcReal++; 00175 /* store the result in the destination buffer. */ 00176 *pCmplxDst++ = 00177 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16); 00178 *pCmplxDst++ = 00179 (q15_t) __SSAT((((q31_t) (*pSrcCmplx++) * (in)) >> 15), 16); 00180 00181 /* Decrement the numSamples loop counter */ 00182 numSamples--; 00183 } 00184 00185 #endif /* #if defined (ARM_MATH_DSP) */ 00186 00187 } 00188 00189 /** 00190 * @} end of CmplxByRealMult group 00191 */ 00192
Generated on Tue Jul 12 2022 16:46:23 by
