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