1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_cmplx_conj_q15.c
4 * Description: Q15 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 Q15 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 @return none
46
47 @par Scaling and Overflow Behavior
48 The function uses saturating arithmetic.
49 The Q15 value -1 (0x8000) is saturated to the maximum allowable positive value 0x7FFF.
50 */
51
52
53 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_cmplx_conj_q15(const q15_t * pSrc,q15_t * pDst,uint32_t numSamples)54 void arm_cmplx_conj_q15(
55 const q15_t * pSrc,
56 q15_t * pDst,
57 uint32_t numSamples)
58 {
59 uint32_t blockSize = numSamples * CMPLX_DIM; /* loop counters */
60 uint32_t blkCnt;
61 q31_t in1;
62
63 q15x8x2_t vecSrc;
64 q15x8_t zero;
65
66 zero = vdupq_n_s16(0);
67
68 /* Compute 8 real samples at a time */
69 blkCnt = blockSize >> 4U;
70 while (blkCnt > 0U)
71 {
72 vecSrc = vld2q(pSrc);
73 vecSrc.val[1] = vqsubq(zero, vecSrc.val[1]);
74 vst2q(pDst,vecSrc);
75 /*
76 * Decrement the blkCnt loop counter
77 * Advance vector source and destination pointers
78 */
79 pSrc += 16;
80 pDst += 16;
81 blkCnt --;
82 }
83
84 /* Tail */
85 blkCnt = (blockSize & 0xF) >> 1;
86
87 while (blkCnt > 0U)
88 {
89 /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
90
91 /* Calculate Complex Conjugate and store result in destination buffer. */
92 *pDst++ = *pSrc++;
93 in1 = *pSrc++;
94 *pDst++ = __SSAT(-in1, 16);
95
96 /* Decrement loop counter */
97 blkCnt--;
98 }
99 }
100 #else
arm_cmplx_conj_q15(const q15_t * pSrc,q15_t * pDst,uint32_t numSamples)101 void arm_cmplx_conj_q15(
102 const q15_t * pSrc,
103 q15_t * pDst,
104 uint32_t numSamples)
105 {
106 uint32_t blkCnt; /* Loop counter */
107 q31_t in1; /* Temporary input variable */
108
109 #if defined (ARM_MATH_LOOPUNROLL) && defined (ARM_MATH_DSP)
110 q31_t in2, in3, in4; /* Temporary input variables */
111 #endif
112
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
125 #if defined (ARM_MATH_DSP)
126 in1 = read_q15x2_ia ((q15_t **) &pSrc);
127 in2 = read_q15x2_ia ((q15_t **) &pSrc);
128 in3 = read_q15x2_ia ((q15_t **) &pSrc);
129 in4 = read_q15x2_ia ((q15_t **) &pSrc);
130
131 #ifndef ARM_MATH_BIG_ENDIAN
132 in1 = __QASX(0, in1);
133 in2 = __QASX(0, in2);
134 in3 = __QASX(0, in3);
135 in4 = __QASX(0, in4);
136 #else
137 in1 = __QSAX(0, in1);
138 in2 = __QSAX(0, in2);
139 in3 = __QSAX(0, in3);
140 in4 = __QSAX(0, in4);
141 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
142
143 in1 = ((uint32_t) in1 >> 16) | ((uint32_t) in1 << 16);
144 in2 = ((uint32_t) in2 >> 16) | ((uint32_t) in2 << 16);
145 in3 = ((uint32_t) in3 >> 16) | ((uint32_t) in3 << 16);
146 in4 = ((uint32_t) in4 >> 16) | ((uint32_t) in4 << 16);
147
148 write_q15x2_ia (&pDst, in1);
149 write_q15x2_ia (&pDst, in2);
150 write_q15x2_ia (&pDst, in3);
151 write_q15x2_ia (&pDst, in4);
152 #else
153 *pDst++ = *pSrc++;
154 in1 = *pSrc++;
155 *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
156
157 *pDst++ = *pSrc++;
158 in1 = *pSrc++;
159 *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
160
161 *pDst++ = *pSrc++;
162 in1 = *pSrc++;
163 *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
164
165 *pDst++ = *pSrc++;
166 in1 = *pSrc++;
167 *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
168
169 #endif /* #if defined (ARM_MATH_DSP) */
170
171 /* Decrement loop counter */
172 blkCnt--;
173 }
174
175 /* Loop unrolling: Compute remaining outputs */
176 blkCnt = numSamples % 0x4U;
177
178 #else
179
180 /* Initialize blkCnt with number of samples */
181 blkCnt = numSamples;
182
183 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
184
185 while (blkCnt > 0U)
186 {
187 /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
188
189 /* Calculate Complex Conjugate and store result in destination buffer. */
190 *pDst++ = *pSrc++;
191 in1 = *pSrc++;
192 #if defined (ARM_MATH_DSP)
193 *pDst++ = __SSAT(-in1, 16);
194 #else
195 *pDst++ = (in1 == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in1;
196 #endif
197
198 /* Decrement loop counter */
199 blkCnt--;
200 }
201
202 }
203 #endif /* defined(ARM_MATH_MVEI) */
204
205 /**
206 @} end of cmplx_conj group
207 */
208