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