Subversion Repositories testOled

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_q31.c
4
 * Description:  Q31 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 Q31 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_q31(
49
  const arm_matrix_instance_q31 * pSrc,
50
  arm_matrix_instance_q31 * pDst)
51
{
52
  q31_t *pIn = pSrc->pData;                      /* input data matrix pointer  */
53
  q31_t *pOut = pDst->pData;                     /* output data matrix pointer  */
54
  q31_t *px;                                     /* Temporary output data matrix pointer */
55
  uint16_t nRows = pSrc->numRows;                /* number of nRows */
56
  uint16_t nColumns = pSrc->numCols;             /* number of nColumns  */
57
 
58
#if defined (ARM_MATH_DSP)
59
 
60
  /* Run the below code for Cortex-M4 and Cortex-M3 */
61
 
62
  uint16_t blkCnt, i = 0U, row = nRows;          /* loop counters */
63
  arm_status status;                             /* status of matrix transpose */
64
 
65
 
66
#ifdef ARM_MATH_MATRIX_CHECK
67
 
68
 
69
  /* Check for matrix mismatch condition */
70
  if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
71
  {
72
    /* Set status as ARM_MATH_SIZE_MISMATCH */
73
    status = ARM_MATH_SIZE_MISMATCH;
74
  }
75
  else
76
#endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
77
 
78
  {
79
    /* Matrix transpose by exchanging the rows with columns */
80
    /* row loop     */
81
    do
82
    {
83
      /* Apply loop unrolling and exchange the columns with row elements */
84
      blkCnt = nColumns >> 2U;
85
 
86
      /* The pointer px is set to starting address of the column being processed */
87
      px = pOut + i;
88
 
89
      /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
90
       ** a second loop below computes the remaining 1 to 3 samples. */
91
      while (blkCnt > 0U)
92
      {
93
        /* Read and store the input element in the destination */
94
        *px = *pIn++;
95
 
96
        /* Update the pointer px to point to the next row of the transposed matrix */
97
        px += nRows;
98
 
99
        /* Read and store the input element in the destination */
100
        *px = *pIn++;
101
 
102
        /* Update the pointer px to point to the next row of the transposed matrix */
103
        px += nRows;
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
        /* Decrement the column loop counter */
118
        blkCnt--;
119
      }
120
 
121
      /* Perform matrix transpose for last 3 samples here. */
122
      blkCnt = nColumns % 0x4U;
123
 
124
      while (blkCnt > 0U)
125
      {
126
        /* Read and store the input element in the destination */
127
        *px = *pIn++;
128
 
129
        /* Update the pointer px to point to the next row of the transposed matrix */
130
        px += nRows;
131
 
132
        /* Decrement the column loop counter */
133
        blkCnt--;
134
      }
135
 
136
#else
137
 
138
  /* Run the below code for Cortex-M0 */
139
 
140
  uint16_t col, i = 0U, row = nRows;             /* loop counters */
141
  arm_status status;                             /* status of matrix transpose */
142
 
143
 
144
#ifdef ARM_MATH_MATRIX_CHECK
145
 
146
  /* Check for matrix mismatch condition */
147
  if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
148
  {
149
    /* Set status as ARM_MATH_SIZE_MISMATCH */
150
    status = ARM_MATH_SIZE_MISMATCH;
151
  }
152
  else
153
#endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
154
 
155
  {
156
    /* Matrix transpose by exchanging the rows with columns */
157
    /* row loop     */
158
    do
159
    {
160
      /* The pointer px is set to starting address of the column being processed */
161
      px = pOut + i;
162
 
163
      /* Initialize column loop counter */
164
      col = nColumns;
165
 
166
      while (col > 0U)
167
      {
168
        /* Read and store the input element in the destination */
169
        *px = *pIn++;
170
 
171
        /* Update the pointer px to point to the next row of the transposed matrix */
172
        px += nRows;
173
 
174
        /* Decrement the column loop counter */
175
        col--;
176
      }
177
 
178
#endif /* #if defined (ARM_MATH_DSP) */
179
 
180
      i++;
181
 
182
      /* Decrement the row loop counter */
183
      row--;
184
 
185
    }
186
    while (row > 0U);            /* row loop end */
187
 
188
    /* set status as ARM_MATH_SUCCESS */
189
    status = ARM_MATH_SUCCESS;
190
  }
191
 
192
  /* Return to application */
193
  return (status);
194
}
195
 
196
/**
197
 * @} end of MatrixTrans group
198
 */