arm_scale_f16.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_scale_f16.c
  4. * Description: Multiplies a floating-point vector by a scalar
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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 "dsp/basic_math_functions_f16.h"
  29. /**
  30. @ingroup groupMath
  31. */
  32. /**
  33. @addtogroup BasicScale
  34. @{
  35. */
  36. /**
  37. @brief Multiplies a floating-point vector by a scalar.
  38. @param[in] pSrc points to the input vector
  39. @param[in] scale scale factor to be applied
  40. @param[out] pDst points to the output vector
  41. @param[in] blockSize number of samples in each vector
  42. */
  43. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  44. #include "arm_helium_utils.h"
  45. void arm_scale_f16(
  46. const float16_t * pSrc,
  47. float16_t scale,
  48. float16_t * pDst,
  49. uint32_t blockSize)
  50. {
  51. uint32_t blkCnt; /* Loop counter */
  52. f16x8_t vec1;
  53. f16x8_t res;
  54. /* Compute 4 outputs at a time */
  55. blkCnt = blockSize >> 3U;
  56. while (blkCnt > 0U)
  57. {
  58. /* C = A + offset */
  59. /* Add offset and then store the results in the destination buffer. */
  60. vec1 = vld1q(pSrc);
  61. res = vmulq(vec1,scale);
  62. vst1q(pDst, res);
  63. /* Increment pointers */
  64. pSrc += 8;
  65. pDst += 8;
  66. /* Decrement the loop counter */
  67. blkCnt--;
  68. }
  69. /* Tail */
  70. blkCnt = blockSize & 0x7;
  71. if (blkCnt > 0U)
  72. {
  73. mve_pred16_t p0 = vctp16q(blkCnt);
  74. vec1 = vld1q((float16_t const *) pSrc);
  75. vstrhq_p(pDst, vmulq(vec1, scale), p0);
  76. }
  77. }
  78. #else
  79. #if defined(ARM_FLOAT16_SUPPORTED)
  80. void arm_scale_f16(
  81. const float16_t *pSrc,
  82. float16_t scale,
  83. float16_t *pDst,
  84. uint32_t blockSize)
  85. {
  86. uint32_t blkCnt; /* Loop counter */
  87. #if defined (ARM_MATH_LOOPUNROLL)
  88. /* Loop unrolling: Compute 4 outputs at a time */
  89. blkCnt = blockSize >> 2U;
  90. while (blkCnt > 0U)
  91. {
  92. /* C = A * scale */
  93. /* Scale input and store result in destination buffer. */
  94. *pDst++ = (_Float16)(*pSrc++) * (_Float16)scale;
  95. *pDst++ = (_Float16)(*pSrc++) * (_Float16)scale;
  96. *pDst++ = (_Float16)(*pSrc++) * (_Float16)scale;
  97. *pDst++ = (_Float16)(*pSrc++) * (_Float16)scale;
  98. /* Decrement loop counter */
  99. blkCnt--;
  100. }
  101. /* Loop unrolling: Compute remaining outputs */
  102. blkCnt = blockSize % 0x4U;
  103. #else
  104. /* Initialize blkCnt with number of samples */
  105. blkCnt = blockSize;
  106. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  107. while (blkCnt > 0U)
  108. {
  109. /* C = A * scale */
  110. /* Scale input and store result in destination buffer. */
  111. *pDst++ = (_Float16)(*pSrc++) * (_Float16)scale;
  112. /* Decrement loop counter */
  113. blkCnt--;
  114. }
  115. }
  116. #endif
  117. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  118. /**
  119. @} end of BasicScale group
  120. */