1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_scale_f32.c
4 * Description: Multiplies a floating-point vector by a scalar
6 * $Date: 27. January 2017
9 * Target Processor: Cortex-M cores
10 * -------------------------------------------------------------------- */
12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
14 * SPDX-License-Identifier: Apache-2.0
16 * Licensed under the Apache License, Version 2.0 (the License); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
20 * www.apache.org/licenses/LICENSE-2.0
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
36 * @defgroup scale Vector Scale
38 * Multiply a vector by a scalar value. For floating-point data, the algorithm used is:
41 * pDst[n] = pSrc[n] * scale, 0 <= n < blockSize.
44 * In the fixed-point Q7, Q15, and Q31 functions, <code>scale</code> is represented by
45 * a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
46 * The shift allows the gain of the scaling operation to exceed 1.0.
47 * The algorithm used with fixed-point data is:
50 * pDst[n] = (pSrc[n] * scaleFract) << shift, 0 <= n < blockSize.
53 * The overall scale factor applied to the fixed-point data is
55 * scale = scaleFract * 2^shift.
58 * The functions support in-place computation allowing the source and destination
59 * pointers to reference the same memory buffer.
68 * @brief Multiplies a floating-point vector by a scalar.
69 * @param[in] *pSrc points to the input vector
70 * @param[in] scale scale factor to be applied
71 * @param[out] *pDst points to the output vector
72 * @param[in] blockSize number of samples in the vector
83 uint32_t blkCnt
; /* loop counter */
84 #if defined (ARM_MATH_DSP)
86 /* Run the below code for Cortex-M4 and Cortex-M3 */
87 float32_t in1
, in2
, in3
, in4
; /* temporary variabels */
90 blkCnt
= blockSize
>> 2U;
92 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
93 ** a second loop below computes the remaining 1 to 3 samples. */
97 /* Scale the input and then store the results in the destination buffer. */
98 /* read input samples from source */
102 /* multiply with scaling factor */
105 /* read input sample from source */
108 /* multiply with scaling factor */
111 /* read input sample from source */
114 /* multiply with scaling factor */
117 /* store the result to destination */
123 /* update pointers to process next samples */
127 /* Decrement the loop counter */
131 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
132 ** No loop unrolling is used. */
133 blkCnt
= blockSize
% 0x4U
;
137 /* Run the below code for Cortex-M0 */
139 /* Initialize blkCnt with number of samples */
142 #endif /* #if defined (ARM_MATH_DSP) */
147 /* Scale the input and then store the result in the destination buffer. */
148 *pDst
++ = (*pSrc
++) * scale
;
150 /* Decrement the loop counter */
156 * @} end of scale group