HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
simd_test_utility.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "simd.hpp"
8#include "../macros.hpp"
9#include <gtest/gtest.h>
10
11
12
13namespace hi { inline namespace v1 { namespace detail {
14
15// The helper function for {ASSERT|EXPECT}_EQ.
16template<typename T, std::size_t N>
17::testing::AssertionResult
18CmpHelperEQ(const char *lhs_expression, const char *rhs_expression, ::hi::simd<T, N> const& lhs, ::hi::simd<T, N> const& rhs)
19{
20 if (equal(lhs, rhs)) {
21 return ::testing::AssertionSuccess();
22 }
23
24 return ::testing::internal::CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
25}
26
27template<typename T, std::size_t N>
28::testing::AssertionResult
29CmpHelperNE(const char *lhs_expression, const char *rhs_expression, ::hi::simd<T, N> const& lhs, ::hi::simd<T, N> const& rhs)
30{
31 if (not equal(lhs, rhs)) {
32 return ::testing::AssertionSuccess();
33 }
34
35 return ::testing::internal::CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
36}
37
38// The helper function for {ASSERT|EXPECT}_EQ.
39template<typename T, std::size_t N>
40::testing::AssertionResult CmpHelperEQ(
41 const char *lhs_expression,
42 const char *rhs_expression,
43 ::hi::native_simd<T, N> const& lhs,
44 ::hi::native_simd<T, N> const& rhs)
45{
46 if (equal(lhs, rhs)) {
47 return ::testing::AssertionSuccess();
48 }
49
50 return ::testing::internal::CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
51}
52
53template<typename T, std::size_t N>
54::testing::AssertionResult CmpHelperNE(
55 const char *lhs_expression,
56 const char *rhs_expression,
57 ::hi::native_simd<T, N> const& lhs,
58 ::hi::native_simd<T, N> const& rhs)
59{
60 if (not equal(lhs, rhs)) {
61 return ::testing::AssertionSuccess();
62 }
63
64 return ::testing::internal::CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
65}
66
67}}} // namespace hi::v1::detail
68
69#define HI_ASSERT_SIMD_EQ(val1, val2) ASSERT_PRED_FORMAT2(hi::detail::CmpHelperEQ, val1, val2)
70#define HI_ASSERT_SIMD_NE(val1, val2) ASSERT_PRED_FORMAT2(hi::detail::CmpHelperNE, val1, val2)
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A native-SIMD type.
Definition native_simd_utility.hpp:162
T equal(T... args)