1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_negate_f32.c
4 * Description: Negates floating-point vectors
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/basic_math_functions.h"
30
31 /**
32 @ingroup groupMath
33 */
34
35 /**
36 @defgroup BasicNegate Vector Negate
37
38 Negates the elements of a vector.
39
40 <pre>
41 pDst[n] = -pSrc[n], 0 <= n < blockSize.
42 </pre>
43
44 The functions support in-place computation allowing the source and
45 destination pointers to reference the same memory buffer.
46 There are separate functions for floating-point, Q7, Q15, and Q31 data types.
47 */
48
49 /**
50 @addtogroup BasicNegate
51 @{
52 */
53
54 /**
55 @brief Negates the elements of a floating-point vector.
56 @param[in] pSrc points to input vector.
57 @param[out] pDst points to output vector.
58 @param[in] blockSize number of samples in each vector.
59 @return none
60 */
61
62 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
63
64 #include "arm_helium_utils.h"
65
arm_negate_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)66 void arm_negate_f32(
67 const float32_t * pSrc,
68 float32_t * pDst,
69 uint32_t blockSize)
70 {
71 uint32_t blkCnt; /* Loop counter */
72 f32x4_t vec1;
73 f32x4_t res;
74
75
76 /* Compute 4 outputs at a time */
77 blkCnt = blockSize >> 2U;
78 while (blkCnt > 0U)
79 {
80 /* C = |A| */
81
82 /* Calculate absolute values and then store the results in the destination buffer. */
83 vec1 = vld1q(pSrc);
84 res = vnegq(vec1);
85 vst1q(pDst, res);
86
87 /* Increment pointers */
88 pSrc += 4;
89 pDst += 4;
90
91 /* Decrement the loop counter */
92 blkCnt--;
93 }
94
95 /* Tail */
96 blkCnt = blockSize & 0x3;
97 if (blkCnt > 0U)
98 {
99 /* C = |A| */
100 mve_pred16_t p0 = vctp32q(blkCnt);
101 vec1 = vld1q((float32_t const *) pSrc);
102 vstrwq_p(pDst, vnegq(vec1), p0);
103 }
104
105 }
106
107 #else
arm_negate_f32(const float32_t * pSrc,float32_t * pDst,uint32_t blockSize)108 void arm_negate_f32(
109 const float32_t * pSrc,
110 float32_t * pDst,
111 uint32_t blockSize)
112 {
113 uint32_t blkCnt; /* Loop counter */
114
115 #if defined(ARM_MATH_NEON_EXPERIMENTAL) && !defined(ARM_MATH_AUTOVECTORIZE)
116 f32x4_t vec1;
117 f32x4_t res;
118
119 /* Compute 4 outputs at a time */
120 blkCnt = blockSize >> 2U;
121
122 while (blkCnt > 0U)
123 {
124 /* C = -A */
125
126 /* Negate and then store the results in the destination buffer. */
127 vec1 = vld1q_f32(pSrc);
128 res = vnegq_f32(vec1);
129 vst1q_f32(pDst, res);
130
131 /* Increment pointers */
132 pSrc += 4;
133 pDst += 4;
134
135 /* Decrement the loop counter */
136 blkCnt--;
137 }
138
139 /* Tail */
140 blkCnt = blockSize & 0x3;
141
142 #else
143 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
144
145 /* Loop unrolling: Compute 4 outputs at a time */
146 blkCnt = blockSize >> 2U;
147
148 while (blkCnt > 0U)
149 {
150 /* C = -A */
151
152 /* Negate and store result in destination buffer. */
153 *pDst++ = -*pSrc++;
154
155 *pDst++ = -*pSrc++;
156
157 *pDst++ = -*pSrc++;
158
159 *pDst++ = -*pSrc++;
160
161 /* Decrement loop counter */
162 blkCnt--;
163 }
164
165 /* Loop unrolling: Compute remaining outputs */
166 blkCnt = blockSize % 0x4U;
167
168 #else
169
170 /* Initialize blkCnt with number of samples */
171 blkCnt = blockSize;
172
173 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
174 #endif /* #if defined(ARM_MATH_NEON_EXPERIMENTAL) */
175
176 while (blkCnt > 0U)
177 {
178 /* C = -A */
179
180 /* Negate and store result in destination buffer. */
181 *pDst++ = -*pSrc++;
182
183 /* Decrement loop counter */
184 blkCnt--;
185 }
186
187 }
188 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
189
190 /**
191 @} end of BasicNegate group
192 */
193