// SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. #ifndef XRT_DETAIL_BITMASK_H #define XRT_DETAIL_BITMASK_H #ifdef __cplusplus # include #endif #ifdef __cplusplus // Allow enum classes to be used at bitmasks namespace xrt::detail { template constexpr std::enable_if_t, T> operator|(T lhs, T rhs) { using U = std::underlying_type_t; return static_cast(static_cast(lhs) | static_cast(rhs)); } template constexpr std::enable_if_t, T> operator&(T lhs, T rhs) { using U = std::underlying_type_t; return static_cast(static_cast(lhs) & static_cast(rhs)); } template constexpr std::enable_if_t, T> operator^(T lhs, T rhs) { using U = std::underlying_type_t; return static_cast(static_cast(lhs) ^ static_cast(rhs)); } template constexpr std::enable_if_t, T> operator~(T rhs) { using U = std::underlying_type_t; return static_cast(~static_cast(rhs)); // NOLINT } template constexpr std::enable_if_t, T&> operator|=(T& lhs, T rhs) { using U = std::underlying_type_t; lhs = static_cast(static_cast(lhs) | static_cast(rhs)); return lhs; } template constexpr std::enable_if_t, T&> operator&=(T& lhs, T rhs) { using U = std::underlying_type_t; lhs = static_cast(static_cast(lhs) & static_cast(rhs)); return lhs; } template constexpr std::enable_if_t, T&> operator^=(T& lhs, T rhs) { using U = std::underlying_type_t; lhs = static_cast(static_cast(lhs) ^ static_cast(rhs)); return lhs; } template constexpr std::enable_if_t, bool> operator!(T rhs) { return !static_cast(static_cast>(rhs)); } } // xrt::detail #endif #endif