about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/example/std_example.rs
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-13 13:26:33 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-05-13 13:26:33 +0000
commit75f8bdbca4965896c3d3ead656f6a13e8409a78b (patch)
treed8fba5cd3ad9aee184393d91c0c1b01fc5e76faa /compiler/rustc_codegen_cranelift/example/std_example.rs
parentabb95639ef2b837dbfe7b5d18f51fadda29711cb (diff)
parent3270432f4b0583104c8b9b6f695bf97d6bbf3ac2 (diff)
downloadrust-75f8bdbca4965896c3d3ead656f6a13e8409a78b.tar.gz
rust-75f8bdbca4965896c3d3ead656f6a13e8409a78b.zip
Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into sync_cg_clif-2024-05-13
Diffstat (limited to 'compiler/rustc_codegen_cranelift/example/std_example.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/example/std_example.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs
index 90d4ab721da..7347b2e7789 100644
--- a/compiler/rustc_codegen_cranelift/example/std_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/std_example.rs
@@ -211,6 +211,21 @@ struct I64X2(i64, i64);
 extern "C" fn foo(_a: I64X2) {}
 
 #[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "sse4.2")]
+#[cfg(not(jit))]
+unsafe fn test_crc32() {
+    assert!(is_x86_feature_detected!("sse4.2"));
+
+    let a = 42u32;
+    let b = 0xdeadbeefu64;
+
+    assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
+    assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
+    assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
+    assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
+}
+
+#[cfg(target_arch = "x86_64")]
 #[target_feature(enable = "sse2")]
 unsafe fn test_simd() {
     assert!(is_x86_feature_detected!("sse2"));
@@ -244,10 +259,14 @@ unsafe fn test_simd() {
 
     test_mm256_shuffle_epi8();
     test_mm256_permute2x128_si256();
+    test_mm256_permutevar8x32_epi32();
 
     #[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)));
     assert_eq!(mask1, 1);
+
+    #[cfg(not(jit))]
+    test_crc32();
 }
 
 #[cfg(target_arch = "x86_64")]
@@ -447,6 +466,16 @@ unsafe fn test_mm256_permute2x128_si256() {
     assert_eq_m256i(r, e);
 }
 
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "avx2")]
+unsafe fn test_mm256_permutevar8x32_epi32() {
+    let a = _mm256_setr_epi32(100, 200, 300, 400, 500, 600, 700, 800);
+    let idx = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0);
+    let r = _mm256_setr_epi32(800, 700, 600, 500, 400, 300, 200, 100);
+    let e = _mm256_permutevar8x32_epi32(a, idx);
+    assert_eq_m256i(r, e);
+}
+
 fn test_checked_mul() {
     let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
     assert_eq!(u, None);