1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_q15_to_float.c
4 * Description: Converts the elements of the Q15 vector to floating-point 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 q15_to_x Convert 16-bit fixed point value
40 */
41
42 /**
43 @addtogroup q15_to_x
44 @{
45 */
46
47 /**
48 @brief Converts the elements of the Q15 vector to f16 vector.
49 @param[in] pSrc points to the Q15 input vector
50 @param[out] pDst points to the f16 output vector
51 @param[in] blockSize number of samples in each vector
52
53 @par Details
54 The equation used for the conversion process is:
55 <pre>
56 pDst[n] = (float16_t) pSrc[n] / 32768; 0 <= n < blockSize.
57 </pre>
58 */
59
60 #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
61
arm_q15_to_f16(const q15_t * pSrc,float16_t * pDst,uint32_t blockSize)62 ARM_DSP_ATTRIBUTE void arm_q15_to_f16(
63 const q15_t * pSrc,
64 float16_t * pDst,
65 uint32_t blockSize)
66 {
67 int32_t blkCnt; /* loop counters */
68 q15x8_t vecDst;
69 q15_t const *pSrcVec;
70
71 pSrcVec = (q15_t const *) pSrc;
72 blkCnt = blockSize >> 3;
73 while (blkCnt > 0)
74 {
75 /* C = (float16_t) A / 32768 */
76 /* convert from q15 to float and then store the results in the destination buffer */
77 vecDst = vld1q(pSrcVec); pSrcVec += 8;
78 vstrhq(pDst, vcvtq_n_f16_s16(vecDst, 15)); pDst += 8;
79 /*
80 * Decrement the blockSize loop counter
81 */
82 blkCnt--;
83 }
84 /*
85 * tail
86 * (will be merged thru tail predication)
87 */
88 blkCnt = blockSize & 7;
89 if (blkCnt > 0)
90 {
91 mve_pred16_t p0 = vctp16q(blkCnt);
92 vecDst = vld1q(pSrcVec); pSrcVec += 8;
93 vstrhq_p(pDst, vcvtq_n_f16_s16(vecDst, 15), p0);
94 }
95 }
96 #else
97
arm_q15_to_f16(const q15_t * pSrc,float16_t * pDst,uint32_t blockSize)98 ARM_DSP_ATTRIBUTE void arm_q15_to_f16(
99 const q15_t * pSrc,
100 float16_t * pDst,
101 uint32_t blockSize)
102 {
103 uint32_t blkCnt; /* Loop counter */
104 const q15_t *pIn = pSrc; /* Source pointer */
105
106 #if defined (ARM_MATH_LOOPUNROLL)
107
108 /* Loop unrolling: Compute 4 outputs at a time */
109 blkCnt = blockSize >> 2U;
110
111 while (blkCnt > 0U)
112 {
113 /* C = (float16_t) A / 32768 */
114
115 /* Convert from q15 to float and store result in destination buffer */
116 *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
117 *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
118 *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
119 *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
120
121 /* Decrement loop counter */
122 blkCnt--;
123 }
124
125 /* Loop unrolling: Compute remaining outputs */
126 blkCnt = blockSize % 0x4U;
127
128 #else
129
130 /* Initialize blkCnt with number of samples */
131 blkCnt = blockSize;
132
133 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
134
135 while (blkCnt > 0U)
136 {
137 /* C = (float16_t) A / 32768 */
138
139 /* Convert from q15 to float and store result in destination buffer */
140 *pDst++ = ((_Float16) *pIn++ / 32768.0f16);
141
142 /* Decrement loop counter */
143 blkCnt--;
144 }
145
146 }
147 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
148
149 /**
150 @} end of q15_to_x group
151 */
152
153 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
154
155