CMSIS DSP Software Library: arm_float_to_q15.c Source File

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

- File List
- Globals

# arm_float_to_q15.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_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 * 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
    00065 void arm_float_to_q15(
    00066   float32_t * pSrc,
    00067   q15_t * pDst,
    00068   uint32_t blockSize)
    00069 {
    00070   float32_t *pIn = pSrc;                         /* Src pointer */
    00071   uint32_t blkCnt;                               /* loop counter */
    00072
    00073 #ifdef ARM_MATH_ROUNDING
    00074
    00075   float32_t in;
    00076
    00077 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00078
    00079 #ifndef ARM_MATH_CM0
    00080
    00081   /* Run the below code for Cortex-M4 and Cortex-M3 */
    00082
    00083   /*loop Unrolling */
    00084   blkCnt = blockSize >> 2u;
    00085
    00086   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00087    ** a second loop below computes the remaining 1 to 3 samples. */
    00088   while(blkCnt > 0u)
    00089   {
    00090
    00091 #ifdef ARM_MATH_ROUNDING
    00092     /* C = A * 32768 */
    00093     /* convert from float to q15 and then store the results in the destination buffer */
    00094     in = *pIn++;
    00095     in = (in * 32768.0f);
    00096     in += in > 0 ? 0.5 : -0.5;
    00097     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00098
    00099     in = *pIn++;
    00100     in = (in * 32768.0f);
    00101     in += in > 0 ? 0.5 : -0.5;
    00102     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00103
    00104     in = *pIn++;
    00105     in = (in * 32768.0f);
    00106     in += in > 0 ? 0.5 : -0.5;
    00107     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00108
    00109     in = *pIn++;
    00110     in = (in * 32768.0f);
    00111     in += in > 0 ? 0.5 : -0.5;
    00112     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00113
    00114 #else
    00115
    00116     /* C = A * 32768 */
    00117     /* convert from float to q15 and then store the results in the destination buffer */
    00118     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00119     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00120     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00121     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00122
    00123 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00124
    00125     /* Decrement the loop counter */
    00126     blkCnt--;
    00127   }
    00128
    00129   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00130    ** No loop unrolling is used. */
    00131   blkCnt = blockSize % 0x4u;
    00132
    00133   while(blkCnt > 0u)
    00134   {
    00135
    00136 #ifdef ARM_MATH_ROUNDING
    00137     /* C = A * 32768 */
    00138     /* convert from float to q15 and then store the results in the destination buffer */
    00139     in = *pIn++;
    00140     in = (in * 32768.0f);
    00141     in += in > 0 ? 0.5 : -0.5;
    00142     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00143
    00144 #else
    00145
    00146     /* C = A * 32768 */
    00147     /* convert from float to q15 and then store the results in the destination buffer */
    00148     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00149
    00150 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00151
    00152     /* Decrement the loop counter */
    00153     blkCnt--;
    00154   }
    00155
    00156
    00157 #else
    00158
    00159   /* Run the below code for Cortex-M0 */
    00160
    00161   /* Loop over blockSize number of values */
    00162   blkCnt = blockSize;
    00163
    00164   while(blkCnt > 0u)
    00165   {
    00166
    00167 #ifdef ARM_MATH_ROUNDING
    00168     /* C = A * 32768 */
    00169     /* convert from float to q15 and then store the results in the destination buffer */
    00170     in = *pIn++;
    00171     in = (in * 32768.0f);
    00172     in += in > 0 ? 0.5f : -0.5f;
    00173     *pDst++ = (q15_t) (__SSAT((q31_t) (in), 16));
    00174
    00175 #else
    00176
    00177     /* C = A * 32768 */
    00178     /* convert from float to q15 and then store the results in the destination buffer */
    00179     *pDst++ = (q15_t) __SSAT((q31_t) (*pIn++ * 32768.0f), 16);
    00180
    00181 #endif /*      #ifdef ARM_MATH_ROUNDING        */
    00182
    00183     /* Decrement the loop counter */
    00184     blkCnt--;
    00185   }
    00186
    00187 #endif /* #ifndef ARM_MATH_CM0 */
    00188
    00189 }
    00190

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines