1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_q7_to_float.c
4  * Description:  Converts the elements of the Q7 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 q7_to_x  Convert 8-bit fixed point value
37  */
38 
39 /**
40   @addtogroup q7_to_x
41   @{
42  */
43 
44 /**
45   @brief         Converts the elements of the Q7 vector to floating-point vector.
46   @param[in]     pSrc       points to the Q7 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] / 128;   0 <= n < blockSize.
54   </pre>
55  */
56 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_q7_to_float(const q7_t * pSrc,float32_t * pDst,uint32_t blockSize)57 ARM_DSP_ATTRIBUTE void arm_q7_to_float(
58   const q7_t * pSrc,
59   float32_t * pDst,
60   uint32_t blockSize)
61 {
62     uint32_t  blkCnt;           /* loop counters */
63     q7x16_t vecDst;
64     q7_t const *pSrcVec;
65 
66     pSrcVec = (q7_t const *) pSrc;
67     blkCnt = blockSize >> 2;
68     while (blkCnt > 0U)
69     {
70         /* C = (float32_t) A / 32768 */
71         /* convert from q7 to float and then store the results in the destination buffer */
72         vecDst = vldrbq_s32(pSrcVec);
73         pSrcVec += 4;
74         vstrwq(pDst, vcvtq_n_f32_s32((int32x4_t)vecDst, 7));
75         pDst += 4;
76         /*
77          * Decrement the blockSize loop counter
78          */
79         blkCnt--;
80     }
81 
82   blkCnt = blockSize & 3;
83   while (blkCnt > 0U)
84   {
85     /* C = (float32_t) A / 128 */
86 
87     /* Convert from q7 to float and store result in destination buffer */
88     *pDst++ = ((float32_t) * pSrcVec++ / 128.0f);
89 
90     /* Decrement loop counter */
91     blkCnt--;
92   }
93 }
94 #else
95 #if defined(ARM_MATH_NEON)
arm_q7_to_float(const q7_t * pSrc,float32_t * pDst,uint32_t blockSize)96 ARM_DSP_ATTRIBUTE void arm_q7_to_float(
97   const q7_t * pSrc,
98   float32_t * pDst,
99   uint32_t blockSize)
100 {
101   const q7_t *pIn = pSrc;                              /* Src pointer */
102   uint32_t blkCnt;                               /* loop counter */
103 
104   int8x16_t inV;
105   int16x8_t inVLO, inVHI;
106   int32x4_t inVLL, inVLH, inVHL, inVHH;
107   float32x4_t outV;
108 
109   blkCnt = blockSize >> 4U;
110 
111   /* Compute 16 outputs at a time.
112    ** a second loop below computes the remaining 1 to 15 samples. */
113   while (blkCnt > 0U)
114   {
115     /* C = (float32_t) A / 128 */
116     /* Convert from q7 to float and then store the results in the destination buffer */
117     inV = vld1q_s8(pIn);
118     pIn += 16;
119 
120     inVLO = vmovl_s8(vget_low_s8(inV));
121     inVHI = vmovl_s8(vget_high_s8(inV));
122 
123     inVLL = vmovl_s16(vget_low_s16(inVLO));
124     inVLH = vmovl_s16(vget_high_s16(inVLO));
125     inVHL = vmovl_s16(vget_low_s16(inVHI));
126     inVHH = vmovl_s16(vget_high_s16(inVHI));
127 
128     outV = vcvtq_n_f32_s32(inVLL,7);
129     vst1q_f32(pDst, outV);
130     pDst += 4;
131 
132     outV = vcvtq_n_f32_s32(inVLH,7);
133     vst1q_f32(pDst, outV);
134     pDst += 4;
135 
136     outV = vcvtq_n_f32_s32(inVHL,7);
137     vst1q_f32(pDst, outV);
138     pDst += 4;
139 
140     outV = vcvtq_n_f32_s32(inVHH,7);
141     vst1q_f32(pDst, outV);
142     pDst += 4;
143 
144     /* Decrement the loop counter */
145     blkCnt--;
146   }
147 
148   /* If the blockSize is not a multiple of 16, compute any remaining output samples here.
149    ** No loop unrolling is used. */
150   blkCnt = blockSize & 0xF;
151 
152   while (blkCnt > 0U)
153   {
154     /* C = (float32_t) A / 128 */
155     /* Convert from q7 to float and then store the results in the destination buffer */
156     *pDst++ = ((float32_t) * pIn++ / 128.0f);
157 
158     /* Decrement the loop counter */
159     blkCnt--;
160   }
161 }
162 #else
arm_q7_to_float(const q7_t * pSrc,float32_t * pDst,uint32_t blockSize)163 ARM_DSP_ATTRIBUTE void arm_q7_to_float(
164   const q7_t * pSrc,
165         float32_t * pDst,
166         uint32_t blockSize)
167 {
168         uint32_t blkCnt;                               /* Loop counter */
169   const q7_t *pIn = pSrc;                              /* Source pointer */
170 
171 #if defined (ARM_MATH_LOOPUNROLL)
172 
173   /* Loop unrolling: Compute 4 outputs at a time */
174   blkCnt = blockSize >> 2U;
175 
176   while (blkCnt > 0U)
177   {
178     /* C = (float32_t) A / 128 */
179 
180     /* Convert from q7 to float and store result in destination buffer */
181     *pDst++ = ((float32_t) * pIn++ / 128.0f);
182     *pDst++ = ((float32_t) * pIn++ / 128.0f);
183     *pDst++ = ((float32_t) * pIn++ / 128.0f);
184     *pDst++ = ((float32_t) * pIn++ / 128.0f);
185 
186     /* Decrement loop counter */
187     blkCnt--;
188   }
189 
190   /* Loop unrolling: Compute remaining outputs */
191   blkCnt = blockSize % 0x4U;
192 
193 #else
194 
195   /* Initialize blkCnt with number of samples */
196   blkCnt = blockSize;
197 
198 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
199 
200   while (blkCnt > 0U)
201   {
202     /* C = (float32_t) A / 128 */
203 
204     /* Convert from q7 to float and store result in destination buffer */
205     *pDst++ = ((float32_t) * pIn++ / 128.0f);
206 
207     /* Decrement loop counter */
208     blkCnt--;
209   }
210 
211 }
212 #endif /* #if defined(ARM_MATH_NEON) */
213 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
214 
215 /**
216   @} end of q7_to_x group
217  */
218