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 /Tests | |
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 'Tests')
-rw-r--r-- | Tests/AK/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/AK/TestSIMD.cpp | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index 77a288d2ea..e26a38e41f 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -61,6 +61,7 @@ set(AK_TEST_SOURCES TestQuickSort.cpp TestRedBlackTree.cpp TestRefPtr.cpp + TestSIMD.cpp TestSinglyLinkedList.cpp TestSourceGenerator.cpp TestSourceLocation.cpp diff --git a/Tests/AK/TestSIMD.cpp b/Tests/AK/TestSIMD.cpp new file mode 100644 index 0000000000..251904cbf2 --- /dev/null +++ b/Tests/AK/TestSIMD.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023, Jelle Raaijmakers <jelle@gmta.nl> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibTest/TestCase.h> + +#include <AK/SIMD.h> +#include <AK/SIMDMath.h> + +TEST_CASE(exp) +{ + AK::SIMD::f32x4 v = { .2f, .4f, .6f, .8f }; + auto result = AK::SIMD::exp(v); + + EXPECT_APPROXIMATE(result[0], 1.22140276f); + EXPECT_APPROXIMATE(result[1], 1.49182470f); + EXPECT_APPROXIMATE(result[2], 1.82211880f); + EXPECT_APPROXIMATE(result[3], 2.22554093f); +} + +TEST_CASE(exp_approximate) +{ + AK::SIMD::f32x4 v = { .2f, .4f, .6f, .8f }; + auto result = AK::SIMD::exp_approximate(v); + constexpr float accuracy = .001f; + + EXPECT(fabsf(result[0] - 1.22140276f) <= accuracy); + EXPECT(fabsf(result[1] - 1.49182470f) <= accuracy); + EXPECT(fabsf(result[2] - 1.82211880f) <= accuracy); + EXPECT(fabsf(result[3] - 2.22554093f) <= accuracy); +} |