-
Notifications
You must be signed in to change notification settings - Fork 489
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
Document RFC 2867: instruction_set attribute #1253
Conversation
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.
src/attributes/codegen.md
Outdated
|
||
The `instruction_set` attribute may be applied to a function to enable code generation for a specific | ||
instruction set supported by the target architecture. Currently, this is only available for `ARMv4T` | ||
devices where the architecture has "ARM code" and "Thumb code" available and a single program may |
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.
Instead of "ARMv4T
devices", might it perhaps be a little more specific to say "the ARMv4T
architecture"? I know there likely won't be any confusion, but I'd like to use precise phrasing when possible.
Part of the problem talking about this clearly is that the reference has shied away from platform specific stuff, so it can be difficult to talk about things without also talking about target triples and such. AFAIK, the presence of ARMv4T
can't be detected through cfg
can it?
Also, can this maybe be structured so that it can be easily be extended in the future, and makes it clear which values to use? Perhaps something like:
The following values are available on targets for the ARMv4T
architecture:
arm::a32
— Uses ARM code.arm::t32
— Uses Thumb code.
Or something like that? Then, if support for other architectures is added, they can just add more lists (or if more ARM modes are added, just extend the list).
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.
You can use the armv4t target triple to detect it afaik, @Lokathor is the best person to ask as he's the most prevalent user currently
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.
So first minor point: ARMv? (with a v
) and ARM? (without a v
) are different numbering systems, because of course. So, if you go looking up details about this stuff keep that in mind.
Starting with ARMv4T and onward, ARM CPUs support a system called "interworking". This is currently what the instruction_set
attribute is all about. I'm told that theoretically MIPS also has some sort of system where the instruction_set
attribute would be appropriate, but I was told that once ever in passing so we can reasonably treat this attribute at ARM only for now.
Interworking is available in most ARM architectures that came after ARMv4T, but not all of them.
I had to go double check on wikipedia:
All ARMv7 chips support the Thumb instruction set. All chips in the Cortex-A series, Cortex-R series, and ARM11 series support both "ARM instruction set state" and "Thumb instruction set state", while chips in the Cortex-M series support only the Thumb instruction set.
Looking at Rust's target list, thumbv6m-none-eabi
is described as "Bare Cortex-M0, M0+, M1", so I have to assume that you should not use the instruction_set
attribute on that target to set a function for a32
code. However, it's still logically consistent to set a function for t32
on a Cortex-M. That's already the default, and you'd basically be just more strongly re-stating that.
In terms of what you can check with cfg
at compile time, beyond target_arch="arm"
, there's also target_feature = "thumb-mode"
which at least tells you the default code mode.
As far as I know, there isn't a specific way to check for the presence of interworking. If I ask rustc what it thinks about the thumbv4t-none-eabi
target:
$ rustc --print cfg --target thumbv4t-none-eabi
debug_assertions
panic="abort"
target_abi="eabi"
target_arch="arm"
target_endian="little"
target_env=""
target_feature="llvm14-builtins-abi"
target_feature="thumb-mode"
target_has_atomic_equal_alignment="16"
target_has_atomic_equal_alignment="32"
target_has_atomic_equal_alignment="8"
target_has_atomic_equal_alignment="ptr"
target_has_atomic_load_store="16"
target_has_atomic_load_store="32"
target_has_atomic_load_store="8"
target_has_atomic_load_store="ptr"
target_os="none"
target_pointer_width="32"
target_vendor="unknown"
Which... sure doesn't seem to indicate if interworking is specifically allowed.
I know that the assembler knows if it's assembling interworking code (example, but I don't know if rustc lets you know this in any way.
But if we go check the thumbv6m-none-eabi
target we see:
$ rustc --print cfg --target thumbv6m-none-eabi
debug_assertions
panic="abort"
target_abi="eabi"
target_arch="arm"
target_endian="little"
target_env=""
target_feature="llvm14-builtins-abi"
target_feature="mclass"
target_feature="thumb-mode"
target_feature="v5te"
target_feature="v6"
target_has_atomic_equal_alignment="16"
target_has_atomic_equal_alignment="32"
target_has_atomic_equal_alignment="8"
target_has_atomic_equal_alignment="ptr"
target_has_atomic_load_store="16"
target_has_atomic_load_store="32"
target_has_atomic_load_store="8"
target_has_atomic_load_store="ptr"
target_os="none"
target_pointer_width="32"
target_vendor="unknown"
So we can probably say that if target_feature="mclass"
is set then you should not try interworking.
@xd009642 how does the rustc
decide if the attribute is allowed?
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.
Looking back at code to refresh myself, there's a has_thumb_interworking
bool for each target, it's only true for:
- armv4t_unknown_linux_gnueabi
- armv5te_unknown_linux_gnueabi
- armv5te_unknown_linux_musleabi
So docs should be adjusted in some way to mention armv5te as well (I'll do that tomorrow it's after midnight here)
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.
uhhhhhhhhhhhhhhhhhh, I've certainly used the attribute on the thumbv4t-none-eabi
target, so either your check is broken somehow or you're looking at the wrong part of the code.
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.
Nope I just missed it, each spec is in their own file and I stopped reading when I hit the module mod in commit diff, should have read thumbv4t_none_eabi
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.
If there's a way to query the info in each spec i.e. https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/armv4t_none_eabi.rs we could amend the docs to instead tell people how to see if their target supports interworking given has_thumb_interworking: true,
is a requirement for the attribute
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.
I know that the assembler knows if it's assembling interworking code (example, but I don't know if rustc lets you know this in any way.
asm_args
is entirely unused.
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.
oh maybe that's why my code breaks randomly sometimes
@ehuss just checking if there's any changes I should do for this PR 👀 . Given the FCP closed and the stabilisation PR is open (rust-lang/rust#102458) I'd be interested in just pushing things along in any way I can |
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.
Thanks! I'll go ahead and merge. If there is need to clarify or adjust which targets these work on, followup PRs would be appreciated.
Update books ## rust-lang/book 1 commits in 3f64052c048c6def93b94a2b514ee88bba918744..a60f4316ec923a5ac2ed6a2eba6960edb832d855 2022-11-16 15:07:18 UTC to 2022-11-16 15:07:18 UTC - Fix Install MdBook command (rust-lang/book#3424) ## rust-embedded/book 4 commits in c533348edd69f11a8f4225d633a05d7093fddbf3..19f798d448835a4888e3b3eae7fe69f1d61d8681 2022-11-17 15:08:11 UTC to 2022-11-08 23:27:57 UTC - start/hardware.md: Fix typo (rust-embedded/book#336) - doc: Fix `arm-none-eabi-gdb` installation instruction for Fedora 27 or newer to just use `gdb` (rust-embedded/book#335) - Update singletons.md (rust-embedded/book#334) - Remove incorrect claim HashMap is avail in no_std (rust-embedded/book#333) ## rust-lang/nomicon 2 commits in 05532356e7a4dbea2330aabb77611f5179493bb8..ae406aa5287a9e025abb72343aaceec98458c117 2022-11-21 22:48:20 UTC to 2022-11-15 00:29:20 UTC - Improve chapter about `Vec<T>` (rust-lang/nomicon#381) - Grammar change for 3.4: Limits of Lifetimes (lifetime-mismatch.md) (rust-lang/nomicon#386) ## rust-lang/reference 9 commits in 9f0cc13ffcd27c1fbe1ab766a9491e15ddcf4d19..3ae62681ff236d5528ef7c8c28ba7c6b2ecc6731 2022-12-05 00:51:50 UTC to 2022-11-15 20:43:30 UTC - Document that type parameter `Self` is unsized by default (rust-lang/reference#1285) - replace `crateid` term with `crate_name` (rust-lang/reference#1310) - Document native library modifier `verbatim` (rust-lang/reference#1299) - Update literal suffix docs for rust-lang#102944 (rust-lang/reference#1305) - update aliasing rules section of the reference (rust-lang/reference#1290) - Document RFC 2867: instruction_set attribute (rust-lang/reference#1253) - Fix a minor typo in the "Higher-ranked trait bounds" section (rust-lang/reference#1288) - Disallow newline directly following `//` (rust-lang/reference#1294) - Add an anchor to the "forwarding macro fragments" paragraph (rust-lang/reference#1300) ## rust-lang/rust-by-example 5 commits in 2b15c0abf2bada6e00553814336bc3e2d8399097..a9869b4a3c4cac3bc6099b41f088679e268400b8 2022-11-27 19:03:05 UTC to 2022-11-11 18:54:53 UTC - Migrate from highfive to triagebot (rust-lang/rust-by-example#1647) - Simpler version of the read_lines script. (rust-lang/rust-by-example#1641) - Fix comment in "Formatted print" example code (rust-lang/rust-by-example#1638) - Added a missing backtick in a comment in chapter 15.4. (rust-lang/rust-by-example#1642) - Clarify the confusing closure example rust-lang#1611 (rust-lang/rust-by-example#1643) ## rust-lang/rustc-dev-guide 13 commits in d0dc6c97a6486f68bac782fff135086eae6d77ec..e269950a57fa6fcda356426545fb5aa3691a7ced 2022-12-03 23:09:24 UTC to 2022-11-08 21:35:38 UTC - Remove duplicate paragraph (rust-lang/rustc-dev-guide#1523) - clarify subtree tool policy (rust-lang/rustc-dev-guide#1518) - Typo (rust-lang/rustc-dev-guide#1520) - Link directly to the section on `--keep-stage` (rust-lang/rustc-dev-guide#1515) - do an actual link to detect if it breaks in future (rust-lang/rustc-dev-guide#1517) - Triage some date-check items (rust-lang/rustc-dev-guide#1513) - Update path for `try_mark_green` implementation (rust-lang/rustc-dev-guide#1512) - Fix a broken design docs link about unused substs bug (rust-lang/rustc-dev-guide#1511) - updating-llvm: keep a calm tone (rust-lang/rustc-dev-guide#1449) - date-check: updating-llvm (rust-lang/rustc-dev-guide#1424) - rewrite the section about regions in the trait solver (rust-lang/rustc-dev-guide#1508) - Consistent ordered list indexing (rust-lang/rustc-dev-guide#1509) - Document multiple alternative suggestions on diagnostic structs (rust-lang/rustc-dev-guide#1486)
Update books ## rust-lang/book 1 commits in 3f64052c048c6def93b94a2b514ee88bba918744..a60f4316ec923a5ac2ed6a2eba6960edb832d855 2022-11-16 15:07:18 UTC to 2022-11-16 15:07:18 UTC - Fix Install MdBook command (rust-lang/book#3424) ## rust-embedded/book 4 commits in c533348edd69f11a8f4225d633a05d7093fddbf3..19f798d448835a4888e3b3eae7fe69f1d61d8681 2022-11-17 15:08:11 UTC to 2022-11-08 23:27:57 UTC - start/hardware.md: Fix typo (rust-embedded/book#336) - doc: Fix `arm-none-eabi-gdb` installation instruction for Fedora 27 or newer to just use `gdb` (rust-embedded/book#335) - Update singletons.md (rust-embedded/book#334) - Remove incorrect claim HashMap is avail in no_std (rust-embedded/book#333) ## rust-lang/nomicon 2 commits in 05532356e7a4dbea2330aabb77611f5179493bb8..ae406aa5287a9e025abb72343aaceec98458c117 2022-11-21 22:48:20 UTC to 2022-11-15 00:29:20 UTC - Improve chapter about `Vec<T>` (rust-lang/nomicon#381) - Grammar change for 3.4: Limits of Lifetimes (lifetime-mismatch.md) (rust-lang/nomicon#386) ## rust-lang/reference 9 commits in 9f0cc13ffcd27c1fbe1ab766a9491e15ddcf4d19..3ae62681ff236d5528ef7c8c28ba7c6b2ecc6731 2022-12-05 00:51:50 UTC to 2022-11-15 20:43:30 UTC - Document that type parameter `Self` is unsized by default (rust-lang/reference#1285) - replace `crateid` term with `crate_name` (rust-lang/reference#1310) - Document native library modifier `verbatim` (rust-lang/reference#1299) - Update literal suffix docs for rust-lang#102944 (rust-lang/reference#1305) - update aliasing rules section of the reference (rust-lang/reference#1290) - Document RFC 2867: instruction_set attribute (rust-lang/reference#1253) - Fix a minor typo in the "Higher-ranked trait bounds" section (rust-lang/reference#1288) - Disallow newline directly following `//` (rust-lang/reference#1294) - Add an anchor to the "forwarding macro fragments" paragraph (rust-lang/reference#1300) ## rust-lang/rust-by-example 5 commits in 2b15c0abf2bada6e00553814336bc3e2d8399097..a9869b4a3c4cac3bc6099b41f088679e268400b8 2022-11-27 19:03:05 UTC to 2022-11-11 18:54:53 UTC - Migrate from highfive to triagebot (rust-lang/rust-by-example#1647) - Simpler version of the read_lines script. (rust-lang/rust-by-example#1641) - Fix comment in "Formatted print" example code (rust-lang/rust-by-example#1638) - Added a missing backtick in a comment in chapter 15.4. (rust-lang/rust-by-example#1642) - Clarify the confusing closure example rust-lang#1611 (rust-lang/rust-by-example#1643) ## rust-lang/rustc-dev-guide 13 commits in d0dc6c97a6486f68bac782fff135086eae6d77ec..e269950a57fa6fcda356426545fb5aa3691a7ced 2022-12-03 23:09:24 UTC to 2022-11-08 21:35:38 UTC - Remove duplicate paragraph (rust-lang/rustc-dev-guide#1523) - clarify subtree tool policy (rust-lang/rustc-dev-guide#1518) - Typo (rust-lang/rustc-dev-guide#1520) - Link directly to the section on `--keep-stage` (rust-lang/rustc-dev-guide#1515) - do an actual link to detect if it breaks in future (rust-lang/rustc-dev-guide#1517) - Triage some date-check items (rust-lang/rustc-dev-guide#1513) - Update path for `try_mark_green` implementation (rust-lang/rustc-dev-guide#1512) - Fix a broken design docs link about unused substs bug (rust-lang/rustc-dev-guide#1511) - updating-llvm: keep a calm tone (rust-lang/rustc-dev-guide#1449) - date-check: updating-llvm (rust-lang/rustc-dev-guide#1424) - rewrite the section about regions in the trait solver (rust-lang/rustc-dev-guide#1508) - Consistent ordered list indexing (rust-lang/rustc-dev-guide#1509) - Document multiple alternative suggestions on diagnostic structs (rust-lang/rustc-dev-guide#1486)
Update books ## rust-lang/book 1 commits in 3f64052c048c6def93b94a2b514ee88bba918744..a60f4316ec923a5ac2ed6a2eba6960edb832d855 2022-11-16 15:07:18 UTC to 2022-11-16 15:07:18 UTC - Fix Install MdBook command (rust-lang/book#3424) ## rust-embedded/book 4 commits in c533348edd69f11a8f4225d633a05d7093fddbf3..19f798d448835a4888e3b3eae7fe69f1d61d8681 2022-11-17 15:08:11 UTC to 2022-11-08 23:27:57 UTC - start/hardware.md: Fix typo (rust-embedded/book#336) - doc: Fix `arm-none-eabi-gdb` installation instruction for Fedora 27 or newer to just use `gdb` (rust-embedded/book#335) - Update singletons.md (rust-embedded/book#334) - Remove incorrect claim HashMap is avail in no_std (rust-embedded/book#333) ## rust-lang/nomicon 2 commits in 05532356e7a4dbea2330aabb77611f5179493bb8..ae406aa5287a9e025abb72343aaceec98458c117 2022-11-21 22:48:20 UTC to 2022-11-15 00:29:20 UTC - Improve chapter about `Vec<T>` (rust-lang/nomicon#381) - Grammar change for 3.4: Limits of Lifetimes (lifetime-mismatch.md) (rust-lang/nomicon#386) ## rust-lang/reference 9 commits in 9f0cc13ffcd27c1fbe1ab766a9491e15ddcf4d19..3ae62681ff236d5528ef7c8c28ba7c6b2ecc6731 2022-12-05 00:51:50 UTC to 2022-11-15 20:43:30 UTC - Document that type parameter `Self` is unsized by default (rust-lang/reference#1285) - replace `crateid` term with `crate_name` (rust-lang/reference#1310) - Document native library modifier `verbatim` (rust-lang/reference#1299) - Update literal suffix docs for rust-lang#102944 (rust-lang/reference#1305) - update aliasing rules section of the reference (rust-lang/reference#1290) - Document RFC 2867: instruction_set attribute (rust-lang/reference#1253) - Fix a minor typo in the "Higher-ranked trait bounds" section (rust-lang/reference#1288) - Disallow newline directly following `//` (rust-lang/reference#1294) - Add an anchor to the "forwarding macro fragments" paragraph (rust-lang/reference#1300) ## rust-lang/rust-by-example 5 commits in 2b15c0abf2bada6e00553814336bc3e2d8399097..a9869b4a3c4cac3bc6099b41f088679e268400b8 2022-11-27 19:03:05 UTC to 2022-11-11 18:54:53 UTC - Migrate from highfive to triagebot (rust-lang/rust-by-example#1647) - Simpler version of the read_lines script. (rust-lang/rust-by-example#1641) - Fix comment in "Formatted print" example code (rust-lang/rust-by-example#1638) - Added a missing backtick in a comment in chapter 15.4. (rust-lang/rust-by-example#1642) - Clarify the confusing closure example rust-lang#1611 (rust-lang/rust-by-example#1643) ## rust-lang/rustc-dev-guide 13 commits in d0dc6c97a6486f68bac782fff135086eae6d77ec..e269950a57fa6fcda356426545fb5aa3691a7ced 2022-12-03 23:09:24 UTC to 2022-11-08 21:35:38 UTC - Remove duplicate paragraph (rust-lang/rustc-dev-guide#1523) - clarify subtree tool policy (rust-lang/rustc-dev-guide#1518) - Typo (rust-lang/rustc-dev-guide#1520) - Link directly to the section on `--keep-stage` (rust-lang/rustc-dev-guide#1515) - do an actual link to detect if it breaks in future (rust-lang/rustc-dev-guide#1517) - Triage some date-check items (rust-lang/rustc-dev-guide#1513) - Update path for `try_mark_green` implementation (rust-lang/rustc-dev-guide#1512) - Fix a broken design docs link about unused substs bug (rust-lang/rustc-dev-guide#1511) - updating-llvm: keep a calm tone (rust-lang/rustc-dev-guide#1449) - date-check: updating-llvm (rust-lang/rustc-dev-guide#1424) - rewrite the section about regions in the trait solver (rust-lang/rustc-dev-guide#1508) - Consistent ordered list indexing (rust-lang/rustc-dev-guide#1509) - Document multiple alternative suggestions on diagnostic structs (rust-lang/rustc-dev-guide#1486)
Update books ## rust-lang/book 1 commits in 3f64052c048c6def93b94a2b514ee88bba918744..a60f4316ec923a5ac2ed6a2eba6960edb832d855 2022-11-16 15:07:18 UTC to 2022-11-16 15:07:18 UTC - Fix Install MdBook command (rust-lang/book#3424) ## rust-embedded/book 4 commits in c533348edd69f11a8f4225d633a05d7093fddbf3..19f798d448835a4888e3b3eae7fe69f1d61d8681 2022-11-17 15:08:11 UTC to 2022-11-08 23:27:57 UTC - start/hardware.md: Fix typo (rust-embedded/book#336) - doc: Fix `arm-none-eabi-gdb` installation instruction for Fedora 27 or newer to just use `gdb` (rust-embedded/book#335) - Update singletons.md (rust-embedded/book#334) - Remove incorrect claim HashMap is avail in no_std (rust-embedded/book#333) ## rust-lang/nomicon 2 commits in 05532356e7a4dbea2330aabb77611f5179493bb8..ae406aa5287a9e025abb72343aaceec98458c117 2022-11-21 22:48:20 UTC to 2022-11-15 00:29:20 UTC - Improve chapter about `Vec<T>` (rust-lang/nomicon#381) - Grammar change for 3.4: Limits of Lifetimes (lifetime-mismatch.md) (rust-lang/nomicon#386) ## rust-lang/reference 9 commits in 9f0cc13ffcd27c1fbe1ab766a9491e15ddcf4d19..3ae62681ff236d5528ef7c8c28ba7c6b2ecc6731 2022-12-05 00:51:50 UTC to 2022-11-15 20:43:30 UTC - Document that type parameter `Self` is unsized by default (rust-lang/reference#1285) - replace `crateid` term with `crate_name` (rust-lang/reference#1310) - Document native library modifier `verbatim` (rust-lang/reference#1299) - Update literal suffix docs for rust-lang#102944 (rust-lang/reference#1305) - update aliasing rules section of the reference (rust-lang/reference#1290) - Document RFC 2867: instruction_set attribute (rust-lang/reference#1253) - Fix a minor typo in the "Higher-ranked trait bounds" section (rust-lang/reference#1288) - Disallow newline directly following `//` (rust-lang/reference#1294) - Add an anchor to the "forwarding macro fragments" paragraph (rust-lang/reference#1300) ## rust-lang/rust-by-example 5 commits in 2b15c0abf2bada6e00553814336bc3e2d8399097..a9869b4a3c4cac3bc6099b41f088679e268400b8 2022-11-27 19:03:05 UTC to 2022-11-11 18:54:53 UTC - Migrate from highfive to triagebot (rust-lang/rust-by-example#1647) - Simpler version of the read_lines script. (rust-lang/rust-by-example#1641) - Fix comment in "Formatted print" example code (rust-lang/rust-by-example#1638) - Added a missing backtick in a comment in chapter 15.4. (rust-lang/rust-by-example#1642) - Clarify the confusing closure example rust-lang#1611 (rust-lang/rust-by-example#1643) ## rust-lang/rustc-dev-guide 13 commits in d0dc6c97a6486f68bac782fff135086eae6d77ec..e269950a57fa6fcda356426545fb5aa3691a7ced 2022-12-03 23:09:24 UTC to 2022-11-08 21:35:38 UTC - Remove duplicate paragraph (rust-lang/rustc-dev-guide#1523) - clarify subtree tool policy (rust-lang/rustc-dev-guide#1518) - Typo (rust-lang/rustc-dev-guide#1520) - Link directly to the section on `--keep-stage` (rust-lang/rustc-dev-guide#1515) - do an actual link to detect if it breaks in future (rust-lang/rustc-dev-guide#1517) - Triage some date-check items (rust-lang/rustc-dev-guide#1513) - Update path for `try_mark_green` implementation (rust-lang/rustc-dev-guide#1512) - Fix a broken design docs link about unused substs bug (rust-lang/rustc-dev-guide#1511) - updating-llvm: keep a calm tone (rust-lang/rustc-dev-guide#1449) - date-check: updating-llvm (rust-lang/rustc-dev-guide#1424) - rewrite the section about regions in the trait solver (rust-lang/rustc-dev-guide#1508) - Consistent ordered list indexing (rust-lang/rustc-dev-guide#1509) - Document multiple alternative suggestions on diagnostic structs (rust-lang/rustc-dev-guide#1486)
As part of the stabilisation work: rust-lang/rust#74727 this PR adds some documentation for the instruction set attribute. I've popped this in the codegen attributes as that seemed rather self-explanatory. It's currently fairly brief but feels "enough" to me, enough at least to get some feedback on iterate on.