diff --git a/src/common/types.h b/src/common/types.h index a5b33c021..7bd0e494c 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -232,3 +232,42 @@ ALWAYS_INLINE constexpr T SignExtendN(T value) static_cast::type>(rhs)); \ return lhs; \ } + +#define IMPLEMENT_STATIC_FRIEND_ENUM_CLASS_BITWISE_OPERATORS(type_) \ + ALWAYS_INLINE constexpr static friend type_ operator&(type_ lhs, type_ rhs) \ + { \ + return static_cast(static_cast::type>(lhs) & \ + static_cast::type>(rhs)); \ + } \ + ALWAYS_INLINE constexpr static friend type_ operator|(type_ lhs, type_ rhs) \ + { \ + return static_cast(static_cast::type>(lhs) | \ + static_cast::type>(rhs)); \ + } \ + ALWAYS_INLINE constexpr static friend type_ operator^(type_ lhs, type_ rhs) \ + { \ + return static_cast(static_cast::type>(lhs) ^ \ + static_cast::type>(rhs)); \ + } \ + ALWAYS_INLINE constexpr static friend type_ operator~(type_ val) \ + { \ + return static_cast(~static_cast::type>(val)); \ + } \ + ALWAYS_INLINE constexpr static friend type_& operator&=(type_& lhs, type_ rhs) \ + { \ + lhs = static_cast(static_cast::type>(lhs) & \ + static_cast::type>(rhs)); \ + return lhs; \ + } \ + ALWAYS_INLINE constexpr static friend type_& operator|=(type_& lhs, type_ rhs) \ + { \ + lhs = static_cast(static_cast::type>(lhs) | \ + static_cast::type>(rhs)); \ + return lhs; \ + } \ + ALWAYS_INLINE constexpr static friend type_& operator^=(type_& lhs, type_ rhs) \ + { \ + lhs = static_cast(static_cast::type>(lhs) ^ \ + static_cast::type>(rhs)); \ + return lhs; \ + }