You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The *`target_feature`[attribute]* may be applied to a function to
97
-
enable code generation of that function for specific platform architecture
98
-
features. It uses the [MetaListNameValueStr] syntax with a single key of
99
-
`enable` whose value is a string of comma-separated feature names to enable.
96
+
The *`target_feature`[attribute]* may be applied to a function to enable code generation of that function for specific platform architecture features. It uses the [MetaListNameValueStr] syntax with a single key of `enable` whose value is a string of comma-separated feature names to enable.
100
97
101
98
```rust
102
99
# #[cfg(target_feature ="avx2")]
@@ -105,26 +102,19 @@ fn foo_avx2() {}
105
102
```
106
103
107
104
r[attributes.codegen.target_feature.arch]
108
-
Each [target architecture] has a set of features that may be enabled. It is an
109
-
error to specify a feature for a target architecture that the crate is not
110
-
being compiled for.
105
+
Each [target architecture] has a set of features that may be enabled. It is an error to specify a feature for a target architecture that the crate is not being compiled for.
111
106
112
107
r[attributes.codegen.target_feature.closures]
113
-
Closures defined within a `target_feature`-annotated function inherit the
114
-
attribute from the enclosing function.
108
+
Closures defined within a `target_feature`-annotated function inherit the attribute from the enclosing function.
115
109
116
110
r[attributes.codegen.target_feature.target-ub]
117
-
It is [undefined behavior] to call a function that is compiled with a feature
118
-
that is not supported on the current platform the code is running on, *except*
119
-
if the platform explicitly documents this to be safe.
111
+
It is [undefined behavior] to call a function that is compiled with a feature that is not supported on the current platform the code is running on, *except* if the platform explicitly documents this to be safe.
The following restrictions apply unless otherwise specified by the platform rules below:
123
115
124
-
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be safely called within a caller that enables all the `target_feature`s that the callee enables.
125
-
This restriction does not apply in an `unsafe` context.
126
-
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be coerced to *safe* function pointers in contexts that enable all the `target_feature`s that the coercee enables.
127
-
This restriction does not apply to `unsafe` function pointers.
116
+
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be safely called within a caller that enables all the `target_feature`s that the callee enables. This restriction does not apply in an `unsafe` context.
117
+
- Safe `#[target_feature]` functions (and closures that inherit the attribute) can only be coerced to *safe* function pointers in contexts that enable all the `target_feature`s that the coercee enables. This restriction does not apply to `unsafe` function pointers.
128
118
129
119
Implicitly enabled features are included in this rule. For example an `sse2` function can call ones marked with `sse`.
130
120
@@ -169,9 +159,7 @@ The `#[target_feature]` attribute is not allowed on the following places:
169
159
- safe default functions in traits
170
160
171
161
r[attributes.codegen.target_feature.inline]
172
-
Functions marked with `target_feature` are not inlined into a context that
173
-
does not support the given features. The `#[inline(always)]` attribute may not
174
-
be used with a `target_feature` attribute.
162
+
Functions marked with `target_feature` are not inlined into a context that does not support the given features. The `#[inline(always)]` attribute may not be used with a `target_feature` attribute.
175
163
176
164
r[attributes.codegen.target_feature.availability]
177
165
### Available features
@@ -181,9 +169,7 @@ The following is a list of the available feature names.
181
169
r[attributes.codegen.target_feature.x86]
182
170
#### `x86` or `x86_64`
183
171
184
-
Executing code with unsupported features is undefined behavior on this platform.
185
-
Hence on this platform usage of `#[target_feature]` functions follows the
Executing code with unsupported features is undefined behavior on this platform. Hence on this platform usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
On this platform the usage of `#[target_feature]` functions follows the [above restrictions][attributes.codegen.target_feature.safety-restrictions].
397
379
398
-
Further documentation on these features can be found in their respective
399
-
specification. Many specifications are described in the [RISC-V ISA Manual] or
400
-
in another manual hosted on the [RISC-V GitHub Account].
380
+
Further documentation on these features can be found in their respective specification. Many specifications are described in the [RISC-V ISA Manual] or in another manual hosted on the [RISC-V GitHub Account].
401
381
402
382
[RISC-V ISA Manual]: https://github.com/riscv/riscv-isa-manual
Safe `#[target_feature]` functions may always be used in safe contexts on Wasm
457
-
platforms. It is impossible to cause undefined behavior via the
458
-
`#[target_feature]` attribute because attempting to use instructions
459
-
unsupported by the Wasm engine will fail at load time without the risk of being
460
-
interpreted in a way different from what the compiler expected.
436
+
Safe `#[target_feature]` functions may always be used in safe contexts on Wasm platforms. It is impossible to cause undefined behavior via the `#[target_feature]` attribute because attempting to use instructions unsupported by the Wasm engine will fail at load time without the risk of being interpreted in a way different from what the compiler expected.
See the [`target_feature` conditional compilation option] for selectively
491
-
enabling or disabling compilation of code based on compile-time settings. Note
492
-
that this option is not affected by the `target_feature` attribute, and is
493
-
only driven by the features enabled for the entire crate.
466
+
See the [`target_feature` conditional compilation option] for selectively enabling or disabling compilation of code based on compile-time settings. Note that this option is not affected by the `target_feature` attribute, and is only driven by the features enabled for the entire crate.
494
467
495
468
r[attributes.codegen.target_feature.remark-rt]
496
-
See the [`is_x86_feature_detected`] or [`is_aarch64_feature_detected`] macros
497
-
in the standard library for runtime feature detection on these platforms.
469
+
See the [`is_x86_feature_detected`] or [`is_aarch64_feature_detected`] macros in the standard library for runtime feature detection on these platforms.
498
470
499
471
> [!NOTE]
500
472
> `rustc` has a default set of features enabled for each target and CPU. The CPU may be chosen with the [`-C target-cpu`] flag. Individual features may be enabled or disabled for an entire crate with the [`-C target-feature`] flag.
0 commit comments