-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking Issue for #[instruction_set]
attribute (RFC 2867)
#74727
Comments
I'm going to take a shot at implementing this RFC. I've already got an initial idea of where to start, adding it to |
@pnkfelix do you mind if I message you for guidance once I have a more concrete idea of what my questions are? |
I'll write up some pointers.
|
So I've added the symbols to symbol.rs, and instruction_set to CodegenFnAttrs added an InstructionSet enum, updated codegen_fn_attrs (although not all of the sub-bullet points, it's very happy path only right now). I'll look at the target stuff next since that seems to be the biggest part I'm missing in Thanks that fills in a lot of my open questions 😄 |
I don't know the best way to, from inside the compiler, tell if the target is an ARM arch target. And, even then, to tell if the default codegen will be a32 or t32. I can say that, looking at the platform support page, all the tier2 and tier3 targets that start with Ideally this works for any |
If there's already a way to tell a target that starts with |
So I've attempted to do all the points laid out above to the best of my effort (minus the tests for appropriate errors as I had a feeling my errors are likely to change). There's probably a lot to change as this is my first time working on the compiler, but I think it's ready for some initial feedback - #76260 . |
Current status from today's @rust-lang/lang meeting: updating to account for targets that only support one or another instruction set. |
@joshtriplett are there minutes for the meeting? Or should I just wait till the RFC or issue is updated and adjust the PR? |
@xd009642 I was at the meeting today and attempted to convey the status, though I may have done so inexpertly. What I said was that:
I don't think that the RFC needs an update at all, or that your PR needs any changes other than whatever T-compiler asks for. Feel free to work out any blockers/concerns on the PR with them, and also feel free to comment anything more if I missed a detail. |
So far there's an additional |
Implementation of RFC2867 rust-lang#74727 So I've started work on this, I think my next steps are to make use of the `instruction_set` value in the llvm codegen but this is the point where I begin to get a bit lost. I'm looking at the code but it would be nice to have some guidance on what I've currently done and what I'm doing next 😄
Update: PR merged, starting tomorrow you can use it in your nightly work, presumably we'll have a trial period of at least few releases before considering possible stabilization. |
Is it possible for core library functions to get inlined despite not being specified as one ISA or the other? |
The problem as I understand it is there's only one (T32) copy of the standard library and Rust just emits calls into it despite the function being A32, which LLVM then refuses to inline. A solution could be for Cargo's unstable |
There're definitely other things besides core that the lack of ability to inline kind of makes a drag too, such as the phantom_fields defined by https://docs.rs/crate/gba-proc-macro (which i think my current best bet is to just.. duplicate each function into foo() and a32_foo() versions and call the latter in my code, but I don't like the idea of forking every dependency crate and making duplicate a32 versions of every stub function i need to call) For this case it would definitely benefit me to be able to compile arbitrary dependencies in both modes too, though I'm not sure what that would look like ideally. A lot of code here isn't currently delivering on the zero-cost abstraction promise, in other words :P |
Update 2021-04-06Picking a target that supports using both a32 and t32 code, and that is tier2 so we can see it on goldbolt, please look at the following code:
The exact details of the ARM calling conventions aren't quite important here, but the thing to note within the assembly output is:
Meanwhile let's look at if we can paper over the issue with inline assembly:
"Loka that's just one example though?" Well, sure, but it's a very important one because being able to use these zero-cost intrinsics is the sales pitch of rust. Here's another example: https://rust.godbolt.org/z/bG3bhTd4z:
Summary
|
one thing for consideration is having this not be its own stand-alone attribute applied to functions, but being an available option as a |
@Lokathor any update this month? Thanks for the update last month, we have a meeting next Wed and we'll talk it over. |
I did have a build that managed to create an illegal instruction in debug mode but not release mode, though that might be related to the incremental compilation bug that was recently resolved. I haven't had time to check again since that announcement. |
@nikomatsakis Having worked with this some more, I can say that things are ready for stabilization. the code that you get out of this is pretty bad, but that's just a quality-of-life issue. The interface for how a user marks functions with this attribute wouldn't change at all even if the compiler gets smarter about codegen. EDIT: particularly, this works with inline_asm, which was the major concern way back when. |
We discussed this in today's @rust-lang/lang meeting. Kicking off stabilization of this seems fine. @pnkfelix, as the liaison, want to start a stabilization FCP if you concur? |
ping @pnkfelix |
Okay, I reviewed the update from last year and fixed the first godbolt link ( Its an interesting question, whether to stabilize something that has clear performance issues (in terms of not meeting typical zero-cost expectations). But that is a quality-of-life issue; if users can find utility in this feature even in its current state, then that's an argument for stabilization. I'll go ahead and fire off a stabilization FCP. @rfcbot fcp merge |
Team member @pnkfelix has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
First stabilisation report so let me know if I've done anything wrong 🙏 Request for StabilizationSummaryThe instruction set attribute provides a new function attribute for architectures which support more than one form of machine code. Currently, this is just implemented for CPUs in the ARM family which support a program switching between "ARM code" and "Thumb code". Although other instruction sets could be added in future as unstable features. These two instruction sets appear as follows: Arm code: #[instruction_set(arm::a32)]
fn arm_code_fn() {
// function compiled using arm code
} Thumb code: #[instruction_set(arm::t32)]
fn thumb_code_fn() {
// function compiled using thumb code
} DocumentationCurrently, the only usage is homebrew GameBoy Advance development for ARMv4t and the RFC. Given the number of uses of this feature is currently limited to these people this is potentially fine. Tests
Unresolved Questions
|
@rfcbot concern documentation-pr We need an open PR adding this to the Rust reference! |
@nikomatsakis PR opened with an initial go at the docs: rust-lang/reference#1253 |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Stabilize the `instruction_set` feature Closes rust-lang/rust#74727 FCP is complete on rust-lang/rust#74727 (comment) r? `@pnkfelix` and/or `@nikomatsakis` cc `@xd009642` Signed-off-by: Yuki Okushi <[email protected]>
Stabilize the `instruction_set` feature Closes rust-lang/rust#74727 FCP is complete on rust-lang/rust#74727 (comment) r? `@pnkfelix` and/or `@nikomatsakis` cc `@xd009642` Signed-off-by: Yuki Okushi <[email protected]>
Stabilize the `instruction_set` feature Closes rust-lang/rust#74727 FCP is complete on rust-lang/rust#74727 (comment) r? `@pnkfelix` and/or `@nikomatsakis` cc `@xd009642` Signed-off-by: Yuki Okushi <[email protected]>
This is a tracking issue for the RFC "
#[instruction_set(...)]
attribute" (rust-lang/rfcs#2867).The feature gate for the issue is
#![feature(isa_attribute)]
.The lang-team liaison for this feature is @pnkfelix.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved Questions
instruction_set
and inline assembly always interact correctly? This isn't an implementation blocker but needs to be resolved before Stabilization of the attribute. (Currently, LLVM will not inlinea32
functions intot32
functions and vice versa, because they count as different code targets. However, this is not necessarily a guarantee from LLVM, it could just be the current implementation, so more investigation is needed.)Implementation history
The text was updated successfully, but these errors were encountered: