Elffuss BraidHub

kikocis/kleidiai public

main · 2.1 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#pragma once
8
9#include <limits>
10#include <type_traits>
11
12#include "test/common/bfloat16.hpp"
13#include "test/common/float16.hpp"
14#include "test/common/int2.hpp"
15#include "test/common/int4.hpp"
16
17namespace kai::test {
18
19/// Highest finite value of type `T`.
20template <typename T>
21inline constexpr std::enable_if_t<std::is_arithmetic_v<T>, T> numeric_highest = std::numeric_limits<T>::max();
22
23/// Highest finite value of @ref UInt4.
24template <>
25inline constexpr UInt4 numeric_highest<UInt4>{15};
26
27/// Highest finite value of @ref Int4.
28template <>
29inline constexpr Int4 numeric_highest<Int4>{7};
30
31/// Highest finite value of @ref UInt2.
32template <>
33inline constexpr UInt2 numeric_highest<UInt2>{3};
34
35/// Highest finite value of @ref Int2.
36template <>
37inline constexpr Int2 numeric_highest<Int2>{1};
38
39/// Highest finite value of @ref Float16.
40template <>
41inline constexpr Float16 numeric_highest<Float16> = Float16::from_binary(0x7bff);
42
43/// Highest finite value of @ref BFloat16.
44template <>
45inline constexpr BFloat16 numeric_highest<BFloat16<>> = BFloat16<>::from_binary(0x7f7f);
46
47/// Lowest finite value of type `T`.
48template <typename T>
49inline constexpr std::enable_if_t<std::is_arithmetic_v<T>, T> numeric_lowest = std::numeric_limits<T>::lowest();
50
51/// Lowest finite value of @ref UInt2.
52template <>
53inline constexpr UInt2 numeric_lowest<UInt2>{0};
54
55/// Lowest finite value of @ref Int2.
56template <>
57inline constexpr Int2 numeric_lowest<Int2>{-2};
58
59/// Lowest finite value of @ref UInt4.
60template <>
61inline constexpr UInt4 numeric_lowest<UInt4>{0};
62
63/// Lowest finite value of @ref Int4.
64template <>
65inline constexpr Int4 numeric_lowest<Int4>{-8};
66
67/// Lowest finite value of @ref Float16.
68template <>
69inline constexpr Float16 numeric_lowest<Float16> = Float16::from_binary(0xfbff);
70
71/// Lowest finite value of @ref BFloat16.
72template <>
73inline constexpr BFloat16 numeric_lowest<BFloat16<>> = BFloat16<>::from_binary(0xff7f);
74
75} // namespace kai::test