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