Skip to content

Commit 54efbec

Browse files
committed
Update instruction_set to use the attribute template
1 parent 9571d4d commit 54efbec

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/attributes/codegen.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -614,34 +614,47 @@ trait object whose methods are attributed.
614614
r[attributes.codegen.instruction_set]
615615
## The `instruction_set` attribute
616616

617+
r[attributes.codegen.instruction_set.intro]
618+
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.
619+
620+
> [!EXAMPLE]
621+
> <!-- ignore: arm-only -->
622+
> ```rust,ignore
623+
> #[instruction_set(arm::a32)]
624+
> fn foo_arm_code() {}
625+
>
626+
> #[instruction_set(arm::t32)]
627+
> fn bar_thumb_code() {}
628+
> ```
629+
630+
r[attributes.codegen.instruction_set.syntax]
631+
The `instruction_set` attribute uses the [MetaListPaths] syntax, and a path comprised of the architecture family name and instruction set name.
632+
617633
r[attributes.codegen.instruction_set.allowed-positions]
618-
The *`instruction_set` [attribute]* may be applied to a function to control which instruction set the function will be generated for.
634+
The `instruction_set` attribute may only be applied to:
619635
620-
r[attributes.codegen.instruction_set.behavior]
621-
This allows mixing more than one instruction set in a single program on CPU architectures that support it.
636+
- [Free functions][items.fn]
637+
- [Inherent associated functions][items.associated.fn]
638+
- [Trait impl functions][items.impl.trait]
639+
- [Trait definition functions][items.traits] with a body
640+
- [Closures][expr.closure]
622641
623-
r[attributes.codegen.instruction_set.syntax]
624-
It uses the [MetaListPaths] syntax, and a path comprised of the architecture family name and instruction set name.
642+
> [!NOTE]
643+
> `rustc` currently ignores `instruction_set` in other positions. This may change in the future.
644+
645+
r[attributes.codegen.instruction_set.duplicates]
646+
The `instruction_set` attribute may only be specified once on an item.
625647
626648
r[attributes.codegen.instruction_set.target-limits]
627-
It is a compilation error to use the `instruction_set` attribute on a target that does not support it.
649+
The `instruction_set` attribute may only be used with a target that supports the given value.
628650
629651
r[attributes.codegen.instruction_set.arm]
630-
### On ARM
652+
### `instruction_set` on ARM
631653
632654
For the `ARMv4T` and `ARMv5te` architectures, the following are supported:
633655
* `arm::a32` --- Generate the function as A32 "ARM" code.
634656
* `arm::t32` --- Generate the function as T32 "Thumb" code.
635657
636-
<!-- ignore: arm-only -->
637-
```rust,ignore
638-
#[instruction_set(arm::a32)]
639-
fn foo_arm_code() {}
640-
641-
#[instruction_set(arm::t32)]
642-
fn bar_thumb_code() {}
643-
```
644-
645658
Using the `instruction_set` attribute has the following effects:
646659
647660
* 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.

0 commit comments

Comments
 (0)