Skip to content

Commit f70f643

Browse files
author
Daniel Smith
committed
Constanting the arguments
1 parent 0238065 commit f70f643

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

crates/core_arch/src/x86/avx512f.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub unsafe fn _mm512_setr_epi32(
104104
#[inline]
105105
#[target_feature(enable = "avx512f")]
106106
#[cfg_attr(test, assert_instr(vgatherdpd, scale = 1))]
107+
#[rustc_args_required_const(2)]
107108
pub unsafe fn _mm512_i32gather_pd(offsets: __m256i, slice: *const u8, scale: i32) -> __m512d {
108109
let zero = _mm512_setzero_pd().as_f64x8();
109110
let neg_one = -1;
@@ -114,7 +115,7 @@ pub unsafe fn _mm512_i32gather_pd(offsets: __m256i, slice: *const u8, scale: i32
114115
vgatherdpd(zero, slice, offsets, neg_one, $imm8)
115116
};
116117
}
117-
let r = constify_imm8!(scale, call);
118+
let r = constify_imm8_gather!(scale, call);
118119
transmute(r)
119120
}
120121

@@ -124,6 +125,7 @@ pub unsafe fn _mm512_i32gather_pd(offsets: __m256i, slice: *const u8, scale: i32
124125
#[inline]
125126
#[target_feature(enable = "avx512f")]
126127
#[cfg_attr(test, assert_instr(vgatherdpd, scale = 1))]
128+
#[rustc_args_required_const(4)]
127129
pub unsafe fn _mm512_mask_i32gather_pd(
128130
src: __m512d,
129131
mask: __mmask8,
@@ -139,7 +141,7 @@ pub unsafe fn _mm512_mask_i32gather_pd(
139141
vgatherdpd(src, slice, offsets, mask as i8, $imm8)
140142
};
141143
}
142-
let r = constify_imm8!(scale, call);
144+
let r = constify_imm8_gather!(scale, call);
143145
transmute(r)
144146
}
145147

@@ -149,6 +151,7 @@ pub unsafe fn _mm512_mask_i32gather_pd(
149151
#[inline]
150152
#[target_feature(enable = "avx512f")]
151153
#[cfg_attr(test, assert_instr(vgatherqpd, scale = 1))]
154+
#[rustc_args_required_const(2)]
152155
pub unsafe fn _mm512_i64gather_pd(offsets: __m512i, slice: *const u8, scale: i32) -> __m512d {
153156
let zero = _mm512_setzero_pd().as_f64x8();
154157
let neg_one = -1;
@@ -159,7 +162,7 @@ pub unsafe fn _mm512_i64gather_pd(offsets: __m512i, slice: *const u8, scale: i32
159162
vgatherqpd(zero, slice, offsets, neg_one, $imm8)
160163
};
161164
}
162-
let r = constify_imm8!(scale, call);
165+
let r = constify_imm8_gather!(scale, call);
163166
transmute(r)
164167
}
165168

@@ -169,6 +172,7 @@ pub unsafe fn _mm512_i64gather_pd(offsets: __m512i, slice: *const u8, scale: i32
169172
#[inline]
170173
#[target_feature(enable = "avx512f")]
171174
#[cfg_attr(test, assert_instr(vgatherqpd, scale = 1))]
175+
#[rustc_args_required_const(4)]
172176
pub unsafe fn _mm512_mask_i64gather_pd(
173177
src: __m512d,
174178
mask: __mmask8,
@@ -184,7 +188,7 @@ pub unsafe fn _mm512_mask_i64gather_pd(
184188
vgatherqpd(src, slice, offsets, mask as i8, $imm8)
185189
};
186190
}
187-
let r = constify_imm8!(scale, call);
191+
let r = constify_imm8_gather!(scale, call);
188192
transmute(r)
189193
}
190194

