diff --git a/Fusion/FusionConfig.h b/Fusion/FusionConfig.h new file mode 100644 index 0000000..4f0304a --- /dev/null +++ b/Fusion/FusionConfig.h @@ -0,0 +1,28 @@ +/** + * @file FusionConfig.h + * @author Seb Madgwick + * @brief Library configuration. + */ + +#ifndef FUSION_CONFIG_H +#define FUSION_CONFIG_H + +//------------------------------------------------------------------------------ +// Definitions + +/** + * @brief Uncomment this definition or add as a preprocessor definition to use + * normal square root operations. + */ +//#define FUSION_USE_NORMAL_SQRT + +/** + * @brief Uncomment this definition or add as a preprocessor definition to + * disable inline functions. + */ +//#define FUSION_NO_INLINE + +#endif + +//------------------------------------------------------------------------------ +// End of file diff --git a/Fusion/FusionInline.h b/Fusion/FusionInline.h index e52c114..0a51e4f 100644 --- a/Fusion/FusionInline.h +++ b/Fusion/FusionInline.h @@ -7,10 +7,17 @@ #ifndef FUSION_INLINE_H #define FUSION_INLINE_H +//------------------------------------------------------------------------------ +// Includes + +#include "FusionConfig.h" + //------------------------------------------------------------------------------ // Definitions -#if defined _MSC_VER +#if defined FUSION_NO_INLINE +#define FUSION_INLINE inline +#elif defined _MSC_VER #define FUSION_INLINE __forceinline #elif defined __GNUC__ #define FUSION_INLINE inline __attribute__((always_inline)) diff --git a/Fusion/FusionMath.h b/Fusion/FusionMath.h index d85816a..f584309 100644 --- a/Fusion/FusionMath.h +++ b/Fusion/FusionMath.h @@ -10,6 +10,7 @@ //------------------------------------------------------------------------------ // Includes +#include "FusionConfig.h" #include "FusionInline.h" #include #include @@ -111,12 +112,6 @@ typedef union { #define M_PI (3.14159265358979323846) #endif -/** - * @brief Include this definition or add as a preprocessor definition to use - * normal square root operations. - */ -//#define FUSION_USE_NORMAL_SQRT - //------------------------------------------------------------------------------ // Inline functions - Degrees and radians conversion diff --git a/README.md b/README.md index ff345ee..f39ae2f 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,12 @@ where: Sensors are often mounted such that their axes are not aligned with the body axes. The library provides the `FusionRemap` function to remap sensor axes to the body frame using one of the 24 possible orthogonal axis permutations defined by `FusionRemapAlignment`. -## Fast inverse square root +## Optimisations -Fusion uses [Pizer's implementation](https://pizer.wordpress.com/2008/10/12/fast-inverse-square-root/) of the [fast inverse square root](https://en.wikipedia.org/wiki/Fast_inverse_square_root) algorithm for vector and quaternion normalisation. Including the definition `FUSION_USE_NORMAL_SQRT` in [FusionMath.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionMath.h) or adding this as a preprocessor definition will use normal square root operations for all normalisation calculations. This will slow down execution speed for a small increase in accuracy. The increase in accuracy will typically be too small to observe on any practical system. +### Inline functions + +The `FUSION_INLINE` macro implements either `__forceinline` or `inline __attribute__((always_inline))` to inline functions and optimise for speed at the cost of program size. This can be disabled by uncommenting the `FUSION_NO_INLINE` in [FusionConfig.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionConfig.h) or adding this as a preprocessor definition. + +### Fast inverse square root + +Vector and quaternion normalisation operations use [Pizer's implementation](https://pizer.wordpress.com/2008/10/12/fast-inverse-square-root/) of the [fast inverse square root](https://en.wikipedia.org/wiki/Fast_inverse_square_root) algorithm. This increases speed for devices without an FPU, at a negligible cost to accuracy. Uncommenting `FUSION_USE_NORMAL_SQRT` in [FusionConfig.h](https://github.com/xioTechnologies/Fusion/blob/main/Fusion/FusionConfig.h) or adding this as a preprocessor definition will use normal square root for all operations.