annotate f103c8/Drivers/CMSIS/DSP_Lib/Source/BasicMathFunctions/arm_abs_q31.c @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0c59e7a7782a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /* ----------------------------------------------------------------------
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * $Date: 19. March 2015
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * $Revision: V.1.4.5
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * Project: CMSIS DSP Library
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 * Title: arm_abs_q31.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * Description: Q31 vector absolute value.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 * Redistribution and use in source and binary forms, with or without
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 * modification, are permitted provided that the following conditions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 * are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 * - Redistributions of source code must retain the above copyright
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 * notice, this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 * - Redistributions in binary form must reproduce the above copyright
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 * notice, this list of conditions and the following disclaimer in
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 * the documentation and/or other materials provided with the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 * distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 * - Neither the name of ARM LIMITED nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 * may be used to endorse or promote products derived from this
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 * software without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 * POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 * -------------------------------------------------------------------- */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 #include "arm_math.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44 * @ingroup groupMath
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48 * @addtogroup BasicAbs
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 * @brief Q31 vector absolute value.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55 * @param[in] *pSrc points to the input buffer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 * @param[out] *pDst points to the output buffer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 * @param[in] blockSize number of samples in each vector
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 * @return none.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 * <b>Scaling and Overflow Behavior:</b>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 * \par
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 * The function uses saturating arithmetic.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 * The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 void arm_abs_q31(
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 q31_t * pSrc,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68 q31_t * pDst,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 uint32_t blockSize)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71 uint32_t blkCnt; /* loop counter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72 q31_t in; /* Input value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 #ifndef ARM_MATH_CM0_FAMILY
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76 /* Run the below code for Cortex-M4 and Cortex-M3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 q31_t in1, in2, in3, in4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79 /*loop Unrolling */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 blkCnt = blockSize >> 2u;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 ** a second loop below computes the remaining 1 to 3 samples. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 while(blkCnt > 0u)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86 /* C = |A| */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 /* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and then store the results in the destination buffer. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 in1 = *pSrc++;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 in2 = *pSrc++;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 in3 = *pSrc++;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 in4 = *pSrc++;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 *pDst++ = (in1 > 0) ? in1 : (q31_t)__QSUB(0, in1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 *pDst++ = (in2 > 0) ? in2 : (q31_t)__QSUB(0, in2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 *pDst++ = (in3 > 0) ? in3 : (q31_t)__QSUB(0, in3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96 *pDst++ = (in4 > 0) ? in4 : (q31_t)__QSUB(0, in4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 /* Decrement the loop counter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 blkCnt--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 ** No loop unrolling is used. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 blkCnt = blockSize % 0x4u;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 /* Run the below code for Cortex-M0 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 /* Initialize blkCnt with number of samples */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 blkCnt = blockSize;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 while(blkCnt > 0u)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 /* C = |A| */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 /* Calculate absolute value of the input (if -1 then saturated to 0x7fffffff) and then store the results in the destination buffer. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 in = *pSrc++;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 *pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 /* Decrement the loop counter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 blkCnt--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 * @} end of BasicAbs group
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130 */