arm_offset_f32.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_offset_f32.c
  4. * Description: Floating-point vector offset
  5. *
  6. * $Date: 27. January 2017
  7. * $Revision: V.1.5.1
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2017 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 offset Vector Offset
  34. *
  35. * Adds a constant offset to each element of a vector.
  36. *
  37. * <pre>
  38. * pDst[n] = pSrc[n] + offset, 0 <= n < blockSize.
  39. * </pre>
  40. *
  41. * The functions support in-place computation allowing the source and
  42. * destination pointers to reference the same memory buffer.
  43. * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
  44. */
  45. /**
  46. * @addtogroup offset
  47. * @{
  48. */
  49. /**
  50. * @brief Adds a constant offset to a floating-point vector.
  51. * @param[in] *pSrc points to the input vector
  52. * @param[in] offset is the offset to be added
  53. * @param[out] *pDst points to the output vector
  54. * @param[in] blockSize number of samples in the vector
  55. * @return none.
  56. */
  57. void arm_offset_f32(
  58. float32_t * pSrc,
  59. float32_t offset,
  60. float32_t * pDst,
  61. uint32_t blockSize)
  62. {
  63. uint32_t blkCnt; /* loop counter */
  64. #if defined (ARM_MATH_DSP)
  65. /* Run the below code for Cortex-M4 and Cortex-M3 */
  66. float32_t in1, in2, in3, in4;
  67. /*loop Unrolling */
  68. blkCnt = blockSize >> 2U;
  69. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  70. ** a second loop below computes the remaining 1 to 3 samples. */
  71. while (blkCnt > 0U)
  72. {
  73. /* C = A + offset */
  74. /* Add offset and then store the results in the destination buffer. */
  75. /* read samples from source */
  76. in1 = *pSrc;
  77. in2 = *(pSrc + 1);
  78. /* add offset to input */
  79. in1 = in1 + offset;
  80. /* read samples from source */
  81. in3 = *(pSrc + 2);
  82. /* add offset to input */
  83. in2 = in2 + offset;
  84. /* read samples from source */
  85. in4 = *(pSrc + 3);
  86. /* add offset to input */
  87. in3 = in3 + offset;
  88. /* store result to destination */
  89. *pDst = in1;
  90. /* add offset to input */
  91. in4 = in4 + offset;
  92. /* store result to destination */
  93. *(pDst + 1) = in2;
  94. /* store result to destination */
  95. *(pDst + 2) = in3;
  96. /* store result to destination */
  97. *(pDst + 3) = in4;
  98. /* update pointers to process next samples */
  99. pSrc += 4U;
  100. pDst += 4U;
  101. /* Decrement the loop counter */
  102. blkCnt--;
  103. }
  104. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  105. ** No loop unrolling is used. */
  106. blkCnt = blockSize % 0x4U;
  107. #else
  108. /* Run the below code for Cortex-M0 */
  109. /* Initialize blkCnt with number of samples */
  110. blkCnt = blockSize;
  111. #endif /* #if defined (ARM_MATH_DSP) */
  112. while (blkCnt > 0U)
  113. {
  114. /* C = A + offset */
  115. /* Add offset and then store the result in the destination buffer. */
  116. *pDst++ = (*pSrc++) + offset;
  117. /* Decrement the loop counter */
  118. blkCnt--;
  119. }
  120. }
  121. /**
  122. * @} end of offset group
  123. */