arm_mat_trans_q31.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
  3. *
  4. * $Date: 31. July 2014
  5. * $Revision: V1.4.4
  6. *
  7. * Project: CMSIS DSP Library
  8. * Title: arm_mat_trans_q31.c
  9. *
  10. * Description: Q31 matrix transpose.
  11. *
  12. * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. * - Neither the name of ARM LIMITED nor the names of its contributors
  24. * may be used to endorse or promote products derived from this
  25. * software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  30. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  31. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  32. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  33. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  35. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. * -------------------------------------------------------------------- */
  40. #include "arm_math.h"
  41. /**
  42. * @ingroup groupMatrix
  43. */
  44. /**
  45. * @addtogroup MatrixTrans
  46. * @{
  47. */
  48. /*
  49. * @brief Q31 matrix transpose.
  50. * @param[in] *pSrc points to the input matrix
  51. * @param[out] *pDst points to the output matrix
  52. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  53. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  54. */
  55. arm_status arm_mat_trans_q31(
  56. const arm_matrix_instance_q31 * pSrc,
  57. arm_matrix_instance_q31 * pDst)
  58. {
  59. q31_t *pIn = pSrc->pData; /* input data matrix pointer */
  60. q31_t *pOut = pDst->pData; /* output data matrix pointer */
  61. q31_t *px; /* Temporary output data matrix pointer */
  62. uint16_t nRows = pSrc->numRows; /* number of nRows */
  63. uint16_t nColumns = pSrc->numCols; /* number of nColumns */
  64. #ifndef ARM_MATH_CM0_FAMILY
  65. /* Run the below code for Cortex-M4 and Cortex-M3 */
  66. uint16_t blkCnt, i = 0u, row = nRows; /* loop counters */
  67. arm_status status; /* status of matrix transpose */
  68. #ifdef ARM_MATH_MATRIX_CHECK
  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. /* Matrix transpose by exchanging the rows with columns */
  79. /* row loop */
  80. do
  81. {
  82. /* Apply loop unrolling and exchange the columns with row elements */
  83. blkCnt = nColumns >> 2u;
  84. /* The pointer px is set to starting address of the column being processed */
  85. px = pOut + i;
  86. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  87. ** a second loop below computes the remaining 1 to 3 samples. */
  88. while(blkCnt > 0u)
  89. {
  90. /* Read and store the input element in the destination */
  91. *px = *pIn++;
  92. /* Update the pointer px to point to the next row of the transposed matrix */
  93. px += nRows;
  94. /* Read and store the input element in the destination */
  95. *px = *pIn++;
  96. /* Update the pointer px to point to the next row of the transposed matrix */
  97. px += nRows;
  98. /* Read and store the input element in the destination */
  99. *px = *pIn++;
  100. /* Update the pointer px to point to the next row of the transposed matrix */
  101. px += nRows;
  102. /* Read and store the input element in the destination */
  103. *px = *pIn++;
  104. /* Update the pointer px to point to the next row of the transposed matrix */
  105. px += nRows;
  106. /* Decrement the column loop counter */
  107. blkCnt--;
  108. }
  109. /* Perform matrix transpose for last 3 samples here. */
  110. blkCnt = nColumns % 0x4u;
  111. while(blkCnt > 0u)
  112. {
  113. /* Read and store the input element in the destination */
  114. *px = *pIn++;
  115. /* Update the pointer px to point to the next row of the transposed matrix */
  116. px += nRows;
  117. /* Decrement the column loop counter */
  118. blkCnt--;
  119. }
  120. #else
  121. /* Run the below code for Cortex-M0 */
  122. uint16_t col, i = 0u, row = nRows; /* loop counters */
  123. arm_status status; /* status of matrix transpose */
  124. #ifdef ARM_MATH_MATRIX_CHECK
  125. /* Check for matrix mismatch condition */
  126. if((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  127. {
  128. /* Set status as ARM_MATH_SIZE_MISMATCH */
  129. status = ARM_MATH_SIZE_MISMATCH;
  130. }
  131. else
  132. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  133. {
  134. /* Matrix transpose by exchanging the rows with columns */
  135. /* row loop */
  136. do
  137. {
  138. /* The pointer px is set to starting address of the column being processed */
  139. px = pOut + i;
  140. /* Initialize column loop counter */
  141. col = nColumns;
  142. while(col > 0u)
  143. {
  144. /* Read and store the input element in the destination */
  145. *px = *pIn++;
  146. /* Update the pointer px to point to the next row of the transposed matrix */
  147. px += nRows;
  148. /* Decrement the column loop counter */
  149. col--;
  150. }
  151. #endif /* #ifndef ARM_MATH_CM0_FAMILY */
  152. i++;
  153. /* Decrement the row loop counter */
  154. row--;
  155. }
  156. while(row > 0u); /* row loop end */
  157. /* set status as ARM_MATH_SUCCESS */
  158. status = ARM_MATH_SUCCESS;
  159. }
  160. /* Return to application */
  161. return (status);
  162. }
  163. /**
  164. * @} end of MatrixTrans group
  165. */