Skip to content

Commit 6cebe68

Browse files
committed
cross-checks: rust-checks: Replace simd dependency with core::simd and core::arch calls
1 parent ca5dce7 commit 6cebe68

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

cross-checks/rust-checks/runtime/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ publish = false
1313
[features]
1414
xcheck-with-dlsym = []
1515
xcheck-with-weak = []
16-
djb2-ssse3 = ["simd"]
16+
djb2-ssse3 = []
1717
libc-hash = ["libc"]
1818
fixed-length-array-hash = []
1919

2020
[dependencies]
21-
simd = { version = "0.2", optional = true }
2221
libc = { version = "0.2", optional = true, default-features = false }

cross-checks/rust-checks/runtime/src/hash/djb2.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ impl Hasher for Djb2Hasher {
2727
#[cfg(feature = "djb2-ssse3")]
2828
#[inline]
2929
fn write(&mut self, bytes: &[u8]) {
30-
use simd::u32x4;
31-
use simd::x86::ssse3::Ssse3U32x4;
30+
use core::simd::u32x4;
3231

3332
let mut u32_chunks = bytes.chunks(4);
3433
let last_chunk = if bytes.len() % 4 != 0 {
@@ -37,14 +36,15 @@ impl Hasher for Djb2Hasher {
3736
None
3837
};
3938
self.0 = u32_chunks.fold(self.0, |h, cb| {
40-
let cvec = u32x4::new(cb[0] as u32, cb[1] as u32, cb[2] as u32, cb[3] as u32);
39+
let cvec = u32x4::from_array([cb[0] as u32, cb[1] as u32, cb[2] as u32, cb[3] as u32]);
4140
// The djb2 factors: powers of 33 from 33^3 to 33^0
42-
const DJB2_FACTORS: u32x4 = u32x4::new(35937, 1089, 33, 1);
41+
const DJB2_FACTORS: u32x4 = u32x4::from_array([35937, 1089, 33, 1]);
4342
let cmul = cvec * DJB2_FACTORS;
44-
let ch1 = Ssse3U32x4::hadd(cmul, cmul);
45-
let ch2 = Ssse3U32x4::hadd(ch1, ch1);
43+
let ch1 = unsafe { core::arch::x86_64::_mm_hadd_epi32(cmul.into(), cmul.into()) };
44+
let ch2 = unsafe { core::arch::x86_64::_mm_hadd_epi32(ch1, ch1) };
45+
let cval = unsafe { core::arch::x86_64::_mm_extract_epi32(ch2, 0) };
4646
// h = h * 33^4 + ch2[0]
47-
h.wrapping_mul(1185921u32).wrapping_add(ch2.extract(0))
47+
h.wrapping_mul(1185921u32).wrapping_add(cval as u32)
4848
});
4949
// Add in the last 1-3 bytes manually
5050
if let Some(last_bytes) = last_chunk {

cross-checks/rust-checks/runtime/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#![cfg_attr(feature = "xcheck-with-dlsym", feature(libc))]
55
#![cfg_attr(feature = "xcheck-with-weak", feature(linkage))]
66
#![cfg_attr(feature = "libc-hash", feature(libc))]
7+
#![cfg_attr(feature = "djb2-ssse3", feature(portable_simd))]
78
#![no_std]
89

9-
#[cfg(feature = "djb2-ssse3")]
10-
extern crate simd;
11-
1210
#[cfg(feature = "libc-hash")]
1311
extern crate libc;
1412

0 commit comments

Comments
 (0)