From 399f38f2ae6481aee9d7b7a3a7ad436b127dd0bd Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 19 Jul 2026 17:54:35 +0200 Subject: kstd: move bitfiled_enum header --- arch/x86_64/arch/cpu/control_register.hpp | 8 +-- arch/x86_64/arch/cpu/model_specific_register.hpp | 8 +-- arch/x86_64/arch/memory/page_table.hpp | 8 +-- kapi/kapi/memory/page_mapper.hpp | 6 +-- libs/acpi/acpi/data/madt.hpp | 4 +- libs/kstd/kstd.dox | 7 --- libs/kstd/kstd/bitfield_enum.hpp | 68 ++++++++++++++++++++++++ libs/kstd/kstd/ext/bitfield_enum.hpp | 65 ---------------------- 8 files changed, 85 insertions(+), 89 deletions(-) create mode 100644 libs/kstd/kstd/bitfield_enum.hpp delete mode 100644 libs/kstd/kstd/ext/bitfield_enum.hpp diff --git a/arch/x86_64/arch/cpu/control_register.hpp b/arch/x86_64/arch/cpu/control_register.hpp index ad307081..127d1e24 100644 --- a/arch/x86_64/arch/cpu/control_register.hpp +++ b/arch/x86_64/arch/cpu/control_register.hpp @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -60,7 +60,7 @@ namespace arch::cpu }; } // namespace arch::cpu -namespace kstd::ext +namespace kstd { template<> struct is_bitfield_enum : std::true_type @@ -71,7 +71,7 @@ namespace kstd::ext struct is_bitfield_enum : std::true_type { }; -} // namespace kstd::ext +} // namespace kstd namespace arch::cpu { @@ -95,7 +95,7 @@ namespace arch::cpu //! @note This specialization provides the implementation for the case in which the value type of the control register //! is an enum. template - struct control_register_with_flags>> + struct control_register_with_flags>> { //! The type of the flags used by this control register using flags = ValueType; diff --git a/arch/x86_64/arch/cpu/model_specific_register.hpp b/arch/x86_64/arch/cpu/model_specific_register.hpp index cf07737f..1410c343 100644 --- a/arch/x86_64/arch/cpu/model_specific_register.hpp +++ b/arch/x86_64/arch/cpu/model_specific_register.hpp @@ -3,7 +3,7 @@ // IWYU pragma: private, include -#include +#include #include #include @@ -27,7 +27,7 @@ namespace arch::cpu } // namespace arch::cpu -namespace kstd::ext +namespace kstd { template<> @@ -35,7 +35,7 @@ namespace kstd::ext { }; -} // namespace kstd::ext +} // namespace kstd namespace arch::cpu { @@ -62,7 +62,7 @@ namespace arch::cpu //! @note This specialization provides the implementation for the case in which the value type of the model specific //! register is a bitfield enum. template - struct model_specific_register_with_flags>> + struct model_specific_register_with_flags>> { //! The of the flags used by this model specific register. using flags = ValueType; diff --git a/arch/x86_64/arch/memory/page_table.hpp b/arch/x86_64/arch/memory/page_table.hpp index f288e3da..5bb4e1aa 100644 --- a/arch/x86_64/arch/memory/page_table.hpp +++ b/arch/x86_64/arch/memory/page_table.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include #include @@ -36,7 +36,7 @@ namespace arch::memory //! An entry in a page table may have any combination of these flags active at the same time. The final flags of a //! page are determined as the strictest combination (logical AND) of all flags along the hierarchy. //! - //! @note This is a bitfield enum as defined by kstd::ext::bitfield_enum. + //! @note This is a bitfield enum as defined by kstd::bitfield_enum. enum struct flags : std::uint64_t { empty = 0, @@ -146,13 +146,13 @@ namespace arch::memory } // namespace arch::memory -namespace kstd::ext +namespace kstd { template<> struct is_bitfield_enum : std::true_type { }; -} // namespace kstd::ext +} // namespace kstd namespace arch::memory { diff --git a/kapi/kapi/memory/page_mapper.hpp b/kapi/kapi/memory/page_mapper.hpp index 579c14fd..ec7e7c68 100644 --- a/kapi/kapi/memory/page_mapper.hpp +++ b/kapi/kapi/memory/page_mapper.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -79,12 +79,12 @@ namespace kapi::memory } // namespace kapi::memory -namespace kstd::ext +namespace kstd { template<> struct is_bitfield_enum : std::true_type { }; -} // namespace kstd::ext +} // namespace kstd #endif \ No newline at end of file diff --git a/libs/acpi/acpi/data/madt.hpp b/libs/acpi/acpi/data/madt.hpp index 4d992613..2bff7470 100644 --- a/libs/acpi/acpi/data/madt.hpp +++ b/libs/acpi/acpi/data/madt.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -110,7 +110,7 @@ namespace acpi } // namespace acpi template<> -struct kstd::ext::is_bitfield_enum : std::true_type +struct kstd::is_bitfield_enum : std::true_type { }; diff --git a/libs/kstd/kstd.dox b/libs/kstd/kstd.dox index 5920a3cb..39a2d05e 100644 --- a/libs/kstd/kstd.dox +++ b/libs/kstd/kstd.dox @@ -5,10 +5,3 @@ //! freestanding environment, since it relies on operating system support (e.g. memory allocation). The implementations //! found here, aim to be reasonably close to the specifications found in the C++ language standard (ISO14482). //! However, some differences exists, for example the lack of exceptions. - -//! @namespace kstd::ext -//! Extensions to the Standard Library. -//! -//! This namespace includes custom extensions to what is defined for the C++ Standard Library. These extensions not -//! portable per-se, since they are not implemented by other Standard Library implementations. Whenever possible, -//! Standard Library conformant types, functions, etc. should be used throughout the TeachOS codebase. diff --git a/libs/kstd/kstd/bitfield_enum.hpp b/libs/kstd/kstd/bitfield_enum.hpp new file mode 100644 index 00000000..047052e4 --- /dev/null +++ b/libs/kstd/kstd/bitfield_enum.hpp @@ -0,0 +1,68 @@ +#ifndef KSTD_EXT_BITFIELD_ENUM_HPP +#define KSTD_EXT_BITFIELD_ENUM_HPP + +#include +#include +#include + +namespace kstd +{ + + template + requires std::is_enum_v + struct is_bitfield_enum : std::false_type + { + }; + + //! @concept Specifies that an enum is to be used to define bits in a bitfield. + template + concept bitfield_enum = is_bitfield_enum::value; + +}; // namespace kstd + +template +constexpr auto operator|(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) | std::to_underlying(rhs))); +} + +template +constexpr auto operator|=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs | rhs; +} + +template +constexpr auto operator&(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) & std::to_underlying(rhs))); +} + +template +constexpr auto operator&=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs & rhs; +} + +template +constexpr auto operator^(EnumType lhs, EnumType rhs) -> EnumType +{ + return std::bit_cast( + static_cast>(std::to_underlying(lhs) ^ std::to_underlying(rhs))); +} + +template +constexpr auto operator^=(EnumType & lhs, EnumType rhs) -> EnumType & +{ + return lhs = lhs ^ rhs; +} + +template +constexpr auto operator~(EnumType lhs) -> EnumType +{ + return std::bit_cast(static_cast>(~std::to_underlying(lhs))); +} + +#endif \ No newline at end of file diff --git a/libs/kstd/kstd/ext/bitfield_enum.hpp b/libs/kstd/kstd/ext/bitfield_enum.hpp deleted file mode 100644 index 80fe9d29..00000000 --- a/libs/kstd/kstd/ext/bitfield_enum.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef KSTD_EXT_BITFIELD_ENUM_HPP -#define KSTD_EXT_BITFIELD_ENUM_HPP - -#include -#include -#include - -namespace kstd::ext -{ - - template - requires std::is_enum_v - struct is_bitfield_enum : std::false_type - { - }; - - //! @concept Specifies that an enum is to be used to define bits in a bitfield. - template - concept bitfield_enum = is_bitfield_enum::value; - -}; // namespace kstd::ext - -template -constexpr auto operator|(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) | std::to_underlying(rhs)); -} - -template -constexpr auto operator|=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs | rhs; -} - -template -constexpr auto operator&(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) & std::to_underlying(rhs)); -} - -template -constexpr auto operator&=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs & rhs; -} - -template -constexpr auto operator^(EnumType lhs, EnumType rhs) -> EnumType -{ - return std::bit_cast(std::to_underlying(lhs) ^ std::to_underlying(rhs)); -} - -template -constexpr auto operator^=(EnumType & lhs, EnumType rhs) -> EnumType & -{ - return lhs = lhs ^ rhs; -} - -template -constexpr auto operator~(EnumType lhs) -> EnumType -{ - return std::bit_cast(~std::to_underlying(lhs)); -} - -#endif \ No newline at end of file -- cgit v1.2.3