1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
10 * Description: Q7 vector absolute value.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
29 * Version 0.0.7 2010/06/10
30 * Misra-C changes done
31 * -------------------------------------------------------------------- */
40 * @addtogroup BasicAbs
45 * @brief Q7 vector absolute value.
46 * @param[in] *pSrc points to the input buffer
47 * @param[out] *pDst points to the output buffer
48 * @param[in] blockSize number of samples in each vector
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 */
66 /* Run the below code for Cortex-M4 and Cortex-M3 */
67 q7_t in1; /* Input value1 */
68 q7_t in2; /* Input value2 */
69 q7_t in3; /* Input value3 */
70 q7_t in4; /* Input value4 */
74 blkCnt = blockSize >> 2u;
76 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
77 ** a second loop below computes the remaining 1 to 3 samples. */
87 /* Store the Absolute result in the destination buffer by packing the 4 values in single cycle */
89 __PACKq7(((in1 > 0) ? in1 : __SSAT(-in1, 8)),
90 ((in2 > 0) ? in2 : __SSAT(-in2, 8)),
91 ((in3 > 0) ? in3 : __SSAT(-in3, 8)),
92 ((in4 > 0) ? in4 : __SSAT(-in4, 8)));
94 /* Decrement the loop counter */
98 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
99 ** No loop unrolling is used. */
100 blkCnt = blockSize % 0x4u;
108 /* Store the Absolute result in the destination buffer */
109 *pDst++ = (in1 > 0) ? in1 : __SSAT(-in1, 8);
111 /* Decrement the loop counter */
117 /* Run the below code for Cortex-M0 */
119 q7_t in; /* Temporary input varible */
121 /* Initialize blkCnt with number of samples */
130 /* Store the Absolute result in the destination buffer */
131 *pDst++ = (in > 0) ? in : __SSAT(-in, 8);
133 /* Decrement the loop counter */
137 #endif /* #ifndef ARM_MATH_CM0 */
142 * @} end of BasicAbs group