Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5#include <limits>
6#include <ostream>
7#include <type_traits>
8
9#include <cmath>
10
11#ifdef __clang__
12# pragma clang diagnostic push
13# pragma clang diagnostic ignored "-Wmismatched-tags"
14#endif
15#define HALF_ROUND_STYLE 1
16#define HALF_ROUND_TIES_TO_EVEN 1
17#include <half.hpp>
18#ifdef __clang__
19# pragma clang diagnostic pop
20#endif
21
22namespace thorin {
23// clang-format off
24
25#define THORIN_1_8_16_32_64(m) m(1) m(8) m(16) m(32) m(64)
26#define THORIN_8_16_32_64(m) m(8) m(16) m(32) m(64)
27#define THORIN_16_32_64(m) m(16) m(32) m(64)
28
29/// @name Aliases for some Base Types
30///@{
31// using CODE1, CODE2, ... here as a workaround for Doxygen
32#define CODE1(i) \
33 using s ## i = int ## i ##_t; \
34 using u ## i = uint ## i ##_t;
36#undef CODE1
37
38using half_float::half;
39using u1 = bool;
40using f16 = half;
41using f32 = float;
42using f64 = double;
43using level_t = u64;
44using nat_t = u64;
45using node_t = u8;
46using flags_t = u64;
47using plugin_t = u64;
48using tag_t = u8;
49using sub_t = u8;
50///@}
51
52namespace detail {
53template<int> struct w2u_ { using type = void; };
54template<int> struct w2s_ { using type = void; };
55template<int> struct w2f_ { using type = void; };
56template<> struct w2u_<1> { using type = bool; }; ///< Map both signed 1 and unsigned 1 to `bool`.
57template<> struct w2s_<1> { using type = bool; }; ///< See above.
58
59#define CODE2(i) \
60 template<> struct w2u_<i> { using type = u ## i; }; \
61 template<> struct w2s_<i> { using type = s ## i; };
63#undef CODE2
64
65#define CODE3(i) \
66 template<> struct w2f_<i> { using type = f ## i; };
68#undef CODE3
69} // namespace detail
70
71/// @name Width to Signed/Unsigned/Float
72///@{
73template<int w> using w2u = typename detail::w2u_<w>::type;
74template<int w> using w2s = typename detail::w2s_<w>::type;
75template<int w> using w2f = typename detail::w2f_<w>::type;
76///@}
77
78/// @name User-Defined Literals
79///@{
80#define CODE4(i) \
81 constexpr s ## i operator"" _s ## i(unsigned long long int s) { return s ## i(s); } \
82 constexpr u ## i operator"" _u ## i(unsigned long long int u) { return u ## i(u); }
84#undef CODE4
85
86/// A `size_t` literal. Use `0_s` to disambiguate `0` from `nullptr`.
87constexpr size_t operator""_s(unsigned long long int i) { return size_t(i); }
88constexpr nat_t operator""_n(unsigned long long int i) { return nat_t(i); }
89inline /*constexpr*/ f16 operator""_f16(long double d) { return f16(float(d)); } // wait till fixed upstream
90constexpr f32 operator""_f32(long double d) { return f32(d); }
91constexpr f64 operator""_f64(long double d) { return f64(d); }
92///@}
93
94/// @name rem
95///@{
96inline half rem(half a, half b) { return fmod(a, b); }
97inline float rem(float a, float b) { return std::fmod(a, b); }
98inline double rem(double a, double b) { return std::fmod(a, b); }
99inline long double rem(long double a, long double b) { return std::fmod(a, b); }
100///@}
101
102// clang-format on
103} // namespace thorin
Definition cfg.h:11
u8 sub_t
Definition types.h:49
uint64_t u64
Definition types.h:35
typename detail::w2s_< w >::type w2s
Definition types.h:74
u64 nat_t
Definition types.h:44
typename detail::w2u_< w >::type w2u
Definition types.h:73
half f16
Definition types.h:40
half rem(half a, half b)
Definition types.h:96
bool u1
Definition types.h:39
typename detail::w2f_< w >::type w2f
Definition types.h:75
uint8_t u8
Definition types.h:35
u8 tag_t
Definition types.h:48
u64 plugin_t
Definition types.h:47
u8 node_t
Definition types.h:45
u64 level_t
Definition types.h:43
u64 flags_t
Definition types.h:46
float f32
Definition types.h:41
double f64
Definition types.h:42
#define CODE4(i)
Definition types.h:80
#define CODE1(i)
Definition types.h:32
#define CODE3(i)
Definition types.h:65
#define THORIN_8_16_32_64(m)
Definition types.h:26
#define THORIN_16_32_64(m)
Definition types.h:27
#define CODE2(i)
Definition types.h:59