arm_mat_trans_q31.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_q31.c
  4. * Description: Q31 matrix transpose
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/matrix_functions.h"
  29. /**
  30. @ingroup groupMatrix
  31. */
  32. /**
  33. @addtogroup MatrixTrans
  34. @{
  35. */
  36. /**
  37. @brief Q31 matrix transpose.
  38. @param[in] pSrc points to input matrix
  39. @param[out] pDst points to output matrix
  40. @return execution status
  41. - \ref ARM_MATH_SUCCESS : Operation successful
  42. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  43. */
  44. #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
  45. #include "arm_helium_utils.h"
  46. arm_status arm_mat_trans_q31(
  47. const arm_matrix_instance_q31 * pSrc,
  48. arm_matrix_instance_q31 * pDst)
  49. {
  50. arm_status status; /* status of matrix transpose */
  51. #ifdef ARM_MATH_MATRIX_CHECK
  52. /* Check for matrix mismatch condition */
  53. if ((pSrc->numRows != pDst->numCols) ||
  54. (pSrc->numCols != pDst->numRows) )
  55. {
  56. /* Set status as ARM_MATH_SIZE_MISMATCH */
  57. status = ARM_MATH_SIZE_MISMATCH;
  58. }
  59. else
  60. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  61. {
  62. if (pDst->numRows == pDst->numCols)
  63. {
  64. if (pDst->numCols == 2)
  65. return arm_mat_trans_32bit_2x2_mve((uint32_t *)pSrc->pData, (uint32_t *)pDst->pData);
  66. if (pDst->numCols == 3)
  67. return arm_mat_trans_32bit_3x3_mve((uint32_t *)pSrc->pData, (uint32_t *)pDst->pData);
  68. if (pDst->numCols == 4)
  69. return arm_mat_trans_32bit_4x4_mve((uint32_t *)pSrc->pData, (uint32_t *)pDst->pData);
  70. }
  71. arm_mat_trans_32bit_generic_mve(pSrc->numRows, pSrc->numCols, (uint32_t *)pSrc->pData, (uint32_t *)pDst->pData);
  72. /* Set status as ARM_MATH_SUCCESS */
  73. status = ARM_MATH_SUCCESS;
  74. /* Set status as ARM_MATH_SUCCESS */
  75. status = ARM_MATH_SUCCESS;
  76. }
  77. /* Return to application */
  78. return (status);
  79. }
  80. #else
  81. arm_status arm_mat_trans_q31(
  82. const arm_matrix_instance_q31 * pSrc,
  83. arm_matrix_instance_q31 * pDst)
  84. {
  85. q31_t *pIn = pSrc->pData; /* input data matrix pointer */
  86. q31_t *pOut = pDst->pData; /* output data matrix pointer */
  87. q31_t *px; /* Temporary output data matrix pointer */
  88. uint16_t nRows = pSrc->numRows; /* number of rows */
  89. uint16_t nCols = pSrc->numCols; /* number of columns */
  90. uint32_t col, row = nRows, i = 0U; /* Loop counters */
  91. arm_status status; /* status of matrix transpose */
  92. #ifdef ARM_MATH_MATRIX_CHECK
  93. /* Check for matrix mismatch condition */
  94. if ((pSrc->numRows != pDst->numCols) ||
  95. (pSrc->numCols != pDst->numRows) )
  96. {
  97. /* Set status as ARM_MATH_SIZE_MISMATCH */
  98. status = ARM_MATH_SIZE_MISMATCH;
  99. }
  100. else
  101. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  102. {
  103. /* Matrix transpose by exchanging the rows with columns */
  104. /* row loop */
  105. do
  106. {
  107. /* Pointer px is set to starting address of column being processed */
  108. px = pOut + i;
  109. #if defined (ARM_MATH_LOOPUNROLL)
  110. /* Loop unrolling: Compute 4 outputs at a time */
  111. col = nCols >> 2U;
  112. while (col > 0U) /* column loop */
  113. {
  114. /* Read and store input element in destination */
  115. *px = *pIn++;
  116. /* Update pointer px to point to next row of transposed matrix */
  117. px += nRows;
  118. *px = *pIn++;
  119. px += nRows;
  120. *px = *pIn++;
  121. px += nRows;
  122. *px = *pIn++;
  123. px += nRows;
  124. /* Decrement column loop counter */
  125. col--;
  126. }
  127. /* Loop unrolling: Compute remaining outputs */
  128. col = nCols % 0x4U;
  129. #else
  130. /* Initialize col with number of samples */
  131. col = nCols;
  132. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  133. while (col > 0U)
  134. {
  135. /* Read and store input element in destination */
  136. *px = *pIn++;
  137. /* Update pointer px to point to next row of transposed matrix */
  138. px += nRows;
  139. /* Decrement column loop counter */
  140. col--;
  141. }
  142. i++;
  143. /* Decrement row loop counter */
  144. row--;
  145. } while (row > 0U); /* row loop end */
  146. /* Set status as ARM_MATH_SUCCESS */
  147. status = ARM_MATH_SUCCESS;
  148. }
  149. /* Return to application */
  150. return (status);
  151. }
  152. #endif /* defined(ARM_MATH_MVEI) */
  153. /**
  154. @} end of MatrixTrans group
  155. */