1 /* ----------------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
7 * Project: CMSIS DSP Library
8 * Title: arm_float_to_q7.c
10 * Description: Converts the elements of the floating-point vector to Q7 vector.
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Version 1.0.10 2011/7/15
15 * Big Endian support added and Merged M0 and M3/M4 Source code.
17 * Version 1.0.3 2010/11/29
18 * Re-organized the CMSIS folders and updated documentation.
20 * Version 1.0.2 2010/11/11
21 * Documentation updated.
23 * Version 1.0.1 2010/10/05
24 * Production release and review comments incorporated.
26 * Version 1.0.0 2010/09/20
27 * Production release and review comments incorporated.
28 * ---------------------------------------------------------------------------- */
33 * @ingroup groupSupport
37 * @addtogroup float_to_x
42 * @brief Converts the elements of the floating-point vector to Q7 vector.
43 * @param[in] *pSrc points to the floating-point 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:
52 * pDst[n] = (q7_t)(pSrc[n] * 128); 0 <= n < blockSize.
54 * \par Scaling and Overflow Behavior:
56 * The function uses saturating arithmetic.
57 * Results outside of the allowable Q7 range [0x80 0x7F] will be saturated.
59 * In order to apply rounding, the library should be rebuilt with the ROUNDING macro
60 * defined in the preprocessor section of project options.
69 float32_t *pIn = pSrc; /* Src pointer */
70 uint32_t blkCnt; /* loop counter */
72 #ifdef ARM_MATH_ROUNDING
76 #endif /* #ifdef ARM_MATH_ROUNDING */
80 /* Run the below code for Cortex-M4 and Cortex-M3 */
83 blkCnt = blockSize >> 2u;
85 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
86 ** a second loop below computes the remaining 1 to 3 samples. */
90 #ifdef ARM_MATH_ROUNDING
92 /* convert from float to q7 and then store the results in the destination buffer */
95 in += in > 0 ? 0.5 : -0.5;
96 *pDst++ = (q7_t) (__SSAT((q15_t) (in), 8));
100 in += in > 0 ? 0.5 : -0.5;
101 *pDst++ = (q7_t) (__SSAT((q15_t) (in), 8));
105 in += in > 0 ? 0.5 : -0.5;
106 *pDst++ = (q7_t) (__SSAT((q15_t) (in), 8));
110 in += in > 0 ? 0.5 : -0.5;
111 *pDst++ = (q7_t) (__SSAT((q15_t) (in), 8));
116 /* convert from float to q7 and then store the results in the destination buffer */
117 *pDst++ = __SSAT((q31_t) (*pIn++ * 128.0f), 8);
118 *pDst++ = __SSAT((q31_t) (*pIn++ * 128.0f), 8);
119 *pDst++ = __SSAT((q31_t) (*pIn++ * 128.0f), 8);
120 *pDst++ = __SSAT((q31_t) (*pIn++ * 128.0f), 8);
122 #endif /* #ifdef ARM_MATH_ROUNDING */
124 /* Decrement the loop counter */
128 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
129 ** No loop unrolling is used. */
130 blkCnt = blockSize % 0x4u;
135 #ifdef ARM_MATH_ROUNDING
137 /* convert from float to q7 and then store the results in the destination buffer */
140 in += in > 0 ? 0.5 : -0.5;
141 *pDst++ = (q7_t) (__SSAT((q15_t) (in), 8));
146 /* convert from float to q7 and then store the results in the destination buffer */
147 *pDst++ = __SSAT((q31_t) (*pIn++ * 128.0f), 8);
149 #endif /* #ifdef ARM_MATH_ROUNDING */
151 /* Decrement the loop counter */
158 /* Run the below code for Cortex-M0 */
161 /* Loop over blockSize number of values */
166 #ifdef ARM_MATH_ROUNDING
168 /* convert from float to q7 and then store the results in the destination buffer */
171 in += in > 0 ? 0.5f : -0.5f;
172 *pDst++ = (q7_t) (__SSAT((q31_t) (in), 8));
177 /* convert from float to q7 and then store the results in the destination buffer */
178 *pDst++ = (q7_t) __SSAT((q31_t) (*pIn++ * 128.0f), 8);
180 #endif /* #ifdef ARM_MATH_ROUNDING */
182 /* Decrement the loop counter */
186 #endif /* #ifndef ARM_MATH_CM0 */
191 * @} end of float_to_x group