Skip to content

Commit 89f67b3

Browse files
authored
Merge pull request #1912 from ehuss/instruction_set
Update `instruction_set` to use the attribute template
2 parents 00405f8 + 71d7c2a commit 89f67b3

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

src/attributes/codegen.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -634,41 +634,53 @@ trait object whose methods are attributed.
634634
> [!NOTE]
635635
> The aforementioned shim for function pointers is necessary because `rustc` implements `track_caller` in a codegen context by appending an implicit parameter to the function ABI, but this would be unsound for an indirect call because the parameter is not a part of the function's type and a given function pointer type may or may not refer to a function with the attribute. The creation of a shim hides the implicit parameter from callers of the function pointer, preserving soundness.
636636
637+
<!-- template:attributes -->
637638
r[attributes.codegen.instruction_set]
638639
## The `instruction_set` attribute
639640

640-
r[attributes.codegen.instruction_set.allowed-positions]
641-
The *`instruction_set` [attribute]* may be applied to a function to control which instruction set the function will be generated for.
641+
r[attributes.codegen.instruction_set.intro]
642+
The *`instruction_set` [attribute]* specifies the instruction set that a function will use during code generation. This allows mixing more than one instruction set in a single program.
642643

643-
r[attributes.codegen.instruction_set.behavior]
644-
This allows mixing more than one instruction set in a single program on CPU architectures that support it.
644+
> [!EXAMPLE]
645+
> <!-- ignore: arm-only -->
646+
> ```rust,ignore
647+
> #[instruction_set(arm::a32)]
648+
> fn arm_code() {}
649+
>
650+
> #[instruction_set(arm::t32)]
651+
> fn thumb_code() {}
652+
> ```
645653
646654
r[attributes.codegen.instruction_set.syntax]
647-
It uses the [MetaListPaths] syntax, and a path comprised of the architecture family name and instruction set name.
655+
The `instruction_set` attribute uses the [MetaListPaths] syntax to specify a single path consisting of the architecture family name and instruction set name.
656+
657+
r[attributes.codegen.instruction_set.allowed-positions]
658+
The `instruction_set` attribute may only be applied to functions, including [closures][expr.closure], [free functions][items.fn], and associated functions defined (i.e. with a body) in [inherent impls][items.associated.fn], [trait impls][items.impl.trait], and [trait definitions][items.traits].
659+
660+
> [!NOTE]
661+
> `rustc` ignores use in other positions but lints against it. This may become an error in the future.
662+
663+
r[attributes.codegen.instruction_set.duplicates]
664+
The `instruction_set` attribute may be used only once on a function.
648665
649666
r[attributes.codegen.instruction_set.target-limits]
650-
It is a compilation error to use the `instruction_set` attribute on a target that does not support it.
667+
The `instruction_set` attribute may only be used with a target that supports the given value.
651668
652-
r[attributes.codegen.instruction_set.arm]
653-
### On ARM
669+
r[attributes.codegen.instruction_set.inline-asm]
670+
When the `instruction_set` attribute is used, any inline assembly in the function must use the specified instruction set instead of the target default.
654671
655-
For the `ARMv4T` and `ARMv5te` architectures, the following are supported:
656-
* `arm::a32` --- Generate the function as A32 "ARM" code.
657-
* `arm::t32` --- Generate the function as T32 "Thumb" code.
672+
r[attributes.codegen.instruction_set.arm]
673+
### `instruction_set` on ARM
658674
659-
<!-- ignore: arm-only -->
660-
```rust,ignore
661-
#[instruction_set(arm::a32)]
662-
fn foo_arm_code() {}
675+
When targeting the `ARMv4T` and `ARMv5te` architectures, the supported values for `instruction_set` are:
663676
664-
#[instruction_set(arm::t32)]
665-
fn bar_thumb_code() {}
666-
```
677+
- `arm::a32` --- Generate the function as A32 "ARM" code.
678+
- `arm::t32` --- Generate the function as T32 "Thumb" code.
667679
668-
Using the `instruction_set` attribute has the following effects:
680+
If the address of the function is taken as a function pointer, the low bit of the address will depend on the selected instruction set:
669681
670-
* If the address of the function is taken as a function pointer, the low bit of the address will be set to 0 (arm) or 1 (thumb) depending on the instruction set.
671-
* Any inline assembly in the function must use the specified instruction set instead of the target default.
682+
- For `arm::a32` ("ARM"), it will be 0.
683+
- For `arm::t32` ("Thumb"), it will be 1.
672684
673685
[`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu
674686
[`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature

0 commit comments

Comments
 (0)