summaryrefslogtreecommitdiff
path: root/Tests/AK/TestSIMD.cpp
blob: 251904cbf22343e129a3062e4c5207044d5374a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
}