1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_shift_q15.c
4 * Description: Shifts the elements of a Q15 vector by a specified number of bits
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 Shifts the elements of a Q15 vector a specified number of bits.
42 * @param[in] *pSrc points to the input vector
43 * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
44 * @param[out] *pDst points to the output vector
45 * @param[in] blockSize number of samples in the vector
48 * <b>Scaling and Overflow Behavior:</b>
50 * The function uses saturating arithmetic.
51 * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.
60 uint32_t blkCnt
; /* loop counter */
61 uint8_t sign
; /* Sign of shiftBits */
63 #if defined (ARM_MATH_DSP)
65 /* Run the below code for Cortex-M4 and Cortex-M3 */
67 q15_t in1
, in2
; /* Temporary variables */
71 blkCnt
= blockSize
>> 2U;
73 /* Getting the sign of shiftBits */
74 sign
= (shiftBits
& 0x80);
76 /* If the shift value is positive then do right shift else left shift */
79 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
80 ** a second loop below computes the remaining 1 to 3 samples. */
86 /* C = A << shiftBits */
87 /* Shift the inputs and then store the results in the destination buffer. */
88 #ifndef ARM_MATH_BIG_ENDIAN
90 *__SIMD32(pDst
)++ = __PKHBT(__SSAT((in1
<< shiftBits
), 16),
91 __SSAT((in2
<< shiftBits
), 16), 16);
95 *__SIMD32(pDst
)++ = __PKHBT(__SSAT((in2
<< shiftBits
), 16),
96 __SSAT((in1
<< shiftBits
), 16), 16);
98 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
103 #ifndef ARM_MATH_BIG_ENDIAN
105 *__SIMD32(pDst
)++ = __PKHBT(__SSAT((in1
<< shiftBits
), 16),
106 __SSAT((in2
<< shiftBits
), 16), 16);
110 *__SIMD32(pDst
)++ = __PKHBT(__SSAT((in2
<< shiftBits
), 16),
111 __SSAT((in1
<< shiftBits
), 16), 16);
113 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
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
;
125 /* C = A << shiftBits */
126 /* Shift and then store the results in the destination buffer. */
127 *pDst
++ = __SSAT((*pSrc
++ << shiftBits
), 16);
129 /* Decrement the loop counter */
135 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
136 ** a second loop below computes the remaining 1 to 3 samples. */
143 /* C = A >> shiftBits */
144 /* Shift the inputs and then store the results in the destination buffer. */
145 #ifndef ARM_MATH_BIG_ENDIAN
147 *__SIMD32(pDst
)++ = __PKHBT((in1
>> -shiftBits
),
148 (in2
>> -shiftBits
), 16);
152 *__SIMD32(pDst
)++ = __PKHBT((in2
>> -shiftBits
),
153 (in1
>> -shiftBits
), 16);
155 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
160 #ifndef ARM_MATH_BIG_ENDIAN
162 *__SIMD32(pDst
)++ = __PKHBT((in1
>> -shiftBits
),
163 (in2
>> -shiftBits
), 16);
167 *__SIMD32(pDst
)++ = __PKHBT((in2
>> -shiftBits
),
168 (in1
>> -shiftBits
), 16);
170 #endif /* #ifndef ARM_MATH_BIG_ENDIAN */
172 /* Decrement the loop counter */
176 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
177 ** No loop unrolling is used. */
178 blkCnt
= blockSize
% 0x4U
;
182 /* C = A >> shiftBits */
183 /* Shift the inputs and then store the results in the destination buffer. */
184 *pDst
++ = (*pSrc
++ >> -shiftBits
);
186 /* Decrement the loop counter */
193 /* Run the below code for Cortex-M0 */
195 /* Getting the sign of shiftBits */
196 sign
= (shiftBits
& 0x80);
198 /* If the shift value is positive then do right shift else left shift */
201 /* Initialize blkCnt with number of samples */
206 /* C = A << shiftBits */
207 /* Shift and then store the results in the destination buffer. */
208 *pDst
++ = __SSAT(((q31_t
) * pSrc
++ << shiftBits
), 16);
210 /* Decrement the loop counter */
216 /* Initialize blkCnt with number of samples */
221 /* C = A >> shiftBits */
222 /* Shift the inputs and then store the results in the destination buffer. */
223 *pDst
++ = (*pSrc
++ >> -shiftBits
);
225 /* Decrement the loop counter */
230 #endif /* #if defined (ARM_MATH_DSP) */
235 * @} end of shift group