00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R DSP Library 00008 * Title: arm_mat_trans_q31.c 00009 * 00010 * Description: Q31 matrix transpose. 00011 * 00012 * Target Processor: Cortex-R4/R5 00013 * 00014 * Version 1.0.0 2011/03/08 00015 * Alpha release. 00016 * 00017 * Version 1.0.1 2011/09/30 00018 * Beta release. 00019 * 00020 * Version 2.0.0 2011/12/15 00021 * Final release. 00022 * 00023 * -------------------------------------------------------------------- */ 00024 00025 #include "arm_math.h" 00026 00036 /* 00037 * @brief Q31 matrix transpose. 00038 * @param[in] *pSrc points to the input matrix 00039 * @param[out] *pDst points to the output matrix 00040 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> 00041 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00042 */ 00043 00044 arm_status arm_mat_trans_q31( 00045 const arm_matrix_instance_q31 * pSrc, 00046 arm_matrix_instance_q31 * pDst) 00047 { 00048 q31_t *pIn = pSrc->pData; /* input data matrix pointer */ 00049 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00050 q31_t *px; /* Temporary output data matrix pointer */ 00051 uint16_t nRows = pSrc->numRows; /* number of nRows */ 00052 uint16_t nColumns = pSrc->numCols; /* number of nColumns */ 00053 uint16_t blkCnt, i = 0u, row = nRows; /* loop counters */ 00054 arm_status status; /* status of matrix transpose */ 00055 q31_t in1, in2, in3, in4; 00056 00057 #ifdef ARM_MATH_MATRIX_CHECK 00058 /* Check for matrix mismatch condition */ 00059 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 00060 { 00061 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00062 status = ARM_MATH_SIZE_MISMATCH; 00063 } 00064 else 00065 #endif 00066 { 00067 /* Matrix transpose by exchanging the rows with columns */ 00068 /* row loop */ 00069 do 00070 { 00071 /* Apply loop unrolling and exchange the columns with row elements */ 00072 blkCnt = nColumns >> 3u; 00073 00074 /* The pointer px is set to starting address of the column being processed */ 00075 px = pOut + i; 00076 00077 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00078 ** a second loop below computes the remaining 1 to 3 samples. */ 00079 while(blkCnt > 0u) 00080 { 00081 /* Read and store the input element in the destination */ 00082 in1 = pIn[0]; 00083 *px = in1; 00084 00085 /* Update the pointer px to point to the next row of the transposed matrix */ 00086 px += nRows; 00087 00088 /* Read and store the input element in the destination */ 00089 in2 = pIn[1]; 00090 *px = in2; 00091 00092 /* Update the pointer px to point to the next row of the transposed matrix */ 00093 px += nRows; 00094 00095 /* Read and store the input element in the destination */ 00096 in3 = pIn[2]; 00097 *px = in3; 00098 00099 /* Update the pointer px to point to the next row of the transposed matrix */ 00100 px += nRows; 00101 00102 /* Read and store the input element in the destination */ 00103 in4 = pIn[3]; 00104 *px = in4; 00105 00106 /* Update the pointer px to point to the next row of the transposed matrix */ 00107 px += nRows; 00108 00109 /* Read and store the input element in the destination */ 00110 in1 = pIn[4]; 00111 *px = in1; 00112 00113 /* Update the pointer px to point to the next row of the transposed matrix */ 00114 px += nRows; 00115 00116 /* Read and store the input element in the destination */ 00117 in2 = pIn[5]; 00118 *px = in2; 00119 00120 /* Update the pointer px to point to the next row of the transposed matrix */ 00121 px += nRows; 00122 00123 /* Read and store the input element in the destination */ 00124 in3 = pIn[6]; 00125 *px = in3; 00126 00127 /* Update the pointer px to point to the next row of the transposed matrix */ 00128 px += nRows; 00129 00130 /* Read and store the input element in the destination */ 00131 in4 = pIn[7]; 00132 *px = in4; 00133 00134 /* Update the pointer px to point to the next row of the transposed matrix */ 00135 px += nRows; 00136 00137 /* Update the pointer pIn to point to the next column of the matrix */ 00138 pIn += 8u; 00139 00140 /* Decrement the column loop counter */ 00141 blkCnt--; 00142 } 00143 00144 /* Perform matrix transpose for last 3 samples here. */ 00145 blkCnt = nColumns % 0x8u; 00146 00147 while(blkCnt > 0u) 00148 { 00149 /* Read and store the input element in the destination */ 00150 *px = *pIn++; 00151 00152 /* Update the pointer px to point to the next row of the transposed matrix */ 00153 px += nRows; 00154 00155 /* Decrement the column loop counter */ 00156 blkCnt--; 00157 } 00158 00159 i++; 00160 00161 /* Decrement the row loop counter */ 00162 row--; 00163 00164 } 00165 while(row > 0u); /* row loop end */ 00166 00167 /* set status as ARM_MATH_SUCCESS */ 00168 status = ARM_MATH_SUCCESS; 00169 } 00170 00171 /* Return to application */ 00172 return (status); 00173 } 00174