1 /* ----------------------------------------------------------------------
2 * Project: CMSIS DSP Library
3 * Title: arm_quaternion_inverse_f32.c
4 * Description: Floating-point quaternion inverse
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
29 #include "dsp/quaternion_math_functions.h"
30 #include <math.h>
31
32 /**
33 @ingroup groupQuaternionMath
34 */
35
36 /**
37 @defgroup QuatInverse Quaternion Inverse
38
39 Compute the inverse of a quaternion.
40 */
41
42 /**
43 @addtogroup QuatInverse
44 @{
45 */
46
47 /**
48 @brief Floating-point quaternion inverse.
49 @param[in] pInputQuaternions points to the input vector of quaternions
50 @param[out] pInverseQuaternions points to the output vector of inverse quaternions
51 @param[in] nbQuaternions number of quaternions in each vector
52 @return none
53 */
54
55
56 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
57
58 #include "arm_helium_utils.h"
59
arm_quaternion_inverse_f32(const float32_t * pInputQuaternions,float32_t * pInverseQuaternions,uint32_t nbQuaternions)60 void arm_quaternion_inverse_f32(const float32_t *pInputQuaternions,
61 float32_t *pInverseQuaternions,
62 uint32_t nbQuaternions)
63 {
64 f32x4_t vec1,vec2;
65 float32_t squaredSum;
66
67 for(uint32_t i=0; i < nbQuaternions; i++)
68 {
69
70 vec1 = vld1q(pInputQuaternions);
71 vec2 = vmulq(vec1,vec1);
72 squaredSum = vecAddAcrossF32Mve(vec2);
73
74
75 vec1 = vmulq_n_f32(vec1, 1.0f / squaredSum);
76 vec1 = vsetq_lane_f32(-vgetq_lane(vec1, 0),vec1,0);
77 vec1 = vnegq_f32(vec1);
78
79 vst1q(pInverseQuaternions, vec1);
80
81
82 pInputQuaternions += 4;
83 pInverseQuaternions += 4;
84
85 }
86 }
87
88 #else
arm_quaternion_inverse_f32(const float32_t * pInputQuaternions,float32_t * pInverseQuaternions,uint32_t nbQuaternions)89 void arm_quaternion_inverse_f32(const float32_t *pInputQuaternions,
90 float32_t *pInverseQuaternions,
91 uint32_t nbQuaternions)
92 {
93 float32_t temp;
94
95 for(uint32_t i=0; i < nbQuaternions; i++)
96 {
97
98 temp = SQ(pInputQuaternions[4 * i + 0]) +
99 SQ(pInputQuaternions[4 * i + 1]) +
100 SQ(pInputQuaternions[4 * i + 2]) +
101 SQ(pInputQuaternions[4 * i + 3]);
102
103 pInverseQuaternions[4 * i + 0] = pInputQuaternions[4 * i + 0] / temp;
104 pInverseQuaternions[4 * i + 1] = -pInputQuaternions[4 * i + 1] / temp;
105 pInverseQuaternions[4 * i + 2] = -pInputQuaternions[4 * i + 2] / temp;
106 pInverseQuaternions[4 * i + 3] = -pInputQuaternions[4 * i + 3] / temp;
107 }
108 }
109 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
110
111 /**
112 @} end of QuatInverse group
113 */
114