CMSIS DSP Library from CMSIS 2.0. See http://www.onarm.com/cmsis/ for full details
Dependents: K22F_DSP_Matrix_least_square BNO055-ELEC3810 1BNO055 ECE4180Project--Slave2 ... more
arm_mat_scale_q31.c
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_mat_scale_q31.c 00009 * 00010 * Description: Multiplies a Q31 matrix by a scalar. 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 * Version 0.0.5 2010/04/26 00027 * incorporated review comments and updated with latest CMSIS layer 00028 * 00029 * Version 0.0.3 2010/03/10 00030 * Initial version 00031 * -------------------------------------------------------------------- */ 00032 00033 #include "arm_math.h" 00034 00035 /** 00036 * @ingroup groupMatrix 00037 */ 00038 00039 /** 00040 * @addtogroup MatrixScale 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief Q31 matrix scaling. 00046 * @param[in] *pSrc points to input matrix 00047 * @param[in] scaleFract fractional portion of the scale factor 00048 * @param[in] shift number of bits to shift the result by 00049 * @param[out] *pDst points to output matrix structure 00050 * @return The function returns either 00051 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. 00052 * 00053 * @details 00054 * <b>Scaling and Overflow Behavior:</b> 00055 * \par 00056 * The input data <code>*pSrc</code> and <code>scaleFract</code> are in 1.31 format. 00057 * These are multiplied to yield a 2.62 intermediate result and this is shifted with saturation to 1.31 format. 00058 */ 00059 00060 arm_status arm_mat_scale_q31( 00061 const arm_matrix_instance_q31 * pSrc, 00062 q31_t scaleFract, 00063 int32_t shift, 00064 arm_matrix_instance_q31 * pDst) 00065 { 00066 q31_t *pIn = pSrc->pData; /* input data matrix pointer */ 00067 q31_t *pOut = pDst->pData; /* output data matrix pointer */ 00068 q63_t out; /* temporary variable to hold output value */ 00069 uint32_t numSamples; /* total number of elements in the matrix */ 00070 int32_t totShift = 31 - shift; /* shift to apply after scaling */ 00071 uint32_t blkCnt; /* loop counters */ 00072 arm_status status; /* status of matrix scaling */ 00073 00074 #ifdef ARM_MATH_MATRIX_CHECK 00075 /* Check for matrix mismatch */ 00076 if((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols)) 00077 { 00078 /* Set status as ARM_MATH_SIZE_MISMATCH */ 00079 status = ARM_MATH_SIZE_MISMATCH; 00080 } 00081 else 00082 #endif 00083 { 00084 /* Total number of samples in the input matrix */ 00085 numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; 00086 00087 /* Loop Unrolling */ 00088 blkCnt = numSamples >> 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 /* C(m,n) = A(m,n) * k */ 00095 /* Scale, saturate and then store the results in the destination buffer. */ 00096 out = ((q63_t) * pIn++ * scaleFract) >> totShift; 00097 *pOut++ = clip_q63_to_q31(out); 00098 out = ((q63_t) * pIn++ * scaleFract) >> totShift; 00099 *pOut++ = clip_q63_to_q31(out); 00100 out = ((q63_t) * pIn++ * scaleFract) >> totShift; 00101 *pOut++ = clip_q63_to_q31(out); 00102 out = ((q63_t) * pIn++ * scaleFract) >> totShift; 00103 *pOut++ = clip_q63_to_q31(out); 00104 00105 /* Decrement the numSamples loop counter */ 00106 blkCnt--; 00107 } 00108 00109 /* If the numSamples is not a multiple of 4, compute any remaining output samples here. 00110 ** No loop unrolling is used. */ 00111 blkCnt = numSamples % 0x4u; 00112 00113 while(blkCnt > 0u) 00114 { 00115 /* C(m,n) = A(m,n) * k */ 00116 /* Scale, saturate and then store the results in the destination buffer. */ 00117 out = ((q63_t) * pIn++ * scaleFract) >> totShift; 00118 *pOut++ = clip_q63_to_q31(out); 00119 00120 /* Decrement the numSamples loop counter */ 00121 blkCnt--; 00122 } 00123 00124 /* Set status as ARM_MATH_SUCCESS */ 00125 status = ARM_MATH_SUCCESS; 00126 } 00127 00128 /* Return to application */ 00129 return (status); 00130 } 00131 00132 /** 00133 * @} end of MatrixScale group 00134 */
Generated on Tue Jul 12 2022 14:13:53 by 1.7.2