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
29 #include "dsp/matrix_functions.h"
30
31 /**
32 @ingroup groupMatrix
33 */
34
35
36 /**
37 @addtogroup MatrixSub
38 @{
39 */
40
41 /**
42 @brief Floating-point matrix subtraction.
43 @param[in] pSrcA points to the first input matrix structure
44 @param[in] pSrcB points to the second input matrix structure
45 @param[out] pDst points to output matrix structure
46 @return execution status
47 - \ref ARM_MATH_SUCCESS : Operation successful
48 - \ref ARM_MATH_SIZE_MISMATCH : Matrix size check failed
49 */
50
arm_mat_sub_f64(const arm_matrix_instance_f64 * pSrcA,const arm_matrix_instance_f64 * pSrcB,arm_matrix_instance_f64 * pDst)51 arm_status arm_mat_sub_f64(
52 const arm_matrix_instance_f64 * pSrcA,
53 const arm_matrix_instance_f64 * pSrcB,
54 arm_matrix_instance_f64 * pDst)
55 {
56 float64_t *pInA = pSrcA->pData; /* input data matrix pointer A */
57 float64_t *pInB = pSrcB->pData; /* input data matrix pointer B */
58 float64_t *pOut = pDst->pData; /* output data matrix pointer */
59
60 uint64_t numSamples; /* total number of elements in the matrix */
61 uint64_t blkCnt; /* loop counters */
62 arm_status status; /* status of matrix subtraction */
63
64 #ifdef ARM_MATH_MATRIX_CHECK
65
66 /* Check for matrix mismatch condition */
67 if ((pSrcA->numRows != pSrcB->numRows) ||
68 (pSrcA->numCols != pSrcB->numCols) ||
69 (pSrcA->numRows != pDst->numRows) ||
70 (pSrcA->numCols != pDst->numCols) )
71 {
72 /* Set status as ARM_MATH_SIZE_MISMATCH */
73 status = ARM_MATH_SIZE_MISMATCH;
74 }
75 else
76
77 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
78
79 {
80 /* Total number of samples in input matrix */
81 numSamples = (uint64_t) pSrcA->numRows * pSrcA->numCols;
82
83 #if defined (ARM_MATH_LOOPUNROLL)
84
85 /* Loop unrolling: Compute 4 outputs at a time */
86 blkCnt = numSamples >> 2U;
87
88 while (blkCnt > 0U)
89 {
90 /* C(m,n) = A(m,n) - B(m,n) */
91
92 /* Subtract and store result in destination buffer. */
93 *pOut++ = (*pInA++) - (*pInB++);
94 *pOut++ = (*pInA++) - (*pInB++);
95 *pOut++ = (*pInA++) - (*pInB++);
96 *pOut++ = (*pInA++) - (*pInB++);
97
98 /* Decrement loop counter */
99 blkCnt--;
100 }
101
102 /* Loop unrolling: Compute remaining outputs */
103 blkCnt = numSamples % 0x4U;
104
105 #else
106
107 /* Initialize blkCnt with number of samples */
108 blkCnt = numSamples;
109
110 #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
111
112 while (blkCnt > 0U)
113 {
114 /* C(m,n) = A(m,n) - B(m,n) */
115
116 /* Subtract and store result in destination buffer. */
117 *pOut++ = (*pInA++) - (*pInB++);
118
119 /* Decrement loop counter */
120 blkCnt--;
121 }
122
123 /* Set status as ARM_MATH_SUCCESS */
124 status = ARM_MATH_SUCCESS;
125 }
126
127 /* Return to application */
128 return (status);
129 }
130
131 /**
132 @} end of MatrixSub group
133 */
134