diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 23:56:19 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 23:56:19 +0800 |
| commit | 7ee5d1913c7cfd0261f86b0ff7be6968b8c07d84 (patch) | |
| tree | 446dafb95e2f792fee922602b74709c5b9e0777c /backend/utils | |
| parent | f0cfb240d80cb9f4444fb996350c1f88bc69a142 (diff) | |
| download | rcc-project-7ee5d1913c7cfd0261f86b0ff7be6968b8c07d84.tar.gz rcc-project-7ee5d1913c7cfd0261f86b0ff7be6968b8c07d84.tar.xz | |
[Support] Use standard power-of-two checks
Diffstat (limited to 'backend/utils')
| -rw-r--r-- | backend/utils/TableGen/Common/CodeGenInstruction.cpp | 3 | ||||
| -rw-r--r-- | backend/utils/TableGen/Common/CodeGenTarget.cpp | 9 | ||||
| -rw-r--r-- | backend/utils/TableGen/Common/CodeGenTarget.h | 1 |
3 files changed, 5 insertions, 8 deletions
diff --git a/backend/utils/TableGen/Common/CodeGenInstruction.cpp b/backend/utils/TableGen/Common/CodeGenInstruction.cpp index a34f5ab..e7f5ddc 100644 --- a/backend/utils/TableGen/Common/CodeGenInstruction.cpp +++ b/backend/utils/TableGen/Common/CodeGenInstruction.cpp @@ -4,6 +4,7 @@ #include <algorithm> #include <array> +#include <bit> #include <cstdint> #include <limits> #include <ranges> @@ -218,7 +219,7 @@ pipelineStageEnumerator(std::string_view Value) noexcept { const bool IsUnsigned = Predicate.Kind == "unsigned"; if (Predicate.ID == 0 || !isIdentifier(Predicate.Symbol) || Predicate.Name.empty() || (!IsSigned && !IsUnsigned) || Predicate.Bits == 0 || Predicate.Bits > 63 || - !isPowerOfTwo(Predicate.Alignment) || !IDs.insert(Predicate.ID).second || + !std::has_single_bit(Predicate.Alignment) || !IDs.insert(Predicate.ID).second || !Symbols.insert(Predicate.Symbol).second || !Names.insert(Predicate.Name).second) { fail(Predicate.Range, "immediate predicates require nonzero unique IDs, symbols, names, a signed or " diff --git a/backend/utils/TableGen/Common/CodeGenTarget.cpp b/backend/utils/TableGen/Common/CodeGenTarget.cpp index d4c9795..478457c 100644 --- a/backend/utils/TableGen/Common/CodeGenTarget.cpp +++ b/backend/utils/TableGen/Common/CodeGenTarget.cpp @@ -6,6 +6,7 @@ #include "rcc/TableGen/Parser.h" #include <algorithm> +#include <bit> #include <cstddef> #include <ranges> #include <string> @@ -15,10 +16,6 @@ namespace rcc::targetgen { -[[nodiscard]] bool isPowerOfTwo(std::uint64_t Value) noexcept { - return Value != 0 && (Value & (Value - 1U)) == 0; -} - CodeGenTarget::CodeGenTarget(const DescriptionAST &Input, std::string SourceName) : Input(Input), SourceName(std::move(SourceName)) {} @@ -105,8 +102,8 @@ void CodeGenTarget::fail(TextRange Range, std::string Message) { IntegerClass == ClassBySymbol.end() || FloatingClass == ClassBySymbol.end() || PreservedMask == Result.RegisterMasks.end() || Convention.StackAlignmentBytes == 0 || Convention.StackArgumentAlignmentBytes == 0 || - !isPowerOfTwo(Convention.StackAlignmentBytes) || - !isPowerOfTwo(Convention.StackArgumentAlignmentBytes) || + !std::has_single_bit(Convention.StackAlignmentBytes) || + !std::has_single_bit(Convention.StackArgumentAlignmentBytes) || Convention.StackAlignmentBytes % Convention.StackArgumentAlignmentBytes != 0 || Convention.ShadowSpaceBytes % Convention.StackArgumentAlignmentBytes != 0 || !IDs.insert(Convention.ID).second || !Symbols.insert(Convention.Symbol).second || diff --git a/backend/utils/TableGen/Common/CodeGenTarget.h b/backend/utils/TableGen/Common/CodeGenTarget.h index 2ab6db1..a2aed7c 100644 --- a/backend/utils/TableGen/Common/CodeGenTarget.h +++ b/backend/utils/TableGen/Common/CodeGenTarget.h @@ -426,7 +426,6 @@ instructionFlagEnumerator(std::string_view Value) noexcept; pseudoOwnerEnumerator(std::string_view Value) noexcept; [[nodiscard]] std::optional<std::string_view> pipelineStageEnumerator(std::string_view Value) noexcept; -[[nodiscard]] bool isPowerOfTwo(std::uint64_t Value) noexcept; class CodeGenTarget final { public: |
