00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. July 2011 00005 * $Revision: V1.0.10 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_mat_trans_q31.c 00009 * 00010 * Description: Q31 matrix transpose. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 00013 * 00014 * Version 1.0.10 2011/7/15 00015 * Big Endian support added and Merged M0 and M3/M4 Source code. 00016 * 00017 * Version 1.0.3 2010/11/29 00018 * Re-organized the CMSIS folders and updated documentation. 00019 * 00020 * Version 1.0.2 2010/11/11 00021 * Documentation updated. 00022 * 00023 * Version 1.0.1 2010/10/05 00024 * Production release and review comments incorporated. 00025 * 00026 * Version 1.0.0 2010/09/20 00027 * Production release and review comments incorporated. 00028 * 00029 * Version 0.0.5 2010/04/26 00030 * incorporated review comments and updated with latest CMSIS layer 00031 * 00032 * Version 0.0.3 2010/03/10 00033 * Initial version 00034 * -------------------------------------------------------------------- */ 00035 00036 #include "arm_math.h" 00037 00047 /* 00048 * @brief Q31 matrix transpose. 00049 * @param[in] *pSrc points to the input matrix 00050 * @param[out] *pDst points to the output matrix 00051 * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> 00052 * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00053 */ 00054 00055 arm_status arm_mat_trans_q31( 00056 const arm_matrix_instance_q31 * pSrc, 00057 arm_matrix_instance_q31 * pDst) 00058 { 00059 q31_t *pIn = pSrc->pData; /* input data matrix pointer */ 00060 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00061 q31_t *px; /* Temporary output data matrix pointer */ 00062 uint16_t nRows = pSrc->numRows; /* number of nRows */ 00063 uint16_t nColumns = pSrc->numCols; /* number of nColumns */ 00064 00065 #ifndef ARM_MATH_CM0 00066 00067 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00068 00069 uint16_t blkCnt, i = 0u, row = nRows; /* loop counters */ 00070 arm_status status; /* status of matrix transpose */ 00071 00072 00073 #ifdef ARM_MATH_MATRIX_CHECK 00074 00075 00076 /* Check for matrix mismatch condition */ 00077 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 00078 { 00079 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00080 status = ARM_MATH_SIZE_MISMATCH; 00081 } 00082 else 00083 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ 00084 00085 { 00086 /* Matrix transpose by exchanging the rows with columns */ 00087 /* row loop */ 00088 do 00089 { 00090 /* Apply loop unrolling and exchange the columns with row elements */ 00091 blkCnt = nColumns >> 2u; 00092 00093 /* The pointer px is set to starting address of the column being processed */ 00094 px = pOut + i; 00095 00096 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00097 ** a second loop below computes the remaining 1 to 3 samples. */ 00098 while(blkCnt > 0u) 00099 { 00100 /* Read and store the input element in the destination */ 00101 *px = *pIn++; 00102 00103 /* Update the pointer px to point to the next row of the transposed matrix */ 00104 px += nRows; 00105 00106 /* Read and store the input element in the destination */ 00107 *px = *pIn++; 00108 00109 /* Update the pointer px to point to the next row of the transposed matrix */ 00110 px += nRows; 00111 00112 /* Read and store the input element in the destination */ 00113 *px = *pIn++; 00114 00115 /* Update the pointer px to point to the next row of the transposed matrix */ 00116 px += nRows; 00117 00118 /* Read and store the input element in the destination */ 00119 *px = *pIn++; 00120 00121 /* Update the pointer px to point to the next row of the transposed matrix */ 00122 px += nRows; 00123 00124 /* Decrement the column loop counter */ 00125 blkCnt--; 00126 } 00127 00128 /* Perform matrix transpose for last 3 samples here. */ 00129 blkCnt = nColumns % 0x4u; 00130 00131 while(blkCnt > 0u) 00132 { 00133 /* Read and store the input element in the destination */ 00134 *px = *pIn++; 00135 00136 /* Update the pointer px to point to the next row of the transposed matrix */ 00137 px += nRows; 00138 00139 /* Decrement the column loop counter */ 00140 blkCnt--; 00141 } 00142 00143 #else 00144 00145 /* Run the below code for Cortex-M0 */ 00146 00147 uint16_t col, i = 0u, row = nRows; /* loop counters */ 00148 arm_status status; /* status of matrix transpose */ 00149 00150 00151 #ifdef ARM_MATH_MATRIX_CHECK 00152 00153 /* Check for matrix mismatch condition */ 00154 if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 00155 { 00156 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00157 status = ARM_MATH_SIZE_MISMATCH; 00158 } 00159 else 00160 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ 00161 00162 { 00163 /* Matrix transpose by exchanging the rows with columns */ 00164 /* row loop */ 00165 do 00166 { 00167 /* The pointer px is set to starting address of the column being processed */ 00168 px = pOut + i; 00169 00170 /* Initialize column loop counter */ 00171 col = nColumns; 00172 00173 while(col > 0u) 00174 { 00175 /* Read and store the input element in the destination */ 00176 *px = *pIn++; 00177 00178 /* Update the pointer px to point to the next row of the transposed matrix */ 00179 px += nRows; 00180 00181 /* Decrement the column loop counter */ 00182 col--; 00183 } 00184 00185 #endif /* #ifndef ARM_MATH_CM0 */ 00186 00187 i++; 00188 00189 /* Decrement the row loop counter */ 00190 row--; 00191 00192 } 00193 while(row > 0u); /* row loop end */ 00194 00195 /* set status as ARM_MATH_SUCCESS */ 00196 status = ARM_MATH_SUCCESS; 00197 } 00198 00199 /* Return to application */ 00200 return (status); 00201 } 00202