arm_quaternion_conjugate_f32.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_quaternion_conjugate_f32.c
  4. * Description: Floating-point quaternion conjugate
  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/quaternion_math_functions.h"
  29. #include <math.h>
  30. /**
  31. @ingroup groupQuaternionMath
  32. */
  33. /**
  34. @defgroup QuatConjugate Quaternion Conjugate
  35. Compute the conjugate of a quaternion.
  36. */
  37. /**
  38. @addtogroup QuatConjugate
  39. @{
  40. */
  41. /**
  42. @brief Floating-point quaternion conjugates.
  43. @param[in] pInputQuaternions points to the input vector of quaternions
  44. @param[out] pConjugateQuaternions points to the output vector of conjugate quaternions
  45. @param[in] nbQuaternions number of quaternions in each vector
  46. @return none
  47. */
  48. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  49. #include "arm_helium_utils.h"
  50. void arm_quaternion_conjugate_f32(const float32_t *pInputQuaternions,
  51. float32_t *pConjugateQuaternions,
  52. uint32_t nbQuaternions)
  53. {
  54. f32x4_t vec1;
  55. for(uint32_t i=0; i < nbQuaternions; i++)
  56. {
  57. vec1 = vld1q(pInputQuaternions);
  58. vec1 = vsetq_lane_f32(-vgetq_lane(vec1, 0),vec1,0);
  59. vec1 = vnegq_f32(vec1);
  60. vst1q(pConjugateQuaternions, vec1);
  61. pInputQuaternions += 4;
  62. pConjugateQuaternions += 4;
  63. }
  64. }
  65. #else
  66. void arm_quaternion_conjugate_f32(const float32_t *pInputQuaternions,
  67. float32_t *pConjugateQuaternions,
  68. uint32_t nbQuaternions)
  69. {
  70. for(uint32_t i=0; i < nbQuaternions; i++)
  71. {
  72. pConjugateQuaternions[4 * i + 0] = pInputQuaternions[4 * i + 0];
  73. pConjugateQuaternions[4 * i + 1] = -pInputQuaternions[4 * i + 1];
  74. pConjugateQuaternions[4 * i + 2] = -pInputQuaternions[4 * i + 2];
  75. pConjugateQuaternions[4 * i + 3] = -pInputQuaternions[4 * i + 3];
  76. }
  77. }
  78. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  79. /**
  80. @} end of QuatConjugate group
  81. */