summaryrefslogtreecommitdiff
path: root/AK/SIMDMath.h
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2023-02-17 17:06:03 +0100
committerAndreas Kling <kling@serenityos.org>2023-02-18 01:45:00 +0100
commitf4342c9118fb7a4be5d305dcad8b65939a6fca20 (patch)
tree335fc6663cf0f90964e429a24f4a2c75fcacabd0 /AK/SIMDMath.h
parent3275d659bfc5a7c429b8b6a34023a47c9b8de551 (diff)
downloadserenity-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.h9
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)