diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-15 01:03:21 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-15 01:03:21 +0800 |
| commit | 0ff8758f879231610bf92bee2123061fd7cfe01d (patch) | |
| tree | 288ccc605fab8abcbcbc2d61cf365a285211016e /backend/lib/Support/APInt.cpp | |
| parent | f6fdfb8d484b4e52cdb24a94a31b0f00d41a5eb7 (diff) | |
| download | rcc-project-0ff8758f879231610bf92bee2123061fd7cfe01d.tar.gz rcc-project-0ff8758f879231610bf92bee2123061fd7cfe01d.tar.xz | |
[GlobalISel] Legalize constants and implicit definitions
Diffstat (limited to 'backend/lib/Support/APInt.cpp')
| -rw-r--r-- | backend/lib/Support/APInt.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/backend/lib/Support/APInt.cpp b/backend/lib/Support/APInt.cpp index 74cbc56..9a6a49c 100644 --- a/backend/lib/Support/APInt.cpp +++ b/backend/lib/Support/APInt.cpp @@ -348,6 +348,26 @@ Expected<APInt> APInt::sext(std::uint32_t NewBitWidth) const { return create(NewBitWidth, ResultWords); } +Expected<APInt> APInt::logicalShiftRight(std::size_t Amount) const { + if (BitWidth == 0) + return makeUnexpected(ErrorCode::InvalidArgument, + "APInt logical shift requires a nonzero width"); + std::vector<std::uint64_t> ResultWords(wordCount(BitWidth), 0); + if (Amount >= BitWidth) + return create(BitWidth, ResultWords); + + const std::size_t WordOffset = Amount / 64U; + const unsigned BitOffset = static_cast<unsigned>(Amount % 64U); + for (std::size_t Index = 0; Index + WordOffset < Words.size(); ++Index) { + std::uint64_t Value = Words[Index + WordOffset] >> BitOffset; + if (BitOffset != 0 && Index + WordOffset + 1U < Words.size()) + Value |= Words[Index + WordOffset + 1U] << (64U - BitOffset); + ResultWords[Index] = Value; + } + ResultWords.back() &= highWordMask(BitWidth); + return create(BitWidth, ResultWords); +} + int APInt::compare(const APInt &Other) const noexcept { const std::size_t LeftCount = significantWordCount(Words); const std::size_t RightCount = significantWordCount(Other.Words); |
