Merge branch 'jnosky/master'
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Source / BasicMathFunctions / arm_abs_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_abs_f32.c   
9 *   
10 * Description:  Vector absolute value.   
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 #include <math.h>
35
36 /**   
37  * @ingroup groupMath   
38  */
39
40 /**   
41  * @defgroup BasicAbs Vector Absolute Value   
42  *   
43  * Computes the absolute value of a vector on an element-by-element basis.   
44  *   
45  * <pre>   
46  *     pDst[n] = abs(pSrcA[n]),   0 <= n < blockSize.   
47  * </pre>   
48  *   
49  * The operation can be done in-place by setting the input and output pointers to the same buffer.   
50  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.   
51  */
52
53 /**   
54  * @addtogroup BasicAbs   
55  * @{   
56  */
57
58 /**   
59  * @brief Floating-point vector absolute value.   
60  * @param[in]       *pSrc points to the input buffer   
61  * @param[out]      *pDst points to the output buffer   
62  * @param[in]       blockSize number of samples in each vector   
63  * @return none.   
64  */
65
66 void arm_abs_f32(
67   float32_t * pSrc,
68   float32_t * pDst,
69   uint32_t blockSize)
70 {
71   uint32_t blkCnt;                               /* loop counter */
72
73 #ifndef ARM_MATH_CM0
74
75   /* Run the below code for Cortex-M4 and Cortex-M3 */
76
77   /*loop Unrolling */
78   blkCnt = blockSize >> 2u;
79
80   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
81    ** a second loop below computes the remaining 1 to 3 samples. */
82   while(blkCnt > 0u)
83   {
84     /* C = |A| */
85     /* Calculate absolute and then store the results in the destination buffer. */
86     *pDst++ = fabsf(*pSrc++);
87     *pDst++ = fabsf(*pSrc++);
88     *pDst++ = fabsf(*pSrc++);
89     *pDst++ = fabsf(*pSrc++);
90
91     /* Decrement the loop counter */
92     blkCnt--;
93   }
94
95   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
96    ** No loop unrolling is used. */
97   blkCnt = blockSize % 0x4u;
98
99 #else
100
101   /* Run the below code for Cortex-M0 */
102
103   /* Initialize blkCnt with number of samples */
104   blkCnt = blockSize;
105
106 #endif /*   #ifndef ARM_MATH_CM0   */
107
108   while(blkCnt > 0u)
109   {
110     /* C = |A| */
111     /* Calculate absolute and then store the results in the destination buffer. */
112     *pDst++ = fabsf(*pSrc++);
113
114     /* Decrement the loop counter */
115     blkCnt--;
116   }
117
118 }
119
120 /**   
121  * @} end of BasicAbs group   
122  */