arm_negate_f32.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_negate_f32.c
  4. * Description: Negates floating-point vectors
  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 negate Vector Negate
  34. *
  35. * Negates the elements of a vector.
  36. *
  37. * <pre>
  38. * pDst[n] = -pSrc[n], 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 negate
  47. * @{
  48. */
  49. /**
  50. * @brief Negates the elements of a floating-point vector.
  51. * @param[in] *pSrc points to the input vector
  52. * @param[out] *pDst points to the output vector
  53. * @param[in] blockSize number of samples in the vector
  54. * @return none.
  55. */
  56. void arm_negate_f32(
  57. float32_t * pSrc,
  58. float32_t * pDst,
  59. uint32_t blockSize)
  60. {
  61. uint32_t blkCnt; /* loop counter */
  62. #if defined (ARM_MATH_DSP)
  63. /* Run the below code for Cortex-M4 and Cortex-M3 */
  64. float32_t in1, in2, in3, in4; /* temporary variables */
  65. /*loop Unrolling */
  66. blkCnt = blockSize >> 2U;
  67. /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
  68. ** a second loop below computes the remaining 1 to 3 samples. */
  69. while (blkCnt > 0U)
  70. {
  71. /* read inputs from source */
  72. in1 = *pSrc;
  73. in2 = *(pSrc + 1);
  74. in3 = *(pSrc + 2);
  75. in4 = *(pSrc + 3);
  76. /* negate the input */
  77. in1 = -in1;
  78. in2 = -in2;
  79. in3 = -in3;
  80. in4 = -in4;
  81. /* store the result to destination */
  82. *pDst = in1;
  83. *(pDst + 1) = in2;
  84. *(pDst + 2) = in3;
  85. *(pDst + 3) = in4;
  86. /* update pointers to process next samples */
  87. pSrc += 4U;
  88. pDst += 4U;
  89. /* Decrement the loop counter */
  90. blkCnt--;
  91. }
  92. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  93. ** No loop unrolling is used. */
  94. blkCnt = blockSize % 0x4U;
  95. #else
  96. /* Run the below code for Cortex-M0 */
  97. /* Initialize blkCnt with number of samples */
  98. blkCnt = blockSize;
  99. #endif /* #if defined (ARM_MATH_DSP) */
  100. while (blkCnt > 0U)
  101. {
  102. /* C = -A */
  103. /* Negate and then store the results in the destination buffer. */
  104. *pDst++ = -*pSrc++;
  105. /* Decrement the loop counter */
  106. blkCnt--;
  107. }
  108. }
  109. /**
  110. * @} end of negate group
  111. */