CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_cmplx_conj_q15.c Source File

arm_cmplx_conj_q15.c

00001 /* ----------------------------------------------------------------------    
00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.    
00003 *    
00004 * $Date:        19. October 2015
00005 * $Revision:    V.1.4.5 a
00006 *    
00007 * Project:      CMSIS DSP Library    
00008 * Title:        arm_cmplx_conj_q15.c    
00009 *    
00010 * Description:  Q15 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 
00041 #include "arm_math.h"
00042 
00043 /**    
00044  * @ingroup groupCmplxMath    
00045  */
00046 
00047 /**    
00048  * @addtogroup cmplx_conj    
00049  * @{    
00050  */
00051 
00052 /**    
00053  * @brief  Q15 complex conjugate.    
00054  * @param  *pSrc points to the input vector    
00055  * @param  *pDst points to the output vector    
00056  * @param  numSamples number of complex samples in each vector    
00057  * @return none.    
00058  *    
00059  * <b>Scaling and Overflow Behavior:</b>    
00060  * \par    
00061  * The function uses saturating arithmetic.    
00062  * The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.    
00063  */
00064 
00065 void arm_cmplx_conj_q15(
00066   q15_t * pSrc,
00067   q15_t * pDst,
00068   uint32_t numSamples)
00069 {
00070 
00071 #ifndef ARM_MATH_CM0_FAMILY
00072 
00073   /* Run the below code for Cortex-M4 and Cortex-M3 */
00074   uint32_t blkCnt;                               /* loop counter */
00075   q31_t in1, in2, in3, in4;
00076   q31_t zero = 0;
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     in1 = *__SIMD32(pSrc)++;
00088     in2 = *__SIMD32(pSrc)++;
00089     in3 = *__SIMD32(pSrc)++;
00090     in4 = *__SIMD32(pSrc)++;
00091 
00092 #ifndef ARM_MATH_BIG_ENDIAN
00093 
00094     in1 = __QASX(zero, in1);
00095     in2 = __QASX(zero, in2);
00096     in3 = __QASX(zero, in3);
00097     in4 = __QASX(zero, in4);
00098 
00099 #else
00100 
00101     in1 = __QSAX(zero, in1);
00102     in2 = __QSAX(zero, in2);
00103     in3 = __QSAX(zero, in3);
00104     in4 = __QSAX(zero, in4);
00105 
00106 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
00107 
00108     in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
00109     in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
00110     in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
00111     in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
00112 
00113     *__SIMD32(pDst)++ = in1;
00114     *__SIMD32(pDst)++ = in2;
00115     *__SIMD32(pDst)++ = in3;
00116     *__SIMD32(pDst)++ = in4;
00117 
00118     /* Decrement the loop counter */
00119     blkCnt--;
00120   }
00121 
00122   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.    
00123    ** No loop unrolling is used. */
00124   blkCnt = numSamples % 0x4u;
00125 
00126   while(blkCnt > 0u)
00127   {
00128     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
00129     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
00130     *pDst++ = *pSrc++;
00131     *pDst++ = __SSAT(-*pSrc++, 16);
00132 
00133     /* Decrement the loop counter */
00134     blkCnt--;
00135   }
00136 
00137 #else
00138 
00139   q15_t in;
00140 
00141   /* Run the below code for Cortex-M0 */
00142 
00143   while(numSamples > 0u)
00144   {
00145     /* realOut + j (imagOut) = realIn+ j (-1) imagIn */
00146     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
00147     *pDst++ = *pSrc++;
00148     in = *pSrc++;
00149     *pDst++ = (in == (q15_t) 0x8000) ? 0x7fff : -in;
00150 
00151     /* Decrement the loop counter */
00152     numSamples--;
00153   }
00154 
00155 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
00156 
00157 }
00158 
00159 /**    
00160  * @} end of cmplx_conj group    
00161  */