Skip to content

Commit 5ffe310

Browse files
ehusstraviscross
authored andcommitted
Update instruction_set to use the attribute template
1 parent 00405f8 commit 5ffe310

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
@@ -637,34 +637,47 @@ trait object whose methods are attributed.
637637
r[attributes.codegen.instruction_set]
638638
## The `instruction_set` attribute
639639

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.
640+
r[attributes.codegen.instruction_set.intro]
641+
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.
642642

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.
643+
> [!EXAMPLE]
644+
> <!-- ignore: arm-only -->
645+
> ```rust,ignore
646+
> #[instruction_set(arm::a32)]
647+
> fn foo_arm_code() {}
648+
>
649+
> #[instruction_set(arm::t32)]
650+
> fn bar_thumb_code() {}
651+
> ```
645652
646653
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.
654+
The `instruction_set` attribute uses the [MetaListPaths] syntax, and a path comprised of the architecture family name and instruction set name.
655+
656+
r[attributes.codegen.instruction_set.allowed-positions]
657+
The `instruction_set` attribute may only be applied to:
658+
659+
- [Free functions][items.fn]
660+
- [Inherent associated functions][items.associated.fn]
661+
- [Trait impl functions][items.impl.trait]
662+
- [Trait definition functions][items.traits] with a body
663+
- [Closures][expr.closure]
664+
665+
> [!NOTE]
666+
> `rustc` currently ignores `instruction_set` in other positions. This may change in the future.
667+
668+
r[attributes.codegen.instruction_set.duplicates]
669+
The `instruction_set` attribute may only be specified once on an item.
648670
649671
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.
672+
The `instruction_set` attribute may only be used with a target that supports the given value.
651673
652674
r[attributes.codegen.instruction_set.arm]
653-
### On ARM
675+
### `instruction_set` on ARM
654676
655677
For the `ARMv4T` and `ARMv5te` architectures, the following are supported:
656678
* `arm::a32` --- Generate the function as A32 "ARM" code.
657679
* `arm::t32` --- Generate the function as T32 "Thumb" code.
658680
659-
<!-- ignore: arm-only -->
660-
```rust,ignore
661-
#[instruction_set(arm::a32)]
662-
fn foo_arm_code() {}
663-
664-
#[instruction_set(arm::t32)]
665-
fn bar_thumb_code() {}
666-
```
667-
668681
Using the `instruction_set` attribute has the following effects:
669682
670683
* 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)