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