1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
4 * Description: Q7 vector absolute value
6 * $Date: 27. January 2017
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.
36 * @addtogroup BasicAbs
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
47 * \par Conditions for optimum performance
48 * Input and output buffers should be aligned by 32-bit
51 * <b>Scaling and Overflow Behavior:</b>
53 * The function uses saturating arithmetic.
54 * The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
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 */
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. */
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
);
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 */
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 */
115 /* Decrement the loop counter */
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
;
124 /* Run the below code for Cortex-M0 */
127 #endif /* #define ARM_MATH_CM0_FAMILY */
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 */
144 * @} end of BasicAbs group