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  * @defgroup f16_to_x  Convert 16-bit floating point value
40  */
41 
42 /**
43   @addtogroup f16_to_x
44   @{
45  */
46 
47 /**
48   @brief         Converts the elements of the f16 vector to f32 vector.
49   @param[in]     pSrc       points to the f16 input vector
50   @param[out]    pDst       points to the f32 output vector
51   @param[in]     blockSize  number of samples in each vector
52   @return        none
53 
54  */
55 
56 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && defined(__CMSIS_GCC_H)
57 #pragma GCC warning "Scalar version of arm_f16_to_float built. Helium version has build issues with gcc."
58 #endif
59 
60 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) &&  !defined(__CMSIS_GCC_H)
61 
arm_f16_to_float(const float16_t * pSrc,float32_t * pDst,uint32_t blockSize)62 void arm_f16_to_float(
63   const float16_t * pSrc,
64         float32_t * pDst,
65         uint32_t blockSize)
66 {
67     int32_t  blkCnt;           /* loop counters */
68     float16x8_t vecDst;
69     float32x4x2_t tmp;
70 
71     blkCnt = blockSize >> 3;
72     while (blkCnt > 0)
73     {
74         vecDst = vldrhq_f16(pSrc);
75         pSrc += 8;
76 
77         tmp.val[0] = vcvtbq_f32_f16(vecDst);
78         tmp.val[1] = vcvttq_f32_f16(vecDst);
79         vst2q(pDst,tmp);
80 
81         pDst += 8;
82         /*
83          * Decrement the blockSize loop counter
84          */
85         blkCnt--;
86     }
87     /*
88      * tail
89      * (will be merged thru tail predication)
90      */
91     blkCnt = blockSize & 7;
92     while (blkCnt > 0)
93     {
94 
95         *pDst++ = (float32_t) *pSrc++;
96         /*
97          * Decrement the loop counter
98          */
99         blkCnt--;
100     }
101 }
102 
103 #else
arm_f16_to_float(const float16_t * pSrc,float32_t * pDst,uint32_t blockSize)104 void arm_f16_to_float(
105   const float16_t * pSrc,
106         float32_t * pDst,
107         uint32_t blockSize)
108 {
109     const float16_t *pIn = pSrc;      /* Src pointer */
110     uint32_t  blkCnt;           /* loop counter */
111 
112     /*
113      * Loop over blockSize number of values
114      */
115     blkCnt = blockSize;
116 
117     while (blkCnt > 0U)
118     {
119 
120         *pDst++ = (float32_t) * pIn++;
121         /*
122          * Decrement the loop counter
123          */
124         blkCnt--;
125     }
126 }
127 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
128 
129 /**
130   @} end of f16_to_x group
131  */
132 
133 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
134 
135