Skip to content

Commit 9059a74

Browse files
committed
test x86 crc intrinsics
1 parent e7b6662 commit 9059a74

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: example/std_example.rs

+18
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ struct I64X2(i64, i64);
210210
#[allow(improper_ctypes_definitions)]
211211
extern "C" fn foo(_a: I64X2) {}
212212

213+
#[cfg(target_arch = "x86_64")]
214+
#[target_feature(enable = "sse4.2")]
215+
#[cfg(not(jit))]
216+
unsafe fn test_crc32() {
217+
assert!(is_x86_feature_detected!("sse4.2"));
218+
219+
let a = 42u32;
220+
let b = 0xdeadbeefu64;
221+
222+
assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
223+
assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
224+
assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
225+
assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
226+
}
227+
213228
#[cfg(target_arch = "x86_64")]
214229
#[target_feature(enable = "sse2")]
215230
unsafe fn test_simd() {
@@ -248,6 +263,9 @@ unsafe fn test_simd() {
248263
#[rustfmt::skip]
249264
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)));
250265
assert_eq!(mask1, 1);
266+
267+
#[cfg(not(jit))]
268+
test_crc32();
251269
}
252270

253271
#[cfg(target_arch = "x86_64")]

0 commit comments

Comments
 (0)