summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_cranelift/example
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /compiler/rustc_codegen_cranelift/example
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_cranelift/example')
-rw-r--r--compiler/rustc_codegen_cranelift/example/alloc_example.rs7
-rw-r--r--compiler/rustc_codegen_cranelift/example/mini_core.rs15
-rw-r--r--compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs18
-rw-r--r--compiler/rustc_codegen_cranelift/example/std_example.rs68
4 files changed, 95 insertions, 13 deletions
diff --git a/compiler/rustc_codegen_cranelift/example/alloc_example.rs b/compiler/rustc_codegen_cranelift/example/alloc_example.rs
index d994e2fbc..117eed5af 100644
--- a/compiler/rustc_codegen_cranelift/example/alloc_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/alloc_example.rs
@@ -1,4 +1,4 @@
-#![feature(start, core_intrinsics, alloc_error_handler)]
+#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
#![no_std]
extern crate alloc;
@@ -27,6 +27,11 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
core::intrinsics::abort();
}
+#[lang = "eh_personality"]
+fn eh_personality() -> ! {
+ loop {}
+}
+
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let world: Box<&str> = Box::new("Hello World!\0");
diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs
index ea97e9f06..79ca4c039 100644
--- a/compiler/rustc_codegen_cranelift/example/mini_core.rs
+++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs
@@ -502,6 +502,9 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
drop_in_place(to_drop);
}
+#[lang = "unpin"]
+pub auto trait Unpin {}
+
#[lang = "deref"]
pub trait Deref {
type Target: ?Sized;
@@ -526,7 +529,7 @@ impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsiz
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
#[lang = "owned_box"]
-pub struct Box<T: ?Sized>(Unique<T>, ());
+pub struct Box<T: ?Sized, A = ()>(Unique<T>, A);
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
@@ -541,9 +544,10 @@ impl<T> Box<T> {
}
}
-impl<T: ?Sized> Drop for Box<T> {
+impl<T: ?Sized, A> Drop for Box<T, A> {
fn drop(&mut self) {
- // drop is currently performed by compiler.
+ // inner value is dropped by compiler
+ libc::free(self.0.pointer.0 as *mut u8);
}
}
@@ -560,11 +564,6 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
libc::malloc(size)
}
-#[lang = "box_free"]
-unsafe fn box_free<T: ?Sized>(ptr: Unique<T>, _alloc: ()) {
- libc::free(ptr.pointer.0 as *mut u8);
-}
-
#[lang = "drop"]
pub trait Drop {
fn drop(&mut self);
diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
index 5a55aa215..d97fab9eb 100644
--- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
+++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
@@ -322,7 +322,12 @@ fn main() {
#[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
test_tls();
- #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
+ #[cfg(all(
+ not(jit),
+ not(no_unstable_features),
+ target_arch = "x86_64",
+ any(target_os = "linux", target_os = "macos")
+ ))]
unsafe {
global_asm_test();
}
@@ -350,12 +355,17 @@ fn main() {
let _a = f.0[0];
}
-#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "darwin")))]
+#[cfg(all(
+ not(jit),
+ not(no_unstable_features),
+ target_arch = "x86_64",
+ any(target_os = "linux", target_os = "macos")
+))]
extern "C" {
fn global_asm_test();
}
-#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
+#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))]
global_asm! {
"
.global global_asm_test
@@ -365,7 +375,7 @@ global_asm! {
"
}
-#[cfg(all(not(jit), target_arch = "x86_64", target_os = "darwin"))]
+#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "macos"))]
global_asm! {
"
.global _global_asm_test
diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs
index ab4045d11..1bf0ff64c 100644
--- a/compiler/rustc_codegen_cranelift/example/std_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/std_example.rs
@@ -197,6 +197,10 @@ unsafe fn test_simd() {
test_mm_extract_epi8();
test_mm_insert_epi16();
+ test_mm_shuffle_epi8();
+
+ test_mm256_shuffle_epi8();
+ test_mm256_permute2x128_si256();
#[rustfmt::skip]
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
@@ -294,6 +298,12 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
}
#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx")]
+pub unsafe fn assert_eq_m256i(a: __m256i, b: __m256i) {
+ assert_eq!(std::mem::transmute::<_, [u64; 4]>(a), std::mem::transmute::<_, [u64; 4]>(b))
+}
+
+#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_cvtsi128_si64() {
let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0]));
@@ -336,6 +346,64 @@ unsafe fn test_mm_insert_epi16() {
assert_eq_m128i(r, e);
}
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "ssse3")]
+unsafe fn test_mm_shuffle_epi8() {
+ #[rustfmt::skip]
+ let a = _mm_setr_epi8(
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ );
+ #[rustfmt::skip]
+ let b = _mm_setr_epi8(
+ 4, 128_u8 as i8, 4, 3,
+ 24, 12, 6, 19,
+ 12, 5, 5, 10,
+ 4, 1, 8, 0,
+ );
+ let expected = _mm_setr_epi8(5, 0, 5, 4, 9, 13, 7, 4, 13, 6, 6, 11, 5, 2, 9, 1);
+ let r = _mm_shuffle_epi8(a, b);
+ assert_eq_m128i(r, expected);
+}
+
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx2")]
+unsafe fn test_mm256_shuffle_epi8() {
+ #[rustfmt::skip]
+ let a = _mm256_setr_epi8(
+ 1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32,
+ );
+ #[rustfmt::skip]
+ let b = _mm256_setr_epi8(
+ 4, 128u8 as i8, 4, 3, 24, 12, 6, 19,
+ 12, 5, 5, 10, 4, 1, 8, 0,
+ 4, 128u8 as i8, 4, 3, 24, 12, 6, 19,
+ 12, 5, 5, 10, 4, 1, 8, 0,
+ );
+ #[rustfmt::skip]
+ let expected = _mm256_setr_epi8(
+ 5, 0, 5, 4, 9, 13, 7, 4,
+ 13, 6, 6, 11, 5, 2, 9, 1,
+ 21, 0, 21, 20, 25, 29, 23, 20,
+ 29, 22, 22, 27, 21, 18, 25, 17,
+ );
+ let r = _mm256_shuffle_epi8(a, b);
+ assert_eq_m256i(r, expected);
+}
+
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx2")]
+unsafe fn test_mm256_permute2x128_si256() {
+ let a = _mm256_setr_epi64x(100, 200, 500, 600);
+ let b = _mm256_setr_epi64x(300, 400, 700, 800);
+ let r = _mm256_permute2x128_si256::<0b00_01_00_11>(a, b);
+ let e = _mm256_setr_epi64x(700, 800, 500, 600);
+ assert_eq_m256i(r, e);
+}
+
fn test_checked_mul() {
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
assert_eq!(u, None);