arm_mat_sub_f64.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_mat_sub_f64.c
  4. * Description: Floating-point matrix subtraction
  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. @defgroup MatrixSub Matrix Subtraction
  34. Subtract two matrices.
  35. \image html MatrixSubtraction.gif "Subraction of two 3 x 3 matrices"
  36. The functions check to make sure that
  37. <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same
  38. number of rows and columns.
  39. */
  40. /**
  41. @addtogroup MatrixSub
  42. @{
  43. */
  44. /**
  45. @brief Floating-point matrix subtraction.
  46. @param[in] pSrcA points to the first input matrix structure
  47. @param[in] pSrcB points to the second input matrix structure
  48. @param[out] pDst points to output matrix structure
  49. @return execution status
  50. - \ref ARM_MATH_SUCCESS : Operation successful
  51. - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
  52. */
  53. arm_status arm_mat_sub_f64(
  54. const arm_matrix_instance_f64 * pSrcA,
  55. const arm_matrix_instance_f64 * pSrcB,
  56. arm_matrix_instance_f64 * pDst)
  57. {
  58. float64_t *pInA = pSrcA->pData; /* input data matrix pointer A */
  59. float64_t *pInB = pSrcB->pData; /* input data matrix pointer B */
  60. float64_t *pOut = pDst->pData; /* output data matrix pointer */
  61. uint64_t numSamples; /* total number of elements in the matrix */
  62. uint64_t blkCnt; /* loop counters */
  63. arm_status status; /* status of matrix subtraction */
  64. #ifdef ARM_MATH_MATRIX_CHECK
  65. /* Check for matrix mismatch condition */
  66. if ((pSrcA->numRows != pSrcB->numRows) ||
  67. (pSrcA->numCols != pSrcB->numCols) ||
  68. (pSrcA->numRows != pDst->numRows) ||
  69. (pSrcA->numCols != pDst->numCols) )
  70. {
  71. /* Set status as ARM_MATH_SIZE_MISMATCH */
  72. status = ARM_MATH_SIZE_MISMATCH;
  73. }
  74. else
  75. #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
  76. {
  77. /* Total number of samples in input matrix */
  78. numSamples = (uint64_t) pSrcA->numRows * pSrcA->numCols;
  79. #if defined (ARM_MATH_LOOPUNROLL)
  80. /* Loop unrolling: Compute 4 outputs at a time */
  81. blkCnt = numSamples >> 2U;
  82. while (blkCnt > 0U)
  83. {
  84. /* C(m,n) = A(m,n) - B(m,n) */
  85. /* Subtract and store result in destination buffer. */
  86. *pOut++ = (*pInA++) - (*pInB++);
  87. *pOut++ = (*pInA++) - (*pInB++);
  88. *pOut++ = (*pInA++) - (*pInB++);
  89. *pOut++ = (*pInA++) - (*pInB++);
  90. /* Decrement loop counter */
  91. blkCnt--;
  92. }
  93. /* Loop unrolling: Compute remaining outputs */
  94. blkCnt = numSamples % 0x4U;
  95. #else
  96. /* Initialize blkCnt with number of samples */
  97. blkCnt = numSamples;
  98. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  99. while (blkCnt > 0U)
  100. {
  101. /* C(m,n) = A(m,n) - B(m,n) */
  102. /* Subtract and store result in destination buffer. */
  103. *pOut++ = (*pInA++) - (*pInB++);
  104. /* Decrement loop counter */
  105. blkCnt--;
  106. }
  107. /* Set status as ARM_MATH_SUCCESS */
  108. status = ARM_MATH_SUCCESS;
  109. }
  110. /* Return to application */
  111. return (status);
  112. }
  113. /**
  114. @} end of MatrixSub group
  115. */