@@ -97,39 +97,29 @@ but we haven't specified how we are actually compiling our Rust program above:
97
97
register, and the behavior is undefined because of an ABI mismatch.
98
98
99
99
<a name =" layout_unspecified " >1</a >: its layout is currently unspecified but that
100
- is not relevant for this issue since if 256-bit registers are not available they
101
- cannot be used anyways, which is what matters here .
100
+ is not relevant for this issue - what matters is that 256-bit registers are not
101
+ available and therefore they cannot be used .
102
102
103
- So, first of all, is this a big deal?
104
-
105
- Currently, one cannot use SIMD types in C FFI in stable Rust, so technically,
106
- nothing is broken yet, and no, this is not a big deal: stable Rust is still
107
- safe! However, we would like to be able to call C FFI functions without
108
- introducing undefined behavior independently of which ` -C target-features ` are
109
- passed, so the example code shown above has to be rejected by the compiler.
110
-
111
- Second, you might be wondering: why is ` __m256 ` available even if ` AVX ` is not
112
- available? That's a good question. We want to use ` __m256 ` in some parts of
103
+ You might be wondering: why is ` __m256 ` available even if ` AVX ` is not
104
+ available? The reason is that we want to use ` __m256 ` in some parts of
113
105
Rust's programs even if ` AVX ` is not globally enabled, and currently we don't
114
106
have great infrastructure for conditionally allowing it in some parts of the
115
107
program and not others.
116
108
117
109
Ideally, one should only be able to use ` __m256 ` and operations on it if ` AVX `
118
- is available. Which leads to how can we fix this ?
119
-
120
- The most trivial solution would be to just always require
121
- ` #[target_feature(enable = X)] ` in C FFI functions using SIMD types, where
122
- "unblocking" the use of each type requires one or two particular feature to be
123
- enabled, e.g., ` avx ` or ` avx2 ` in the case of ` __m256 ` .
110
+ is available, and this is exactly what this RFC proposes for using vector types
111
+ in C FFI: to always require ` #[target_feature(enable = X)] ` in C FFI functions
112
+ using SIMD types, where "unblocking" the use of each type requires some
113
+ particular feature to be enabled, e.g., ` avx ` or ` avx2 ` in the case of ` __m256 ` .
124
114
125
115
That is, the compiler would reject the example above with an error:
126
116
127
117
```
128
118
error[E1337]: `__m256` on C FFI requires `#[target_feature(enable = "avx")]`
129
119
--> src/main.rs:7:15
130
120
|
131
- 7 | fn foo(x: __m25a6 ) -> __m256;
132
- | ^^^^^^^
121
+ 7 | fn foo(x: __m256 ) -> __m256;
122
+ | ^^^^^^
133
123
```
134
124
135
125
And the following program would always have defined behavior
@@ -149,6 +139,9 @@ fn main() {
149
139
}
150
140
```
151
141
142
+ independently of the ` -C target-feature ` s used globally to compile the whole
143
+ binary.
144
+
152
145
Note here that:
153
146
154
147
* ` extern "C" foo ` is compiled with ` AVX ` enabled, so ` foo ` takes an ` __m256 `
0 commit comments