1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_float_to_q15.c
4 * Description: Converts the elements of the floating-point vector to Q15 vector
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/support_functions_f16.h"
30
31 #if defined(ARM_FLOAT16_SUPPORTED)
32
33
34 /**
35 @ingroup groupSupport
36 */
37
38 /**
39 @addtogroup float_to_x
40 @{
41 */
42
43 /**
44 @brief Converts the elements of the floating-point vector to f16 vector.
45 @param[in] pSrc points to the f32 input vector
46 @param[out] pDst points to the f16 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) && defined(__CMSIS_GCC_H)
51 #pragma message "Scalar version of arm_float_to_f16 built. Helium version has build issues with gcc."
52 #endif
53
54 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && !defined(__CMSIS_GCC_H)
55
arm_float_to_f16(const float32_t * pSrc,float16_t * pDst,uint32_t blockSize)56 void arm_float_to_f16(
57 const float32_t * pSrc,
58 float16_t * pDst,
59 uint32_t blockSize)
60 {
61 int32_t blkCnt; /* loop counters */
62 float32x4x2_t tmp;
63 float16x8_t vecDst;
64 float32_t const *pSrcVec;
65
66
67 pSrcVec = (float32_t const *) pSrc;
68 blkCnt = blockSize >> 3;
69 while (blkCnt > 0)
70 {
71 /* convert from float32 to float16 and then store the results in the destination buffer */
72 tmp = vld2q(pSrcVec); pSrcVec += 8;
73 /* narrow / merge */
74 vecDst = vcvtbq_f16_f32(vecDst, tmp.val[0]);
75 vecDst = vcvttq_f16_f32(vecDst, tmp.val[1]);
76 vst1q(pDst, vecDst); pDst += 8;
77 /*
78 * Decrement the blockSize loop counter
79 */
80 blkCnt--;
81 }
82
83 /*
84 * tail
85 */
86 blkCnt = blockSize & 7;
87 if (blkCnt > 0)
88 {
89 mve_pred16_t p0 = vctp16q(blkCnt);
90 tmp = vld2q(pSrcVec);
91 vecDst = vcvtbq_f16_f32(vecDst, tmp.val[0]);
92 vecDst = vcvttq_f16_f32(vecDst, tmp.val[1]);
93 vstrhq_p(pDst, vecDst, p0);
94 }
95 }
96
97 #else
98
arm_float_to_f16(const float32_t * pSrc,float16_t * pDst,uint32_t blockSize)99 void arm_float_to_f16(
100 const float32_t * pSrc,
101 float16_t * pDst,
102 uint32_t blockSize)
103 {
104 const float32_t *pIn = pSrc; /* Src pointer */
105 uint32_t blkCnt; /* loop counter */
106
107 /*
108 * Loop over blockSize number of values
109 */
110 blkCnt = blockSize;
111
112 while (blkCnt > 0U)
113 {
114
115 *pDst++ = (float16_t) * pIn++;
116 /*
117 * Decrement the loop counter
118 */
119 blkCnt--;
120 }
121 }
122 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
123
124 /**
125 @} end of float_to_x group
126 */
127
128 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
129
130