Skip to content
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

Avoid redundant instructions in x86 inline asm #233

Merged
merged 3 commits into from
Feb 22, 2022

Conversation

sunfishcode
Copy link
Member

This is inspired by an idea from @m-ou-se in #project-inline-asm in the Rust zulip. We can't use esi as an explicit inline asm operand, but we can request a register and test whether we got esi using .ifnes. When we do get esi, avoid swapping it into place.

And, eliminate a redundant push/pop in indirect_syscall5.

While here, add some comments and tidy up the arch/inline/mod.rs file.

@Urgau
Copy link
Contributor

Urgau commented Feb 16, 2022

There are some ongoing debate in T-lang about what subsets of assembly instructions are guaranteed to be available and some that they want to disallow (because a different codegen or implementation might not have it), this includes the .if/.ifnes/... operands.

@sunfishcode
Copy link
Member Author

There are some ongoing debate in T-lang about what subsets of assembly instructions are guaranteed to be available and some that they want to disallow (because a different codegen or implementation might not have it), this includes the .if/.ifnes/... operands.

Interesting, thanks for mentioning that! Restricting the set of directives is a good idea, and I encourage T-lang to do so; there are a lot of directives and they can interact with compilers in undocumented and undesigned ways.

If .if/.endif/etc. are disallowed, we can simply remove those directives here once nightly starts enforcing the new rules. They're a very minor optimization in this context.

@sunfishcode
Copy link
Member Author

Ah, looking at the list here, it appears the plan is not to enforce the restrictions, but to say that things not on the list have assembler-specific behavior. Accordingly, I've now removed the optimization that uses .ifnes from this PR, to avoid depending on what will be considered assembler-specific behavior.

@sunfishcode sunfishcode merged commit 14a9977 into main Feb 22, 2022
@sunfishcode sunfishcode deleted the sunfishcode/x86-inline-asm-opt branch February 22, 2022 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants