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