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.h"
30
31 /**
32 @ingroup groupSupport
33 */
34
35 /**
36 * @defgroup q15_to_x Convert 16-bit fixed point value
37 */
38
39 /**
40 @addtogroup q15_to_x
41 @{
42 */
43
44 /**
45 @brief Converts the elements of the Q15 vector to floating-point vector.
46 @param[in] pSrc points to the Q15 input vector
47 @param[out] pDst points to the floating-point output vector
48 @param[in] blockSize number of samples in each vector
49
50 @par Details
51 The equation used for the conversion process is:
52 <pre>
53 pDst[n] = (float32_t) pSrc[n] / 32768; 0 <= n < blockSize.
54 </pre>
55 */
56
57 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_q15_to_float(const q15_t * pSrc,float32_t * pDst,uint32_t blockSize)58 void arm_q15_to_float(
59 const q15_t * pSrc,
60 float32_t * pDst,
61 uint32_t blockSize)
62 {
63 uint32_t blkCnt;
64
65 q15x8_t vecDst;
66 q15_t const *pSrcVec;
67
68 pSrcVec = (q15_t const *) pSrc;
69 blkCnt = blockSize >> 2;
70 while (blkCnt > 0U)
71 {
72 /* C = (float32_t) A / 32768 */
73 /* convert from q15 to float and then store the results in the destination buffer */
74 vecDst = vldrhq_s32(pSrcVec);
75 pSrcVec += 4;
76 vstrwq(pDst, vcvtq_n_f32_s32((int32x4_t)vecDst, 15));
77 pDst += 4;
78 /*
79 * Decrement the blockSize loop counter
80 */
81 blkCnt--;
82 }
83
84 blkCnt = blockSize & 3;
85 while (blkCnt > 0U)
86 {
87 /* C = (float32_t) A / 32768 */
88
89 /* Convert from q15 to float and store result in destination buffer */
90 *pDst++ = ((float32_t) *pSrcVec++ / 32768.0f);
91
92 /* Decrement loop counter */
93 blkCnt--;
94 }
95 }
96 #else
97 #if defined(ARM_MATH_NEON_EXPERIMENTAL)
arm_q15_to_float(const q15_t * pSrc,float32_t * pDst,uint32_t blockSize)98 void arm_q15_to_float(
99 const q15_t * pSrc,
100 float32_t * pDst,
101 uint32_t blockSize)
102 {
103 const q15_t *pIn = pSrc; /* Src pointer */
104 uint32_t blkCnt; /* loop counter */
105
106 int16x8_t inV;
107 int32x4_t inV0, inV1;
108 float32x4_t outV;
109
110 blkCnt = blockSize >> 3U;
111
112 /* Compute 8 outputs at a time.
113 ** a second loop below computes the remaining 1 to 7 samples. */
114 while (blkCnt > 0U)
115 {
116 /* C = (float32_t) A / 32768 */
117 /* convert from q15 to float and then store the results in the destination buffer */
118 inV = vld1q_s16(pIn);
119 pIn += 8;
120
121 inV0 = vmovl_s16(vget_low_s16(inV));
122 inV1 = vmovl_s16(vget_high_s16(inV));
123
124 outV = vcvtq_n_f32_s32(inV0,15);
125 vst1q_f32(pDst, outV);
126 pDst += 4;
127
128 outV = vcvtq_n_f32_s32(inV1,15);
129 vst1q_f32(pDst, outV);
130 pDst += 4;
131
132 /* Decrement the loop counter */
133 blkCnt--;
134 }
135
136 /* If the blockSize is not a multiple of 8, compute any remaining output samples here.
137 ** No loop unrolling is used. */
138 blkCnt = blockSize & 7;
139
140
141 while (blkCnt > 0U)
142 {
143 /* C = (float32_t) A / 32768 */
144 /* convert from q15 to float and then store the results in the destination buffer */
145 *pDst++ = ((float32_t) * pIn++ / 32768.0f);
146
147 /* Decrement the loop counter */
148 blkCnt--;
149 }
150 }
151 #else
arm_q15_to_float(const q15_t * pSrc,float32_t * pDst,uint32_t blockSize)152 void arm_q15_to_float(
153 const q15_t * pSrc,
154 float32_t * pDst,
155 uint32_t blockSize)
156 {
157 uint32_t blkCnt; /* Loop counter */
158 const q15_t *pIn = pSrc; /* Source pointer */
159
160 #if defined (ARM_MATH_LOOPUNROLL)
161
162 /* Loop unrolling: Compute 4 outputs at a time */
163 blkCnt = blockSize >> 2U;
164
165 while (blkCnt > 0U)
166 {
167 /* C = (float32_t) A / 32768 */
168
169 /* Convert from q15 to float and store result in destination buffer */
170 *pDst++ = ((float32_t) * pIn++ / 32768.0f);
171 *pDst++ = ((float32_t) * pIn++ / 32768.0f);
172 *pDst++ = ((float32_t) * pIn++ / 32768.0f);
173 *pDst++ = ((float32_t) * pIn++ / 32768.0f);
174
175 /* Decrement loop counter */
176 blkCnt--;
177 }
178
179 /* Loop unrolling: Compute remaining outputs */
180 blkCnt = blockSize % 0x4U;
181
182 #else
183
184 /* Initialize blkCnt with number of samples */
185 blkCnt = blockSize;
186
187 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
188
189 while (blkCnt > 0U)
190 {
191 /* C = (float32_t) A / 32768 */
192
193 /* Convert from q15 to float and store result in destination buffer */
194 *pDst++ = ((float32_t) *pIn++ / 32768.0f);
195
196 /* Decrement loop counter */
197 blkCnt--;
198 }
199
200 }
201 #endif /* #if defined(ARM_MATH_NEON) */
202 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
203
204 /**
205 @} end of q15_to_x group
206 */
207