arm_mat_trans_q15.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_q15.c
  4. * Description: Q15 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 Q15 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_q15(
  45. const arm_matrix_instance_q15 * pSrc,
  46. arm_matrix_instance_q15 * pDst)
  47. {
  48. q15_t *pIn = pSrc->pData; /* input data matrix pointer */
  49. q15_t *pOut = pDst->pData; /* output data matrix pointer */
  50. uint16_t nRows = pSrc->numRows; /* number of rows */
  51. uint16_t nCols = pSrc->numCols; /* number of columns */
  52. uint32_t col, row = nRows, i = 0U; /* Loop counters */
  53. arm_status status; /* status of matrix transpose */
  54. #if defined (ARM_MATH_LOOPUNROLL)
  55. q31_t in; /* variable to hold temporary output */
  56. #endif
  57. #ifdef ARM_MATH_MATRIX_CHECK
  58. /* Check for matrix mismatch condition */
  59. if ((pSrc->numRows != pDst->numCols) ||
  60. (pSrc->numCols != pDst->numRows) )
  61. {
  62. /* Set status as ARM_MATH_SIZE_MISMATCH */
  63. status = ARM_MATH_SIZE_MISMATCH;
  64. }
  65. else
  66. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  67. {
  68. /* Matrix transpose by exchanging the rows with columns */
  69. /* row loop */
  70. do
  71. {
  72. /* Pointer pOut is set to starting address of column being processed */
  73. pOut = pDst->pData + i;
  74. #if defined (ARM_MATH_LOOPUNROLL)
  75. /* Loop unrolling: Compute 4 outputs at a time */
  76. col = nCols >> 2U;
  77. while (col > 0U) /* column loop */
  78. {
  79. /* Read two elements from row */
  80. in = read_q15x2_ia ((q15_t **) &pIn);
  81. /* Unpack and store one element in destination */
  82. #ifndef ARM_MATH_BIG_ENDIAN
  83. *pOut = (q15_t) in;
  84. #else
  85. *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
  86. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  87. /* Update pointer pOut to point to next row of transposed matrix */
  88. pOut += nRows;
  89. /* Unpack and store second element in destination */
  90. #ifndef ARM_MATH_BIG_ENDIAN
  91. *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
  92. #else
  93. *pOut = (q15_t) in;
  94. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  95. /* Update pointer pOut to point to next row of transposed matrix */
  96. pOut += nRows;
  97. /* Read two elements from row */
  98. in = read_q15x2_ia ((q15_t **) &pIn);
  99. /* Unpack and store one element in destination */
  100. #ifndef ARM_MATH_BIG_ENDIAN
  101. *pOut = (q15_t) in;
  102. #else
  103. *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
  104. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  105. /* Update pointer pOut to point to next row of transposed matrix */
  106. pOut += nRows;
  107. /* Unpack and store second element in destination */
  108. #ifndef ARM_MATH_BIG_ENDIAN
  109. *pOut = (q15_t) ((in & (q31_t) 0xffff0000) >> 16);
  110. #else
  111. *pOut = (q15_t) in;
  112. #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
  113. /* Update pointer pOut to point to next row of transposed matrix */
  114. pOut += nRows;
  115. /* Decrement column loop counter */
  116. col--;
  117. }
  118. /* Loop unrolling: Compute remaining outputs */
  119. col = nCols % 0x4U;
  120. #else
  121. /* Initialize col with number of samples */
  122. col = nCols;
  123. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  124. while (col > 0U)
  125. {
  126. /* Read and store input element in destination */
  127. *pOut = *pIn++;
  128. /* Update pointer pOut to point to next row of transposed matrix */
  129. pOut += nRows;
  130. /* Decrement column loop counter */
  131. col--;
  132. }
  133. i++;
  134. /* Decrement row loop counter */
  135. row--;
  136. } while (row > 0U); /* row loop end */
  137. /* Set status as ARM_MATH_SUCCESS */
  138. status = ARM_MATH_SUCCESS;
  139. }
  140. /* Return to application */
  141. return (status);
  142. }
  143. /**
  144. @} end of MatrixTrans group
  145. */