1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_shift_q7.c
4 * Description: Processing function for the Q7 Shifting
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.
42 * @brief Shifts the elements of a Q7 vector a specified number of bits.
43 * @param[in] *pSrc points to the input vector
44 * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
45 * @param[out] *pDst points to the output vector
46 * @param[in] blockSize number of samples in the vector
49 * \par Conditions for optimum performance
50 * Input and output buffers should be aligned by 32-bit
53 * <b>Scaling and Overflow Behavior:</b>
55 * The function uses saturating arithmetic.
56 * Results outside of the allowable Q7 range [0x8 0x7F] will be saturated.
65 uint32_t blkCnt
; /* loop counter */
66 uint8_t sign
; /* Sign of shiftBits */
68 #if defined (ARM_MATH_DSP)
70 /* Run the below code for Cortex-M4 and Cortex-M3 */
71 q7_t in1
; /* Input value1 */
72 q7_t in2
; /* Input value2 */
73 q7_t in3
; /* Input value3 */
74 q7_t in4
; /* Input value4 */
78 blkCnt
= blockSize
>> 2U;
80 /* Getting the sign of shiftBits */
81 sign
= (shiftBits
& 0x80);
83 /* If the shift value is positive then do right shift else left shift */
86 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
87 ** a second loop below computes the remaining 1 to 3 samples. */
90 /* C = A << shiftBits */
97 /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
98 *__SIMD32(pDst
)++ = __PACKq7(__SSAT((in1
<< shiftBits
), 8),
99 __SSAT((in2
<< shiftBits
), 8),
100 __SSAT((in3
<< shiftBits
), 8),
101 __SSAT((in4
<< shiftBits
), 8));
102 /* Update source pointer to process next sampels */
105 /* Decrement the loop counter */
109 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
110 ** No loop unrolling is used. */
111 blkCnt
= blockSize
% 0x4U
;
115 /* C = A << shiftBits */
116 /* Shift the input and then store the result in the destination buffer. */
117 *pDst
++ = (q7_t
) __SSAT((*pSrc
++ << shiftBits
), 8);
119 /* Decrement the loop counter */
125 shiftBits
= -shiftBits
;
126 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
127 ** a second loop below computes the remaining 1 to 3 samples. */
130 /* C = A >> shiftBits */
137 /* Store the Shifted result in the destination buffer in single cycle by packing the outputs */
138 *__SIMD32(pDst
)++ = __PACKq7((in1
>> shiftBits
), (in2
>> shiftBits
),
139 (in3
>> shiftBits
), (in4
>> shiftBits
));
144 /* Decrement the loop counter */
148 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
149 ** No loop unrolling is used. */
150 blkCnt
= blockSize
% 0x4U
;
154 /* C = A >> shiftBits */
155 /* Shift the input and then store the result in the destination buffer. */
157 *pDst
++ = (in1
>> shiftBits
);
159 /* Decrement the loop counter */
166 /* Run the below code for Cortex-M0 */
168 /* Getting the sign of shiftBits */
169 sign
= (shiftBits
& 0x80);
171 /* If the shift value is positive then do right shift else left shift */
174 /* Initialize blkCnt with number of samples */
179 /* C = A << shiftBits */
180 /* Shift the input and then store the result in the destination buffer. */
181 *pDst
++ = (q7_t
) __SSAT(((q15_t
) * pSrc
++ << shiftBits
), 8);
183 /* Decrement the loop counter */
189 /* Initialize blkCnt with number of samples */
194 /* C = A >> shiftBits */
195 /* Shift the input and then store the result in the destination buffer. */
196 *pDst
++ = (*pSrc
++ >> -shiftBits
);
198 /* Decrement the loop counter */
203 #endif /* #if defined (ARM_MATH_DSP) */
207 * @} end of shift group