@@ -194,6 +198,7 @@ pub unsafe fn _mm512_mask_i64gather_pd(
194198
#[inline]
195199
#[target_feature(enable = "avx512f")]
196200
#[cfg_attr(test, assert_instr(vgatherqps, scale = 1))]
201+
#[rustc_args_required_const(2)]
197202
pub unsafe fn _mm512_i64gather_ps(offsets: __m512i, slice: *const u8, scale: i32) -> __m256 {
198203
let zero = _mm256_setzero_ps().as_f32x8();
199204
let neg_one = -1;
@@ -204,7 +209,7 @@ pub unsafe fn _mm512_i64gather_ps(offsets: __m512i, slice: *const u8, scale: i32
204209
vgatherqps(zero, slice, offsets, neg_one, $imm8)
205210
};
206211
}
207-
let r = constify_imm8!(scale, call);
212+
let r = constify_imm8_gather!(scale, call);
208213
transmute(r)
209214
}
210215

@@ -214,6 +219,7 @@ pub unsafe fn _mm512_i64gather_ps(offsets: __m512i, slice: *const u8, scale: i32
214219
#[inline]
215220
#[target_feature(enable = "avx512f")]
216221
#[cfg_attr(test, assert_instr(vgatherqps, scale = 1))]
222+
#[rustc_args_required_const(4)]
217223
pub unsafe fn _mm512_mask_i64gather_ps(
218224
src: __m256,
219225
mask: __mmask8,
@@ -229,7 +235,7 @@ pub unsafe fn _mm512_mask_i64gather_ps(
229235
vgatherqps(src, slice, offsets, mask as i8, $imm8)
230236
};
231237
}
232-
let r = constify_imm8!(scale, call);
238+
let r = constify_imm8_gather!(scale, call);
233239
transmute(r)
234240
}
235241

@@ -239,6 +245,7 @@ pub unsafe fn _mm512_mask_i64gather_ps(
239245
#[inline]
240246
#[target_feature(enable = "avx512f")]
241247
#[cfg_attr(test, assert_instr(vpgatherdq, scale = 1))]
248+
#[rustc_args_required_const(2)]
242249
pub unsafe fn _mm512_i32gather_epi64(offsets: __m256i, slice: *const u8, scale: i32) -> __m512i {
243250
let zero = _mm512_setzero_si512().as_i64x8();
244251
let neg_one = -1;
@@ -249,7 +256,7 @@ pub unsafe fn _mm512_i32gather_epi64(offsets: __m256i, slice: *const u8, scale:
249256
vpgatherdq(zero, slice, offsets, neg_one, $imm8)
250257
};
251258
}
252-
let r = constify_imm8!(scale, call);
259+
let r = constify_imm8_gather!(scale, call);
253260
transmute(r)
254261
}
255262

@@ -259,6 +266,7 @@ pub unsafe fn _mm512_i32gather_epi64(offsets: __m256i, slice: *const u8, scale:
259266
#[inline]
260267
#[target_feature(enable = "avx512f")]
261268
#[cfg_attr(test, assert_instr(vpgatherdq, scale = 1))]
269+
#[rustc_args_required_const(4)]
262270
pub unsafe fn _mm512_mask_i32gather_epi64(
263271
src: __m512i,
264272
mask: __mmask8,
@@ -275,7 +283,7 @@ pub unsafe fn _mm512_mask_i32gather_epi64(
275283
vpgatherdq(src, slice, offsets, mask, $imm8)
276284
};
277285
}
278-
let r = constify_imm8!(scale, call);
286+
let r = constify_imm8_gather!(scale, call);
279287
transmute(r)
280288
}
281289

@@ -285,6 +293,7 @@ pub unsafe fn _mm512_mask_i32gather_epi64(
285293
#[inline]
286294
#[target_feature(enable = "avx512f")]
287295
#[cfg_attr(test, assert_instr(vpgatherqq, scale = 1))]
296+
#[rustc_args_required_const(2)]
288297
pub unsafe fn _mm512_i64gather_epi64(offsets: __m512i, slice: *const u8, scale: i32) -> __m512i {
289298
let zero = _mm512_setzero_si512().as_i64x8();
290299
let neg_one = -1;
@@ -295,7 +304,7 @@ pub unsafe fn _mm512_i64gather_epi64(offsets: __m512i, slice: *const u8, scale:
295304
vpgatherqq(zero, slice, offsets, neg_one, $imm8)
296305
};
297306
}
298-
let r = constify_imm8!(scale, call);
307+
let r = constify_imm8_gather!(scale, call);
299308
transmute(r)
300309
}
301310

