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