- 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:        29. November 2010
    00005 * $Revision:    V1.0.3
    00006 *
    00007 * Project:      CMSIS DSP Library
    00008 * Title:        arm_float_to_q31.c
    00009 *
    00010 * Description:  Processing function for the Conversion from float to Q31
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3
    00013 *
    00014 * Version 1.0.3 2010/11/29
    00015 *    Re-organized the CMSIS folders and updated documentation.
    00016 *
    00017 * Version 1.0.2 2010/11/11
    00018 *    Documentation updated.
    00019 *
    00020 * Version 1.0.1 2010/10/05
    00021 *    Production release and review comments incorporated.
    00022 *
    00023 * Version 1.0.0 2010/09/20
    00024 *    Production release and review comments incorporated.
    00025 * ---------------------------------------------------------------------------- */
    00026
    00027 #include "arm_math.h"
    00028
    00066 void arm_float_to_q31(
    00067   float32_t * pSrc,
    00068   q31_t * pDst,
    00069   uint32_t blockSize)
    00070 {
    00071   float32_t *pIn = pSrc;                         /* Src pointer */
    00072   uint32_t blkCnt;                               /* loop counter */
    00073
    00074 #ifdef ARM_MATH_ROUNDING
    00075
    00076   float32_t in;
    00077
    00078 #endif
    00079
    00080
    00081   /*loop Unrolling */
    00082   blkCnt = blockSize >> 2u;
    00083
    00084   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00085    ** a second loop below computes the remaining 1 to 3 samples. */
    00086   while(blkCnt > 0u)
    00087   {
    00088 #ifdef ARM_MATH_ROUNDING
    00089     /* C = A * 32768 */
    00090     /* convert from float to Q31 and then store the results in the destination buffer */
    00091     in = *pIn++;
    00092     in = (in * 2147483648.0f);
    00093     in += in > 0 ? 0.5 : -0.5;
    00094     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00095
    00096     in = *pIn++;
    00097     in = (in * 2147483648.0f);
    00098     in += in > 0 ? 0.5 : -0.5;
    00099     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00100
    00101     in = *pIn++;
    00102     in = (in * 2147483648.0f);
    00103     in += in > 0 ? 0.5 : -0.5;
    00104     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00105
    00106     in = *pIn++;
    00107     in = (in * 2147483648.0f);
    00108     in += in > 0 ? 0.5 : -0.5;
    00109     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00110
    00111 #else
    00112
    00113     /* C = A * 2147483648 */
    00114     /* convert from float to Q31 and then store the results in the destination buffer */
    00115     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00116     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00117     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00118     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00119
    00120 #endif
    00121
    00122     /* Decrement the loop counter */
    00123     blkCnt--;
    00124   }
    00125
    00126   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00127    ** No loop unrolling is used. */
    00128   blkCnt = blockSize % 0x4u;
    00129
    00130   while(blkCnt > 0u)
    00131   {
    00132 #ifdef ARM_MATH_ROUNDING
    00133
    00134     /* C = A * 2147483648 */
    00135     /* convert from float to Q31 and then store the results in the destination buffer */
    00136     in = *pIn++;
    00137     in = (in * 2147483648.0f);
    00138     in += in > 0 ? 0.5 : -0.5;
    00139     *pDst++ = clip_q63_to_q31((q63_t) (in));
    00140
    00141 #else
    00142
    00143     /* C = A * 2147483648 */
    00144     /* convert from float to Q31 and then store the results in the destination buffer */
    00145     *pDst++ = clip_q63_to_q31((q63_t) (*pIn++ * 2147483648.0f));
    00146
    00147 #endif
    00148
    00149     /* Decrement the loop counter */
    00150     blkCnt--;
    00151   }
    00152 }
    00153

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines