CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_cmplx_conj_q31.c Source File

arm_cmplx_conj_q31.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_conj_q31.c    
00009 *    
00010 * Description:  Q31 complex conjugate.    
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 #include "arm_math.h"
00041 
00042 /**        
00043  * @ingroup groupCmplxMath        
00044  */
00045 
00046 /**        
00047  * @addtogroup cmplx_conj        
00048  * @{        
00049  */
00050 
00051 /**        
00052  * @brief  Q31 complex conjugate.        
00053  * @param  *pSrc points to the input vector        
00054  * @param  *pDst points to the output vector        
00055  * @param  numSamples number of complex samples in each vector        
00056  * @return none.        
00057  *        
00058  * <b>Scaling and Overflow Behavior:</b>        
00059  * \par        
00060  * The function uses saturating arithmetic.        
00061  * The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF.        
00062  */
00063 
00064 void arm_cmplx_conj_q31(
00065   q31_t * pSrc,
00066   q31_t * pDst,
00067   uint32_t numSamples)
00068 {
00069   uint32_t blkCnt;                               /* loop counter */
00070   q31_t in;                                      /* Input value */
00071 
00072 #ifndef ARM_MATH_CM0_FAMILY
00073 
00074   /* Run the below code for Cortex-M4 and Cortex-M3 */
00075   q31_t inR1, inR2, inR3, inR4;                  /* Temporary real variables */
00076   q31_t inI1, inI2, inI3, inI4;                  /* Temporary imaginary variables */
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[0]+jC[1] = A[0]+ j (-1) A[1] */
00086     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
00087     /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
00088     /* read real input sample */
00089     inR1 = pSrc[0];
00090     /* store real input sample */
00091     pDst[0] = inR1;
00092 
00093     /* read imaginary input sample */
00094     inI1 = pSrc[1];
00095 
00096     /* read real input sample */
00097     inR2 = pSrc[2];
00098     /* store real input sample */
00099     pDst[2] = inR2;
00100 
00101     /* read imaginary input sample */
00102     inI2 = pSrc[3];
00103 
00104     /* negate imaginary input sample */
00105     inI1 = __QSUB(0, inI1);
00106 
00107     /* read real input sample */
00108     inR3 = pSrc[4];
00109     /* store real input sample */
00110     pDst[4] = inR3;
00111 
00112     /* read imaginary input sample */
00113     inI3 = pSrc[5];
00114 
00115     /* negate imaginary input sample */
00116     inI2 = __QSUB(0, inI2);
00117 
00118     /* read real input sample */
00119     inR4 = pSrc[6];
00120     /* store real input sample */
00121     pDst[6] = inR4;
00122 
00123     /* negate imaginary input sample */
00124     inI3 = __QSUB(0, inI3);
00125 
00126     /* store imaginary input sample */
00127     inI4 = pSrc[7];
00128 
00129     /* store imaginary input samples */
00130     pDst[1] = inI1;
00131 
00132     /* negate imaginary input sample */
00133     inI4 = __QSUB(0, inI4);
00134 
00135     /* store imaginary input samples */
00136     pDst[3] = inI2;
00137 
00138     /* increment source pointer by 8 to proecess next samples */
00139     pSrc += 8u;
00140 
00141     /* store imaginary input samples */
00142     pDst[5] = inI3;
00143     pDst[7] = inI4;
00144 
00145     /* increment destination pointer by 8 to process next samples */
00146     pDst += 8u;
00147 
00148     /* Decrement the 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 #else
00157 
00158   /* Run the below code for Cortex-M0 */
00159   blkCnt = numSamples;
00160 
00161 
00162 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
00163 
00164   while(blkCnt > 0u)
00165   {
00166     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
00167     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
00168     /* Saturated to 0x7fffffff if the input is -1(0x80000000) */
00169     *pDst++ = *pSrc++;
00170     in = *pSrc++;
00171     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
00172 
00173     /* Decrement the loop counter */
00174     blkCnt--;
00175   }
00176 }
00177 
00178 /**        
00179  * @} end of cmplx_conj group        
00180  */