Skip to content

Commit 488c28a

Browse files
gnzlbgalexcrichton
authored andcommitted
More run-time detection improvements (rust-lang#242)
* [core/runtime] use getauxval on non-x86 platforms * test coresimd::auxv against auxv crate * add test files from auxv crate * [arm] use simd_test macro * formatting * missing docs * improve docs * reading /proc/self/auxv succeeds only if reading all fields succeeds * remove cc-crate build dependency * getauxval succeeds only if hwcap/hwcap2 are non-zero * fix formatting * move getauxval to stdsimd * delete getauxval-wrapper.c * remove auxv crate dev-dependency from coresimd
1 parent cb136a4 commit 488c28a

37 files changed

+1100
-729
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ maintenance = { status = "experimental" }
2424
[dependencies]
2525
coresimd = { version = "0.0.3", path = "coresimd/" }
2626

27+
[dev-dependencies]
28+
auxv = "0.3.3"
29+
2730
[profile.release]
2831
debug = true
2932
opt-level = 3

coresimd/src/aarch64/neon.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! ARMv8 NEON intrinsics
1+
//! ARMv8 ASIMD intrinsics
2+
3+
// FIXME: replace neon with asimd
24

35
#[cfg(test)]
46
use stdsimd_test::assert_instr;
@@ -39,41 +41,43 @@ pub unsafe fn vaddd_u64(a: u64, b: u64) -> u64 {
3941

4042
#[cfg(test)]
4143
mod tests {
42-
use super::*;
44+
use super::f64x2;
45+
use aarch64::neon;
46+
use stdsimd_test::simd_test;
4347

44-
#[test]
45-
fn vadd_f64_() {
48+
#[simd_test = "neon"]
49+
unsafe fn vadd_f64() {
4650
let a = 1.;
4751
let b = 8.;
4852
let e = 9.;
49-
let r = unsafe { vadd_f64(a, b) };
53+
let r = neon::vadd_f64(a, b);
5054
assert_eq!(r, e);
5155
}
5256

53-
#[test]
54-
fn vaddq_f64_() {
57+
#[simd_test = "neon"]
58+
unsafe fn vaddq_f64() {
5559
let a = f64x2::new(1., 2.);
5660
let b = f64x2::new(8., 7.);
5761
let e = f64x2::new(9., 9.);
58-
let r = unsafe { vaddq_f64(a, b) };
62+
let r = neon::vaddq_f64(a, b);
5963
assert_eq!(r, e);
6064
}
6165

62-
#[test]
63-
fn vaddd_s64_() {
66+
#[simd_test = "neon"]
67+
unsafe fn vaddd_s64() {
6468
let a = 1;
6569
let b = 8;
6670
let e = 9;
67-
let r = unsafe { vaddd_s64(a, b) };
71+
let r = neon::vaddd_s64(a, b);
6872
assert_eq!(r, e);
6973
}
7074

71-
#[test]
72-
fn vaddd_u64_() {
75+
#[simd_test = "neon"]
76+
unsafe fn vaddd_u64() {
7377
let a = 1;
7478
let b = 8;
7579
let e = 9;
76-
let r = unsafe { vaddd_u64(a, b) };
80+
let r = neon::vaddd_u64(a, b);
7781
assert_eq!(r, e);
7882
}
7983
}

coresimd/src/arm/neon.rs

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -214,199 +214,201 @@ pub unsafe fn vrsqrte_f32(a: f32x2) -> f32x2 {
214214

215215
#[cfg(test)]
216216
mod tests {
217-
use super::*;
217+
use stdsimd_test::simd_test;
218+
use simd::*;
219+
use arm::neon;
218220

219-
#[test]
220-
fn vadd_s8_() {
221+
#[simd_test = "neon"]
222+
unsafe fn vadd_s8() {
221223
let a = i8x8::new(1, 2, 3, 4, 5, 6, 7, 8);
222224
let b = i8x8::new(8, 7, 6, 5, 4, 3, 2, 1);
223225
let e = i8x8::new(9, 9, 9, 9, 9, 9, 9, 9);
224-
let r = unsafe { vadd_s8(a, b) };
226+
let r = neon::vadd_s8(a, b);
225227
assert_eq!(r, e);
226228
}
227229

228-
#[test]
229-
fn vaddq_s8_() {
230+
#[simd_test = "neon"]
231+
unsafe fn vaddq_s8() {
230232
let a = i8x16::new(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8);
231233
let b = i8x16::new(8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1);
232234
let e = i8x16::new(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9);
233-
let r = unsafe { vaddq_s8(a, b) };
235+
let r = neon::vaddq_s8(a, b);
234236
assert_eq!(r, e);
235237
}
236238

237-
#[test]
238-
fn vadd_s16_() {
239+
#[simd_test = "neon"]
240+
unsafe fn vadd_s16() {
239241
let a = i16x4::new(1, 2, 3, 4);
240242
let b = i16x4::new(8, 7, 6, 5);
241243
let e = i16x4::new(9, 9, 9, 9);
242-
let r = unsafe { vadd_s16(a, b) };
244+
let r = neon::vadd_s16(a, b);
243245
assert_eq!(r, e);
244246
}
245247

246-
#[test]
247-
fn vaddq_s16_() {
248+
#[simd_test = "neon"]
249+
unsafe fn vaddq_s16() {
248250
let a = i16x8::new(1, 2, 3, 4, 5, 6, 7, 8);
249251
let b = i16x8::new(8, 7, 6, 5, 4, 3, 2, 1);
250252
let e = i16x8::new(9, 9, 9, 9, 9, 9, 9, 9);
251-
let r = unsafe { vaddq_s16(a, b) };
253+
let r = neon::vaddq_s16(a, b);
252254
assert_eq!(r, e);
253255
}
254256

255-
#[test]
256-
fn vadd_s32_() {
257+
#[simd_test = "neon"]
258+
unsafe fn vadd_s32() {
257259
let a = i32x2::new(1, 2);
258260
let b = i32x2::new(8, 7);
259261
let e = i32x2::new(9, 9);
260-
let r = unsafe { vadd_s32(a, b) };
262+
let r = neon::vadd_s32(a, b);
261263
assert_eq!(r, e);
262264
}
263265

264-
#[test]
265-
fn vaddq_s32_() {
266+
#[simd_test = "neon"]
267+
unsafe fn vaddq_s32() {
266268
let a = i32x4::new(1, 2, 3, 4);
267269
let b = i32x4::new(8, 7, 6, 5);
268270
let e = i32x4::new(9, 9, 9, 9);
269-
let r = unsafe { vaddq_s32(a, b) };
271+
let r = neon::vaddq_s32(a, b);
270272
assert_eq!(r, e);
271273
}
272274

273-
#[test]
274-
fn vadd_u8_() {
275+
#[simd_test = "neon"]
276+
unsafe fn vadd_u8() {
275277
let a = u8x8::new(1, 2, 3, 4, 5, 6, 7, 8);
276278
let b = u8x8::new(8, 7, 6, 5, 4, 3, 2, 1);
277279
let e = u8x8::new(9, 9, 9, 9, 9, 9, 9, 9);
278-
let r = unsafe { vadd_u8(a, b) };
280+
let r = neon::vadd_u8(a, b);
279281
assert_eq!(r, e);
280282
}
281283

282-
#[test]
283-
fn vaddq_u8_() {
284+
#[simd_test = "neon"]
285+
unsafe fn vaddq_u8() {
284286
let a = u8x16::new(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8);
285287
let b = u8x16::new(8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 1);
286288
let e = u8x16::new(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9);
287-
let r = unsafe { vaddq_u8(a, b) };
289+
let r = neon::vaddq_u8(a, b);
288290
assert_eq!(r, e);
289291
}
290292

291-
#[test]
292-
fn vadd_u16_() {
293+
#[simd_test = "neon"]
294+
unsafe fn vadd_u16() {
293295
let a = u16x4::new(1, 2, 3, 4);
294296
let b = u16x4::new(8, 7, 6, 5);
295297
let e = u16x4::new(9, 9, 9, 9);
296-
let r = unsafe { vadd_u16(a, b) };
298+
let r = neon::vadd_u16(a, b);
297299
assert_eq!(r, e);
298300
}
299301

300-
#[test]
301-
fn vaddq_u16_() {
302+
#[simd_test = "neon"]
303+
unsafe fn vaddq_u16() {
302304
let a = u16x8::new(1, 2, 3, 4, 5, 6, 7, 8);
303305
let b = u16x8::new(8, 7, 6, 5, 4, 3, 2, 1);
304306
let e = u16x8::new(9, 9, 9, 9, 9, 9, 9, 9);
305-
let r = unsafe { vaddq_u16(a, b) };
307+
let r = neon::vaddq_u16(a, b);
306308
assert_eq!(r, e);
307309
}
308310

309-
#[test]
310-
fn vadd_u32_() {
311+
#[simd_test = "neon"]
312+
unsafe fn vadd_u32() {
311313
let a = u32x2::new(1, 2);
312314
let b = u32x2::new(8, 7);
313315
let e = u32x2::new(9, 9);
314-
let r = unsafe { vadd_u32(a, b) };
316+
let r = neon::vadd_u32(a, b);
315317
assert_eq!(r, e);
316318
}
317319

318-
#[test]
319-
fn vaddq_u32_() {
320+
#[simd_test = "neon"]
321+
unsafe fn vaddq_u32() {
320322
let a = u32x4::new(1, 2, 3, 4);
321323
let b = u32x4::new(8, 7, 6, 5);
322324
let e = u32x4::new(9, 9, 9, 9);
323-
let r = unsafe { vaddq_u32(a, b) };
325+
let r = neon::vaddq_u32(a, b);
324326
assert_eq!(r, e);
325327
}
326328

327-
#[test]
328-
fn vadd_f32_() {
329+
#[simd_test = "neon"]
330+
unsafe fn vadd_f32() {
329331
let a = f32x2::new(1., 2.);
330332
let b = f32x2::new(8., 7.);
331333
let e = f32x2::new(9., 9.);
332-
let r = unsafe { vadd_f32(a, b) };
334+
let r = neon::vadd_f32(a, b);
333335
assert_eq!(r, e);
334336
}
335337

336-
#[test]
337-
fn vaddq_f32_() {
338+
#[simd_test = "neon"]
339+
unsafe fn vaddq_f32() {
338340
let a = f32x4::new(1., 2., 3., 4.);
339341
let b = f32x4::new(8., 7., 6., 5.);
340342
let e = f32x4::new(9., 9., 9., 9.);
341-
let r = unsafe { vaddq_f32(a, b) };
343+
let r = neon::vaddq_f32(a, b);
342344
assert_eq!(r, e);
343345
}
344346

345-
#[test]
346-
fn vaddl_s8_() {
347+
#[simd_test = "neon"]
348+
unsafe fn vaddl_s8() {
347349
let v = ::std::i8::MAX;
348350
let a = i8x8::new(v, v, v, v, v, v, v, v);
349351
let v = 2 * (v as i16);
350352
let e = i16x8::new(v, v, v, v, v, v, v, v);
351-
let r = unsafe { vaddl_s8(a, a) };
353+
let r = neon::vaddl_s8(a, a);
352354
assert_eq!(r, e);
353355
}
354356

355-
#[test]
356-
fn vaddl_s16_() {
357+
#[simd_test = "neon"]
358+
unsafe fn vaddl_s16() {
357359
let v = ::std::i16::MAX;
358360
let a = i16x4::new(v, v, v, v);
359361
let v = 2 * (v as i32);
360362
let e = i32x4::new(v, v, v, v);
361-
let r = unsafe { vaddl_s16(a, a) };
363+
let r = neon::vaddl_s16(a, a);
362364
assert_eq!(r, e);
363365
}
364366

365-
#[test]
366-
fn vaddl_s32_() {
367+
#[simd_test = "neon"]
368+
unsafe fn vaddl_s32() {
367369
let v = ::std::i32::MAX;
368370
let a = i32x2::new(v, v);
369371
let v = 2 * (v as i64);
370372
let e = i64x2::new(v, v);
371-
let r = unsafe { vaddl_s32(a, a) };
373+
let r = neon::vaddl_s32(a, a);
372374
assert_eq!(r, e);
373375
}
374376

375-
#[test]
376-
fn vaddl_u8_() {
377+
#[simd_test = "neon"]
378+
unsafe fn vaddl_u8() {
377379
let v = ::std::u8::MAX;
378380
let a = u8x8::new(v, v, v, v, v, v, v, v);
379381
let v = 2 * (v as u16);
380382
let e = u16x8::new(v, v, v, v, v, v, v, v);
381-
let r = unsafe { vaddl_u8(a, a) };
383+
let r = neon::vaddl_u8(a, a);
382384
assert_eq!(r, e);
383385
}
384386

385-
#[test]
386-
fn vaddl_u16_() {
387+
#[simd_test = "neon"]
388+
unsafe fn vaddl_u16() {
387389
let v = ::std::u16::MAX;
388390
let a = u16x4::new(v, v, v, v);
389391
let v = 2 * (v as u32);
390392
let e = u32x4::new(v, v, v, v);
391-
let r = unsafe { vaddl_u16(a, a) };
393+
let r = neon::vaddl_u16(a, a);
392394
assert_eq!(r, e);
393395
}
394396

395-
#[test]
396-
fn vaddl_u32_() {
397+
#[simd_test = "neon"]
398+
unsafe fn vaddl_u32() {
397399
let v = ::std::u32::MAX;
398400
let a = u32x2::new(v, v);
399401
let v = 2 * (v as u64);
400402
let e = u64x2::new(v, v);
401-
let r = unsafe { vaddl_u32(a, a) };
403+
let r = neon::vaddl_u32(a, a);
402404
assert_eq!(r, e);
403405
}
404406

405-
#[test]
406-
fn vrsqrt_f32_() {
407+
#[simd_test = "neon"]
408+
unsafe fn vrsqrt_f32() {
407409
let a = f32x2::new(1.0, 2.0);
408410
let e = f32x2::new(0.9980469, 0.7050781);
409-
let r = unsafe { vrsqrte_f32(a) };
411+
let r = neon::vrsqrte_f32(a);
410412
assert_eq!(r, e);
411413
}
412414
}

coresimd/src/lib.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#![allow(unused_features)]
1414
#![feature(const_fn, link_llvm_intrinsics, platform_intrinsics, repr_simd,
1515
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
16-
const_atomic_usize_new, stmt_expr_attributes, core_intrinsics)]
16+
const_atomic_usize_new, stmt_expr_attributes, core_intrinsics,
17+
crate_in_paths)]
1718
#![cfg_attr(test, feature(proc_macro, test, repr_align, attr_literals))]
1819
#![cfg_attr(feature = "cargo-clippy",
1920
allow(inline_always, too_many_arguments, cast_sign_loss,
@@ -56,18 +57,32 @@ pub mod vendor {
5657
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64",
5758
target_arch = "arm", target_arch = "aarch64")))]
5859
pub use nvptx::*;
60+
}
5961

60-
#[cfg(
61-
// x86/x86_64:
62-
any(target_arch = "x86", target_arch = "x86_64")
63-
)]
64-
pub use runtime::{__unstable_detect_feature, __Feature};
62+
/// Run-time feature detection.
63+
#[doc(hidden)]
64+
pub mod __vendor_runtime {
65+
#[cfg(any(target_arch = "x86", target_arch = "x86_64",
66+
all(target_os = "linux",
67+
any(target_arch = "arm", target_arch = "aarch64",
68+
target_arch = "powerpc64"))))]
69+
pub use runtime::core::*;
70+
71+
// Re-exports `coresimd` run-time building blocks for usage in the
72+
// `stdsimd` run-time.
73+
#[cfg(all(target_os = "linux",
74+
any(target_arch = "arm", target_arch = "aarch64",
75+
target_arch = "powerpc64")))]
76+
#[doc(hidden)]
77+
pub mod __runtime {
78+
pub use runtime::*;
79+
}
6580
}
6681

67-
#[cfg(
68-
// x86/x86_64:
69-
any(target_arch = "x86", target_arch = "x86_64")
70-
)]
82+
#[cfg(any(target_arch = "x86", target_arch = "x86_64",
83+
all(target_os = "linux",
84+
any(target_arch = "arm", target_arch = "aarch64",
85+
target_arch = "powerpc64"))))]
7186
#[macro_use]
7287
mod runtime;
7388

0 commit comments

Comments
 (0)