1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_q15_to_q31.c
4 * Description: Converts the elements of the Q15 vector to Q31 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 @addtogroup q15_to_x
37 @{
38 */
39
40 /**
41 @brief Converts the elements of the Q15 vector to Q31 vector.
42 @param[in] pSrc points to the Q15 input vector
43 @param[out] pDst points to the Q31 output vector
44 @param[in] blockSize number of samples in each vector
45
46 @par Details
47 The equation used for the conversion process is:
48 <pre>
49 pDst[n] = (q31_t) pSrc[n] << 16; 0 <= n < blockSize.
50 </pre>
51 */
52 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_q15_to_q31(const q15_t * pSrc,q31_t * pDst,uint32_t blockSize)53 ARM_DSP_ATTRIBUTE void arm_q15_to_q31(
54 const q15_t * pSrc,
55 q31_t * pDst,
56 uint32_t blockSize)
57 {
58
59 uint32_t blkCnt;
60
61 q31x4_t vecDst;
62
63 blkCnt = blockSize>> 2;
64 while (blkCnt > 0U)
65 {
66
67 /* C = (q31_t)A << 16 */
68 /* convert from q15 to q31 and then store the results in the destination buffer */
69 /* load q15 + 32-bit widening */
70 vecDst = vldrhq_s32((q15_t const *) pSrc);
71 vecDst = vshlq_n(vecDst, 16);
72 vstrwq_s32(pDst, vecDst);
73
74 /*
75 * Decrement the blockSize loop counter
76 * Advance vector source and destination pointers
77 */
78 pDst += 4;
79 pSrc += 4;
80 blkCnt --;
81 }
82
83 blkCnt = blockSize & 3;
84 while (blkCnt > 0U)
85 {
86 /* C = (q31_t) A << 16 */
87
88 /* Convert from q15 to q31 and store result in destination buffer */
89 *pDst++ = (q31_t) *pSrc++ << 16;
90
91 /* Decrement loop counter */
92 blkCnt--;
93 }
94 }
95 #else
arm_q15_to_q31(const q15_t * pSrc,q31_t * pDst,uint32_t blockSize)96 ARM_DSP_ATTRIBUTE void arm_q15_to_q31(
97 const q15_t * pSrc,
98 q31_t * pDst,
99 uint32_t blockSize)
100 {
101 uint32_t blkCnt; /* Loop counter */
102 const q15_t *pIn = pSrc; /* Source pointer */
103
104 #if defined (ARM_MATH_LOOPUNROLL)
105 q31_t in1, in2;
106 q31_t out1, out2, out3, out4;
107 #endif
108
109 #if defined (ARM_MATH_LOOPUNROLL)
110
111 /* Loop unrolling: Compute 4 outputs at a time */
112 blkCnt = blockSize >> 2U;
113
114 while (blkCnt > 0U)
115 {
116 /* C = (q31_t)A << 16 */
117
118 /* Convert from q15 to q31 and store result in destination buffer */
119 in1 = read_q15x2_ia (&pIn);
120 in2 = read_q15x2_ia (&pIn);
121
122 #ifndef ARM_MATH_BIG_ENDIAN
123
124 /* extract lower 16 bits to 32 bit result */
125 out1 = in1 << 16U;
126 /* extract upper 16 bits to 32 bit result */
127 out2 = in1 & 0xFFFF0000;
128 /* extract lower 16 bits to 32 bit result */
129 out3 = in2 << 16U;
130 /* extract upper 16 bits to 32 bit result */
131 out4 = in2 & 0xFFFF0000;
132
133 #else
134
135 /* extract upper 16 bits to 32 bit result */
136 out1 = in1 & 0xFFFF0000;
137 /* extract lower 16 bits to 32 bit result */
138 out2 = in1 << 16U;
139 /* extract upper 16 bits to 32 bit result */
140 out3 = in2 & 0xFFFF0000;
141 /* extract lower 16 bits to 32 bit result */
142 out4 = in2 << 16U;
143
144 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
145
146 *pDst++ = out1;
147 *pDst++ = out2;
148 *pDst++ = out3;
149 *pDst++ = out4;
150
151 /* Decrement loop counter */
152 blkCnt--;
153 }
154
155 /* Loop unrolling: Compute remaining outputs */
156 blkCnt = blockSize % 0x4U;
157
158 #else
159
160 /* Initialize blkCnt with number of samples */
161 blkCnt = blockSize;
162
163 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
164
165 while (blkCnt > 0U)
166 {
167 /* C = (q31_t) A << 16 */
168
169 /* Convert from q15 to q31 and store result in destination buffer */
170 *pDst++ = (q31_t) *pIn++ << 16;
171
172 /* Decrement loop counter */
173 blkCnt--;
174 }
175
176 }
177 #endif /* defined(ARM_MATH_MVEI) */
178
179 /**
180 @} end of q15_to_x group
181 */
182