1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_negate_f16.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_f16.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_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
63
64 #include "arm_helium_utils.h"
65
arm_negate_f16(const float16_t * pSrc,float16_t * pDst,uint32_t blockSize)66 void arm_negate_f16(
67 const float16_t * pSrc,
68 float16_t * pDst,
69 uint32_t blockSize)
70 {
71 uint32_t blkCnt; /* Loop counter */
72 f16x8_t vec1;
73 f16x8_t res;
74
75
76 /* Compute 4 outputs at a time */
77 blkCnt = blockSize >> 3U;
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 += 8;
89 pDst += 8;
90
91 /* Decrement the loop counter */
92 blkCnt--;
93 }
94
95 /* Tail */
96 blkCnt = blockSize & 0x7;
97 if (blkCnt > 0U)
98 {
99 /* C = |A| */
100 mve_pred16_t p0 = vctp16q(blkCnt);
101 vec1 = vld1q((float16_t const *) pSrc);
102 vstrhq_p(pDst, vnegq(vec1), p0);
103 }
104
105 }
106
107 #else
108 #if defined(ARM_FLOAT16_SUPPORTED)
arm_negate_f16(const float16_t * pSrc,float16_t * pDst,uint32_t blockSize)109 void arm_negate_f16(
110 const float16_t * pSrc,
111 float16_t * pDst,
112 uint32_t blockSize)
113 {
114 uint32_t blkCnt; /* Loop counter */
115
116
117 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
118
119 /* Loop unrolling: Compute 4 outputs at a time */
120 blkCnt = blockSize >> 2U;
121
122 while (blkCnt > 0U)
123 {
124 /* C = -A */
125
126 /* Negate and store result in destination buffer. */
127 *pDst++ = -*pSrc++;
128
129 *pDst++ = -*pSrc++;
130
131 *pDst++ = -*pSrc++;
132
133 *pDst++ = -*pSrc++;
134
135 /* Decrement loop counter */
136 blkCnt--;
137 }
138
139 /* Loop unrolling: Compute remaining outputs */
140 blkCnt = blockSize % 0x4U;
141
142 #else
143
144 /* Initialize blkCnt with number of samples */
145 blkCnt = blockSize;
146
147 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
148
149 while (blkCnt > 0U)
150 {
151 /* C = -A */
152
153 /* Negate and store result in destination buffer. */
154 *pDst++ = -*pSrc++;
155
156 /* Decrement loop counter */
157 blkCnt--;
158 }
159
160 }
161 #endif
162 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
163
164 /**
165 @} end of BasicNegate group
166 */
167