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