@@ -305,6 +314,7 @@ pub unsafe fn _mm512_i64gather_epi64(offsets: __m512i, slice: *const u8, scale:
305314
#[inline]
306315
#[target_feature(enable = "avx512f")]
307316
#[cfg_attr(test, assert_instr(vpgatherqq, scale = 1))]
317+
#[rustc_args_required_const(4)]
308318
pub unsafe fn _mm512_mask_i64gather_epi64(
309319
src: __m512i,
310320
mask: __mmask8,
@@ -321,7 +331,7 @@ pub unsafe fn _mm512_mask_i64gather_epi64(
321331
vpgatherqq(src, slice, offsets, mask, $imm8)
322332
};
323333
}
324-
let r = constify_imm8!(scale, call);
334+
let r = constify_imm8_gather!(scale, call);
325335
transmute(r)
326336
}
327337

@@ -331,6 +341,7 @@ pub unsafe fn _mm512_mask_i64gather_epi64(
331341
#[inline]
332342
#[target_feature(enable = "avx512f")]
333343
#[cfg_attr(test, assert_instr(vpgatherqd, scale = 1))]
344+
#[rustc_args_required_const(2)]
334345
pub unsafe fn _mm512_i64gather_epi32(offsets: __m512i, slice: *const u8, scale: i32) -> __m256i {
335346
let zeros = _mm256_setzero_si256().as_i32x8();
336347
let neg_one = -1;
@@ -341,7 +352,7 @@ pub unsafe fn _mm512_i64gather_epi32(offsets: __m512i, slice: *const u8, scale:
341352
vpgatherqd(zeros, slice, offsets, neg_one, $imm8)
342353
};
343354
}
344-
let r = constify_imm8!(scale, call);
355+
let r = constify_imm8_gather!(scale, call);
345356
transmute(r)
346357
}
347358

@@ -351,6 +362,7 @@ pub unsafe fn _mm512_i64gather_epi32(offsets: __m512i, slice: *const u8, scale:
351362
#[inline]
352363
#[target_feature(enable = "avx512f")]
353364
#[cfg_attr(test, assert_instr(vpgatherqd, scale = 1))]
365+
#[rustc_args_required_const(4)]
354366
pub unsafe fn _mm512_mask_i64gather_epi32(
355367
src: __m256i,
356368
mask: __mmask8,
@@ -367,7 +379,7 @@ pub unsafe fn _mm512_mask_i64gather_epi32(
367379
vpgatherqd(src, slice, offsets, mask, $imm8)
368380
};
369381
}
370-
let r = constify_imm8!(scale, call);
382+
let r = constify_imm8_gather!(scale, call);
371383
transmute(r)
372384
}
373385

crates/core_arch/src/x86/macros.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ macro_rules! constify_imm2 {
9292
};
9393
}
9494

95+
// For gather intsructions, the only valid values for scale are 1, 2, 4 and 8.
96+
// This macro enforces that.
97+
#[allow(unused)]
98+
macro_rules! constify_imm8_gather {
99+
($imm8:expr, $expand:ident) => {
100+
#[allow(overflowing_literals)]
101+
match ($imm8) {
102+
1 => $expand!(1),
103+
2 => $expand!(2),
104+
4 => $expand!(4),
105+
8 => $expand!(8),
106+
_ => panic!("Only 1, 2, 4, and 8 are valid values"),
107+
}
108+
};
109+
}
110+
95111
#[cfg(test)]
96112
macro_rules! assert_approx_eq {
97113
($a:expr, $b:expr, $eps:expr) => {{

0 commit comments

Comments
 (0)