-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[NFC][MC][Decoder] Extract fixed pieces of decoder code into new header file #154802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // Disassembler decoder helper functions. | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef LLVM_MC_MCDECODER_H | ||
| #define LLVM_MC_MCDECODER_H | ||
|
|
||
| #include "llvm/MC/MCDisassembler/MCDisassembler.h" | ||
| #include "llvm/Support/MathExtras.h" | ||
| #include <cassert> | ||
|
|
||
| namespace llvm::MCD { | ||
|
|
||
| // Helper to propagate SoftFail status. Returns false if the status is Fail; | ||
| // callers are expected to early-exit in that condition. (Note, the '&' operator | ||
| // is correct to propagate the values of this enum; see comment on 'enum | ||
| // DecodeStatus'.) | ||
| inline bool Check(MCDisassembler::DecodeStatus &Out, | ||
| MCDisassembler::DecodeStatus In) { | ||
| Out = static_cast<MCDisassembler::DecodeStatus>(Out & In); | ||
| return Out != MCDisassembler::Fail; | ||
| } | ||
|
|
||
| // fieldFromInstruction - Extracts a given span of bits from the instruction | ||
| // bits and return it as an integer. | ||
| template <typename IntType> | ||
| #if defined(_MSC_VER) && !defined(__clang__) | ||
| __declspec(noinline) | ||
| #endif | ||
| inline std::enable_if_t<std::is_integral_v<IntType>, IntType> | ||
| fieldFromInstruction(const IntType &Insn, unsigned StartBit, unsigned NumBits) { | ||
| assert(StartBit + NumBits <= 64 && "Cannot support >64-bit extractions!"); | ||
| assert(StartBit + NumBits <= (sizeof(IntType) * 8) && | ||
| "Instruction field out of bounds!"); | ||
| const IntType Mask = maskTrailingOnes<IntType>(NumBits); | ||
| return (Insn >> StartBit) & Mask; | ||
| } | ||
|
|
||
| template <typename InsnType> | ||
| inline std::enable_if_t<!std::is_integral_v<InsnType>, uint64_t> | ||
| fieldFromInstruction(const InsnType &Insn, unsigned StartBit, | ||
| unsigned NumBits) { | ||
| return Insn.extractBitsAsZExtValue(NumBits, StartBit); | ||
| } | ||
|
|
||
| // Helper function for inserting bits extracted from an encoded instruction into | ||
| // an integer-typed field. | ||
| template <typename IntType> | ||
| static std::enable_if_t<std::is_integral_v<IntType>, void> | ||
| insertBits(IntType &field, IntType bits, unsigned startBit, unsigned numBits) { | ||
| // Check that no bit beyond numBits is set, so that a simple bitwise | | ||
| // is sufficient. | ||
| assert((~(((IntType)1 << numBits) - 1) & bits) == 0 && | ||
| "bits has more than numBits bits set"); | ||
| assert(startBit + numBits <= sizeof(IntType) * 8); | ||
| (void)numBits; | ||
| field |= bits << startBit; | ||
| } | ||
|
|
||
| } // namespace llvm::MCD | ||
|
|
||
| #endif // LLVM_MC_MCDECODER_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.