Skip to content

Commit e024391

Browse files
committed
Clarify that extern "Rust" is safe, even when simd types are used
1 parent 3ccd7d2 commit e024391

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/abi.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,23 @@ A type has *simd abi requirements* if:
7474
* It is a aggregate type, which has a type with *simd abi requirements* as a field.
7575

7676
r[abi.compatibility.simd-target-feature]
77-
A type with *simd abi requirements* may have one or more *salient target features* . In the case of an aggregate type, the set of *salient target features* is the union of the set of *salient target features* of each field with *simd abi requirements*.
77+
A type with *simd abi requirements* may have one or more [*salient target features*][target_feature] . In the case of an aggregate type, the set of [*salient target features*][target_feature] is the union of the set of [*salient target features*][target_feature] of each field with *simd abi requirements*.
7878

7979
> [!TARGET-SPECIFIC]
80-
> On x86 and x86-64, the *salient target features* of the `simd` types are:
80+
> On x86 and x86-64, the [*salient target features*][target_feature] of the `simd` types are:
8181
> * [`__m128`], [`__m128i`], [`__m128f`], and [`__m128d`]: `sse`
8282
> * [`__m256`], [`__m256i`], [`__m256f`], and [`__m256d`]: `avx`
8383
> * [`__m512`], [`__m512i`], [`__m512f`], and [`__m512d`]: `avx512f` and `avx512vl`
8484
8585
r[abi.compatibility.call]
86-
A call to a function `f` via a function item or function pointer with a given signature `S` is valid only if the signature of `f` is *compatible* with the signature `S`, and, if the type of any parameter, the return type, or the type of any argument passed via C-varargs has *simd abi requirements*, each *salient target feature* of that type is either set at both the definition site of the function, and at the call site, or is set at neither site. The behaviour a call that is not valid is undefined.
86+
A call to a function `f` via a function item or function pointer with a given signature `S` is valid only if the signature of `f` is *compatible* with the signature `S`, and:
87+
* The ABI tag of the function is `extern "Rust"`, or
88+
* If the type of any parameter, the return type, or the type of any argument passed via C-varargs has *simd abi requirements*, each [*salient target features*][target_feature]of that type is either set at both the definition site of the function, and at the call site, or is set at neither site.
89+
90+
The behaviour a call that is not valid is undefined.
91+
92+
> [!NOTE]
93+
> the ABI tag `extern "Rust"` is the default when the `extern` keyword is not used (either to declare the function within an [`extern` block], or as a [function qualifier][extern functions]). Thus it is safe to call most functions that use simd types.
8794
8895

8996
[`__m128`]: https://doc.rust-lang.org/stable/core/arch/x86_64/struct.__m128.html
@@ -101,7 +108,6 @@ A call to a function `f` via a function item or function pointer with a given si
101108

102109
## The `used` attribute
103110

104-
105111
r[abi.used]
106112

107113
```abnf
@@ -231,6 +237,8 @@ pub static VAR1: u32 = 1;
231237
>
232238
>
233239
240+
241+
234242
[_MetaWord_]: attributes.md#meta-item-attribute-syntax
235243
[_MetaNameValueStr_]: attributes.md#meta-item-attribute-syntax
236244
[`static` items]: items/static-items.md
@@ -240,3 +248,4 @@ pub static VAR1: u32 = 1;
240248
[function]: items/functions.md
241249
[item]: items.md
242250
[static]: items/static-items.md
251+
[target_feature]: attributes/codegen.md#the-target_feature-attribute

0 commit comments

Comments
 (0)