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 /**
37 @addtogroup BasicNegate
38 @{
39 */
40
41 /**
42 @brief Negates the elements of a floating-point vector.
43 @param[in] pSrc points to input vector.
44 @param[out] pDst points to output vector.
45 @param[in] blockSize number of samples in each vector.
46 @return none
47 */
48
49 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
50
51 #include "arm_helium_utils.h"
52
arm_negate_f16(const float16_t * pSrc,float16_t * pDst,uint32_t blockSize)53 void arm_negate_f16(
54 const float16_t * pSrc,
55 float16_t * pDst,
56 uint32_t blockSize)
57 {
58 uint32_t blkCnt; /* Loop counter */
59 f16x8_t vec1;
60 f16x8_t res;
61
62
63 /* Compute 4 outputs at a time */
64 blkCnt = blockSize >> 3U;
65 while (blkCnt > 0U)
66 {
67 /* C = |A| */
68
69 /* Calculate absolute values and then store the results in the destination buffer. */
70 vec1 = vld1q(pSrc);
71 res = vnegq(vec1);
72 vst1q(pDst, res);
73
74 /* Increment pointers */
75 pSrc += 8;
76 pDst += 8;
77
78 /* Decrement the loop counter */
79 blkCnt--;
80 }
81
82 /* Tail */
83 blkCnt = blockSize & 0x7;
84 if (blkCnt > 0U)
85 {
86 /* C = |A| */
87 mve_pred16_t p0 = vctp16q(blkCnt);
88 vec1 = vld1q((float16_t const *) pSrc);
89 vstrhq_p(pDst, vnegq(vec1), p0);
90 }
91
92 }
93
94 #else
95 #if defined(ARM_FLOAT16_SUPPORTED)
arm_negate_f16(const float16_t * pSrc,float16_t * pDst,uint32_t blockSize)96 void arm_negate_f16(
97 const float16_t * pSrc,
98 float16_t * pDst,
99 uint32_t blockSize)
100 {
101 uint32_t blkCnt; /* Loop counter */
102
103
104 #if defined (ARM_MATH_LOOPUNROLL) && !defined(ARM_MATH_AUTOVECTORIZE)
105
106 /* Loop unrolling: Compute 4 outputs at a time */
107 blkCnt = blockSize >> 2U;
108
109 while (blkCnt > 0U)
110 {
111 /* C = -A */
112
113 /* Negate and store result in destination buffer. */
114 *pDst++ = -(_Float16)*pSrc++;
115
116 *pDst++ = -(_Float16)*pSrc++;
117
118 *pDst++ = -(_Float16)*pSrc++;
119
120 *pDst++ = -(_Float16)*pSrc++;
121
122 /* Decrement loop counter */
123 blkCnt--;
124 }
125
126 /* Loop unrolling: Compute remaining outputs */
127 blkCnt = blockSize % 0x4U;
128
129 #else
130
131 /* Initialize blkCnt with number of samples */
132 blkCnt = blockSize;
133
134 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
135
136 while (blkCnt > 0U)
137 {
138 /* C = -A */
139
140 /* Negate and store result in destination buffer. */
141 *pDst++ = -(_Float16)*pSrc++;
142
143 /* Decrement loop counter */
144 blkCnt--;
145 }
146
147 }
148 #endif
149 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
150
151 /**
152 @} end of BasicNegate group
153 */
154