arm_negate_q31.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_negate_q31.c
  4. * Description: Negates Q31 vectors
  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. @addtogroup BasicNegate
  34. @{
  35. */
  36. /**
  37. @brief Negates the elements of a Q31 vector.
  38. @param[in] pSrc points to the input vector.
  39. @param[out] pDst points to the output vector.
  40. @param[in] blockSize number of samples in each vector.
  41. @return none
  42. @par Scaling and Overflow Behavior
  43. The function uses saturating arithmetic.
  44. The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
  45. */
  46. void arm_negate_q31(
  47. const q31_t * pSrc,
  48. q31_t * pDst,
  49. uint32_t blockSize)
  50. {
  51. uint32_t blkCnt; /* Loop counter */
  52. q31_t in; /* Temporary input variable */
  53. #if defined (ARM_MATH_LOOPUNROLL)
  54. /* Loop unrolling: Compute 4 outputs at a time */
  55. blkCnt = blockSize >> 2U;
  56. while (blkCnt > 0U)
  57. {
  58. /* C = -A */
  59. /* Negate and store result in destination buffer. */
  60. in = *pSrc++;
  61. #if defined (ARM_MATH_DSP)
  62. *pDst++ = __QSUB(0, in);
  63. #else
  64. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  65. #endif
  66. in = *pSrc++;
  67. #if defined (ARM_MATH_DSP)
  68. *pDst++ = __QSUB(0, in);
  69. #else
  70. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  71. #endif
  72. in = *pSrc++;
  73. #if defined (ARM_MATH_DSP)
  74. *pDst++ = __QSUB(0, in);
  75. #else
  76. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  77. #endif
  78. in = *pSrc++;
  79. #if defined (ARM_MATH_DSP)
  80. *pDst++ = __QSUB(0, in);
  81. #else
  82. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  83. #endif
  84. /* Decrement loop counter */
  85. blkCnt--;
  86. }
  87. /* Loop unrolling: Compute remaining outputs */
  88. blkCnt = blockSize % 0x4U;
  89. #else
  90. /* Initialize blkCnt with number of samples */
  91. blkCnt = blockSize;
  92. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  93. while (blkCnt > 0U)
  94. {
  95. /* C = -A */
  96. /* Negate and store result in destination buffer. */
  97. in = *pSrc++;
  98. #if defined (ARM_MATH_DSP)
  99. *pDst++ = __QSUB(0, in);
  100. #else
  101. *pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
  102. #endif
  103. /* Decrement loop counter */
  104. blkCnt--;
  105. }
  106. }
  107. /**
  108. @} end of BasicNegate group
  109. */