-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[X86][MC] Remove duplicated code in X86DisassemblerDecoder.h by defining macro helpers (NFCI) #72341
Merged
Conversation
This file contains 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
…ing macro helpers (NFCI)
@llvm/pr-subscribers-backend-x86 Author: Shengchen Kan (KanRobert) ChangesFull diff: https://github.com/llvm/llvm-project/pull/72341.diff 1 Files Affected:
diff --git a/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h b/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
index 2d728143d3c9aa4..074f14dbeac581f 100644
--- a/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
+++ b/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
@@ -20,56 +20,77 @@
namespace llvm {
namespace X86Disassembler {
-
-// Accessor functions for various fields of an Intel instruction
-#define modFromModRM(modRM) (((modRM) & 0xc0) >> 6)
-#define regFromModRM(modRM) (((modRM) & 0x38) >> 3)
-#define rmFromModRM(modRM) ((modRM) & 0x7)
-#define scaleFromSIB(sib) (((sib) & 0xc0) >> 6)
-#define indexFromSIB(sib) (((sib) & 0x38) >> 3)
-#define baseFromSIB(sib) ((sib) & 0x7)
-#define wFromREX(rex) (((rex) & 0x8) >> 3)
-#define rFromREX(rex) (((rex) & 0x4) >> 2)
-#define xFromREX(rex) (((rex) & 0x2) >> 1)
-#define bFromREX(rex) ((rex) & 0x1)
-
-#define rFromEVEX2of4(evex) (((~(evex)) & 0x80) >> 7)
-#define xFromEVEX2of4(evex) (((~(evex)) & 0x40) >> 6)
-#define bFromEVEX2of4(evex) (((~(evex)) & 0x20) >> 5)
-#define r2FromEVEX2of4(evex) (((~(evex)) & 0x10) >> 4)
-#define mmmFromEVEX2of4(evex) ((evex) & 0x7)
-#define wFromEVEX3of4(evex) (((evex) & 0x80) >> 7)
-#define vvvvFromEVEX3of4(evex) (((~(evex)) & 0x78) >> 3)
-#define ppFromEVEX3of4(evex) ((evex) & 0x3)
-#define zFromEVEX4of4(evex) (((evex) & 0x80) >> 7)
-#define l2FromEVEX4of4(evex) (((evex) & 0x40) >> 6)
-#define lFromEVEX4of4(evex) (((evex) & 0x20) >> 5)
-#define bFromEVEX4of4(evex) (((evex) & 0x10) >> 4)
-#define v2FromEVEX4of4(evex) (((~evex) & 0x8) >> 3)
-#define aaaFromEVEX4of4(evex) ((evex) & 0x7)
-
-#define rFromVEX2of3(vex) (((~(vex)) & 0x80) >> 7)
-#define xFromVEX2of3(vex) (((~(vex)) & 0x40) >> 6)
-#define bFromVEX2of3(vex) (((~(vex)) & 0x20) >> 5)
-#define mmmmmFromVEX2of3(vex) ((vex) & 0x1f)
-#define wFromVEX3of3(vex) (((vex) & 0x80) >> 7)
-#define vvvvFromVEX3of3(vex) (((~(vex)) & 0x78) >> 3)
-#define lFromVEX3of3(vex) (((vex) & 0x4) >> 2)
-#define ppFromVEX3of3(vex) ((vex) & 0x3)
-
-#define rFromVEX2of2(vex) (((~(vex)) & 0x80) >> 7)
-#define vvvvFromVEX2of2(vex) (((~(vex)) & 0x78) >> 3)
-#define lFromVEX2of2(vex) (((vex) & 0x4) >> 2)
-#define ppFromVEX2of2(vex) ((vex) & 0x3)
-
-#define rFromXOP2of3(xop) (((~(xop)) & 0x80) >> 7)
-#define xFromXOP2of3(xop) (((~(xop)) & 0x40) >> 6)
-#define bFromXOP2of3(xop) (((~(xop)) & 0x20) >> 5)
-#define mmmmmFromXOP2of3(xop) ((xop) & 0x1f)
-#define wFromXOP3of3(xop) (((xop) & 0x80) >> 7)
-#define vvvvFromXOP3of3(vex) (((~(vex)) & 0x78) >> 3)
-#define lFromXOP3of3(xop) (((xop) & 0x4) >> 2)
-#define ppFromXOP3of3(xop) ((xop) & 0x3)
+// Helper macros
+#define bitFromOffset0(val) ((val) & 0x1)
+#define bitFromOffset1(val) (((val) >> 1) & 0x1)
+#define bitFromOffset2(val) (((val) >> 2) & 0x1)
+#define bitFromOffset3(val) (((val) >> 3) & 0x1)
+#define bitFromOffset4(val) (((val) >> 4) & 0x1)
+#define bitFromOffset5(val) (((val) >> 5) & 0x1)
+#define bitFromOffset6(val) (((val) >> 6) & 0x1)
+#define bitFromOffset7(val) (((val) >> 7) & 0x1)
+#define twoBitsFromOffset0(val) ((val) & 0x3)
+#define twoBitsFromOffset6(val) (((val) >> 6) & 0x3)
+#define threeBitsFromOffset0(val) ((val) & 0x7)
+#define threeBitsFromOffset3(val) (((val) >> 3) & 0x7)
+#define fiveBitsFromOffset0(val) ((val) & 0x1f)
+#define invertedBitFromOffset3(val) (((~(val)) >> 3) & 0x1)
+#define invertedBitFromOffset4(val) (((~(val)) >> 4) & 0x1)
+#define invertedBitFromOffset5(val) (((~(val)) >> 5) & 0x1)
+#define invertedBitFromOffset6(val) (((~(val)) >> 6) & 0x1)
+#define invertedBitFromOffset7(val) (((~(val)) >> 7) & 0x1)
+#define invertedFourBitsFromOffset3(val) (((~(val)) >> 3) & 0xf)
+// MOD/RM
+#define modFromModRM(modRM) twoBitsFromOffset6(modRM)
+#define regFromModRM(modRM) threeBitsFromOffset3(modRM)
+#define rmFromModRM(modRM) threeBitsFromOffset0(modRM)
+// SIB
+#define scaleFromSIB(sib) twoBitsFromOffset6(sib)
+#define indexFromSIB(sib) threeBitsFromOffset3(sib)
+#define baseFromSIB(sib) threeBitsFromOffset0(sib)
+// REX
+#define wFromREX(rex) bitFromOffset3(rex)
+#define rFromREX(rex) bitFromOffset2(rex)
+#define xFromREX(rex) bitFromOffset1(rex)
+#define bFromREX(rex) bitFromOffset0(rex)
+// XOP
+#define rFromXOP2of3(xop) invertedBitFromOffset7(xop)
+#define xFromXOP2of3(xop) invertedBitFromOffset6(xop)
+#define bFromXOP2of3(xop) invertedBitFromOffset5(xop)
+#define mmmmmFromXOP2of3(xop) fiveBitsFromOffset0(xop)
+#define wFromXOP3of3(xop) bitFromOffset7(xop)
+#define vvvvFromXOP3of3(xop) invertedFourBitsFromOffset3(xop)
+#define lFromXOP3of3(xop) bitFromOffset2(xop)
+#define ppFromXOP3of3(xop) twoBitsFromOffset0(xop)
+// VEX2
+#define rFromVEX2of2(vex) invertedBitFromOffset7(vex)
+#define vvvvFromVEX2of2(vex) invertedFourBitsFromOffset3(vex)
+#define lFromVEX2of2(vex) bitFromOffset2(vex)
+#define ppFromVEX2of2(vex) twoBitsFromOffset0(vex)
+// VEX3
+#define rFromVEX2of3(vex) invertedBitFromOffset7(vex)
+#define xFromVEX2of3(vex) invertedBitFromOffset6(vex)
+#define bFromVEX2of3(vex) invertedBitFromOffset5(vex)
+#define mmmmmFromVEX2of3(vex) fiveBitsFromOffset0(vex)
+#define wFromVEX3of3(vex) bitFromOffset7(vex)
+#define vvvvFromVEX3of3(vex) invertedFourBitsFromOffset3(vex)
+#define lFromVEX3of3(vex) bitFromOffset2(vex)
+#define ppFromVEX3of3(vex) twoBitsFromOffset0(vex)
+// EVEX
+#define rFromEVEX2of4(evex) invertedBitFromOffset7(evex)
+#define xFromEVEX2of4(evex) invertedBitFromOffset6(evex)
+#define bFromEVEX2of4(evex) invertedBitFromOffset5(evex)
+#define r2FromEVEX2of4(evex) invertedBitFromOffset4(evex)
+#define mmmFromEVEX2of4(evex) threeBitsFromOffset0(evex)
+#define wFromEVEX3of4(evex) bitFromOffset7(evex)
+#define vvvvFromEVEX3of4(evex) invertedFourBitsFromOffset3(evex)
+#define ppFromEVEX3of4(evex) twoBitsFromOffset0(evex)
+#define zFromEVEX4of4(evex) bitFromOffset7(evex)
+#define l2FromEVEX4of4(evex) bitFromOffset6(evex)
+#define lFromEVEX4of4(evex) bitFromOffset5(evex)
+#define bFromEVEX4of4(evex) bitFromOffset4(evex)
+#define v2FromEVEX4of4(evex) invertedBitFromOffset3(evex)
+#define aaaFromEVEX4of4(evex) threeBitsFromOffset0(evex)
// These enums represent Intel registers for use by the decoder.
#define REGS_8BIT \
|
zahiraam
pushed a commit
to zahiraam/llvm-project
that referenced
this pull request
Nov 20, 2023
…ing macro helpers (NFCI) (llvm#72341)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.