CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details
Dependents: K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more
src/Cortex-M4-M3/MatrixFunctions/arm_mat_trans_q15.c@0:1014af42efd9, 2011-03-10 (annotated)
- Committer:
- simon
- Date:
- Thu Mar 10 15:07:50 2011 +0000
- Revision:
- 0:1014af42efd9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:1014af42efd9 | 1 | /* ---------------------------------------------------------------------- |
simon | 0:1014af42efd9 | 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. |
simon | 0:1014af42efd9 | 3 | * |
simon | 0:1014af42efd9 | 4 | * $Date: 29. November 2010 |
simon | 0:1014af42efd9 | 5 | * $Revision: V1.0.3 |
simon | 0:1014af42efd9 | 6 | * |
simon | 0:1014af42efd9 | 7 | * Project: CMSIS DSP Library |
simon | 0:1014af42efd9 | 8 | * Title: arm_mat_trans_q15.c |
simon | 0:1014af42efd9 | 9 | * |
simon | 0:1014af42efd9 | 10 | * Description: Q15 matrix transpose. |
simon | 0:1014af42efd9 | 11 | * |
simon | 0:1014af42efd9 | 12 | * Target Processor: Cortex-M4/Cortex-M3 |
simon | 0:1014af42efd9 | 13 | * |
simon | 0:1014af42efd9 | 14 | * Version 1.0.3 2010/11/29 |
simon | 0:1014af42efd9 | 15 | * Re-organized the CMSIS folders and updated documentation. |
simon | 0:1014af42efd9 | 16 | * |
simon | 0:1014af42efd9 | 17 | * Version 1.0.2 2010/11/11 |
simon | 0:1014af42efd9 | 18 | * Documentation updated. |
simon | 0:1014af42efd9 | 19 | * |
simon | 0:1014af42efd9 | 20 | * Version 1.0.1 2010/10/05 |
simon | 0:1014af42efd9 | 21 | * Production release and review comments incorporated. |
simon | 0:1014af42efd9 | 22 | * |
simon | 0:1014af42efd9 | 23 | * Version 1.0.0 2010/09/20 |
simon | 0:1014af42efd9 | 24 | * Production release and review comments incorporated. |
simon | 0:1014af42efd9 | 25 | * |
simon | 0:1014af42efd9 | 26 | * Version 0.0.5 2010/04/26 |
simon | 0:1014af42efd9 | 27 | * incorporated review comments and updated with latest CMSIS layer |
simon | 0:1014af42efd9 | 28 | * |
simon | 0:1014af42efd9 | 29 | * Version 0.0.3 2010/03/10 |
simon | 0:1014af42efd9 | 30 | * Initial version |
simon | 0:1014af42efd9 | 31 | * -------------------------------------------------------------------- */ |
simon | 0:1014af42efd9 | 32 | |
simon | 0:1014af42efd9 | 33 | #include "arm_math.h" |
simon | 0:1014af42efd9 | 34 | |
simon | 0:1014af42efd9 | 35 | /** |
simon | 0:1014af42efd9 | 36 | * @ingroup groupMatrix |
simon | 0:1014af42efd9 | 37 | */ |
simon | 0:1014af42efd9 | 38 | |
simon | 0:1014af42efd9 | 39 | /** |
simon | 0:1014af42efd9 | 40 | * @addtogroup MatrixTrans |
simon | 0:1014af42efd9 | 41 | * @{ |
simon | 0:1014af42efd9 | 42 | */ |
simon | 0:1014af42efd9 | 43 | |
simon | 0:1014af42efd9 | 44 | /* |
simon | 0:1014af42efd9 | 45 | * @brief Q15 matrix transpose. |
simon | 0:1014af42efd9 | 46 | * @param[in] *pSrc points to the input matrix |
simon | 0:1014af42efd9 | 47 | * @param[out] *pDst points to the output matrix |
simon | 0:1014af42efd9 | 48 | * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> |
simon | 0:1014af42efd9 | 49 | * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. |
simon | 0:1014af42efd9 | 50 | */ |
simon | 0:1014af42efd9 | 51 | |
simon | 0:1014af42efd9 | 52 | arm_status arm_mat_trans_q15( |
simon | 0:1014af42efd9 | 53 | const arm_matrix_instance_q15 * pSrc, |
simon | 0:1014af42efd9 | 54 | arm_matrix_instance_q15 * pDst) |
simon | 0:1014af42efd9 | 55 | { |
simon | 0:1014af42efd9 | 56 | q15_t *pSrcA = pSrc->pData; /* input data matrix pointer */ |
simon | 0:1014af42efd9 | 57 | q15_t *pOut = pDst->pData; /* output data matrix pointer */ |
simon | 0:1014af42efd9 | 58 | // q15_t *pDst = pDst->pData; /* output data matrix pointer */ |
simon | 0:1014af42efd9 | 59 | uint16_t nRows = pSrc->numRows; /* number of nRows */ |
simon | 0:1014af42efd9 | 60 | uint16_t nColumns = pSrc->numCols; /* number of nColumns */ |
simon | 0:1014af42efd9 | 61 | uint16_t col, row = nRows, i = 0u; /* row and column loop counters */ |
simon | 0:1014af42efd9 | 62 | q31_t in; /* variable to hold temporary output */ |
simon | 0:1014af42efd9 | 63 | arm_status status; /* status of matrix transpose */ |
simon | 0:1014af42efd9 | 64 | |
simon | 0:1014af42efd9 | 65 | |
simon | 0:1014af42efd9 | 66 | #ifdef ARM_MATH_MATRIX_CHECK |
simon | 0:1014af42efd9 | 67 | /* Check for matrix mismatch condition */ |
simon | 0:1014af42efd9 | 68 | if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) |
simon | 0:1014af42efd9 | 69 | { |
simon | 0:1014af42efd9 | 70 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
simon | 0:1014af42efd9 | 71 | status = ARM_MATH_SIZE_MISMATCH; |
simon | 0:1014af42efd9 | 72 | } |
simon | 0:1014af42efd9 | 73 | else |
simon | 0:1014af42efd9 | 74 | #endif |
simon | 0:1014af42efd9 | 75 | { |
simon | 0:1014af42efd9 | 76 | /* Matrix transpose by exchanging the rows with columns */ |
simon | 0:1014af42efd9 | 77 | /* row loop */ |
simon | 0:1014af42efd9 | 78 | do |
simon | 0:1014af42efd9 | 79 | { |
simon | 0:1014af42efd9 | 80 | /* Apply loop unrolling and exchange the columns with row elements */ |
simon | 0:1014af42efd9 | 81 | col = nColumns >> 2u; |
simon | 0:1014af42efd9 | 82 | |
simon | 0:1014af42efd9 | 83 | /* The pointer pOut is set to starting address of the column being processed */ |
simon | 0:1014af42efd9 | 84 | pOut = pDst->pData + i; |
simon | 0:1014af42efd9 | 85 | |
simon | 0:1014af42efd9 | 86 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
simon | 0:1014af42efd9 | 87 | ** a second loop below computes the remaining 1 to 3 samples. */ |
simon | 0:1014af42efd9 | 88 | while(col > 0u) |
simon | 0:1014af42efd9 | 89 | { |
simon | 0:1014af42efd9 | 90 | /* Read two elements from the row */ |
simon | 0:1014af42efd9 | 91 | in = *__SIMD32(pSrcA)++; |
simon | 0:1014af42efd9 | 92 | |
simon | 0:1014af42efd9 | 93 | /* Unpack and store one element in the destination */ |
simon | 0:1014af42efd9 | 94 | *pOut = (q15_t) in; |
simon | 0:1014af42efd9 | 95 | |
simon | 0:1014af42efd9 | 96 | /* Update the pointer pOut to point to the next row of the transposed matrix */ |
simon | 0:1014af42efd9 | 97 | pOut += nRows; |
simon | 0:1014af42efd9 | 98 | |
simon | 0:1014af42efd9 | 99 | /* Unpack and store the second element in the destination */ |
simon | 0:1014af42efd9 | 100 | *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16); |
simon | 0:1014af42efd9 | 101 | |
simon | 0:1014af42efd9 | 102 | /* Update the pointer pOut to point to the next row of the transposed matrix */ |
simon | 0:1014af42efd9 | 103 | pOut += nRows; |
simon | 0:1014af42efd9 | 104 | |
simon | 0:1014af42efd9 | 105 | /* Read two elements from the row */ |
simon | 0:1014af42efd9 | 106 | in = *__SIMD32(pSrcA)++; |
simon | 0:1014af42efd9 | 107 | |
simon | 0:1014af42efd9 | 108 | /* Unpack and store one element in the destination */ |
simon | 0:1014af42efd9 | 109 | *pOut = (q15_t) in; |
simon | 0:1014af42efd9 | 110 | |
simon | 0:1014af42efd9 | 111 | /* Update the pointer pOut to point to the next row of the transposed matrix */ |
simon | 0:1014af42efd9 | 112 | pOut += nRows; |
simon | 0:1014af42efd9 | 113 | |
simon | 0:1014af42efd9 | 114 | /* Unpack and store the second element in the destination */ |
simon | 0:1014af42efd9 | 115 | *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16); |
simon | 0:1014af42efd9 | 116 | |
simon | 0:1014af42efd9 | 117 | /* Update the pointer pOut to point to the next row of the transposed matrix */ |
simon | 0:1014af42efd9 | 118 | pOut += nRows; |
simon | 0:1014af42efd9 | 119 | |
simon | 0:1014af42efd9 | 120 | /* Decrement the column loop counter */ |
simon | 0:1014af42efd9 | 121 | col--; |
simon | 0:1014af42efd9 | 122 | } |
simon | 0:1014af42efd9 | 123 | |
simon | 0:1014af42efd9 | 124 | /* Perform matrix transpose for last 3 samples here. */ |
simon | 0:1014af42efd9 | 125 | col = nColumns % 0x4u; |
simon | 0:1014af42efd9 | 126 | |
simon | 0:1014af42efd9 | 127 | while(col > 0u) |
simon | 0:1014af42efd9 | 128 | { |
simon | 0:1014af42efd9 | 129 | /* Read and store the input element in the destination */ |
simon | 0:1014af42efd9 | 130 | *pOut = *pSrcA++; |
simon | 0:1014af42efd9 | 131 | |
simon | 0:1014af42efd9 | 132 | /* Update the pointer pOut to point to the next row of the transposed matrix */ |
simon | 0:1014af42efd9 | 133 | pOut += nRows; |
simon | 0:1014af42efd9 | 134 | |
simon | 0:1014af42efd9 | 135 | /* Decrement the column loop counter */ |
simon | 0:1014af42efd9 | 136 | col--; |
simon | 0:1014af42efd9 | 137 | } |
simon | 0:1014af42efd9 | 138 | |
simon | 0:1014af42efd9 | 139 | i++; |
simon | 0:1014af42efd9 | 140 | |
simon | 0:1014af42efd9 | 141 | /* Decrement the row loop counter */ |
simon | 0:1014af42efd9 | 142 | row--; |
simon | 0:1014af42efd9 | 143 | |
simon | 0:1014af42efd9 | 144 | } while(row > 0u); |
simon | 0:1014af42efd9 | 145 | |
simon | 0:1014af42efd9 | 146 | /* set status as ARM_MATH_SUCCESS */ |
simon | 0:1014af42efd9 | 147 | status = ARM_MATH_SUCCESS; |
simon | 0:1014af42efd9 | 148 | } |
simon | 0:1014af42efd9 | 149 | /* Return to application */ |
simon | 0:1014af42efd9 | 150 | return (status); |
simon | 0:1014af42efd9 | 151 | } |
simon | 0:1014af42efd9 | 152 | |
simon | 0:1014af42efd9 | 153 | /** |
simon | 0:1014af42efd9 | 154 | * @} end of MatrixTrans group |
simon | 0:1014af42efd9 | 155 | */ |