diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2023-02-17 17:06:03 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-18 01:45:00 +0100 |
commit | f4342c9118fb7a4be5d305dcad8b65939a6fca20 (patch) | |
tree | 335fc6663cf0f90964e429a24f4a2c75fcacabd0 /AK/SIMDMath.h | |
parent | 3275d659bfc5a7c429b8b6a34023a47c9b8de551 (diff) | |
download | serenity-f4342c9118fb7a4be5d305dcad8b65939a6fca20.zip |
AK: Add `AK::SIMD::exp_approximate`
This approximation tries to generate values within 0.1% of their actual
expected value. Microbenchmarks indicate that this iterative SIMD
version can be up to 60x faster than `AK::SIMD::exp`.
Diffstat (limited to 'AK/SIMDMath.h')
-rw-r--r-- | AK/SIMDMath.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/AK/SIMDMath.h b/AK/SIMDMath.h index ca0708858a..5356d184c5 100644 --- a/AK/SIMDMath.h +++ b/AK/SIMDMath.h @@ -66,6 +66,15 @@ ALWAYS_INLINE static f32x4 exp(f32x4 v) }; } +ALWAYS_INLINE static f32x4 exp_approximate(f32x4 v) +{ + static constexpr int number_of_iterations = 10; + auto result = 1.f + v / (1 << number_of_iterations); + for (int i = 0; i < number_of_iterations; ++i) + result *= result; + return result; +} + ALWAYS_INLINE static f32x4 sqrt(f32x4 v) { #if ARCH(x86_64) |