|
| 1 | +#ifndef __DATA_TYPE_H__ |
| 2 | +#define __DATA_TYPE_H__ |
| 3 | + |
| 4 | +typedef struct DataLayout { |
| 5 | + unsigned short |
| 6 | + packed : 8, |
| 7 | + sign : 1, |
| 8 | + size : 7, |
| 9 | + mantissa : 8, |
| 10 | + exponent : 8; |
| 11 | + |
| 12 | + bool operator==(const DataLayout &other) const { |
| 13 | + union TypePun { |
| 14 | + DataLayout layout; |
| 15 | + unsigned int i; |
| 16 | + } pun; |
| 17 | + pun.layout = *this; |
| 18 | + auto a_ = pun.i; |
| 19 | + pun.layout = other; |
| 20 | + auto b_ = pun.i; |
| 21 | + return a_ == b_; |
| 22 | + } |
| 23 | + |
| 24 | + bool operator!=(const DataLayout &other) const { |
| 25 | + return !(*this == other); |
| 26 | + } |
| 27 | +} DataLayout; |
| 28 | + |
| 29 | +typedef struct DataLayout DT; |
| 30 | + |
| 31 | +// clang-format off |
| 32 | +constexpr static struct DataLayout |
| 33 | + I8 = {1, 1, 1, 7, 0}, |
| 34 | + I16 = {1, 1, 2, 15, 0}, |
| 35 | + I32 = {1, 1, 4, 31, 0}, |
| 36 | + I64 = {1, 1, 8, 63, 0}, |
| 37 | + U8 = {1, 0, 1, 8, 0}, |
| 38 | + U16 = {1, 0, 2, 16, 0}, |
| 39 | + U32 = {1, 0, 4, 32, 0}, |
| 40 | + U64 = {1, 0, 8, 64, 0}, |
| 41 | + F16 = {1, 1, 2, 10, 5}, |
| 42 | + BF16 = {1, 1, 2, 7, 8}, |
| 43 | + F32 = {1, 1, 4, 23, 8}, |
| 44 | + F64 = {1, 1, 8, 52, 11}; |
| 45 | +// clang-format on |
| 46 | + |
| 47 | +#endif// __DATA_TYPE_H__ |
0 commit comments