Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DSP/source/MatrixFunctions/arm_mat_scale_f32.c@0:eedb7d567a5d, 2018-04-12 (annotated)
- Committer:
- robert_lp
- Date:
- Thu Apr 12 01:31:58 2018 +0000
- Revision:
- 0:eedb7d567a5d
CMSIS5 Library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| robert_lp | 0:eedb7d567a5d | 1 | /* ---------------------------------------------------------------------- |
| robert_lp | 0:eedb7d567a5d | 2 | * Project: CMSIS DSP Library |
| robert_lp | 0:eedb7d567a5d | 3 | * Title: arm_mat_scale_f32.c |
| robert_lp | 0:eedb7d567a5d | 4 | * Description: Multiplies a floating-point matrix by a scalar |
| robert_lp | 0:eedb7d567a5d | 5 | * |
| robert_lp | 0:eedb7d567a5d | 6 | * $Date: 27. January 2017 |
| robert_lp | 0:eedb7d567a5d | 7 | * $Revision: V.1.5.1 |
| robert_lp | 0:eedb7d567a5d | 8 | * |
| robert_lp | 0:eedb7d567a5d | 9 | * Target Processor: Cortex-M cores |
| robert_lp | 0:eedb7d567a5d | 10 | * -------------------------------------------------------------------- */ |
| robert_lp | 0:eedb7d567a5d | 11 | /* |
| robert_lp | 0:eedb7d567a5d | 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
| robert_lp | 0:eedb7d567a5d | 13 | * |
| robert_lp | 0:eedb7d567a5d | 14 | * SPDX-License-Identifier: Apache-2.0 |
| robert_lp | 0:eedb7d567a5d | 15 | * |
| robert_lp | 0:eedb7d567a5d | 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| robert_lp | 0:eedb7d567a5d | 17 | * not use this file except in compliance with the License. |
| robert_lp | 0:eedb7d567a5d | 18 | * You may obtain a copy of the License at |
| robert_lp | 0:eedb7d567a5d | 19 | * |
| robert_lp | 0:eedb7d567a5d | 20 | * www.apache.org/licenses/LICENSE-2.0 |
| robert_lp | 0:eedb7d567a5d | 21 | * |
| robert_lp | 0:eedb7d567a5d | 22 | * Unless required by applicable law or agreed to in writing, software |
| robert_lp | 0:eedb7d567a5d | 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| robert_lp | 0:eedb7d567a5d | 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| robert_lp | 0:eedb7d567a5d | 25 | * See the License for the specific language governing permissions and |
| robert_lp | 0:eedb7d567a5d | 26 | * limitations under the License. |
| robert_lp | 0:eedb7d567a5d | 27 | */ |
| robert_lp | 0:eedb7d567a5d | 28 | |
| robert_lp | 0:eedb7d567a5d | 29 | #include "arm_math.h" |
| robert_lp | 0:eedb7d567a5d | 30 | |
| robert_lp | 0:eedb7d567a5d | 31 | /** |
| robert_lp | 0:eedb7d567a5d | 32 | * @ingroup groupMatrix |
| robert_lp | 0:eedb7d567a5d | 33 | */ |
| robert_lp | 0:eedb7d567a5d | 34 | |
| robert_lp | 0:eedb7d567a5d | 35 | /** |
| robert_lp | 0:eedb7d567a5d | 36 | * @defgroup MatrixScale Matrix Scale |
| robert_lp | 0:eedb7d567a5d | 37 | * |
| robert_lp | 0:eedb7d567a5d | 38 | * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the |
| robert_lp | 0:eedb7d567a5d | 39 | * matrix by the scalar. For example: |
| robert_lp | 0:eedb7d567a5d | 40 | * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix" |
| robert_lp | 0:eedb7d567a5d | 41 | * |
| robert_lp | 0:eedb7d567a5d | 42 | * The function checks to make sure that the input and output matrices are of the same size. |
| robert_lp | 0:eedb7d567a5d | 43 | * |
| robert_lp | 0:eedb7d567a5d | 44 | * In the fixed-point Q15 and Q31 functions, <code>scale</code> is represented by |
| robert_lp | 0:eedb7d567a5d | 45 | * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>. |
| robert_lp | 0:eedb7d567a5d | 46 | * The shift allows the gain of the scaling operation to exceed 1.0. |
| robert_lp | 0:eedb7d567a5d | 47 | * The overall scale factor applied to the fixed-point data is |
| robert_lp | 0:eedb7d567a5d | 48 | * <pre> |
| robert_lp | 0:eedb7d567a5d | 49 | * scale = scaleFract * 2^shift. |
| robert_lp | 0:eedb7d567a5d | 50 | * </pre> |
| robert_lp | 0:eedb7d567a5d | 51 | */ |
| robert_lp | 0:eedb7d567a5d | 52 | |
| robert_lp | 0:eedb7d567a5d | 53 | /** |
| robert_lp | 0:eedb7d567a5d | 54 | * @addtogroup MatrixScale |
| robert_lp | 0:eedb7d567a5d | 55 | * @{ |
| robert_lp | 0:eedb7d567a5d | 56 | */ |
| robert_lp | 0:eedb7d567a5d | 57 | |
| robert_lp | 0:eedb7d567a5d | 58 | /** |
| robert_lp | 0:eedb7d567a5d | 59 | * @brief Floating-point matrix scaling. |
| robert_lp | 0:eedb7d567a5d | 60 | * @param[in] *pSrc points to input matrix structure |
| robert_lp | 0:eedb7d567a5d | 61 | * @param[in] scale scale factor to be applied |
| robert_lp | 0:eedb7d567a5d | 62 | * @param[out] *pDst points to output matrix structure |
| robert_lp | 0:eedb7d567a5d | 63 | * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> |
| robert_lp | 0:eedb7d567a5d | 64 | * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. |
| robert_lp | 0:eedb7d567a5d | 65 | * |
| robert_lp | 0:eedb7d567a5d | 66 | */ |
| robert_lp | 0:eedb7d567a5d | 67 | |
| robert_lp | 0:eedb7d567a5d | 68 | arm_status arm_mat_scale_f32( |
| robert_lp | 0:eedb7d567a5d | 69 | const arm_matrix_instance_f32 * pSrc, |
| robert_lp | 0:eedb7d567a5d | 70 | float32_t scale, |
| robert_lp | 0:eedb7d567a5d | 71 | arm_matrix_instance_f32 * pDst) |
| robert_lp | 0:eedb7d567a5d | 72 | { |
| robert_lp | 0:eedb7d567a5d | 73 | float32_t *pIn = pSrc->pData; /* input data matrix pointer */ |
| robert_lp | 0:eedb7d567a5d | 74 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ |
| robert_lp | 0:eedb7d567a5d | 75 | uint32_t numSamples; /* total number of elements in the matrix */ |
| robert_lp | 0:eedb7d567a5d | 76 | uint32_t blkCnt; /* loop counters */ |
| robert_lp | 0:eedb7d567a5d | 77 | arm_status status; /* status of matrix scaling */ |
| robert_lp | 0:eedb7d567a5d | 78 | |
| robert_lp | 0:eedb7d567a5d | 79 | #if defined (ARM_MATH_DSP) |
| robert_lp | 0:eedb7d567a5d | 80 | |
| robert_lp | 0:eedb7d567a5d | 81 | float32_t in1, in2, in3, in4; /* temporary variables */ |
| robert_lp | 0:eedb7d567a5d | 82 | float32_t out1, out2, out3, out4; /* temporary variables */ |
| robert_lp | 0:eedb7d567a5d | 83 | |
| robert_lp | 0:eedb7d567a5d | 84 | #endif // #if defined (ARM_MATH_DSP) |
| robert_lp | 0:eedb7d567a5d | 85 | |
| robert_lp | 0:eedb7d567a5d | 86 | #ifdef ARM_MATH_MATRIX_CHECK |
| robert_lp | 0:eedb7d567a5d | 87 | /* Check for matrix mismatch condition */ |
| robert_lp | 0:eedb7d567a5d | 88 | if ((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols)) |
| robert_lp | 0:eedb7d567a5d | 89 | { |
| robert_lp | 0:eedb7d567a5d | 90 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
| robert_lp | 0:eedb7d567a5d | 91 | status = ARM_MATH_SIZE_MISMATCH; |
| robert_lp | 0:eedb7d567a5d | 92 | } |
| robert_lp | 0:eedb7d567a5d | 93 | else |
| robert_lp | 0:eedb7d567a5d | 94 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
| robert_lp | 0:eedb7d567a5d | 95 | { |
| robert_lp | 0:eedb7d567a5d | 96 | /* Total number of samples in the input matrix */ |
| robert_lp | 0:eedb7d567a5d | 97 | numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; |
| robert_lp | 0:eedb7d567a5d | 98 | |
| robert_lp | 0:eedb7d567a5d | 99 | #if defined (ARM_MATH_DSP) |
| robert_lp | 0:eedb7d567a5d | 100 | |
| robert_lp | 0:eedb7d567a5d | 101 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
| robert_lp | 0:eedb7d567a5d | 102 | |
| robert_lp | 0:eedb7d567a5d | 103 | /* Loop Unrolling */ |
| robert_lp | 0:eedb7d567a5d | 104 | blkCnt = numSamples >> 2; |
| robert_lp | 0:eedb7d567a5d | 105 | |
| robert_lp | 0:eedb7d567a5d | 106 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
| robert_lp | 0:eedb7d567a5d | 107 | ** a second loop below computes the remaining 1 to 3 samples. */ |
| robert_lp | 0:eedb7d567a5d | 108 | while (blkCnt > 0U) |
| robert_lp | 0:eedb7d567a5d | 109 | { |
| robert_lp | 0:eedb7d567a5d | 110 | /* C(m,n) = A(m,n) * scale */ |
| robert_lp | 0:eedb7d567a5d | 111 | /* Scaling and results are stored in the destination buffer. */ |
| robert_lp | 0:eedb7d567a5d | 112 | in1 = pIn[0]; |
| robert_lp | 0:eedb7d567a5d | 113 | in2 = pIn[1]; |
| robert_lp | 0:eedb7d567a5d | 114 | in3 = pIn[2]; |
| robert_lp | 0:eedb7d567a5d | 115 | in4 = pIn[3]; |
| robert_lp | 0:eedb7d567a5d | 116 | |
| robert_lp | 0:eedb7d567a5d | 117 | out1 = in1 * scale; |
| robert_lp | 0:eedb7d567a5d | 118 | out2 = in2 * scale; |
| robert_lp | 0:eedb7d567a5d | 119 | out3 = in3 * scale; |
| robert_lp | 0:eedb7d567a5d | 120 | out4 = in4 * scale; |
| robert_lp | 0:eedb7d567a5d | 121 | |
| robert_lp | 0:eedb7d567a5d | 122 | |
| robert_lp | 0:eedb7d567a5d | 123 | pOut[0] = out1; |
| robert_lp | 0:eedb7d567a5d | 124 | pOut[1] = out2; |
| robert_lp | 0:eedb7d567a5d | 125 | pOut[2] = out3; |
| robert_lp | 0:eedb7d567a5d | 126 | pOut[3] = out4; |
| robert_lp | 0:eedb7d567a5d | 127 | |
| robert_lp | 0:eedb7d567a5d | 128 | /* update pointers to process next sampels */ |
| robert_lp | 0:eedb7d567a5d | 129 | pIn += 4U; |
| robert_lp | 0:eedb7d567a5d | 130 | pOut += 4U; |
| robert_lp | 0:eedb7d567a5d | 131 | |
| robert_lp | 0:eedb7d567a5d | 132 | /* Decrement the numSamples loop counter */ |
| robert_lp | 0:eedb7d567a5d | 133 | blkCnt--; |
| robert_lp | 0:eedb7d567a5d | 134 | } |
| robert_lp | 0:eedb7d567a5d | 135 | |
| robert_lp | 0:eedb7d567a5d | 136 | /* If the numSamples is not a multiple of 4, compute any remaining output samples here. |
| robert_lp | 0:eedb7d567a5d | 137 | ** No loop unrolling is used. */ |
| robert_lp | 0:eedb7d567a5d | 138 | blkCnt = numSamples % 0x4U; |
| robert_lp | 0:eedb7d567a5d | 139 | |
| robert_lp | 0:eedb7d567a5d | 140 | #else |
| robert_lp | 0:eedb7d567a5d | 141 | |
| robert_lp | 0:eedb7d567a5d | 142 | /* Run the below code for Cortex-M0 */ |
| robert_lp | 0:eedb7d567a5d | 143 | |
| robert_lp | 0:eedb7d567a5d | 144 | /* Initialize blkCnt with number of samples */ |
| robert_lp | 0:eedb7d567a5d | 145 | blkCnt = numSamples; |
| robert_lp | 0:eedb7d567a5d | 146 | |
| robert_lp | 0:eedb7d567a5d | 147 | #endif /* #if defined (ARM_MATH_DSP) */ |
| robert_lp | 0:eedb7d567a5d | 148 | |
| robert_lp | 0:eedb7d567a5d | 149 | while (blkCnt > 0U) |
| robert_lp | 0:eedb7d567a5d | 150 | { |
| robert_lp | 0:eedb7d567a5d | 151 | /* C(m,n) = A(m,n) * scale */ |
| robert_lp | 0:eedb7d567a5d | 152 | /* The results are stored in the destination buffer. */ |
| robert_lp | 0:eedb7d567a5d | 153 | *pOut++ = (*pIn++) * scale; |
| robert_lp | 0:eedb7d567a5d | 154 | |
| robert_lp | 0:eedb7d567a5d | 155 | /* Decrement the loop counter */ |
| robert_lp | 0:eedb7d567a5d | 156 | blkCnt--; |
| robert_lp | 0:eedb7d567a5d | 157 | } |
| robert_lp | 0:eedb7d567a5d | 158 | |
| robert_lp | 0:eedb7d567a5d | 159 | /* Set status as ARM_MATH_SUCCESS */ |
| robert_lp | 0:eedb7d567a5d | 160 | status = ARM_MATH_SUCCESS; |
| robert_lp | 0:eedb7d567a5d | 161 | } |
| robert_lp | 0:eedb7d567a5d | 162 | |
| robert_lp | 0:eedb7d567a5d | 163 | /* Return to application */ |
| robert_lp | 0:eedb7d567a5d | 164 | return (status); |
| robert_lp | 0:eedb7d567a5d | 165 | } |
| robert_lp | 0:eedb7d567a5d | 166 | |
| robert_lp | 0:eedb7d567a5d | 167 | /** |
| robert_lp | 0:eedb7d567a5d | 168 | * @} end of MatrixScale group |
| robert_lp | 0:eedb7d567a5d | 169 | */ |
| robert_lp | 0:eedb7d567a5d | 170 |