Merge branch 'jnosky/master'
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / MatrixFunctions / arm_mat_sub_f32.c
1 /* ----------------------------------------------------------------------   
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *   
4 * $Date:        15. July 2011  
5 * $Revision:    V1.0.10  
6 *   
7 * Project:          CMSIS DSP Library   
8 * Title:            arm_mat_sub_f32.c   
9 *   
10 * Description:  Floating-point matrix subtraction.   
11 *   
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 *  
14 * Version 1.0.10 2011/7/15 
15 *    Big Endian support added and Merged M0 and M3/M4 Source code.  
16 *   
17 * Version 1.0.3 2010/11/29  
18 *    Re-organized the CMSIS folders and updated documentation.   
19 *    
20 * Version 1.0.2 2010/11/11   
21 *    Documentation updated.    
22 *   
23 * Version 1.0.1 2010/10/05    
24 *    Production release and review comments incorporated.   
25 *   
26 * Version 1.0.0 2010/09/20    
27 *    Production release and review comments incorporated.   
28 *   
29 * Version 0.0.5  2010/04/26    
30 *    incorporated review comments and updated with latest CMSIS layer   
31 *   
32 * Version 0.0.3  2010/03/10    
33 *    Initial version   
34 * -------------------------------------------------------------------- */
35
36 #include "arm_math.h"
37
38 /**   
39  * @ingroup groupMatrix   
40  */
41
42 /**   
43  * @defgroup MatrixSub Matrix Subtraction   
44  *   
45  * Subtract two matrices.   
46  * \image html MatrixSubtraction.gif "Subraction of two 3 x 3 matrices"   
47  *   
48  * The functions check to make sure that   
49  * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same   
50  * number of rows and columns.   
51  */
52
53 /**   
54  * @addtogroup MatrixSub   
55  * @{   
56  */
57
58 /**   
59  * @brief Floating-point matrix subtraction   
60  * @param[in]       *pSrcA points to the first input matrix structure   
61  * @param[in]       *pSrcB points to the second input matrix structure   
62  * @param[out]      *pDst points to output matrix structure   
63  * @return              The function returns either   
64  * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.   
65  */
66
67 arm_status arm_mat_sub_f32(
68   const arm_matrix_instance_f32 * pSrcA,
69   const arm_matrix_instance_f32 * pSrcB,
70   arm_matrix_instance_f32 * pDst)
71 {
72   float32_t *pIn1 = pSrcA->pData;                /* input data matrix pointer A */
73   float32_t *pIn2 = pSrcB->pData;                /* input data matrix pointer B */
74   float32_t *pOut = pDst->pData;                 /* output data matrix pointer  */
75   uint32_t numSamples;                           /* total number of elements in the matrix  */
76   uint32_t blkCnt;                               /* loop counters */
77   arm_status status;                             /* status of matrix subtraction */
78
79 #ifdef ARM_MATH_MATRIX_CHECK
80
81
82   /* Check for matrix mismatch condition */
83   if((pSrcA->numRows != pSrcB->numRows) ||
84      (pSrcA->numCols != pSrcB->numCols) ||
85      (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
86   {
87     /* Set status as ARM_MATH_SIZE_MISMATCH */
88     status = ARM_MATH_SIZE_MISMATCH;
89   }
90   else
91 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
92
93   {
94     /* Total number of samples in the input matrix */
95     numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
96
97 #ifndef ARM_MATH_CM0
98
99     /* Run the below code for Cortex-M4 and Cortex-M3 */
100
101     /* Loop Unrolling */
102     blkCnt = numSamples >> 2u;
103
104     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
105      ** a second loop below computes the remaining 1 to 3 samples. */
106     while(blkCnt > 0u)
107     {
108       /* C(m,n) = A(m,n) - B(m,n) */
109       /* Subtract and then store the results in the destination buffer. */
110       *pOut++ = (*pIn1++) - (*pIn2++);
111       *pOut++ = (*pIn1++) - (*pIn2++);
112       *pOut++ = (*pIn1++) - (*pIn2++);
113       *pOut++ = (*pIn1++) - (*pIn2++);
114
115       /* Decrement the loop counter */
116       blkCnt--;
117     }
118
119     /* If the numSamples is not a multiple of 4, compute any remaining output samples here.   
120      ** No loop unrolling is used. */
121     blkCnt = numSamples % 0x4u;
122
123 #else
124
125     /* Run the below code for Cortex-M0 */
126
127     /* Initialize blkCnt with number of samples */
128     blkCnt = numSamples;
129
130 #endif /* #ifndef ARM_MATH_CM0 */
131
132     while(blkCnt > 0u)
133     {
134       /* C(m,n) = A(m,n) - B(m,n) */
135       /* Subtract and then store the results in the destination buffer. */
136       *pOut++ = (*pIn1++) - (*pIn2++);
137
138       /* Decrement the loop counter */
139       blkCnt--;
140     }
141     /* Set status as ARM_MATH_SUCCESS */
142     status = ARM_MATH_SUCCESS;
143   }
144
145   /* Return to application */
146   return (status);
147 }
148
149 /**   
150  * @} end of MatrixSub group   
151  */