1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_q7_to_q15.c
4 * Description: Converts the elements of the Q7 vector to Q15 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 q7_to_x
37 @{
38 */
39
40 /**
41 @brief Converts the elements of the Q7 vector to Q15 vector.
42 @param[in] pSrc points to the Q7 input vector
43 @param[out] pDst points to the Q15 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] = (q15_t) pSrc[n] << 8; 0 <= n < blockSize.
51 </pre>
52 */
53
54 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_q7_to_q15(const q7_t * pSrc,q15_t * pDst,uint32_t blockSize)55 void arm_q7_to_q15(
56 const q7_t * pSrc,
57 q15_t * pDst,
58 uint32_t blockSize)
59 {
60
61 uint32_t blkCnt; /* loop counters */
62 q15x8_t vecDst;
63 q7_t const *pSrcVec;
64
65
66 pSrcVec = (q7_t const *) pSrc;
67 blkCnt = blockSize >> 3;
68 while (blkCnt > 0U)
69 {
70 /* C = (q15_t) A << 8 */
71 /* convert from q7 to q15 and then store the results in the destination buffer */
72 /* load q7 + 32-bit widening */
73 vecDst = vldrbq_s16(pSrcVec);
74 pSrcVec += 8;
75 vecDst = vecDst << 8;
76 vstrhq(pDst, vecDst);
77 pDst += 8;
78 /*
79 * Decrement the blockSize loop counter
80 */
81 blkCnt--;
82 }
83
84 blkCnt = blockSize & 7;
85 while (blkCnt > 0U)
86 {
87 /* C = (q15_t) A << 8 */
88
89 /* Convert from q7 to q15 and store result in destination buffer */
90 *pDst++ = (q15_t) * pSrcVec++ << 8;
91
92 /* Decrement loop counter */
93 blkCnt--;
94 }
95
96 }
97 #else
arm_q7_to_q15(const q7_t * pSrc,q15_t * pDst,uint32_t blockSize)98 void arm_q7_to_q15(
99 const q7_t * pSrc,
100 q15_t * pDst,
101 uint32_t blockSize)
102 {
103 uint32_t blkCnt; /* Loop counter */
104 const q7_t *pIn = pSrc; /* Source pointer */
105
106 #if defined (ARM_MATH_LOOPUNROLL) && defined (ARM_MATH_DSP)
107 q31_t in;
108 q31_t in1, in2;
109 q31_t out1, out2;
110 #endif
111
112 #if defined (ARM_MATH_LOOPUNROLL)
113
114 /* Loop unrolling: Compute 4 outputs at a time */
115 blkCnt = blockSize >> 2U;
116
117 while (blkCnt > 0U)
118 {
119 /* C = (q15_t) A << 8 */
120
121 /* Convert from q7 to q15 and store result in destination buffer */
122 #if defined (ARM_MATH_DSP)
123
124 in = read_q7x4_ia ((q7_t **) &pIn);
125
126 /* rotatate in by 8 and extend two q7_t values to q15_t values */
127 in1 = __SXTB16(__ROR(in, 8));
128
129 /* extend remainig two q7_t values to q15_t values */
130 in2 = __SXTB16(in);
131
132 in1 = in1 << 8U;
133 in2 = in2 << 8U;
134
135 in1 = in1 & 0xFF00FF00;
136 in2 = in2 & 0xFF00FF00;
137
138 #ifndef ARM_MATH_BIG_ENDIAN
139 out2 = __PKHTB(in1, in2, 16);
140 out1 = __PKHBT(in2, in1, 16);
141 #else
142 out1 = __PKHTB(in1, in2, 16);
143 out2 = __PKHBT(in2, in1, 16);
144 #endif
145
146 write_q15x2_ia (&pDst, out1);
147 write_q15x2_ia (&pDst, out2);
148
149 #else
150
151 *pDst++ = (q15_t) *pIn++ << 8;
152 *pDst++ = (q15_t) *pIn++ << 8;
153 *pDst++ = (q15_t) *pIn++ << 8;
154 *pDst++ = (q15_t) *pIn++ << 8;
155
156 #endif /* #if defined (ARM_MATH_DSP) */
157
158 /* Decrement loop counter */
159 blkCnt--;
160 }
161
162 /* Loop unrolling: Compute remaining outputs */
163 blkCnt = blockSize % 0x4U;
164
165 #else
166
167 /* Initialize blkCnt with number of samples */
168 blkCnt = blockSize;
169
170 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
171
172 while (blkCnt > 0U)
173 {
174 /* C = (q15_t) A << 8 */
175
176 /* Convert from q7 to q15 and store result in destination buffer */
177 *pDst++ = (q15_t) * pIn++ << 8;
178
179 /* Decrement loop counter */
180 blkCnt--;
181 }
182
183 }
184 #endif /* defined(ARM_MATH_MVEI) */
185
186 /**
187 @} end of q7_to_x group
188 */
189