Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-118423: Add INSTRUCTION_SIZE macro to code generator#125467
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ec8c70109c2f59287eb92c76fce4e3f3b07ed5b375870341d421ebda5154f7fe7e83dc101a5fd1338628ee461d57135103715ce318235321148070e3e6b5926e78ec075e6f6ca3c0d107235d2d5cfb423219078433343ddf9ecb16abfaaff3f3ad10a8f72ef8138a06772f803a718cfba10d4ee3ae7a5dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add a new ``INSTRUCTION_SIZE`` macro to the cases generator which returns | ||
| the current instruction size. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -173,6 +173,8 @@ class Uop: | ||||||
| implicitly_created: bool = False | ||||||
| replicated = 0 | ||||||
| replicates: "Uop | None" = None | ||||||
| # Size of the instruction(s), only set for uops containing the INSTRUCTION_SIZE macro | ||||||
| instruction_size: int | None = None | ||||||
| def dump(self, indent: str) -> None: | ||||||
| print( | ||||||
| @@ -1079,6 +1081,35 @@ def add_instruction(name: str) -> None: | ||||||
| return instmap, len(no_arg), min_instrumented | ||||||
| def get_instruction_size_for_uop(instructions: dict[str, Instruction], uop: Uop) -> int | None: | ||||||
| """Return the size of the instruction that contains the given uop or | ||||||
| `None` if the uop does not contains the `INSTRUCTION_SIZE` macro. | ||||||
| If there is more than one instruction that contains the uop, | ||||||
| ensure that they all have the same size. | ||||||
| """ | ||||||
| for tkn in uop.body: | ||||||
| if tkn.text == "INSTRUCTION_SIZE": | ||||||
| break | ||||||
| else: | ||||||
| return None | ||||||
| size = None | ||||||
| for inst in instructions.values(): | ||||||
| if uop in inst.parts: | ||||||
| if size is None: | ||||||
| size = inst.size | ||||||
| if size != inst.size: | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this to an Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, leave it then. | ||||||
| raise analysis_error( | ||||||
| "All instructions containing a uop with the `INSTRUCTION_SIZE` macro " | ||||||
| f"must have the same size: {size} != {inst.size}", | ||||||
| tkn | ||||||
| ) | ||||||
| if size is None: | ||||||
| raise analysis_error(f"No instruction containing the uop '{uop.name}' was found", tkn) | ||||||
| return size | ||||||
| def analyze_forest(forest: list[parser.AstNode]) -> Analysis: | ||||||
| instructions: dict[str, Instruction] = {} | ||||||
| uops: dict[str, Uop] = {} | ||||||
| @@ -1122,6 +1153,8 @@ def analyze_forest(forest: list[parser.AstNode]) -> Analysis: | ||||||
| continue | ||||||
| if target.text in instructions: | ||||||
| instructions[target.text].is_target = True | ||||||
| for uop in uops.values(): | ||||||
| uop.instruction_size = get_instruction_size_for_uop(instructions, uop) | ||||||
| # Special case BINARY_OP_INPLACE_ADD_UNICODE | ||||||
| # BINARY_OP_INPLACE_ADD_UNICODE is not a normal family member, | ||||||
| # as it is the wrong size, but we need it to maintain an | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test for another instruction that is a different length, but uses
OP:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That test should fail, as the
INSTRUCTION_SIZEis inconsistent.The tier 2
INSTRUCTION_SIZEcannot be both 1 and 2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, sorry I mistakenly thought it should only fail for tier 2 hence I was only checking the instruction in the tier 2 generator. I extended the check to tier 1 as well and the test now fails as expected.