Skip to content

Commit

Permalink
Moving mask to const, eliminating transmutes and ensuring const evalu…
Browse files Browse the repository at this point in the history
…ation and therefore uses the alignment of the destination
  • Loading branch information
valaphee committed Apr 5, 2024
1 parent 677a3b3 commit ac7673c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/simd/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ValueOps for Value {
unsafe {
Self(arch::_mm_xor_si128(
arch::_mm_clmulepi64_si128(
arch::_mm_and_si128(self.0, mem::transmute((1u128 << 32) - 1)),
arch::_mm_and_si128(self.0, MASK),
x_mod_p.0,
0x00,
),
Expand All @@ -63,16 +63,18 @@ impl ValueOps for Value {
// SAFETY: This is only implemented if the target supports sse2, sse4.1, and pclmulqdq
unsafe {
let t1 = arch::_mm_clmulepi64_si128(
arch::_mm_and_si128(self.0, mem::transmute((1u128 << 32) - 1)),
arch::_mm_and_si128(self.0, MASK),
px_u.0,
0x10,
);
let t2 = arch::_mm_clmulepi64_si128(
arch::_mm_and_si128(t1, mem::transmute((1u128 << 32) - 1)),
arch::_mm_and_si128(t1, MASK),
px_u.0,
0x00,
);
arch::_mm_extract_epi32(arch::_mm_xor_si128(self.0, t2), 1) as u32
}
}
}

const MASK: arch::__m128i = unsafe { mem::transmute((1u128 << 32) - 1) };

0 comments on commit ac7673c

Please sign in to comment.