1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cmplx_conj_q31.c
4  * Description:  Q31 complex conjugate
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.0
8  *
9  * Target Processor: Cortex-M and Cortex-A cores
10  * -------------------------------------------------------------------- */
11 /*
12  * Copyright (C) 2010-2021 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 "dsp/complex_math_functions.h"
30 
31 /**
32   @ingroup groupCmplxMath
33  */
34 
35 /**
36   @addtogroup cmplx_conj
37   @{
38  */
39 
40 /**
41   @brief         Q31 complex conjugate.
42   @param[in]     pSrc        points to the input vector
43   @param[out]    pDst        points to the output vector
44   @param[in]     numSamples  number of samples in each vector
45 
46   @par           Scaling and Overflow Behavior
47                    The function uses saturating arithmetic.
48                    The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
49  */
50 
51 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
52 
arm_cmplx_conj_q31(const q31_t * pSrc,q31_t * pDst,uint32_t numSamples)53 ARM_DSP_ATTRIBUTE void arm_cmplx_conj_q31(
54   const q31_t * pSrc,
55         q31_t * pDst,
56         uint32_t numSamples)
57 {
58 
59     uint32_t blockSize = numSamples * CMPLX_DIM;   /* loop counters */
60     uint32_t blkCnt;
61     q31x4x2_t vecSrc;
62     q31_t in;                                      /* Temporary input variable */
63     q31x4_t zero;
64 
65     zero = vdupq_n_s32(0);
66 
67 
68     /* Compute 4 real samples at a time */
69     blkCnt = blockSize >> 3U;
70 
71     while (blkCnt > 0U)
72     {
73 
74         vecSrc = vld2q(pSrc);
75         vecSrc.val[1] = vqsubq(zero, vecSrc.val[1]);
76         vst2q(pDst,vecSrc);
77         /*
78          * Decrement the blkCnt loop counter
79          * Advance vector source and destination pointers
80          */
81         pSrc += 8;
82         pDst += 8;
83         blkCnt --;
84     }
85 
86      /* Tail */
87     blkCnt = (blockSize & 0x7) >> 1;
88 
89     while (blkCnt > 0U)
90     {
91       /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
92 
93       /* Calculate Complex Conjugate and store result in destination buffer. */
94       *pDst++ =  *pSrc++;
95       in = *pSrc++;
96       *pDst++ = __QSUB(0, in);
97 
98       /* Decrement loop counter */
99       blkCnt--;
100     }
101 
102 
103 }
104 #else
105 
arm_cmplx_conj_q31(const q31_t * pSrc,q31_t * pDst,uint32_t numSamples)106 ARM_DSP_ATTRIBUTE void arm_cmplx_conj_q31(
107   const q31_t * pSrc,
108         q31_t * pDst,
109         uint32_t numSamples)
110 {
111         uint32_t blkCnt;                               /* Loop counter */
112         q31_t in;                                      /* Temporary input variable */
113 
114 #if defined (ARM_MATH_LOOPUNROLL)
115 
116   /* Loop unrolling: Compute 4 outputs at a time */
117   blkCnt = numSamples >> 2U;
118 
119   while (blkCnt > 0U)
120   {
121     /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
122 
123     /* Calculate Complex Conjugate and store result in destination buffer. */
124     *pDst++ =  *pSrc++;
125     in = *pSrc++;
126 #if defined (ARM_MATH_DSP)
127     *pDst++ = __QSUB(0, in);
128 #else
129     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
130 #endif
131 
132     *pDst++ =  *pSrc++;
133     in =  *pSrc++;
134 #if defined (ARM_MATH_DSP)
135     *pDst++ = __QSUB(0, in);
136 #else
137     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
138 #endif
139 
140     *pDst++ =  *pSrc++;
141     in = *pSrc++;
142 #if defined (ARM_MATH_DSP)
143     *pDst++ = __QSUB(0, in);
144 #else
145     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
146 #endif
147 
148     *pDst++ =  *pSrc++;
149     in = *pSrc++;
150 #if defined (ARM_MATH_DSP)
151     *pDst++ = __QSUB(0, in);
152 #else
153     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
154 #endif
155 
156     /* Decrement loop counter */
157     blkCnt--;
158   }
159 
160   /* Loop unrolling: Compute remaining outputs */
161   blkCnt = numSamples % 0x4U;
162 
163 #else
164 
165   /* Initialize blkCnt with number of samples */
166   blkCnt = numSamples;
167 
168 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
169 
170   while (blkCnt > 0U)
171   {
172     /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
173 
174     /* Calculate Complex Conjugate and store result in destination buffer. */
175     *pDst++ =  *pSrc++;
176     in = *pSrc++;
177 #if defined (ARM_MATH_DSP)
178     *pDst++ = __QSUB(0, in);
179 #else
180     *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
181 #endif
182 
183     /* Decrement loop counter */
184     blkCnt--;
185   }
186 
187 }
188 #endif /* defined(ARM_MATH_MVEI) */
189 
190 /**
191   @} end of cmplx_conj group
192  */
193