before merging master
[inav.git] / lib / main / CMSIS / DSP / Source / BasicMathFunctions / arm_scale_f32.c
blobc90c0378361f898938590276e7938d321294e5a2
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
7 * $Revision: V.1.5.1
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.
29 #include "arm_math.h"
31 /**
32 * @ingroup groupMath
35 /**
36 * @defgroup scale Vector Scale
38 * Multiply a vector by a scalar value. For floating-point data, the algorithm used is:
40 * <pre>
41 * pDst[n] = pSrc[n] * scale, 0 <= n < blockSize.
42 * </pre>
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:
49 * <pre>
50 * pDst[n] = (pSrc[n] * scaleFract) << shift, 0 <= n < blockSize.
51 * </pre>
53 * The overall scale factor applied to the fixed-point data is
54 * <pre>
55 * scale = scaleFract * 2^shift.
56 * </pre>
58 * The functions support in-place computation allowing the source and destination
59 * pointers to reference the same memory buffer.
62 /**
63 * @addtogroup scale
64 * @{
67 /**
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
73 * @return none.
77 void arm_scale_f32(
78 float32_t * pSrc,
79 float32_t scale,
80 float32_t * pDst,
81 uint32_t blockSize)
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 */
89 /*loop Unrolling */
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. */
94 while (blkCnt > 0U)
96 /* C = A * scale */
97 /* Scale the input and then store the results in the destination buffer. */
98 /* read input samples from source */
99 in1 = *pSrc;
100 in2 = *(pSrc + 1);
102 /* multiply with scaling factor */
103 in1 = in1 * scale;
105 /* read input sample from source */
106 in3 = *(pSrc + 2);
108 /* multiply with scaling factor */
109 in2 = in2 * scale;
111 /* read input sample from source */
112 in4 = *(pSrc + 3);
114 /* multiply with scaling factor */
115 in3 = in3 * scale;
116 in4 = in4 * scale;
117 /* store the result to destination */
118 *pDst = in1;
119 *(pDst + 1) = in2;
120 *(pDst + 2) = in3;
121 *(pDst + 3) = in4;
123 /* update pointers to process next samples */
124 pSrc += 4U;
125 pDst += 4U;
127 /* Decrement the loop counter */
128 blkCnt--;
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;
135 #else
137 /* Run the below code for Cortex-M0 */
139 /* Initialize blkCnt with number of samples */
140 blkCnt = blockSize;
142 #endif /* #if defined (ARM_MATH_DSP) */
144 while (blkCnt > 0U)
146 /* C = A * scale */
147 /* Scale the input and then store the result in the destination buffer. */
148 *pDst++ = (*pSrc++) * scale;
150 /* Decrement the loop counter */
151 blkCnt--;
156 * @} end of scale group