arm_mat_trans_q31.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_q31.c
  4. * Description: Q31 matrix transpose
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "arm_math.h"
  29. /**
  30. * @ingroup groupMatrix
  31. */
  32. /**
  33. * @addtogroup MatrixTrans
  34. * @{
  35. */
  36. /*
  37. * @brief Q31 matrix transpose.
  38. * @param[in] *pSrc points to the input matrix
  39. * @param[out] *pDst points to the output matrix
  40. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  41. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  42. */
  43. arm_status arm_mat_trans_q31(
  44. const arm_matrix_instance_q31 * pSrc,
  45. arm_matrix_instance_q31 * pDst)
  46. {
  47. q31_t *pIn = pSrc->pData; /* input data matrix pointer */
  48. q31_t *pOut = pDst->pData; /* output data matrix pointer */
  49. q31_t *px; /* Temporary output data matrix pointer */
  50. uint16_t nRows = pSrc->numRows; /* number of nRows */
  51. uint16_t nColumns = pSrc->numCols; /* number of nColumns */
  52. #if defined (ARM_MATH_DSP)
  53. /* Run the below code for Cortex-M4 and Cortex-M3 */
  54. uint16_t blkCnt, i = 0U, row = nRows; /* loop counters */
  55. arm_status status; /* status of matrix transpose */
  56. #ifdef ARM_MATH_MATRIX_CHECK
  57. /* Check for matrix mismatch condition */
  58. if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  59. {
  60. /* Set status as ARM_MATH_SIZE_MISMATCH */
  61. status = ARM_MATH_SIZE_MISMATCH;
  62. }
  63. else
  64. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  65. {
  66. /* Matrix transpose by exchanging the rows with columns */
  67. /* row loop */
  68. do
  69. {
  70. /* Apply loop unrolling and exchange the columns with row elements */
  71. blkCnt = nColumns >> 2U;
  72. /* The pointer px is set to starting address of the column being processed */
  73. px = pOut + i;
  74. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  75. ** a second loop below computes the remaining 1 to 3 samples. */
  76. while (blkCnt > 0U)
  77. {
  78. /* Read and store the input element in the destination */
  79. *px = *pIn++;
  80. /* Update the pointer px to point to the next row of the transposed matrix */
  81. px += nRows;
  82. /* Read and store the input element in the destination */
  83. *px = *pIn++;
  84. /* Update the pointer px to point to the next row of the transposed matrix */
  85. px += nRows;
  86. /* Read and store the input element in the destination */
  87. *px = *pIn++;
  88. /* Update the pointer px to point to the next row of the transposed matrix */
  89. px += nRows;
  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. /* Decrement the column loop counter */
  95. blkCnt--;
  96. }
  97. /* Perform matrix transpose for last 3 samples here. */
  98. blkCnt = nColumns % 0x4U;
  99. while (blkCnt > 0U)
  100. {
  101. /* Read and store the input element in the destination */
  102. *px = *pIn++;
  103. /* Update the pointer px to point to the next row of the transposed matrix */
  104. px += nRows;
  105. /* Decrement the column loop counter */
  106. blkCnt--;
  107. }
  108. #else
  109. /* Run the below code for Cortex-M0 */
  110. uint16_t col, i = 0U, row = nRows; /* loop counters */
  111. arm_status status; /* status of matrix transpose */
  112. #ifdef ARM_MATH_MATRIX_CHECK
  113. /* Check for matrix mismatch condition */
  114. if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  115. {
  116. /* Set status as ARM_MATH_SIZE_MISMATCH */
  117. status = ARM_MATH_SIZE_MISMATCH;
  118. }
  119. else
  120. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  121. {
  122. /* Matrix transpose by exchanging the rows with columns */
  123. /* row loop */
  124. do
  125. {
  126. /* The pointer px is set to starting address of the column being processed */
  127. px = pOut + i;
  128. /* Initialize column loop counter */
  129. col = nColumns;
  130. while (col > 0U)
  131. {
  132. /* Read and store the input element in the destination */
  133. *px = *pIn++;
  134. /* Update the pointer px to point to the next row of the transposed matrix */
  135. px += nRows;
  136. /* Decrement the column loop counter */
  137. col--;
  138. }
  139. #endif /* #if defined (ARM_MATH_DSP) */
  140. i++;
  141. /* Decrement the row loop counter */
  142. row--;
  143. }
  144. while (row > 0U); /* row loop end */
  145. /* set status as ARM_MATH_SUCCESS */
  146. status = ARM_MATH_SUCCESS;
  147. }
  148. /* Return to application */
  149. return (status);
  150. }
  151. /**
  152. * @} end of MatrixTrans group
  153. */