1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_negate_q15.c
4 * Description: Negates Q15 vectors
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.
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
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 Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
62 uint32_t blkCnt
; /* loop counter */
65 #if defined (ARM_MATH_DSP)
67 /* Run the below code for Cortex-M4 and Cortex-M3 */
69 q31_t in1
, in2
; /* Temporary variables */
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. */
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 */
100 /* Decrement the loop counter */
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
;
110 /* Run the below code for Cortex-M0 */
112 /* Initialize blkCnt with number of samples */
115 #endif /* #if defined (ARM_MATH_DSP) */
120 /* Negate and then store the result in the destination buffer. */
122 *pDst
++ = (in
== (q15_t
) 0x8000) ? 0x7fff : -in
;
124 /* Decrement the loop counter */
130 * @} end of negate group