Subversion Repositories dashGPS

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2.  * Project:      CMSIS DSP Library
  3.  * Title:        arm_cmplx_conj_q15.c
  4.  * Description:  Q15 complex conjugate
  5.  *
  6.  * $Date:        27. January 2017
  7.  * $Revision:    V.1.5.1
  8.  *
  9.  * Target Processor: Cortex-M cores
  10.  * -------------------------------------------------------------------- */
  11. /*
  12.  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  13.  *
  14.  * SPDX-License-Identifier: Apache-2.0
  15.  *
  16.  * Licensed under the Apache License, Version 2.0 (the License); you may
  17.  * not use this file except in compliance with the License.
  18.  * You may obtain a copy of the License at
  19.  *
  20.  * www.apache.org/licenses/LICENSE-2.0
  21.  *
  22.  * Unless required by applicable law or agreed to in writing, software
  23.  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25.  * See the License for the specific language governing permissions and
  26.  * limitations under the License.
  27.  */
  28.  
  29. #include "arm_math.h"
  30.  
  31. /**
  32.  * @ingroup groupCmplxMath
  33.  */
  34.  
  35. /**
  36.  * @addtogroup cmplx_conj
  37.  * @{
  38.  */
  39.  
  40. /**
  41.  * @brief  Q15 complex conjugate.
  42.  * @param  *pSrc points to the input vector
  43.  * @param  *pDst points to the output vector
  44.  * @param  numSamples number of complex samples in each vector
  45.  * @return none.
  46.  *
  47.  * <b>Scaling and Overflow Behavior:</b>
  48.  * \par
  49.  * The function uses saturating arithmetic.
  50.  * The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
  51.  */
  52.  
  53. void arm_cmplx_conj_q15(
  54.   q15_t * pSrc,
  55.   q15_t * pDst,
  56.   uint32_t numSamples)
  57. {
  58.  
  59. #if defined (ARM_MATH_DSP)
  60.  
  61.   /* Run the below code for Cortex-M4 and Cortex-M3 */
  62.   uint32_t blkCnt;                               /* loop counter */
  63.   q31_t in1, in2, in3, in4;
  64.   q31_t zero = 0;
  65.  
  66.   /*loop Unrolling */
  67.   blkCnt = numSamples >> 2U;
  68.  
  69.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  70.    ** a second loop below computes the remaining 1 to 3 samples. */
  71.   while (blkCnt > 0U)
  72.   {
  73.     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  74.     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  75.     in1 = *__SIMD32(pSrc)++;
  76.     in2 = *__SIMD32(pSrc)++;
  77.     in3 = *__SIMD32(pSrc)++;
  78.     in4 = *__SIMD32(pSrc)++;
  79.  
  80. #ifndef ARM_MATH_BIG_ENDIAN
  81.  
  82.     in1 = __QASX(zero, in1);
  83.     in2 = __QASX(zero, in2);
  84.     in3 = __QASX(zero, in3);
  85.     in4 = __QASX(zero, in4);
  86.  
  87. #else
  88.  
  89.     in1 = __QSAX(zero, in1);
  90.     in2 = __QSAX(zero, in2);
  91.     in3 = __QSAX(zero, in3);
  92.     in4 = __QSAX(zero, in4);
  93.  
  94. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  95.  
  96.     in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
  97.     in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
  98.     in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
  99.     in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
  100.  
  101.     *__SIMD32(pDst)++ = in1;
  102.     *__SIMD32(pDst)++ = in2;
  103.     *__SIMD32(pDst)++ = in3;
  104.     *__SIMD32(pDst)++ = in4;
  105.  
  106.     /* Decrement the loop counter */
  107.     blkCnt--;
  108.   }
  109.  
  110.   /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  111.    ** No loop unrolling is used. */
  112.   blkCnt = numSamples % 0x4U;
  113.  
  114.   while (blkCnt > 0U)
  115.   {
  116.     /* C[0]+jC[1] = A[0]+ j (-1) A[1] */
  117.     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  118.     *pDst++ = *pSrc++;
  119.     *pDst++ = __SSAT(-*pSrc++, 16);
  120.  
  121.     /* Decrement the loop counter */
  122.     blkCnt--;
  123.   }
  124.  
  125. #else
  126.  
  127.   q15_t in;
  128.  
  129.   /* Run the below code for Cortex-M0 */
  130.  
  131.   while (numSamples > 0U)
  132.   {
  133.     /* realOut + j (imagOut) = realIn+ j (-1) imagIn */
  134.     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
  135.     *pDst++ = *pSrc++;
  136.     in = *pSrc++;
  137.     *pDst++ = (in == (q15_t) 0x8000) ? 0x7fff : -in;
  138.  
  139.     /* Decrement the loop counter */
  140.     numSamples--;
  141.   }
  142.  
  143. #endif /* #if defined (ARM_MATH_DSP) */
  144.  
  145. }
  146.  
  147. /**
  148.  * @} end of cmplx_conj group
  149.  */
  150.