1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_q15_to_q7.c
4 * Description: Converts the elements of the Q15 vector to Q7 vector
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.
32 * @ingroup groupSupport
36 * @addtogroup q15_to_x
42 * @brief Converts the elements of the Q15 vector to Q7 vector.
43 * @param[in] *pSrc points to the Q15 input vector
44 * @param[out] *pDst points to the Q7 output vector
45 * @param[in] blockSize length of the input vector
50 * The equation used for the conversion process is:
53 * pDst[n] = (q7_t) pSrc[n] >> 8; 0 <= n < blockSize.
64 q15_t
*pIn
= pSrc
; /* Src pointer */
65 uint32_t blkCnt
; /* loop counter */
67 #if defined (ARM_MATH_DSP)
69 /* Run the below code for Cortex-M4 and Cortex-M3 */
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. */
80 /* C = (q7_t) A >> 8 */
81 /* convert from q15 to q7 and then store the results in the destination buffer */
82 in1
= *__SIMD32(pIn
)++;
83 in2
= *__SIMD32(pIn
)++;
85 #ifndef ARM_MATH_BIG_ENDIAN
87 out1
= __PKHTB(in2
, in1
, 16);
88 out2
= __PKHBT(in2
, in1
, 16);
92 out1
= __PKHTB(in1
, in2
, 16);
93 out2
= __PKHBT(in1
, in2
, 16);
95 #endif // #ifndef ARM_MATH_BIG_ENDIAN
97 /* rotate packed value by 24 */
98 out2
= ((uint32_t) out2
<< 8) | ((uint32_t) out2
>> 24);
100 /* anding with 0xff00ff00 to get two 8 bit values */
101 out1
= out1
& 0xFF00FF00;
102 /* anding with 0x00ff00ff to get two 8 bit values */
103 out2
= out2
& 0x00FF00FF;
105 /* oring two values(contains two 8 bit values) to get four packed 8 bit values */
108 /* store 4 samples at a time to destiantion buffer */
109 *__SIMD32(pDst
)++ = out1
;
111 /* Decrement the loop counter */
115 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
116 ** No loop unrolling is used. */
117 blkCnt
= blockSize
% 0x4U
;
121 /* Run the below code for Cortex-M0 */
123 /* Loop over blockSize number of values */
126 #endif /* #if defined (ARM_MATH_DSP) */
130 /* C = (q7_t) A >> 8 */
131 /* convert from q15 to q7 and then store the results in the destination buffer */
132 *pDst
++ = (q7_t
) (*pIn
++ >> 8);
134 /* Decrement the loop counter */
141 * @} end of q15_to_x group