Merge branch 'jnosky/master'
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_negate_q15.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_negate_q15.c   
9 *   
10 * Description:  Negates Q15 vectors.   
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 negate   
41  * @{   
42  */
43
44 /**   
45  * @brief  Negates the elements of a Q15 vector.   
46  * @param[in]  *pSrc points to the input vector   
47  * @param[out]  *pDst points to the output vector   
48  * @param[in]  blockSize number of samples in the vector   
49  * @return none.   
50  *   
51  * <b>Scaling and Overflow Behavior:</b>   
52  * \par   
53  * The function uses saturating arithmetic.   
54  * The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.   
55  */
56
57 void arm_negate_q15(
58   q15_t * pSrc,
59   q15_t * pDst,
60   uint32_t blockSize)
61 {
62   uint32_t blkCnt;                               /* loop counter */
63
64
65 #ifndef ARM_MATH_CM0
66
67 /* Run the below code for Cortex-M4 and Cortex-M3 */
68
69   q15_t in1, in2;                                /* Temporary variables */
70
71
72   /*loop Unrolling */
73   blkCnt = blockSize >> 2u;
74
75   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
76    ** a second loop below computes the remaining 1 to 3 samples. */
77   while(blkCnt > 0u)
78   {
79     /* C = -A */
80     /* Read two inputs */
81     in1 = *pSrc++;
82     in2 = *pSrc++;
83     /* Negate and then store the results in the destination buffer by packing. */
84
85 #ifndef  ARM_MATH_BIG_ENDIAN
86
87     *__SIMD32(pDst)++ = __PKHBT(__SSAT(-in1, 16), __SSAT(-in2, 16), 16);
88
89 #else
90
91     *__SIMD32(pDst)++ = __PKHBT(__SSAT(-in2, 16), __SSAT(-in1, 16), 16);
92
93 #endif /* #ifndef  ARM_MATH_BIG_ENDIAN    */
94
95     in1 = *pSrc++;
96     in2 = *pSrc++;
97
98 #ifndef  ARM_MATH_BIG_ENDIAN
99
100     *__SIMD32(pDst)++ = __PKHBT(__SSAT(-in1, 16), __SSAT(-in2, 16), 16);
101
102 #else
103
104
105     *__SIMD32(pDst)++ = __PKHBT(__SSAT(-in2, 16), __SSAT(-in1, 16), 16);
106
107 #endif /* #ifndef  ARM_MATH_BIG_ENDIAN    */
108
109     /* Decrement the loop counter */
110     blkCnt--;
111   }
112
113   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
114    ** No loop unrolling is used. */
115   blkCnt = blockSize % 0x4u;
116
117 #else
118
119   /* Run the below code for Cortex-M0 */
120
121   /* Initialize blkCnt with number of samples */
122   blkCnt = blockSize;
123
124 #endif /* #ifndef ARM_MATH_CM0 */
125
126   while(blkCnt > 0u)
127   {
128     /* C = -A */
129     /* Negate and then store the result in the destination buffer. */
130     *pDst++ = __SSAT(-*pSrc++, 16);
131
132     /* Decrement the loop counter */
133     blkCnt--;
134   }
135
136 }
137
138 /**   
139  * @} end of negate group   
140  */