metaforce/Runtime/GCNTypes.hpp

66 lines
4.2 KiB
C++

#pragma once
#include <cstdint>
#include <cstdlib>
using s8 = int8_t;
using u8 = uint8_t;
using s16 = int16_t;
using u16 = uint16_t;
using s32 = int32_t;
using u32 = uint32_t;
using s64 = int64_t;
using u64 = uint64_t;
#ifndef ROUND_UP_256
#define ROUND_UP_256(val) (((val) + 255) & ~255)
#endif
#ifndef ROUND_UP_64
#define ROUND_UP_64(val) (((val) + 63) & ~63)
#endif
#ifndef ROUND_UP_32
#define ROUND_UP_32(val) (((val) + 31) & ~31)
#endif
#ifndef ROUND_UP_16
#define ROUND_UP_16(val) (((val) + 15) & ~15)
#endif
#ifndef ROUND_UP_8
#define ROUND_UP_8(val) (((val) + 7) & ~7)
#endif
#ifndef ROUND_UP_4
#define ROUND_UP_4(val) (((val) + 3) & ~3)
#endif
#ifndef ENABLE_BITWISE_ENUM
#define ENABLE_BITWISE_ENUM(type) \
constexpr type operator|(type a, type b) noexcept { \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) | static_cast<T>(b)); \
} \
constexpr type operator&(type a, type b) noexcept { \
using T = std::underlying_type_t<type>; \
return type(static_cast<T>(a) & static_cast<T>(b)); \
} \
constexpr type& operator|=(type& a, type b) noexcept { \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) | static_cast<T>(b)); \
return a; \
} \
constexpr type& operator&=(type& a, type b) noexcept { \
using T = std::underlying_type_t<type>; \
a = type(static_cast<T>(a) & static_cast<T>(b)); \
return a; \
} \
constexpr type operator~(type key) noexcept { \
using T = std::underlying_type_t<type>; \
return type(~static_cast<T>(key)); \
} \
constexpr bool True(type key) noexcept { \
using T = std::underlying_type_t<type>; \
return static_cast<T>(key) != 0; \
} \
constexpr bool False(type key) noexcept { \
using T = std::underlying_type_t<type>; \
return static_cast<T>(key) == 0; \
}
#endif