CMSIS DSP library
Dependents: performance_timer Surfboard_ gps2rtty Capstone ... more
arm_float_to_q15.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_q15.c 00009 * 00010 * Description: Converts the elements of the floating-point vector to Q15 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 * @addtogroup float_to_x 00049 * @{ 00050 */ 00051 00052 /** 00053 * @brief Converts the elements of the floating-point vector to Q15 vector. 00054 * @param[in] *pSrc points to the floating-point input vector 00055 * @param[out] *pDst points to the Q15 output vector 00056 * @param[in] blockSize length of the input vector 00057 * @return none. 00058 * 00059 * \par Description: 00060 * \par 00061 * The equation used for the conversion process is: 00062 * <pre> 00063 * pDst[n] = (q15_t)(pSrc[n] * 32768); 0 <= n < blockSize. 00064 * </pre> 00065 * \par Scaling and Overflow Behavior: 00066 * \par 00067 * The function uses saturating arithmetic. 00068 * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated. 00069 * \note 00070 * In order to apply rounding, the library should be rebuilt with the ROUNDING macro 00071 * defined in the preprocessor section of project options. 00072 * 00073 */ 00074 00075 00076 void arm_float_to_q15( 00077 float32_t * pSrc, 00078 q15_t * pDst, 00079 uint32_t blockSize) 00080 { 00081 float32_t *pIn = pSrc; /* Src pointer */ 00082 uint32_t blkCnt; /* loop counter */ 00083 00084 #ifdef ARM_MATH_ROUNDING 00085 00086 float32_t in; 00087 00088 #endif /* #ifdef ARM_MATH_ROUNDING */ 00089 00090 #ifndef ARM_MATH_CM0_FAMILY 00091 00092 /* Run the below code for Cortex-M4 and Cortex-M3 */ 00093 00094 /*loop Unrolling */ 00095 blkCnt = blockSize >> 2u; 00096 00097 /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 00098 ** a second loop below computes the remaining 1 to 3 samples. */ 00099 while(blkCnt > 0u) 00100 { 00101 00102 #ifdef ARM_MATH_ROUNDING 00103 /* C = A * 32768 */ 00104 /* convert from float to q15 and then store the results in the destination buffer */ 00105 in = *pIn++; 00106 in = (in * 32768.0f); 00107 in += in > 0.0f ? 0.5f : -0.5f; 00108 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00109 00110 in = *pIn++; 00111 in = (in * 32768.0f); 00112 in += in > 0.0f ? 0.5f : -0.5f; 00113 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00114 00115 in = *pIn++; 00116 in = (in * 32768.0f); 00117 in += in > 0.0f ? 0.5f : -0.5f; 00118 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00119 00120 in = *pIn++; 00121 in = (in * 32768.0f); 00122 in += in > 0.0f ? 0.5f : -0.5f; 00123 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00124 00125 #else 00126 00127 /* C = A * 32768 */ 00128 /* convert from float to q15 and then store the results in the destination buffer */ 00129 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00130 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00131 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00132 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00133 00134 #endif /* #ifdef ARM_MATH_ROUNDING */ 00135 00136 /* Decrement the loop counter */ 00137 blkCnt--; 00138 } 00139 00140 /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 00141 ** No loop unrolling is used. */ 00142 blkCnt = blockSize % 0x4u; 00143 00144 while(blkCnt > 0u) 00145 { 00146 00147 #ifdef ARM_MATH_ROUNDING 00148 /* C = A * 32768 */ 00149 /* convert from float to q15 and then store the results in the destination buffer */ 00150 in = *pIn++; 00151 in = (in * 32768.0f); 00152 in += in > 0.0f ? 0.5f : -0.5f; 00153 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00154 00155 #else 00156 00157 /* C = A * 32768 */ 00158 /* convert from float to q15 and then store the results in the destination buffer */ 00159 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00160 00161 #endif /* #ifdef ARM_MATH_ROUNDING */ 00162 00163 /* Decrement the loop counter */ 00164 blkCnt--; 00165 } 00166 00167 00168 #else 00169 00170 /* Run the below code for Cortex-M0 */ 00171 00172 /* Loop over blockSize number of values */ 00173 blkCnt = blockSize; 00174 00175 while(blkCnt > 0u) 00176 { 00177 00178 #ifdef ARM_MATH_ROUNDING 00179 /* C = A * 32768 */ 00180 /* convert from float to q15 and then store the results in the destination buffer */ 00181 in = *pIn++; 00182 in = (in * 32768.0f); 00183 in += in > 0 ? 0.5f : -0.5f; 00184 *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16)); 00185 00186 #else 00187 00188 /* C = A * 32768 */ 00189 /* convert from float to q15 and then store the results in the destination buffer */ 00190 *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16); 00191 00192 #endif /* #ifdef ARM_MATH_ROUNDING */ 00193 00194 /* Decrement the loop counter */ 00195 blkCnt--; 00196 } 00197 00198 #endif /* #ifndef ARM_MATH_CM0_FAMILY */ 00199 00200 } 00201 00202 /** 00203 * @} end of float_to_x group 00204 */
Generated on Tue Jul 12 2022 11:59:17 by 1.7.2