1 /* ======================================================================= */
2 /* DSP_mat_trans_cn.c -- Matrix Transpose */
3 /* Natural C Implementation */
4 /* */
5 /* Rev 0.0.1 */
6 /* */
7 /* Usage */
8 /* This routine is C-callable and can be called as: */
9 /* */
10 /* void DSP_mat_trans_cn ( */
11 /* const short *restrict x, // Input matrix */
12 /* short rows, // Height of input matrix */
13 /* short columns, // Width of input matrix */
14 /* short *restrict r // Output matrix */
15 /* ); */
16 /* */
17 /* Description */
18 /* The program transposes a matrix of 16-bit values and user- */
19 /* determined dimensions. The result of a matrix transpose is a */
20 /* matrix with the number of rows = number of columns of input matrix */
21 /* and number of columns = number of rows of input matrix The value */
22 /* of an elements of the output matrix is equal to the value of the */
23 /* element from the input matrix with switched coordinates (rows, */
24 /* columns). */
25 /* */
26 /* Assumptions */
27 /* Arrays x and r do not overlap */
28 /* */
29 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ */
30 /* */
31 /* */
32 /* Redistribution and use in source and binary forms, with or without */
33 /* modification, are permitted provided that the following conditions */
34 /* are met: */
35 /* */
36 /* Redistributions of source code must retain the above copyright */
37 /* notice, this list of conditions and the following disclaimer. */
38 /* */
39 /* Redistributions in binary form must reproduce the above copyright */
40 /* notice, this list of conditions and the following disclaimer in the */
41 /* documentation and/or other materials provided with the */
42 /* distribution. */
43 /* */
44 /* Neither the name of Texas Instruments Incorporated nor the names of */
45 /* its contributors may be used to endorse or promote products derived */
46 /* from this software without specific prior written permission. */
47 /* */
48 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
49 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
50 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
51 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
52 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
53 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
54 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
55 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
56 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
57 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
58 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
59 /* */
60 /* ======================================================================= */
62 #pragma CODE_SECTION(DSP_mat_trans_cn, ".text:ansi");
64 #include "DSP_mat_trans_cn.h"
66 void DSP_mat_trans_cn (
67 const short *restrict x, /* Input matrix */
68 short rows, /* Height of input matrix */
69 short columns, /* Width of input matrix */
70 short *restrict r /* Output matrix */
71 )
72 {
73 int i, j;
75 #ifdef NOASSUME
76 _nassert(columns % 4 == 0);
77 _nassert(rows % 4 == 0);
78 _nassert((int)(x) % 8 == 0);
79 _nassert((int)(r) % 8 == 0);
80 _nassert(columns >= 8);
81 _nassert(rows >= 8);
82 #endif
84 /* ------------------------------------------------------------------- */
85 /* Write each column of 'x' to a row of 'r'. */
86 /* ------------------------------------------------------------------- */
87 for (i = 0; i < columns; i++) {
88 for (j = 0; j < rows; j++) {
89 r[(i * rows) + j] = x[i + (columns * j)];
90 }
91 }
92 }
94 /* ======================================================================= */
95 /* End of file: DSP_mat_trans_cn.c */
96 /* ----------------------------------------------------------------------- */
97 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
98 /* All Rights Reserved. */
99 /* ======================================================================= */