From 5b5c72827f5703f57fb7f4d18e437e303ba8bced Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 17 Feb 2026 17:01:16 +0100 Subject: [PATCH] use the unstable carryless_mul instead of a manual implementation --- src/lib.rs | 1 + src/shims/x86/mod.rs | 18 +----------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5722969a31..8e3ae7f262 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, diff --git a/src/shims/x86/mod.rs b/src/shims/x86/mod.rs index dc0d8d48ac..cca6f7a867 100644 --- a/src/shims/x86/mod.rs +++ b/src/shims/x86/mod.rs @@ -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(())