Merge branch 'jnosky/master'
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_sub_q31.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_sub_q31.c   
9 *   
10 * Description:  Q31 vector 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.7  2010/06/10    
30 *    Misra-C changes done   
31 * -------------------------------------------------------------------- */
32
33 #include "arm_math.h"
34
35 /**   
36  * @ingroup groupMath   
37  */
38
39 /**   
40  * @addtogroup BasicSub   
41  * @{   
42  */
43
44 /**   
45  * @brief Q31 vector subtraction.   
46  * @param[in]       *pSrcA points to the first input vector   
47  * @param[in]       *pSrcB points to the second input vector   
48  * @param[out]      *pDst points to the output vector   
49  * @param[in]       blockSize number of samples in each vector   
50  * @return none.   
51  *   
52  * <b>Scaling and Overflow Behavior:</b>   
53  * \par   
54  * The function uses saturating arithmetic.   
55  * Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] will be saturated.   
56  */
57
58 void arm_sub_q31(
59   q31_t * pSrcA,
60   q31_t * pSrcB,
61   q31_t * pDst,
62   uint32_t blockSize)
63 {
64   uint32_t blkCnt;                               /* loop counter */
65
66
67 #ifndef ARM_MATH_CM0
68
69 /* Run the below code for Cortex-M4 and Cortex-M3 */
70   /*loop Unrolling */
71   blkCnt = blockSize >> 2u;
72
73   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
74    ** a second loop below computes the remaining 1 to 3 samples. */
75   while(blkCnt > 0u)
76   {
77     /* C = A - B */
78     /* Subtract and then store the results in the destination buffer. */
79     *pDst++ = __QSUB(*pSrcA++, *pSrcB++);
80     *pDst++ = __QSUB(*pSrcA++, *pSrcB++);
81     *pDst++ = __QSUB(*pSrcA++, *pSrcB++);
82     *pDst++ = __QSUB(*pSrcA++, *pSrcB++);
83
84     /* Decrement the loop counter */
85     blkCnt--;
86   }
87
88   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
89    ** No loop unrolling is used. */
90   blkCnt = blockSize % 0x4u;
91
92   while(blkCnt > 0u)
93   {
94     /* C = A - B */
95     /* Subtract and then store the result in the destination buffer. */
96     *pDst++ = __QSUB(*pSrcA++, *pSrcB++);
97
98     /* Decrement the loop counter */
99     blkCnt--;
100   }
101
102 #else
103
104   /* Run the below code for Cortex-M0 */
105
106   /* Initialize blkCnt with number of samples */
107   blkCnt = blockSize;
108
109   while(blkCnt > 0u)
110   {
111     /* C = A - B */
112     /* Subtract and then store the result in the destination buffer. */
113     *pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrcA++ - *pSrcB++);
114
115     /* Decrement the loop counter */
116     blkCnt--;
117   }
118
119 #endif /* #ifndef ARM_MATH_CM0 */
120
121 }
122
123 /**   
124  * @} end of BasicSub group   
125  */