Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / CMSIS / DSP / Source / BasicMathFunctions / arm_abs_q7.c
blobd0acbfc24eded658a974d887f1d79f2204d4420c
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_abs_q7.c
4 * Description: Q7 vector absolute value
6 * $Date: 27. January 2017
7 * $Revision: V.1.5.1
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupMath
35 /**
36 * @addtogroup BasicAbs
37 * @{
40 /**
41 * @brief Q7 vector absolute value.
42 * @param[in] *pSrc points to the input buffer
43 * @param[out] *pDst points to the output buffer
44 * @param[in] blockSize number of samples in each vector
45 * @return none.
47 * \par Conditions for optimum performance
48 * Input and output buffers should be aligned by 32-bit
51 * <b>Scaling and Overflow Behavior:</b>
52 * \par
53 * The function uses saturating arithmetic.
54 * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
57 void arm_abs_q7(
58 q7_t * pSrc,
59 q7_t * pDst,
60 uint32_t blockSize)
62 uint32_t blkCnt; /* loop counter */
63 q7_t in; /* Input value1 */
65 #if defined (ARM_MATH_DSP)
67 /* Run the below code for Cortex-M4 and Cortex-M3 */
68 q31_t in1, in2, in3, in4; /* temporary input variables */
69 q31_t out1, out2, out3, out4; /* temporary output variables */
71 /*loop Unrolling */
72 blkCnt = blockSize >> 2U;
74 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
75 ** a second loop below computes the remaining 1 to 3 samples. */
76 while (blkCnt > 0U)
78 /* C = |A| */
79 /* Read inputs */
80 in1 = (q31_t) * pSrc;
81 in2 = (q31_t) * (pSrc + 1);
82 in3 = (q31_t) * (pSrc + 2);
84 /* find absolute value */
85 out1 = (in1 > 0) ? in1 : (q31_t)__QSUB8(0, in1);
87 /* read input */
88 in4 = (q31_t) * (pSrc + 3);
90 /* find absolute value */
91 out2 = (in2 > 0) ? in2 : (q31_t)__QSUB8(0, in2);
93 /* store result to destination */
94 *pDst = (q7_t) out1;
96 /* find absolute value */
97 out3 = (in3 > 0) ? in3 : (q31_t)__QSUB8(0, in3);
99 /* find absolute value */
100 out4 = (in4 > 0) ? in4 : (q31_t)__QSUB8(0, in4);
102 /* store result to destination */
103 *(pDst + 1) = (q7_t) out2;
105 /* store result to destination */
106 *(pDst + 2) = (q7_t) out3;
108 /* store result to destination */
109 *(pDst + 3) = (q7_t) out4;
111 /* update pointers to process next samples */
112 pSrc += 4U;
113 pDst += 4U;
115 /* Decrement the loop counter */
116 blkCnt--;
119 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
120 ** No loop unrolling is used. */
121 blkCnt = blockSize % 0x4U;
122 #else
124 /* Run the below code for Cortex-M0 */
125 blkCnt = blockSize;
127 #endif /* #define ARM_MATH_CM0_FAMILY */
129 while (blkCnt > 0U)
131 /* C = |A| */
132 /* Read the input */
133 in = *pSrc++;
135 /* Store the Absolute result in the destination buffer */
136 *pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? 0x7f : -in);
138 /* Decrement the loop counter */
139 blkCnt--;
144 * @} end of BasicAbs group