1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cmplx_conj_f16.c
4  * Description:  Floating-point 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_f16.h"
30 
31 #if defined(ARM_FLOAT16_SUPPORTED)
32 /**
33   @ingroup groupCmplxMath
34  */
35 
36 
37 /**
38   @addtogroup cmplx_conj
39   @{
40  */
41 
42 /**
43   @brief         Floating-point complex conjugate.
44   @param[in]     pSrc        points to the input vector
45   @param[out]    pDst        points to the output vector
46   @param[in]     numSamples  number of samples in each vector
47  */
48 
49 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
50 
arm_cmplx_conj_f16(const float16_t * pSrc,float16_t * pDst,uint32_t numSamples)51 void arm_cmplx_conj_f16(
52     const float16_t * pSrc,
53     float16_t * pDst,
54     uint32_t numSamples)
55 {
56     static const float16_t cmplx_conj_sign[8] = { 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f };
57     uint32_t blockSize = numSamples * CMPLX_DIM;   /* loop counters */
58     uint32_t blkCnt;
59     f16x8_t vecSrc;
60     f16x8_t vecSign;
61 
62     /*
63      * load sign vector
64      */
65     vecSign = *(f16x8_t *) cmplx_conj_sign;
66 
67     /* Compute 4 real samples at a time */
68     blkCnt = blockSize >> 3U;
69 
70     while (blkCnt > 0U)
71     {
72         vecSrc = vld1q(pSrc);
73         vst1q(pDst,vmulq(vecSrc, vecSign));
74         /*
75          * Decrement the blkCnt loop counter
76          * Advance vector source and destination pointers
77          */
78         pSrc += 8;
79         pDst += 8;
80         blkCnt--;
81     }
82 
83      /* Tail */
84     blkCnt = (blockSize & 0x7) >> 1;
85 
86     while (blkCnt > 0U)
87     {
88       /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
89 
90       /* Calculate Complex Conjugate and store result in destination buffer. */
91       *pDst++ =  *pSrc++;
92       *pDst++ = -(_Float16)*pSrc++;
93 
94       /* Decrement loop counter */
95       blkCnt--;
96     }
97 
98 }
99 
100 #else
arm_cmplx_conj_f16(const float16_t * pSrc,float16_t * pDst,uint32_t numSamples)101 void arm_cmplx_conj_f16(
102   const float16_t * pSrc,
103         float16_t * pDst,
104         uint32_t numSamples)
105 {
106         uint32_t blkCnt;                               /* Loop counter */
107 
108 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
109 
110   /* Loop unrolling: Compute 4 outputs at a time */
111   blkCnt = numSamples >> 2U;
112 
113   while (blkCnt > 0U)
114   {
115     /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
116 
117     /* Calculate Complex Conjugate and store result in destination buffer. */
118     *pDst++ =  *pSrc++;
119     *pDst++ = -(_Float16)*pSrc++;
120 
121     *pDst++ =  *pSrc++;
122     *pDst++ = -(_Float16)*pSrc++;
123 
124     *pDst++ =  *pSrc++;
125     *pDst++ = -(_Float16)*pSrc++;
126 
127     *pDst++ =  *pSrc++;
128     *pDst++ = -(_Float16)*pSrc++;
129 
130     /* Decrement loop counter */
131     blkCnt--;
132   }
133 
134   /* Loop unrolling: Compute remaining outputs */
135   blkCnt = numSamples % 0x4U;
136 
137 #else
138 
139   /* Initialize blkCnt with number of samples */
140   blkCnt = numSamples;
141 
142 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
143 
144   while (blkCnt > 0U)
145   {
146     /* C[0] + jC[1] = A[0]+ j(-1)A[1] */
147 
148     /* Calculate Complex Conjugate and store result in destination buffer. */
149     *pDst++ =  *pSrc++;
150     *pDst++ = -(_Float16)*pSrc++;
151 
152     /* Decrement loop counter */
153     blkCnt--;
154   }
155 
156 }
157 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
158 
159 /**
160   @} end of cmplx_conj group
161  */
162 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
163