before merging master
[inav.git] / lib / main / CMSIS / DSP / Source / SupportFunctions / arm_q15_to_q7.c
blob7a45e588878e082370d0dba2044cc365dca222cf
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
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 groupSupport
35 /**
36 * @addtogroup q15_to_x
37 * @{
41 /**
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
46 * @return none.
48 * \par Description:
50 * The equation used for the conversion process is:
52 * <pre>
53 * pDst[n] = (q7_t) pSrc[n] >> 8; 0 <= n < blockSize.
54 * </pre>
59 void arm_q15_to_q7(
60 q15_t * pSrc,
61 q7_t * pDst,
62 uint32_t 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 */
70 q31_t in1, in2;
71 q31_t out1, out2;
73 /*loop Unrolling */
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. */
78 while (blkCnt > 0U)
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);
90 #else
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 */
106 out1 = out1 | out2;
108 /* store 4 samples at a time to destiantion buffer */
109 *__SIMD32(pDst)++ = out1;
111 /* Decrement the loop counter */
112 blkCnt--;
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;
119 #else
121 /* Run the below code for Cortex-M0 */
123 /* Loop over blockSize number of values */
124 blkCnt = blockSize;
126 #endif /* #if defined (ARM_MATH_DSP) */
128 while (blkCnt > 0U)
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 */
135 blkCnt--;
141 * @} end of q15_to_x group