before merging master
[inav.git] / lib / main / CMSIS / DSP / Source / BasicMathFunctions / arm_negate_q15.c
blob9624160f9a69b4024c44492c69245d04b2dc4386
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_negate_q15.c
4 * Description: Negates Q15 vectors
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 negate
37 * @{
40 /**
41 * @brief Negates the elements of a Q15 vector.
42 * @param[in] *pSrc points to the input vector
43 * @param[out] *pDst points to the output vector
44 * @param[in] blockSize number of samples in the 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 Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
57 void arm_negate_q15(
58 q15_t * pSrc,
59 q15_t * pDst,
60 uint32_t blockSize)
62 uint32_t blkCnt; /* loop counter */
63 q15_t in;
65 #if defined (ARM_MATH_DSP)
67 /* Run the below code for Cortex-M4 and Cortex-M3 */
69 q31_t in1, in2; /* Temporary variables */
72 /*loop Unrolling */
73 blkCnt = blockSize >> 2U;
75 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
76 ** a second loop below computes the remaining 1 to 3 samples. */
77 while (blkCnt > 0U)
79 /* C = -A */
80 /* Read two inputs at a time */
81 in1 = _SIMD32_OFFSET(pSrc);
82 in2 = _SIMD32_OFFSET(pSrc + 2);
84 /* negate two samples at a time */
85 in1 = __QSUB16(0, in1);
87 /* negate two samples at a time */
88 in2 = __QSUB16(0, in2);
90 /* store the result to destination 2 samples at a time */
91 _SIMD32_OFFSET(pDst) = in1;
92 /* store the result to destination 2 samples at a time */
93 _SIMD32_OFFSET(pDst + 2) = in2;
96 /* update pointers to process next samples */
97 pSrc += 4U;
98 pDst += 4U;
100 /* Decrement the loop counter */
101 blkCnt--;
104 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
105 ** No loop unrolling is used. */
106 blkCnt = blockSize % 0x4U;
108 #else
110 /* Run the below code for Cortex-M0 */
112 /* Initialize blkCnt with number of samples */
113 blkCnt = blockSize;
115 #endif /* #if defined (ARM_MATH_DSP) */
117 while (blkCnt > 0U)
119 /* C = -A */
120 /* Negate and then store the result in the destination buffer. */
121 in = *pSrc++;
122 *pDst++ = (in == (q15_t) 0x8000) ? 0x7fff : -in;
124 /* Decrement the loop counter */
125 blkCnt--;
130 * @} end of negate group