Subversion Repositories ScreenTimer

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* ----------------------------------------------------------------------
2
 * Project:      CMSIS DSP Library
3
 * Title:        arm_mat_trans_q15.c
4
 * Description:  Q15 matrix transpose
5
 *
6
 * $Date:        27. January 2017
7
 * $Revision:    V.1.5.1
8
 *
9
 * Target Processor: Cortex-M cores
10
 * -------------------------------------------------------------------- */
11
/*
12
 * Copyright (C) 2010-2017 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 "arm_math.h"
30
 
31
/**
32
 * @ingroup groupMatrix
33
 */
34
 
35
/**
36
 * @addtogroup MatrixTrans
37
 * @{
38
 */
39
 
40
/*
41
 * @brief Q15 matrix transpose.
42
 * @param[in]  *pSrc points to the input matrix
43
 * @param[out] *pDst points to the output matrix
44
 * @return      The function returns either  <code>ARM_MATH_SIZE_MISMATCH</code>
45
 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
46
 */
47
 
48
arm_status arm_mat_trans_q15(
49
  const arm_matrix_instance_q15 * pSrc,
50
  arm_matrix_instance_q15 * pDst)
51
{
52
  q15_t *pSrcA = pSrc->pData;                    /* input data matrix pointer */
53
  q15_t *pOut = pDst->pData;                     /* output data matrix pointer */
54
  uint16_t nRows = pSrc->numRows;                /* number of nRows */
55
  uint16_t nColumns = pSrc->numCols;             /* number of nColumns */
56
  uint16_t col, row = nRows, i = 0U;             /* row and column loop counters */
57
  arm_status status;                             /* status of matrix transpose */
58
 
59
#if defined (ARM_MATH_DSP)
60
 
61
  /* Run the below code for Cortex-M4 and Cortex-M3 */
62
#ifndef UNALIGNED_SUPPORT_DISABLE
63
 
64
  q31_t in;                                      /* variable to hold temporary output  */
65
 
66
#else
67
 
68
  q15_t in;
69
 
70
#endif  /*      #ifndef UNALIGNED_SUPPORT_DISABLE       */
71
 
72
#ifdef ARM_MATH_MATRIX_CHECK
73
 
74
 
75
  /* Check for matrix mismatch condition */
76
  if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
77
  {
78
    /* Set status as ARM_MATH_SIZE_MISMATCH */
79
    status = ARM_MATH_SIZE_MISMATCH;
80
  }
81
  else
82
#endif /*      #ifdef ARM_MATH_MATRIX_CHECK    */
83
 
84
  {
85
    /* Matrix transpose by exchanging the rows with columns */
86
    /* row loop     */
87
    do
88
    {
89
 
90
      /* Apply loop unrolling and exchange the columns with row elements */
91
      col = nColumns >> 2U;
92
 
93
      /* The pointer pOut is set to starting address of the column being processed */
94
      pOut = pDst->pData + i;
95
 
96
      /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
97
       ** a second loop below computes the remaining 1 to 3 samples. */
98
      while (col > 0U)
99
      {
100
#ifndef UNALIGNED_SUPPORT_DISABLE
101
 
102
        /* Read two elements from the row */
103
        in = *__SIMD32(pSrcA)++;
104
 
105
        /* Unpack and store one element in the destination */
106
#ifndef ARM_MATH_BIG_ENDIAN
107
 
108
        *pOut = (q15_t) in;
109
 
110
#else
111
 
112
        *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
113
 
114
#endif /*    #ifndef ARM_MATH_BIG_ENDIAN    */
115
 
116
        /* Update the pointer pOut to point to the next row of the transposed matrix */
117
        pOut += nRows;
118
 
119
        /* Unpack and store the second element in the destination */
120
 
121
#ifndef ARM_MATH_BIG_ENDIAN
122
 
123
        *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
124
 
125
#else
126
 
127
        *pOut = (q15_t) in;
128
 
129
#endif /*    #ifndef ARM_MATH_BIG_ENDIAN    */
130
 
131
        /* Update the pointer pOut to point to the next row of the transposed matrix */
132
        pOut += nRows;
133
 
134
        /* Read two elements from the row */
135
#ifndef ARM_MATH_BIG_ENDIAN
136
 
137
        in = *__SIMD32(pSrcA)++;
138
 
139
#else
140
 
141
        in = *__SIMD32(pSrcA)++;
142
 
143
#endif /*    #ifndef ARM_MATH_BIG_ENDIAN    */
144
 
145
        /* Unpack and store one element in the destination */
146
#ifndef ARM_MATH_BIG_ENDIAN
147
 
148
        *pOut = (q15_t) in;
149
 
150
#else
151
 
152
        *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
153
 
154
#endif /*    #ifndef ARM_MATH_BIG_ENDIAN    */
155
 
156
        /* Update the pointer pOut to point to the next row of the transposed matrix */
157
        pOut += nRows;
158
 
159
        /* Unpack and store the second element in the destination */
160
#ifndef ARM_MATH_BIG_ENDIAN
161
 
162
        *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
163
 
164
#else
165
 
166
        *pOut = (q15_t) in;
167
 
168
#endif /*    #ifndef ARM_MATH_BIG_ENDIAN    */
169
 
170
#else
171
        /* Read one element from the row */
172
        in = *pSrcA++;
173
 
174
        /* Store one element in the destination */
175
        *pOut = in;
176
 
177
        /* Update the pointer px to point to the next row of the transposed matrix */
178
        pOut += nRows;
179
 
180
        /* Read one element from the row */
181
        in = *pSrcA++;
182
 
183
        /* Store one element in the destination */
184
        *pOut = in;
185
 
186
        /* Update the pointer px to point to the next row of the transposed matrix */
187
        pOut += nRows;
188
 
189
        /* Read one element from the row */
190
        in = *pSrcA++;
191
 
192
        /* Store one element in the destination */
193
        *pOut = in;
194
 
195
        /* Update the pointer px to point to the next row of the transposed matrix */
196
        pOut += nRows;
197
 
198
        /* Read one element from the row */
199
        in = *pSrcA++;
200
 
201
        /* Store one element in the destination */
202
        *pOut = in;
203
 
204
#endif  /*      #ifndef UNALIGNED_SUPPORT_DISABLE       */
205
 
206
        /* Update the pointer pOut to point to the next row of the transposed matrix */
207
        pOut += nRows;
208
 
209
        /* Decrement the column loop counter */
210
        col--;
211
      }
212
 
213
      /* Perform matrix transpose for last 3 samples here. */
214
      col = nColumns % 0x4U;
215
 
216
#else
217
 
218
  /* Run the below code for Cortex-M0 */
219
 
220
#ifdef ARM_MATH_MATRIX_CHECK
221
 
222
  /* Check for matrix mismatch condition */
223
  if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
224
  {
225
    /* Set status as ARM_MATH_SIZE_MISMATCH */
226
    status = ARM_MATH_SIZE_MISMATCH;
227
  }
228
  else
229
#endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
230
 
231
  {
232
    /* Matrix transpose by exchanging the rows with columns */
233
    /* row loop     */
234
    do
235
    {
236
      /* The pointer pOut is set to starting address of the column being processed */
237
      pOut = pDst->pData + i;
238
 
239
      /* Initialize column loop counter */
240
      col = nColumns;
241
 
242
#endif /* #if defined (ARM_MATH_DSP) */
243
 
244
      while (col > 0U)
245
      {
246
        /* Read and store the input element in the destination */
247
        *pOut = *pSrcA++;
248
 
249
        /* Update the pointer pOut to point to the next row of the transposed matrix */
250
        pOut += nRows;
251
 
252
        /* Decrement the column loop counter */
253
        col--;
254
      }
255
 
256
      i++;
257
 
258
      /* Decrement the row loop counter */
259
      row--;
260
 
261
    } while (row > 0U);
262
 
263
    /* set status as ARM_MATH_SUCCESS */
264
    status = ARM_MATH_SUCCESS;
265
  }
266
  /* Return to application */
267
  return (status);
268
}
269
 
270
/**
271
 * @} end of MatrixTrans group
272
 */