/src/test/run-make-fulldeps/simd-ffi/simd.rs

https://gitlab.com/rust-lang/rust · Rust · 82 lines · 59 code · 14 blank · 9 comment · 2 complexity · d2f4cae57aa4ec621619c4d8d11dec0a MD5 · raw file

  1. // ensures that public symbols are not removed completely
  2. #![crate_type = "lib"]
  3. // we can compile to a variety of platforms, because we don't need
  4. // cross-compiled standard libraries.
  5. #![feature(no_core, auto_traits)]
  6. #![no_core]
  7. #![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)]
  8. #[derive(Copy)]
  9. #[repr(simd)]
  10. pub struct f32x4(f32, f32, f32, f32);
  11. extern "C" {
  12. #[link_name = "llvm.sqrt.v4f32"]
  13. fn vsqrt(x: f32x4) -> f32x4;
  14. }
  15. pub fn foo(x: f32x4) -> f32x4 {
  16. unsafe { vsqrt(x) }
  17. }
  18. #[derive(Copy)]
  19. #[repr(simd)]
  20. pub struct i32x4(i32, i32, i32, i32);
  21. extern "C" {
  22. // _mm_sll_epi32
  23. #[cfg(any(target_arch = "x86", target_arch = "x86-64"))]
  24. #[link_name = "llvm.x86.sse2.psll.d"]
  25. fn integer(a: i32x4, b: i32x4) -> i32x4;
  26. // vmaxq_s32
  27. #[cfg(target_arch = "arm")]
  28. #[link_name = "llvm.arm.neon.vmaxs.v4i32"]
  29. fn integer(a: i32x4, b: i32x4) -> i32x4;
  30. // vmaxq_s32
  31. #[cfg(target_arch = "aarch64")]
  32. #[link_name = "llvm.aarch64.neon.maxs.v4i32"]
  33. fn integer(a: i32x4, b: i32x4) -> i32x4;
  34. // just some substitute foreign symbol, not an LLVM intrinsic; so
  35. // we still get type checking, but not as detailed as (ab)using
  36. // LLVM.
  37. #[cfg(not(any(
  38. target_arch = "x86",
  39. target_arch = "x86-64",
  40. target_arch = "arm",
  41. target_arch = "aarch64"
  42. )))]
  43. fn integer(a: i32x4, b: i32x4) -> i32x4;
  44. }
  45. pub fn bar(a: i32x4, b: i32x4) -> i32x4 {
  46. unsafe { integer(a, b) }
  47. }
  48. #[lang = "sized"]
  49. pub trait Sized {}
  50. #[lang = "copy"]
  51. pub trait Copy {}
  52. impl Copy for f32 {}
  53. impl Copy for i32 {}
  54. pub mod marker {
  55. pub use Copy;
  56. }
  57. #[lang = "freeze"]
  58. auto trait Freeze {}
  59. #[macro_export]
  60. #[rustc_builtin_macro]
  61. macro_rules! Copy {
  62. () => {};
  63. }
  64. #[macro_export]
  65. #[rustc_builtin_macro]
  66. macro_rules! derive {
  67. () => {};
  68. }