提交 | 用户 | age
|
bfc108
|
1 |
/* ----------------------------------------------------------------------
|
Q |
2 |
* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
|
|
3 |
*
|
|
4 |
* $Date: 19. March 2015
|
|
5 |
* $Revision: V.1.4.5
|
|
6 |
*
|
|
7 |
* Project: CMSIS DSP Library
|
|
8 |
* Title: arm_mat_trans_q31.c
|
|
9 |
*
|
|
10 |
* Description: Q31 matrix transpose.
|
|
11 |
*
|
|
12 |
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
|
|
13 |
*
|
|
14 |
* Redistribution and use in source and binary forms, with or without
|
|
15 |
* modification, are permitted provided that the following conditions
|
|
16 |
* are met:
|
|
17 |
* - Redistributions of source code must retain the above copyright
|
|
18 |
* notice, this list of conditions and the following disclaimer.
|
|
19 |
* - Redistributions in binary form must reproduce the above copyright
|
|
20 |
* notice, this list of conditions and the following disclaimer in
|
|
21 |
* the documentation and/or other materials provided with the
|
|
22 |
* distribution.
|
|
23 |
* - Neither the name of ARM LIMITED nor the names of its contributors
|
|
24 |
* may be used to endorse or promote products derived from this
|
|
25 |
* software without specific prior written permission.
|
|
26 |
*
|
|
27 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
28 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
29 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
30 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
31 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
32 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
33 |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
34 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
35 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
36 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
37 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
38 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
39 |
* -------------------------------------------------------------------- */
|
|
40 |
|
|
41 |
#include "arm_math.h"
|
|
42 |
|
|
43 |
/**
|
|
44 |
* @ingroup groupMatrix
|
|
45 |
*/
|
|
46 |
|
|
47 |
/**
|
|
48 |
* @addtogroup MatrixTrans
|
|
49 |
* @{
|
|
50 |
*/
|
|
51 |
|
|
52 |
/*
|
|
53 |
* @brief Q31 matrix transpose.
|
|
54 |
* @param[in] *pSrc points to the input matrix
|
|
55 |
* @param[out] *pDst points to the output matrix
|
|
56 |
* @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
|
|
57 |
* or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
|
|
58 |
*/
|
|
59 |
|
|
60 |
arm_status arm_mat_trans_q31(
|
|
61 |
const arm_matrix_instance_q31 * pSrc,
|
|
62 |
arm_matrix_instance_q31 * pDst)
|
|
63 |
{
|
|
64 |
q31_t *pIn = pSrc->pData; /* input data matrix pointer */
|
|
65 |
q31_t *pOut = pDst->pData; /* output data matrix pointer */
|
|
66 |
q31_t *px; /* Temporary output data matrix pointer */
|
|
67 |
uint16_t nRows = pSrc->numRows; /* number of nRows */
|
|
68 |
uint16_t nColumns = pSrc->numCols; /* number of nColumns */
|
|
69 |
|
|
70 |
#ifndef ARM_MATH_CM0_FAMILY
|
|
71 |
|
|
72 |
/* Run the below code for Cortex-M4 and Cortex-M3 */
|
|
73 |
|
|
74 |
uint16_t blkCnt, i = 0u, row = nRows; /* loop counters */
|
|
75 |
arm_status status; /* status of matrix transpose */
|
|
76 |
|
|
77 |
|
|
78 |
#ifdef ARM_MATH_MATRIX_CHECK
|
|
79 |
|
|
80 |
|
|
81 |
/* Check for matrix mismatch condition */
|
|
82 |
if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
|
|
83 |
{
|
|
84 |
/* Set status as ARM_MATH_SIZE_MISMATCH */
|
|
85 |
status = ARM_MATH_SIZE_MISMATCH;
|
|
86 |
}
|
|
87 |
else
|
|
88 |
#endif /* #ifdef ARM_MATH_MATRIX_CHECK */
|
|
89 |
|
|
90 |
{
|
|
91 |
/* Matrix transpose by exchanging the rows with columns */
|
|
92 |
/* row loop */
|
|
93 |
do
|
|
94 |
{
|
|
95 |
/* Apply loop unrolling and exchange the columns with row elements */
|
|
96 |
blkCnt = nColumns >> 2u;
|
|
97 |
|
|
98 |
/* The pointer px is set to starting address of the column being processed */
|
|
99 |
px = pOut + i;
|
|
100 |
|
|
101 |
/* First part of the processing with loop unrolling. Compute 4 outputs at a time.
|
|
102 |
** a second loop below computes the remaining 1 to 3 samples. */
|
|
103 |
while(blkCnt > 0u)
|
|
104 |
{
|
|
105 |
/* Read and store the input element in the destination */
|
|
106 |
*px = *pIn++;
|
|
107 |
|
|
108 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
109 |
px += nRows;
|
|
110 |
|
|
111 |
/* Read and store the input element in the destination */
|
|
112 |
*px = *pIn++;
|
|
113 |
|
|
114 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
115 |
px += nRows;
|
|
116 |
|
|
117 |
/* Read and store the input element in the destination */
|
|
118 |
*px = *pIn++;
|
|
119 |
|
|
120 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
121 |
px += nRows;
|
|
122 |
|
|
123 |
/* Read and store the input element in the destination */
|
|
124 |
*px = *pIn++;
|
|
125 |
|
|
126 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
127 |
px += nRows;
|
|
128 |
|
|
129 |
/* Decrement the column loop counter */
|
|
130 |
blkCnt--;
|
|
131 |
}
|
|
132 |
|
|
133 |
/* Perform matrix transpose for last 3 samples here. */
|
|
134 |
blkCnt = nColumns % 0x4u;
|
|
135 |
|
|
136 |
while(blkCnt > 0u)
|
|
137 |
{
|
|
138 |
/* Read and store the input element in the destination */
|
|
139 |
*px = *pIn++;
|
|
140 |
|
|
141 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
142 |
px += nRows;
|
|
143 |
|
|
144 |
/* Decrement the column loop counter */
|
|
145 |
blkCnt--;
|
|
146 |
}
|
|
147 |
|
|
148 |
#else
|
|
149 |
|
|
150 |
/* Run the below code for Cortex-M0 */
|
|
151 |
|
|
152 |
uint16_t col, i = 0u, row = nRows; /* loop counters */
|
|
153 |
arm_status status; /* status of matrix transpose */
|
|
154 |
|
|
155 |
|
|
156 |
#ifdef ARM_MATH_MATRIX_CHECK
|
|
157 |
|
|
158 |
/* Check for matrix mismatch condition */
|
|
159 |
if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
|
|
160 |
{
|
|
161 |
/* Set status as ARM_MATH_SIZE_MISMATCH */
|
|
162 |
status = ARM_MATH_SIZE_MISMATCH;
|
|
163 |
}
|
|
164 |
else
|
|
165 |
#endif /* #ifdef ARM_MATH_MATRIX_CHECK */
|
|
166 |
|
|
167 |
{
|
|
168 |
/* Matrix transpose by exchanging the rows with columns */
|
|
169 |
/* row loop */
|
|
170 |
do
|
|
171 |
{
|
|
172 |
/* The pointer px is set to starting address of the column being processed */
|
|
173 |
px = pOut + i;
|
|
174 |
|
|
175 |
/* Initialize column loop counter */
|
|
176 |
col = nColumns;
|
|
177 |
|
|
178 |
while(col > 0u)
|
|
179 |
{
|
|
180 |
/* Read and store the input element in the destination */
|
|
181 |
*px = *pIn++;
|
|
182 |
|
|
183 |
/* Update the pointer px to point to the next row of the transposed matrix */
|
|
184 |
px += nRows;
|
|
185 |
|
|
186 |
/* Decrement the column loop counter */
|
|
187 |
col--;
|
|
188 |
}
|
|
189 |
|
|
190 |
#endif /* #ifndef ARM_MATH_CM0_FAMILY */
|
|
191 |
|
|
192 |
i++;
|
|
193 |
|
|
194 |
/* Decrement the row loop counter */
|
|
195 |
row--;
|
|
196 |
|
|
197 |
}
|
|
198 |
while(row > 0u); /* row loop end */
|
|
199 |
|
|
200 |
/* set status as ARM_MATH_SUCCESS */
|
|
201 |
status = ARM_MATH_SUCCESS;
|
|
202 |
}
|
|
203 |
|
|
204 |
/* Return to application */
|
|
205 |
return (status);
|
|
206 |
}
|
|
207 |
|
|
208 |
/**
|
|
209 |
* @} end of MatrixTrans group
|
|
210 |
*/
|