CMSIS DSP Software Library: arm_float_to_q7.c Source File

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

- File List
- Globals

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

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines