Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / lib / main / CMSIS / DSP / Source / SupportFunctions / arm_float_to_q31.c
blobd17cc3ad5a6517a000134314840b3b3173d0d1c8
1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_float_to_q31.c
4 * Description: Converts the elements of the floating-point vector to Q31 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 * @defgroup float_to_x Convert 32-bit floating point value
39 /**
40 * @addtogroup float_to_x
41 * @{
44 /**
45 * @brief Converts the elements of the floating-point vector to Q31 vector.
46 * @param[in] *pSrc points to the floating-point input vector
47 * @param[out] *pDst points to the Q31 output vector
48 * @param[in] blockSize length of the input vector
49 * @return none.
51 *\par Description:
52 * \par
53 * The equation used for the conversion process is:
55 * <pre>
56 * pDst[n] = (q31_t)(pSrc[n] * 2147483648); 0 <= n < blockSize.
57 * </pre>
58 * <b>Scaling and Overflow Behavior:</b>
59 * \par
60 * The function uses saturating arithmetic.
61 * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated.
63 * \note In order to apply rounding, the library should be rebuilt with the ROUNDING macro
64 * defined in the preprocessor section of project options.
68 void arm_float_to_q31(
69 float32_t * pSrc,
70 q31_t * pDst,
71 uint32_t blockSize)
73 float32_t *pIn = pSrc; /* Src pointer */
74 uint32_t blkCnt; /* loop counter */
76 #ifdef ARM_MATH_ROUNDING
78 float32_t in;
80 #endif /* #ifdef ARM_MATH_ROUNDING */
82 #if defined (ARM_MATH_DSP)
84 /* Run the below code for Cortex-M4 and Cortex-M3 */
86 /*loop Unrolling */
87 blkCnt = blockSize >> 2U;
89 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
90 ** a second loop below computes the remaining 1 to 3 samples. */
91 while (blkCnt > 0U)
94 #ifdef ARM_MATH_ROUNDING
96 /* C = A * 32768 */
97 /* convert from float to Q31 and then store the results in the destination buffer */
98 in = *pIn++;
99 in = (in * 2147483648.0f);
100 in += in > 0.0f ? 0.5f : -0.5f;
101 *pDst++ = clip_q63_to_q31((q63_t) (in));
103 in = *pIn++;
104 in = (in * 2147483648.0f);
105 in += in > 0.0f ? 0.5f : -0.5f;
106 *pDst++ = clip_q63_to_q31((q63_t) (in));
108 in = *pIn++;
109 in = (in * 2147483648.0f);
110 in += in > 0.0f ? 0.5f : -0.5f;
111 *pDst++ = clip_q63_to_q31((q63_t) (in));
113 in = *pIn++;
114 in = (in * 2147483648.0f);
115 in += in > 0.0f ? 0.5f : -0.5f;
116 *pDst++ = clip_q63_to_q31((q63_t) (in));
118 #else
120 /* C = A * 2147483648 */
121 /* convert from float to Q31 and then store the results in the destination buffer */
122 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
123 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
124 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
125 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
127 #endif /* #ifdef ARM_MATH_ROUNDING */
129 /* Decrement the loop counter */
130 blkCnt--;
133 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
134 ** No loop unrolling is used. */
135 blkCnt = blockSize % 0x4U;
137 while (blkCnt > 0U)
140 #ifdef ARM_MATH_ROUNDING
142 /* C = A * 2147483648 */
143 /* convert from float to Q31 and then store the results in the destination buffer */
144 in = *pIn++;
145 in = (in * 2147483648.0f);
146 in += in > 0.0f ? 0.5f : -0.5f;
147 *pDst++ = clip_q63_to_q31((q63_t) (in));
149 #else
151 /* C = A * 2147483648 */
152 /* convert from float to Q31 and then store the results in the destination buffer */
153 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
155 #endif /* #ifdef ARM_MATH_ROUNDING */
157 /* Decrement the loop counter */
158 blkCnt--;
162 #else
164 /* Run the below code for Cortex-M0 */
166 /* Loop over blockSize number of values */
167 blkCnt = blockSize;
169 while (blkCnt > 0U)
172 #ifdef ARM_MATH_ROUNDING
174 /* C = A * 2147483648 */
175 /* convert from float to Q31 and then store the results in the destination buffer */
176 in = *pIn++;
177 in = (in * 2147483648.0f);
178 in += in > 0 ? 0.5f : -0.5f;
179 *pDst++ = clip_q63_to_q31((q63_t) (in));
181 #else
183 /* C = A * 2147483648 */
184 /* convert from float to Q31 and then store the results in the destination buffer */
185 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
187 #endif /* #ifdef ARM_MATH_ROUNDING */
189 /* Decrement the loop counter */
190 blkCnt--;
193 #endif /* #if defined (ARM_MATH_DSP) */
198 * @} end of float_to_x group