arm_mat_trans_f64.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_trans_f64.c
  4. * Description: Floating-point matrix transpose
  5. *
  6. * $Date: 10 August 2022
  7. * $Revision: V1.9.1
  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. @defgroup MatrixTrans Matrix Transpose
  34. Tranposes a matrix.
  35. Transposing an <code>M x N</code> matrix flips it around the center diagonal and results in an <code>N x M</code> matrix.
  36. \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix"
  37. */
  38. /**
  39. @addtogroup MatrixTrans
  40. @{
  41. */
  42. /**
  43. @brief Floating-point matrix transpose.
  44. @param[in] pSrc points to input matrix
  45. @param[out] pDst points to output matrix
  46. @return execution status
  47. - \ref ARM_MATH_SUCCESS : Operation successful
  48. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  49. */
  50. #if defined(ARM_MATH_NEON) && defined(__aarch64__)
  51. arm_status arm_mat_trans_f64(
  52. const arm_matrix_instance_f64 * pSrc,
  53. arm_matrix_instance_f64 * pDst)
  54. {
  55. float64_t *pIn = pSrc->pData; /* input data matrix pointer */
  56. float64_t *pOut = pDst->pData; /* output data matrix pointer */
  57. float64_t *px; /* Temporary output data matrix pointer */
  58. uint16_t nRows = pSrc->numRows; /* number of rows */
  59. uint16_t nColumns = pSrc->numCols; /* number of columns */
  60. uint16_t blkCnt, rowCnt, i = 0U, row = nRows; /* loop counters */
  61. arm_status status; /* status of matrix transpose */
  62. #ifdef ARM_MATH_MATRIX_CHECK
  63. /* Check for matrix mismatch condition */
  64. if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows))
  65. {
  66. /* Set status as ARM_MATH_SIZE_MISMATCH */
  67. status = ARM_MATH_SIZE_MISMATCH;
  68. }
  69. else
  70. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  71. {
  72. /* Matrix transpose by exchanging the rows with columns */
  73. /* Row loop */
  74. rowCnt = row >> 1;
  75. while (rowCnt > 0U)
  76. {
  77. float64_t *row0,*row1;
  78. float64x2x4_t raV;
  79. blkCnt = nColumns >> 2;
  80. /* The pointer px is set to starting address of the column being processed */
  81. px = pOut + i;
  82. /* Compute 4 outputs at a time.
  83. ** a second loop below computes the remaining 1 to 3 samples. */
  84. while (blkCnt > 0U) /* Column loop */
  85. {
  86. row0 = pIn;
  87. row1 = pIn+nColumns;
  88. pIn+=4;
  89. raV = vld4q_lane_f64(row0, raV, 0);
  90. raV = vld4q_lane_f64(row1, raV, 1);
  91. vst1q_f64(px,raV.val[0]);
  92. px += nRows;
  93. vst1q_f64(px,raV.val[1]);
  94. px += nRows;
  95. vst1q_f64(px,raV.val[2]);
  96. px += nRows;
  97. vst1q_f64(px,raV.val[3]);
  98. px += nRows;
  99. /* Decrement the column loop counter */
  100. blkCnt--;
  101. }
  102. /* Perform matrix transpose for last 3 samples here. */
  103. blkCnt = nColumns % 0x4U;
  104. while (blkCnt > 0U)
  105. {
  106. /* Read and store the input element in the destination */
  107. *px++ = *pIn;
  108. *px++ = *(pIn + 1 * nColumns);
  109. px += (nRows - 2);
  110. pIn++;
  111. /* Decrement the column loop counter */
  112. blkCnt--;
  113. }
  114. i += 2;
  115. pIn += 1 * nColumns;
  116. /* Decrement the row loop counter */
  117. rowCnt--;
  118. } /* Row loop end */
  119. rowCnt = row & 1;
  120. while (rowCnt > 0U)
  121. {
  122. blkCnt = nColumns ;
  123. /* The pointer px is set to starting address of the column being processed */
  124. px = pOut + i;
  125. while (blkCnt > 0U)
  126. {
  127. /* Read and store the input element in the destination */
  128. *px = *pIn++;
  129. /* Update the pointer px to point to the next row of the transposed matrix */
  130. px += nRows;
  131. /* Decrement the column loop counter */
  132. blkCnt--;
  133. }
  134. i++;
  135. rowCnt -- ;
  136. }
  137. /* Set status as ARM_MATH_SUCCESS */
  138. status = ARM_MATH_SUCCESS;
  139. }
  140. /* Return to application */
  141. return (status);
  142. }
  143. #else
  144. arm_status arm_mat_trans_f64(
  145. const arm_matrix_instance_f64 * pSrc,
  146. arm_matrix_instance_f64 * pDst)
  147. {
  148. float64_t *pIn = pSrc->pData; /* input data matrix pointer */
  149. float64_t *pOut = pDst->pData; /* output data matrix pointer */
  150. float64_t *px; /* Temporary output data matrix pointer */
  151. uint16_t nRows = pSrc->numRows; /* number of rows */
  152. uint16_t nCols = pSrc->numCols; /* number of columns */
  153. uint64_t col, row = nRows, i = 0U; /* Loop counters */
  154. arm_status status; /* status of matrix transpose */
  155. #ifdef ARM_MATH_MATRIX_CHECK
  156. /* Check for matrix mismatch condition */
  157. if ((pSrc->numRows != pDst->numCols) ||
  158. (pSrc->numCols != pDst->numRows) )
  159. {
  160. /* Set status as ARM_MATH_SIZE_MISMATCH */
  161. status = ARM_MATH_SIZE_MISMATCH;
  162. }
  163. else
  164. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  165. {
  166. /* Matrix transpose by exchanging the rows with columns */
  167. /* row loop */
  168. do
  169. {
  170. /* Pointer px is set to starting address of column being processed */
  171. px = pOut + i;
  172. #if defined (ARM_MATH_LOOPUNROLL)
  173. /* Loop unrolling: Compute 4 outputs at a time */
  174. col = nCols >> 2U;
  175. while (col > 0U) /* column loop */
  176. {
  177. /* Read and store input element in destination */
  178. *px = *pIn++;
  179. /* Update pointer px to point to next row of transposed matrix */
  180. px += nRows;
  181. *px = *pIn++;
  182. px += nRows;
  183. *px = *pIn++;
  184. px += nRows;
  185. *px = *pIn++;
  186. px += nRows;
  187. /* Decrement column loop counter */
  188. col--;
  189. }
  190. /* Loop unrolling: Compute remaining outputs */
  191. col = nCols % 0x4U;
  192. #else
  193. /* Initialize col with number of samples */
  194. col = nCols;
  195. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  196. while (col > 0U)
  197. {
  198. /* Read and store input element in destination */
  199. *px = *pIn++;
  200. /* Update pointer px to point to next row of transposed matrix */
  201. px += nRows;
  202. /* Decrement column loop counter */
  203. col--;
  204. }
  205. i++;
  206. /* Decrement row loop counter */
  207. row--;
  208. } while (row > 0U); /* row loop end */
  209. /* Set status as ARM_MATH_SUCCESS */
  210. status = ARM_MATH_SUCCESS;
  211. }
  212. /* Return to application */
  213. return (status);
  214. }
  215. #endif
  216. /**
  217. * @} end of MatrixTrans group
  218. */