CMSIS DSP Software Library: arm_float_to_q31.c Source File

- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

# arm_float_to_q31.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002 * Copyright (C) 2010 ARM Limited. All rights reserved.
    00003 *
    00004 * $Date:        15. July 2011
    00005 * $Revision:    V1.0.10
    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 * Version 1.0.10 2011/7/15
    00015 *    Big Endian support added and Merged M0 and M3/M4 Source code.
    00016 *
    00017 * Version 1.0.3 2010/11/29
    00018 *    Re-organized the CMSIS folders and updated documentation.
    00019 *
    00020 * Version 1.0.2 2010/11/11
    00021 *    Documentation updated.
    00022 *
    00023 * Version 1.0.1 2010/10/05
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 1.0.0 2010/09/20
    00027 *    Production release and review comments incorporated.
    00028 * ---------------------------------------------------------------------------- */
    00029
    00030 #include "arm_math.h"
    00031
    00069 void arm_float_to_q31(
    00070   float32_t * pSrc,
    00071   q31_t * pDst,
    00072   uint32_t blockSize)
    00073 {
    00074   float32_t *pIn = pSrc;                         /* Src pointer */
    00075   uint32_t blkCnt;                               /* loop counter */
    00076
    00077 #ifdef ARM_MATH_ROUNDING
    00078
    00079   float32_t in;
    00080
    00081 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00082
    00083 #ifndef ARM_MATH_CM0
    00084
    00085   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00086
    00087   /*loop Unrolling */
    00088   blkCnt = blockSize >> 2u;
    00089
    00090   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00091    ** a second loop below computes the remaining 1 to 3 samples. */
    00092   while(blkCnt > 0u)
    00093   {
    00094
    00095 #ifdef ARM_MATH_ROUNDING
    00096
    00097     /* C = A * 32768 */
    00098     /* convert from float to Q31 and then store the results in the destination buffer */
    00099     in = *pIn++;
    00100     in = (in * 2147483648.0f);
    00101     in += in > 0 ? 0.5 : -0.5;
    00102     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00103
    00104     in = *pIn++;
    00105     in = (in * 2147483648.0f);
    00106     in += in > 0 ? 0.5 : -0.5;
    00107     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00108
    00109     in = *pIn++;
    00110     in = (in * 2147483648.0f);
    00111     in += in > 0 ? 0.5 : -0.5;
    00112     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00113
    00114     in = *pIn++;
    00115     in = (in * 2147483648.0f);
    00116     in += in > 0 ? 0.5 : -0.5;
    00117     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00118
    00119 #else
    00120
    00121     /* C = A * 2147483648 */
    00122     /* convert from float to Q31 and then store the results in the destination buffer */
    00123     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00124     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00125     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00126     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00127
    00128 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00129
    00130     /* Decrement the loop counter */
    00131     blkCnt--;
    00132   }
    00133
    00134   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00135    ** No loop unrolling is used. */
    00136   blkCnt = blockSize % 0x4u;
    00137
    00138   while(blkCnt > 0u)
    00139   {
    00140
    00141 #ifdef ARM_MATH_ROUNDING
    00142
    00143     /* C = A * 2147483648 */
    00144     /* convert from float to Q31 and then store the results in the destination buffer */
    00145     in = *pIn++;
    00146     in = (in * 2147483648.0f);
    00147     in += in > 0 ? 0.5 : -0.5;
    00148     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00149
    00150 #else
    00151
    00152     /* C = A * 2147483648 */
    00153     /* convert from float to Q31 and then store the results in the destination buffer */
    00154     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00155
    00156 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00157
    00158     /* Decrement the loop counter */
    00159     blkCnt--;
    00160   }
    00161
    00162
    00163 #else
    00164
    00165   /* Run the below code for Cortex-M0 */
    00166
    00167   /* Loop over blockSize number of values */
    00168   blkCnt = blockSize;
    00169
    00170   while(blkCnt > 0u)
    00171   {
    00172
    00173 #ifdef ARM_MATH_ROUNDING
    00174
    00175     /* C = A * 2147483648 */
    00176     /* convert from float to Q31 and then store the results in the destination buffer */
    00177     in = *pIn++;
    00178     in = (in * 2147483648.0f);
    00179     in += in > 0 ? 0.5f : -0.5f;
    00180     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00181
    00182 #else
    00183
    00184     /* C = A * 2147483648 */
    00185     /* convert from float to Q31 and then store the results in the destination buffer */
    00186     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00187
    00188 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00189
    00190     /* Decrement the loop counter */
    00191     blkCnt--;
    00192   }
    00193
    00194 #endif /* #ifndef ARM_MATH_CM0 */
    00195
    00196 }
    00197

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines