1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_quaternion_norm_f32.c
4  * Description:  Floating-point quaternion Norm
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 QuatNorm Quaternion Norm
38 
39   Compute the norm of a quaternion.
40  */
41 
42 /**
43   @addtogroup QuatNorm
44   @{
45  */
46 
47 /**
48   @brief         Floating-point quaternion Norm.
49   @param[in]     pInputQuaternions       points to the input vector of quaternions
50   @param[out]    pNorms                  points to the output vector of norms
51   @param[in]     nbQuaternions           number of quaternions in the input vector
52  */
53 
54 
55 #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
56 
57 #include "arm_helium_utils.h"
58 
arm_quaternion_norm_f32(const float32_t * pInputQuaternions,float32_t * pNorms,uint32_t nbQuaternions)59 ARM_DSP_ATTRIBUTE void arm_quaternion_norm_f32(const float32_t *pInputQuaternions,
60   float32_t *pNorms,
61   uint32_t nbQuaternions)
62 {
63   f32x4_t vec1;
64   float32_t squaredSum;
65 
66   for(uint32_t i=0; i < nbQuaternions; i++)
67   {
68        vec1 = vld1q(pInputQuaternions);
69        vec1 = vmulq(vec1,vec1);
70        squaredSum = vecAddAcrossF32Mve(vec1);
71        arm_sqrt_f32(squaredSum,pNorms);
72 
73        pInputQuaternions+= 4;
74        pNorms ++;
75   }
76 
77 }
78 
79 #else
80 
arm_quaternion_norm_f32(const float32_t * pInputQuaternions,float32_t * pNorms,uint32_t nbQuaternions)81 ARM_DSP_ATTRIBUTE void arm_quaternion_norm_f32(const float32_t *pInputQuaternions,
82   float32_t *pNorms,
83   uint32_t nbQuaternions)
84 {
85    float32_t temp;
86    uint32_t i;
87 
88    for(i=0; i < nbQuaternions; i++)
89    {
90       temp = ARM_SQ(pInputQuaternions[4 * i + 0]) +
91              ARM_SQ(pInputQuaternions[4 * i + 1]) +
92              ARM_SQ(pInputQuaternions[4 * i + 2]) +
93              ARM_SQ(pInputQuaternions[4 * i + 3]);
94       pNorms[i] = sqrtf(temp);
95    }
96 }
97 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
98 
99 /**
100   @} end of QuatNorm group
101  */
102