1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_q7_to_q31.c
4 * Description: Converts the elements of the Q7 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 q7_to_x
37 @{
38 */
39
40 /**
41 @brief Converts the elements of the Q7 vector to Q31 vector.
42 @param[in] pSrc points to the Q7 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] << 24; 0 <= n < blockSize.
50 </pre>
51 */
52 #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
arm_q7_to_q31(const q7_t * pSrc,q31_t * pDst,uint32_t blockSize)53 ARM_DSP_ATTRIBUTE void arm_q7_to_q31(
54 const q7_t * pSrc,
55 q31_t * pDst,
56 uint32_t blockSize)
57 {
58 uint32_t blkCnt;
59 q31x4_t vecDst;
60
61 blkCnt = blockSize >> 2;
62 while (blkCnt > 0U)
63 {
64
65 /* C = (q31_t)A << 16 */
66 /* convert from q15 to q31 and then store the results in the destination buffer */
67 /* load q15 + 32-bit widening */
68 vecDst = vldrbq_s32((q7_t const *) pSrc);
69 vecDst = vshlq_n(vecDst, 24);
70 vstrwq_s32(pDst, vecDst);
71
72 /*
73 * Decrement the blockSize loop counter
74 * Advance vector source and destination pointers
75 */
76 pDst += 4;
77 pSrc += 4;
78 blkCnt --;
79 }
80
81 blkCnt = blockSize & 3;
82 while (blkCnt > 0U)
83 {
84 /* C = (q31_t) A << 24 */
85
86 /* Convert from q7 to q31 and store result in destination buffer */
87 *pDst++ = (q31_t) *pSrc++ << 24;
88
89 /* Decrement loop counter */
90 blkCnt--;
91 }
92 }
93
94 #else
arm_q7_to_q31(const q7_t * pSrc,q31_t * pDst,uint32_t blockSize)95 ARM_DSP_ATTRIBUTE void arm_q7_to_q31(
96 const q7_t * pSrc,
97 q31_t * pDst,
98 uint32_t blockSize)
99 {
100 uint32_t blkCnt; /* Loop counter */
101 const q7_t *pIn = pSrc; /* Source pointer */
102
103 #if defined (ARM_MATH_LOOPUNROLL)
104
105 q31_t in;
106
107 /* Loop unrolling: Compute 4 outputs at a time */
108 blkCnt = blockSize >> 2U;
109
110 while (blkCnt > 0U)
111 {
112 /* C = (q31_t) A << 24 */
113
114 /* Convert from q7 to q31 and store result in destination buffer */
115 in = read_q7x4_ia (&pIn);
116
117 #ifndef ARM_MATH_BIG_ENDIAN
118
119 *pDst++ = (__ROR(in, 8)) & 0xFF000000;
120 *pDst++ = (__ROR(in, 16)) & 0xFF000000;
121 *pDst++ = (__ROR(in, 24)) & 0xFF000000;
122 *pDst++ = (in & 0xFF000000);
123
124 #else
125
126 *pDst++ = (in & 0xFF000000);
127 *pDst++ = (__ROR(in, 24)) & 0xFF000000;
128 *pDst++ = (__ROR(in, 16)) & 0xFF000000;
129 *pDst++ = (__ROR(in, 8)) & 0xFF000000;
130
131 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
132
133 /* Decrement loop counter */
134 blkCnt--;
135 }
136
137 /* Loop unrolling: Compute remaining outputs */
138 blkCnt = blockSize % 0x4U;
139
140 #else
141
142 /* Initialize blkCnt with number of samples */
143 blkCnt = blockSize;
144
145 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
146
147 while (blkCnt > 0U)
148 {
149 /* C = (q31_t) A << 24 */
150
151 /* Convert from q7 to q31 and store result in destination buffer */
152 *pDst++ = (q31_t) * pIn++ << 24;
153
154 /* Decrement loop counter */
155 blkCnt--;
156 }
157
158 }
159 #endif /* defined(ARM_MATH_MVEI) */
160
161 /**
162 @} end of q7_to_x group
163 */
164