arm_scale_f32.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_scale_f32.c
  4. * Description: Multiplies a floating-point vector by a scalar
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  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
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  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.
  27. */
  28. #include "arm_math.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @defgroup BasicScale Vector Scale
  34. Multiply a vector by a scalar value. For floating-point data, the algorithm used is:
  35. <pre>
  36. pDst[n] = pSrc[n] * scale, 0 <= n < blockSize.
  37. </pre>
  38. In the fixed-point Q7, Q15, and Q31 functions, <code>scale</code> is represented by
  39. a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
  40. The shift allows the gain of the scaling operation to exceed 1.0.
  41. The algorithm used with fixed-point data is:
  42. <pre>
  43. pDst[n] = (pSrc[n] * scaleFract) << shift, 0 <= n < blockSize.
  44. </pre>
  45. The overall scale factor applied to the fixed-point data is
  46. <pre>
  47. scale = scaleFract * 2^shift.
  48. </pre>
  49. The functions support in-place computation allowing the source and destination
  50. pointers to reference the same memory buffer.
  51. */
  52. /**
  53. @addtogroup BasicScale
  54. @{
  55. */
  56. /**
  57. @brief Multiplies a floating-point vector by a scalar.
  58. @param[in] pSrc points to the input vector
  59. @param[in] scale scale factor to be applied
  60. @param[out] pDst points to the output vector
  61. @param[in] blockSize number of samples in each vector
  62. @return none
  63. */
  64. void arm_scale_f32(
  65. const float32_t *pSrc,
  66. float32_t scale,
  67. float32_t *pDst,
  68. uint32_t blockSize)
  69. {
  70. uint32_t blkCnt; /* Loop counter */
  71. #if defined (ARM_MATH_LOOPUNROLL)
  72. /* Loop unrolling: Compute 4 outputs at a time */
  73. blkCnt = blockSize >> 2U;
  74. while (blkCnt > 0U)
  75. {
  76. /* C = A * scale */
  77. /* Scale input and store result in destination buffer. */
  78. *pDst++ = (*pSrc++) * scale;
  79. *pDst++ = (*pSrc++) * scale;
  80. *pDst++ = (*pSrc++) * scale;
  81. *pDst++ = (*pSrc++) * scale;
  82. /* Decrement loop counter */
  83. blkCnt--;
  84. }
  85. /* Loop unrolling: Compute remaining outputs */
  86. blkCnt = blockSize % 0x4U;
  87. #else
  88. /* Initialize blkCnt with number of samples */
  89. blkCnt = blockSize;
  90. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  91. while (blkCnt > 0U)
  92. {
  93. /* C = A * scale */
  94. /* Scale input and store result in destination buffer. */
  95. *pDst++ = (*pSrc++) * scale;
  96. /* Decrement loop counter */
  97. blkCnt--;
  98. }
  99. }
  100. /**
  101. @} end of BasicScale group
  102. */