CMSIS DSP Software Library: arm_mat_scale_q31.c Source File

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

- File List
- Globals

# arm_mat_scale_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_mat_scale_q31.c
    00009 *
    00010 * Description:  Multiplies a Q31 matrix by a scalar.
    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 * Version 0.0.5  2010/04/26
    00030 *    incorporated review comments and updated with latest CMSIS layer
    00031 *
    00032 * Version 0.0.3  2010/03/10
    00033 *    Initial version
    00034 * -------------------------------------------------------------------- */
    00035
    00036 #include "arm_math.h"
    00037
    00063 arm_status arm_mat_scale_q31(
    00064   const arm_matrix_instance_q31 * pSrc,
    00065   q31_t scaleFract,
    00066   int32_t shift,
    00067   arm_matrix_instance_q31 * pDst)
    00068 {
    00069   q31_t *pIn = pSrc->pData;                      /* input data matrix pointer */
    00070   q31_t *pOut = pDst->pData;                     /* output data matrix pointer */
    00071   q63_t out;                                     /* temporary variable to hold output value */
    00072   uint32_t numSamples;                           /* total number of elements in the matrix */
    00073   int32_t totShift = 31 - shift;                 /* shift to apply after scaling */
    00074   uint32_t blkCnt;                               /* loop counters  */
    00075   arm_status status;                             /* status of matrix scaling      */
    00076
    00077 #ifdef ARM_MATH_MATRIX_CHECK
    00078
    00079
    00080   /* Check for matrix mismatch  */
    00081   if((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols))
    00082   {
    00083     /* Set status as ARM_MATH_SIZE_MISMATCH */
    00084     status = ARM_MATH_SIZE_MISMATCH;
    00085   }
    00086   else
    00087 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
    00088
    00089   {
    00090     /* Total number of samples in the input matrix */
    00091     numSamples = (uint32_t) pSrc->numRows * pSrc->numCols;
    00092
    00093 #ifndef ARM_MATH_CM0
    00094
    00095     /* Run the below code for Cortex-M4 and Cortex-M3 */
    00096
    00097     /* Loop Unrolling */
    00098     blkCnt = numSamples >> 2u;
    00099
    00100     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00101      ** a second loop below computes the remaining 1 to 3 samples. */
    00102     while(blkCnt > 0u)
    00103     {
    00104       /* C(m,n) = A(m,n) * k */
    00105       /* Scale, saturate and then store the results in the destination buffer. */
    00106       out = ((q63_t) * pIn++ * scaleFract) >> totShift;
    00107       *pOut++ = clip_q63_to_q31(out);
    00108       out = ((q63_t) * pIn++ * scaleFract) >> totShift;
    00109       *pOut++ = clip_q63_to_q31(out);
    00110       out = ((q63_t) * pIn++ * scaleFract) >> totShift;
    00111       *pOut++ = clip_q63_to_q31(out);
    00112       out = ((q63_t) * pIn++ * scaleFract) >> totShift;
    00113       *pOut++ = clip_q63_to_q31(out);
    00114
    00115       /* Decrement the numSamples loop counter */
    00116       blkCnt--;
    00117     }
    00118
    00119     /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
    00120      ** No loop unrolling is used. */
    00121     blkCnt = numSamples % 0x4u;
    00122
    00123 #else
    00124
    00125     /* Run the below code for Cortex-M0 */
    00126
    00127     /* Initialize blkCnt with number of samples */
    00128     blkCnt = numSamples;
    00129
    00130 #endif /* #ifndef ARM_MATH_CM0 */
    00131
    00132     while(blkCnt > 0u)
    00133     {
    00134       /* C(m,n) = A(m,n) * k */
    00135       /* Scale, saturate and then store the results in the destination buffer. */
    00136       out = ((q63_t) * pIn++ * scaleFract) >> totShift;
    00137       *pOut++ = clip_q63_to_q31(out);
    00138
    00139       /* Decrement the numSamples loop counter */
    00140       blkCnt--;
    00141     }
    00142     /* Set status as ARM_MATH_SUCCESS */
    00143     status = ARM_MATH_SUCCESS;
    00144   }
    00145
    00146   /* Return to application */
    00147   return (status);
    00148 }
    00149

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines