arm_mat_trans_q31.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_q31.c
  4. * Description: Q31 matrix transpose
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 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 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. arm_status arm_mat_trans_q31(
  45. const arm_matrix_instance_q31 * pSrc,
  46. arm_matrix_instance_q31 * pDst)
  47. {
  48. q31_t *pIn = pSrc->pData; /* input data matrix pointer */
  49. q31_t *pOut = pDst->pData; /* output data matrix pointer */
  50. q31_t *px; /* Temporary output data matrix pointer */
  51. uint16_t nRows = pSrc->numRows; /* number of rows */
  52. uint16_t nCols = pSrc->numCols; /* number of columns */
  53. uint32_t col, row = nRows, i = 0U; /* Loop counters */
  54. arm_status status; /* status of matrix transpose */
  55. #ifdef ARM_MATH_MATRIX_CHECK
  56. /* Check for matrix mismatch condition */
  57. if ((pSrc->numRows != pDst->numCols) ||
  58. (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. /* Pointer px is set to starting address of column being processed */
  71. px = pOut + i;
  72. #if defined (ARM_MATH_LOOPUNROLL)
  73. /* Loop unrolling: Compute 4 outputs at a time */
  74. col = nCols >> 2U;
  75. while (col > 0U) /* column loop */
  76. {
  77. /* Read and store input element in destination */
  78. *px = *pIn++;
  79. /* Update pointer px to point to next row of transposed matrix */
  80. px += nRows;
  81. *px = *pIn++;
  82. px += nRows;
  83. *px = *pIn++;
  84. px += nRows;
  85. *px = *pIn++;
  86. px += nRows;
  87. /* Decrement column loop counter */
  88. col--;
  89. }
  90. /* Loop unrolling: Compute remaining outputs */
  91. col = nCols % 0x4U;
  92. #else
  93. /* Initialize col with number of samples */
  94. col = nCols;
  95. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  96. while (col > 0U)
  97. {
  98. /* Read and store input element in destination */
  99. *px = *pIn++;
  100. /* Update pointer px to point to next row of transposed matrix */
  101. px += nRows;
  102. /* Decrement column loop counter */
  103. col--;
  104. }
  105. i++;
  106. /* Decrement row loop counter */
  107. row--;
  108. } while (row > 0U); /* row loop end */
  109. /* Set status as ARM_MATH_SUCCESS */
  110. status = ARM_MATH_SUCCESS;
  111. }
  112. /* Return to application */
  113. return (status);
  114. }
  115. /**
  116. @} end of MatrixTrans group
  117. */