MimIR
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#if defined(__STDCPP_FLOAT16_T__)
7# include <stdfloat>
8#endif
9
10namespace mim {
11// clang-format off
12
13#define MIM_1_8_16_32_64(X) X(1) X(8) X(16) X(32) X(64)
14#define MIM_8_16_32_64(X) X(8) X(16) X(32) X(64)
15#if defined(__STDCPP_FLOAT16_T__)
16# define MIM_F16_32_64(X) X(16) X(32) X(64)
17#else
18# define MIM_F16_32_64(X) X(32) X(64)
19#endif
20
21/// @name Aliases for some Base Types
22// using CODE1, CODE2, ... here as a workaround for Doxygen
23///@{
24#define CODE1(i) \
25 using s ## i = int ## i ##_t; \
26 using u ## i = uint ## i ##_t;
28#undef CODE1
29
30using u1 = bool;
31#if defined(__STDCPP_FLOAT16_T__)
32using f16 = std::float16_t;
33#endif
34using f32 = float;
35using f64 = double;
36using level_t = u64;
37using nat_t = u64;
38using node_t = u8;
39using flags_t = u64;
40using plugin_t = u64;
41using tag_t = u8;
42using sub_t = u8;
43///@}
44
45namespace detail {
46template<int> struct w2u_ { using type = void; };
47template<int> struct w2s_ { using type = void; };
48template<int> struct w2f_ { using type = void; };
49template<> struct w2u_<1> { using type = bool; }; ///< Map both signed 1 and unsigned 1 to `bool`.
50template<> struct w2s_<1> { using type = bool; }; ///< See above.
51
52#define CODE2(i) \
53 template<> struct w2u_<i> { using type = u ## i; }; \
54 template<> struct w2s_<i> { using type = s ## i; };
56#undef CODE2
57
58#define CODE3(i) \
59 template<> struct w2f_<i> { using type = f ## i; };
61#undef CODE3
62} // namespace detail
63
64/// @name Width to Signed/Unsigned/Float
65///@{
66template<int w> using w2u = typename detail::w2u_<w>::type;
67template<int w> using w2s = typename detail::w2s_<w>::type;
68template<int w> using w2f = typename detail::w2f_<w>::type;
69///@}
70
71/// @name User-Defined Literals
72///@{
73#define CODE4(i) \
74 constexpr s ## i operator""_s ## i(unsigned long long int s) { return s ## i(s); } \
75 constexpr u ## i operator""_u ## i(unsigned long long int u) { return u ## i(u); }
77#undef CODE4
78
79constexpr nat_t operator""_n(unsigned long long int i) { return nat_t(i); }
80///@}
81
82/// @name rem
83///@{
84#if defined(__STDCPP_FLOAT16_T__)
85inline f16 rem(f16 a, f16 b) { return std::fmod(a, b); }
86#endif
87inline float rem(float a, float b) { return std::fmod(a, b); }
88inline double rem(double a, double b) { return std::fmod(a, b); }
89inline long double rem(long double a, long double b) { return std::fmod(a, b); }
90///@}
91
92// clang-format on
93} // namespace mim
Definition ast.h:14
u64 nat_t
Definition types.h:37
u8 sub_t
Definition types.h:42
typename detail::w2f_< w >::type w2f
Definition types.h:68
u64 flags_t
Definition types.h:39
double f64
Definition types.h:35
u8 node_t
Definition types.h:38
float rem(float a, float b)
Definition types.h:87
u64 level_t
Definition types.h:36
float f32
Definition types.h:34
typename detail::w2s_< w >::type w2s
Definition types.h:67
u64 plugin_t
Definition types.h:40
bool u1
Definition types.h:30
typename detail::w2u_< w >::type w2u
Definition types.h:66
uint64_t u64
Definition types.h:27
u8 tag_t
Definition types.h:41
uint8_t u8
Definition types.h:27
#define CODE4(i)
Definition types.h:73
#define MIM_F16_32_64(X)
Definition types.h:18
#define CODE1(i)
Definition types.h:24
#define CODE3(i)
Definition types.h:58
#define MIM_8_16_32_64(X)
Definition types.h:14
#define CODE2(i)
Definition types.h:52