Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![feature(derive_coerce_pointee)]
#![feature(arbitrary_self_types)]
#![feature(iter_advance_by)]
#![feature(uint_carryless_mul)]
// Configure clippy and other lints
#![allow(
clippy::collapsible_else_if,
Expand Down
18 changes: 1 addition & 17 deletions src/shims/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,24 +1178,8 @@ fn pclmulqdq<'tcx>(
let index = if (imm8 & 0x10) == 0 { lo } else { hi };
let right = ecx.read_scalar(&ecx.project_index(&right, index)?)?.to_u64()?;

// Perform carry-less multiplication.
//
// This operation is like long multiplication, but ignores all carries.
// That idea corresponds to the xor operator, which is used in the implementation.
//
// Wikipedia has an example https://en.wikipedia.org/wiki/Carry-less_product#Example
let mut result: u128 = 0;

for i in 0..64 {
// if the i-th bit in right is set
if (right & (1 << i)) != 0 {
// xor result with `left` shifted to the left by i positions
result ^= u128::from(left) << i;
}
}

let dest = ecx.project_index(&dest, i)?;
ecx.write_scalar(Scalar::from_u128(result), &dest)?;
ecx.write_scalar(Scalar::from_u128(left.widening_carryless_mul(right)), &dest)?;
}

interp_ok(())
Expand Down
Loading