CMSIS DSP library
Dependents: performance_timer Surfboard_ gps2rtty Capstone ... more
arm_float_to_q31.c
00001 /* ---------------------------------------------------------------------------- 00002 * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 19. March 2015 00005 * $Revision: V.1.4.5 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_float_to_q31.c 00009 * 00010 * Description: Converts the elements of the floating-point vector to Q31 vector. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions 00016 * are met: 00017 * - Redistributions of source code must retain the above copyright 00018 * notice, this list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in 00021 * the documentation and/or other materials provided with the 00022 * distribution. 00023 * - Neither the name of ARM LIMITED nor the names of its contributors 00024 * may be used to endorse or promote products derived from this 00025 * software without specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00028 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00029 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00030 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00031 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00033 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00034 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00036 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00037 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * ---------------------------------------------------------------------------- */ 00040 00041 #include "arm_math.h" 00042 00043 /** 00044 * @ingroup groupSupport 00045 */ 00046 00047 /** 00048 * @defgroup float_to_x Convert 32-bit floating point value 00049 */ 00050 00051 /** 00052 * @addtogroup float_to_x 00053 * @{ 00054 */ 00055 00056 /** 00057 * @brief Converts the elements of the floating-point vector to Q31 vector. 00058 * @param[in] *pSrc points to the floating-point input vector 00059 * @param[out] *pDst points to the Q31 output vector 00060 * @param[in] blockSize length of the input vector 00061 * @return none. 00062 * 00063 *\par Description: 00064 * \par 00065 * The equation used for the conversion process is: 00066 * 00067 * <pre> 00068 * pDst[n] = (q31_t)(pSrc[n] * 2147483648); 0 <= n < blockSize. 00069 * </pre> 00070 * <b>Scaling and Overflow Behavior:</b> 00071 * \par 00072 * The function uses saturating arithmetic. 00073 * Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] will be saturated. 00074 * 00075 * \note In order to apply rounding, the library should be rebuilt with the ROUNDING macro 00076 * defined in the preprocessor section of project options. 00077 */ 00078 00079 00080 void arm_float_to_q31( 00081 float32_t * pSrc, 00082 q31_t * pDst, 00083 uint32_t blockSize) 00084 { 00085 float32_t *pIn = pSrc; /* Src pointer */ 00086 uint32_t blkCnt; /* loop counter */ 00087 00088 #ifdef ARM_MATH_ROUNDING 00089 00090 float32_t in; 00091 00092 #endif /* #ifdef ARM_MATH_ROUNDING */ 00093 00094 #ifndef ARM_MATH_CM0_FAMILY 00095 00096 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00097 00098 /*loop Unrolling */ 00099 blkCnt = blockSize >> 2u; 00100 00101 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00102 ** a second loop below computes the remaining 1 to 3 samples. */ 00103 while(blkCnt > 0u) 00104 { 00105 00106 #ifdef ARM_MATH_ROUNDING 00107 00108 /* C = A * 32768 */ 00109 /* convert from float to Q31 and then store the results in the destination buffer */ 00110 in = *pIn++; 00111 in = (in * 2147483648.0f); 00112 in += in > 0.0f ? 0.5f : -0.5f; 00113 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00114 00115 in = *pIn++; 00116 in = (in * 2147483648.0f); 00117 in += in > 0.0f ? 0.5f : -0.5f; 00118 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00119 00120 in = *pIn++; 00121 in = (in * 2147483648.0f); 00122 in += in > 0.0f ? 0.5f : -0.5f; 00123 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00124 00125 in = *pIn++; 00126 in = (in * 2147483648.0f); 00127 in += in > 0.0f ? 0.5f : -0.5f; 00128 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00129 00130 #else 00131 00132 /* C = A * 2147483648 */ 00133 /* convert from float to Q31 and then store the results in the destination buffer */ 00134 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00135 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00136 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00137 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00138 00139 #endif /* #ifdef ARM_MATH_ROUNDING */ 00140 00141 /* Decrement the loop counter */ 00142 blkCnt--; 00143 } 00144 00145 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00146 ** No loop unrolling is used. */ 00147 blkCnt = blockSize % 0x4u; 00148 00149 while(blkCnt > 0u) 00150 { 00151 00152 #ifdef ARM_MATH_ROUNDING 00153 00154 /* C = A * 2147483648 */ 00155 /* convert from float to Q31 and then store the results in the destination buffer */ 00156 in = *pIn++; 00157 in = (in * 2147483648.0f); 00158 in += in > 0.0f ? 0.5f : -0.5f; 00159 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00160 00161 #else 00162 00163 /* C = A * 2147483648 */ 00164 /* convert from float to Q31 and then store the results in the destination buffer */ 00165 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00166 00167 #endif /* #ifdef ARM_MATH_ROUNDING */ 00168 00169 /* Decrement the loop counter */ 00170 blkCnt--; 00171 } 00172 00173 00174 #else 00175 00176 /* Run the below code for Cortex-M0 */ 00177 00178 /* Loop over blockSize number of values */ 00179 blkCnt = blockSize; 00180 00181 while(blkCnt > 0u) 00182 { 00183 00184 #ifdef ARM_MATH_ROUNDING 00185 00186 /* C = A * 2147483648 */ 00187 /* convert from float to Q31 and then store the results in the destination buffer */ 00188 in = *pIn++; 00189 in = (in * 2147483648.0f); 00190 in += in > 0 ? 0.5f : -0.5f; 00191 *pDst++ = clip_q63_to_q31((q63_t) (in)); 00192 00193 #else 00194 00195 /* C = A * 2147483648 */ 00196 /* convert from float to Q31 and then store the results in the destination buffer */ 00197 *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f)); 00198 00199 #endif /* #ifdef ARM_MATH_ROUNDING */ 00200 00201 /* Decrement the loop counter */ 00202 blkCnt--; 00203 } 00204 00205 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00206 00207 } 00208 00209 /** 00210 * @} end of float_to_x group 00211 */
Generated on Tue Jul 12 2022 11:59:17 by 1.7.2