about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/example/std_example.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-23 13:39:07 +0000
committerbors <bors@rust-lang.org>2024-09-23 13:39:07 +0000
commit648d024a7859e1ab7fdffe5e419b6e35ccb16a4a (patch)
tree4e2ffa6c38645cc8ba47bc39dc6ed267053fff07 /compiler/rustc_codegen_cranelift/example/std_example.rs
parentc22a4215a0f6fb676d3774d3763d9da1462414f5 (diff)
parent6b042f5b5d4bfe629c8440e58d4036b4dfc6ecd9 (diff)
downloadrust-648d024a7859e1ab7fdffe5e419b6e35ccb16a4a.tar.gz
rust-648d024a7859e1ab7fdffe5e419b6e35ccb16a4a.zip
Auto merge of #130716 - bjorn3:sync_cg_clif-2024-09-22, r=bjorn3
Subtree sync for rustc_codegen_cranelift

The main highlight this time is a fix for a miscompilation of RwLock on macOS. Also a Cranelift update and a couple of extra vendor intrinsics on arm64.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
Diffstat (limited to 'compiler/rustc_codegen_cranelift/example/std_example.rs')
-rw-r--r--compiler/rustc_codegen_cranelift/example/std_example.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_cranelift/example/std_example.rs b/compiler/rustc_codegen_cranelift/example/std_example.rs
index 602452d8276..ebaa9c69c81 100644
--- a/compiler/rustc_codegen_cranelift/example/std_example.rs
+++ b/compiler/rustc_codegen_cranelift/example/std_example.rs
@@ -258,6 +258,9 @@ unsafe fn test_simd() {
     test_mm_insert_epi16();
     test_mm_shuffle_epi8();
 
+    #[cfg(not(jit))]
+    test_mm_cmpestri();
+
     test_mm256_shuffle_epi8();
     test_mm256_permute2x128_si256();
     test_mm256_permutevar8x32_epi32();
@@ -429,6 +432,31 @@ unsafe fn test_mm_shuffle_epi8() {
     assert_eq_m128i(r, expected);
 }
 
+// Currently one cannot `load` a &[u8] that is less than 16
+// in length. This makes loading strings less than 16 in length
+// a bit difficult. Rather than `load` and mutate the __m128i,
+// it is easier to memcpy the given string to a local slice with
+// length 16 and `load` the local slice.
+#[cfg(not(jit))]
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "sse4.2")]
+unsafe fn str_to_m128i(s: &[u8]) -> __m128i {
+    assert!(s.len() <= 16);
+    let slice = &mut [0u8; 16];
+    std::ptr::copy_nonoverlapping(s.as_ptr(), slice.as_mut_ptr(), s.len());
+    _mm_loadu_si128(slice.as_ptr() as *const _)
+}
+
+#[cfg(not(jit))]
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "sse4.2")]
+unsafe fn test_mm_cmpestri() {
+    let a = str_to_m128i(b"bar - garbage");
+    let b = str_to_m128i(b"foobar");
+    let i = _mm_cmpestri::<_SIDD_CMP_EQUAL_ORDERED>(a, 3, b, 6);
+    assert_eq!(3, i);
+}
+
 #[cfg(target_arch = "x86_64")]
 #[target_feature(enable = "avx2")]
 unsafe fn test_mm256_shuffle_epi8() {