arm_quaternion_conjugate_f32.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. uint32_t i;
  71. for(i=0; i < nbQuaternions; i++)
  72. {
  73. pConjugateQuaternions[4 * i + 0] = pInputQuaternions[4 * i + 0];
  74. pConjugateQuaternions[4 * i + 1] = -pInputQuaternions[4 * i + 1];
  75. pConjugateQuaternions[4 * i + 2] = -pInputQuaternions[4 * i + 2];
  76. pConjugateQuaternions[4 * i + 3] = -pInputQuaternions[4 * i + 3];
  77. }
  78. }
  79. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  80. /**
  81. @} end of QuatConjugate group
  82. */