Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_cmplx_mult_real_q31.c Source File

arm_cmplx_mult_real_q31.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_cmplx_mult_real_q31.c
00004  * Description:  Q31 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  Q31 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 Q31 range[0x80000000 0x7FFFFFFF] will be saturated.
00053  */
00054 
00055 void arm_cmplx_mult_real_q31(
00056   q31_t * pSrcCmplx,
00057   q31_t * pSrcReal,
00058   q31_t * pCmplxDst,
00059   uint32_t numSamples)
00060 {
00061   q31_t inA1;                                    /* 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 inA2, inA3, inA4;                        /* Temporary variables to hold input data */
00068   q31_t inB1, inB2;                              /* Temporary variabels to hold input data */
00069   q31_t out1, out2, out3, out4;                  /* Temporary variables to hold output data */
00070 
00071   /* loop Unrolling */
00072   blkCnt = numSamples >> 2U;
00073 
00074   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
00075    ** a second loop below computes the remaining 1 to 3 samples. */
00076   while (blkCnt > 0U)
00077   {
00078     /* C[2 * i] = A[2 * i] * B[i].            */
00079     /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
00080     /* read real input from complex input buffer */
00081     inA1 = *pSrcCmplx++;
00082     inA2 = *pSrcCmplx++;
00083     /* read input from real input bufer */
00084     inB1 = *pSrcReal++;
00085     inB2 = *pSrcReal++;
00086     /* read imaginary input from complex input buffer */
00087     inA3 = *pSrcCmplx++;
00088     inA4 = *pSrcCmplx++;
00089 
00090     /* multiply complex input with real input */
00091     out1 = ((q63_t) inA1 * inB1) >> 32;
00092     out2 = ((q63_t) inA2 * inB1) >> 32;
00093     out3 = ((q63_t) inA3 * inB2) >> 32;
00094     out4 = ((q63_t) inA4 * inB2) >> 32;
00095 
00096     /* sature the result */
00097     out1 = __SSAT(out1, 31);
00098     out2 = __SSAT(out2, 31);
00099     out3 = __SSAT(out3, 31);
00100     out4 = __SSAT(out4, 31);
00101 
00102     /* get result in 1.31 format */
00103     out1 = out1 << 1;
00104     out2 = out2 << 1;
00105     out3 = out3 << 1;
00106     out4 = out4 << 1;
00107 
00108     /* store the result to destination buffer */
00109     *pCmplxDst++ = out1;
00110     *pCmplxDst++ = out2;
00111     *pCmplxDst++ = out3;
00112     *pCmplxDst++ = out4;
00113 
00114     /* read real input from complex input buffer */
00115     inA1 = *pSrcCmplx++;
00116     inA2 = *pSrcCmplx++;
00117     /* read input from real input bufer */
00118     inB1 = *pSrcReal++;
00119     inB2 = *pSrcReal++;
00120     /* read imaginary input from complex input buffer */
00121     inA3 = *pSrcCmplx++;
00122     inA4 = *pSrcCmplx++;
00123 
00124     /* multiply complex input with real input */
00125     out1 = ((q63_t) inA1 * inB1) >> 32;
00126     out2 = ((q63_t) inA2 * inB1) >> 32;
00127     out3 = ((q63_t) inA3 * inB2) >> 32;
00128     out4 = ((q63_t) inA4 * inB2) >> 32;
00129 
00130     /* sature the result */
00131     out1 = __SSAT(out1, 31);
00132     out2 = __SSAT(out2, 31);
00133     out3 = __SSAT(out3, 31);
00134     out4 = __SSAT(out4, 31);
00135 
00136     /* get result in 1.31 format */
00137     out1 = out1 << 1;
00138     out2 = out2 << 1;
00139     out3 = out3 << 1;
00140     out4 = out4 << 1;
00141 
00142     /* store the result to destination buffer */
00143     *pCmplxDst++ = out1;
00144     *pCmplxDst++ = out2;
00145     *pCmplxDst++ = out3;
00146     *pCmplxDst++ = out4;
00147 
00148     /* Decrement the numSamples loop counter */
00149     blkCnt--;
00150   }
00151 
00152   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
00153    ** No loop unrolling is used. */
00154   blkCnt = numSamples % 0x4U;
00155 
00156   while (blkCnt > 0U)
00157   {
00158     /* C[2 * i] = A[2 * i] * B[i].            */
00159     /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
00160     /* read real input from complex input buffer */
00161     inA1 = *pSrcCmplx++;
00162     inA2 = *pSrcCmplx++;
00163     /* read input from real input bufer */
00164     inB1 = *pSrcReal++;
00165 
00166     /* multiply complex input with real input */
00167     out1 = ((q63_t) inA1 * inB1) >> 32;
00168     out2 = ((q63_t) inA2 * inB1) >> 32;
00169 
00170     /* sature the result */
00171     out1 = __SSAT(out1, 31);
00172     out2 = __SSAT(out2, 31);
00173 
00174     /* get result in 1.31 format */
00175     out1 = out1 << 1;
00176     out2 = out2 << 1;
00177 
00178     /* store the result to destination buffer */
00179     *pCmplxDst++ = out1;
00180     *pCmplxDst++ = out2;
00181 
00182     /* Decrement the numSamples loop counter */
00183     blkCnt--;
00184   }
00185 
00186 #else
00187 
00188   /* Run the below code for Cortex-M0 */
00189 
00190   while (numSamples > 0U)
00191   {
00192     /* realOut = realA * realB.            */
00193     /* imagReal = imagA * realB.               */
00194     inA1 = *pSrcReal++;
00195     /* store the result in the destination buffer. */
00196     *pCmplxDst++ =
00197       (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
00198     *pCmplxDst++ =
00199       (q31_t) clip_q63_to_q31(((q63_t) * pSrcCmplx++ * inA1) >> 31);
00200 
00201     /* Decrement the numSamples loop counter */
00202     numSamples--;
00203   }
00204 
00205 #endif /* #if defined (ARM_MATH_DSP) */
00206 
00207 }
00208 
00209 /**
00210  * @} end of CmplxByRealMult group
00211  */
00212