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
Copy file name to clipboardExpand all lines: src/abi.md
+18-17Lines changed: 18 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -26,26 +26,28 @@ Two integer types are *abi compatible* if they have the same size and the same s
26
26
> Two integer types with different signedness, such as `u8` and `i8` are not *abi compatible*.
27
27
28
28
r[abi.compatibility.char]
29
-
The type `char`is *abi compatible* with the type `u32`.
29
+
The type `char`is *abi compatible* with the type `u32`.
30
30
31
31
r[abi.compatibility.pointer]
32
32
Two pointer types, `*mut T` and `*const U`, are *abi compatible* if the *metadata type*s of `T` and `U` are the same type.
33
33
34
+
> [!NOTE]
35
+
> [`Sized`] types have a *metadata type* of `()`.
36
+
34
37
> [!NOTE]
35
38
> With transitivity, this applies regardless of the mutability of either pointer type
36
39
37
40
r[abi.compatibility.reference-box]
38
41
The types `&T`, `&mut T`, [`Box<T>`][core::boxed::Box], and [`NonNull<T>`][core::ptr::NonNull], are *abi compatible* with `*const T`
39
42
40
43
> [!NOTE]
41
-
> With transitivity,t hey are also *abi compatible** with each other, and with `*mut T`, as well as references/`Box` to different types that have the same *metadata type*.
42
-
44
+
> With transitivity, they are also *abi compatible* with each other, and with `*mut T`, as well as references/`Box` to different types that have the same *metadata type*.
43
45
44
46
r[abi.compatibility.core]
45
47
The types [`MaybeUninit<T>`][core::mem::MaybeUninit], [`UnsafeCell<T>`][core::cell::UnsafeCell], and [`NonZero<T>`][core::num::NonZero], are *abi compatible* with `T`.
46
48
47
49
r[abi.compatibility.transparent]
48
-
A `struct` declared with the `transparent` representation is *abi compatible* with its field that does not have size 0 and alignment 1, if such a field exists
50
+
A `struct` declared with the `transparent` representation is *abi compatible* with its field that does not have size 0 and alignment 1, if such a field exists.
49
51
50
52
r[abi.compatibilty.zst]
51
53
Two types, `T` and `U`, are *abi compatible* if both have size 0 and alignment 1.
@@ -68,31 +70,36 @@ Two function signatures are compatible if:
68
70
* Each parameter of both signatures, in order, are *abi compatible*, and
69
71
* Either both signatures have C-varargs, or neither signature does.
70
72
73
+
> [!NOTE]
74
+
> A signature is compatible with itself.
75
+
71
76
r[abi.compatibility.simd-abi]
72
77
A type has *simd abi requirements* if:
73
78
* It is a type declared with the standard-library repr-attrbute `simd`,
74
79
* It is a aggregate type, which has a type with *simd abi requirements* as a field.
75
80
81
+
> [!NOTE]
82
+
> The `repr(simd)` attribute cannot be used by Rust code, only by the standard library.
83
+
76
84
r[abi.compatibility.simd-target-feature]
77
85
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*.
78
86
79
87
> [!TARGET-SPECIFIC]
80
88
> On x86 and x86-64, the [*salient target features*][target_feature] of the `simd` types are:
81
-
> *[`__m128`], [`__m128i`], [`__m128f`], and [`__m128d`]: `sse`
82
-
> *[`__m256`], [`__m256i`], [`__m256f`], and [`__m256d`]: `avx`
83
-
> *[`__m512`], [`__m512i`], [`__m512f`], and [`__m512d`]: `avx512f` and `avx512vl`
89
+
> *[`__m128`], [`__m128i`], [`__m128f`], and [`__m128d`] (128-bit vector types): `sse`
90
+
> *[`__m256`], [`__m256i`], [`__m256f`], and [`__m256d`] (256-bit vector types): `avx`
91
+
> *[`__m512`], [`__m512i`], [`__m512f`], and [`__m512d`] (512-bit vector types): `avx512f` and `avx512vl`
84
92
85
93
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:
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.
94
+
A call to a function `f` via a function item or function pointer with a given signature `S` is valid if and only if the signature of the definition`f` is *compatible* with the signature `S`, and:
95
+
* The ABI tag of the signature is `extern "Rust"`, or
96
+
* If any parameter type, 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
97
90
98
The behaviour a call that is not valid is undefined.
91
99
92
100
> [!NOTE]
93
101
> 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.
@@ -192,8 +199,6 @@ The *`no_mangle` attribute* may be specified as a built-in attribute, using the
192
199
r[abi.symbol-name.export_name]
193
200
The *`export_name` attribute* may be specified as a built-in attribute, using the [_MetaNameValueStr_] syntax. The *export name* of an item with the *`no_mangle` attribute* is the content of `STRING_LITERAL`.
194
201
195
-
196
-
197
202
## The `link_section` attribute
198
203
199
204
r[abi.link_section]
@@ -234,10 +239,6 @@ pub static VAR1: u32 = 1;
234
239
> *`.tbss`: Readable and Writable - Uninitialized and Thread-local.
235
240
>
236
241
> This is not an exhaustive list, and generally extended versions of these section names such as `.text.foo`, are also defined with the same properties as the base section.
0 commit comments