-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-118423: Add INSTRUCTION_SIZE
macro to code generator
#125467
Changes from all commits
ec8c701
09c2f59
287eb92
c76fce4
e3f3b07
ed5b375
870341d
421ebda
5154f7f
e7e83dc
101a5fd
1338628
ee461d5
7135103
715ce31
8235321
148070e
3e6b592
6e78ec0
75e6f6c
a3c0d10
7235d2d
5cfb423
2190784
33343dd
f9ecb16
abfaaff
3f3ad10
a8f72ef
8138a06
772f803
a718cfb
a10d4ee
3ae7a5d
File filter
Filter by extension
Conversations
Jump to
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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: | ||||||
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
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
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_SIZE
is inconsistent.The tier 2
INSTRUCTION_SIZE
cannot 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.