Skip to content

Commit d347767

Browse files
authored
Merge pull request #4862 from folkertdev/use-carryless-mul
use the unstable `carryless_mul` in the `pclmul` implementation
2 parents 667066c + 4ff68e4 commit d347767

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

src/tools/miri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(derive_coerce_pointee)]
2323
#![feature(arbitrary_self_types)]
2424
#![feature(macro_metavar_expr)]
25+
#![feature(uint_carryless_mul)]
2526
// Configure clippy and other lints
2627
#![allow(
2728
clippy::collapsible_else_if,

src/tools/miri/src/shims/x86/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,21 +1178,7 @@ fn pclmulqdq<'tcx>(
11781178
let index = if (imm8 & 0x10) == 0 { lo } else { hi };
11791179
let right = ecx.read_scalar(&ecx.project_index(&right, index)?)?.to_u64()?;
11801180

1181-
// Perform carry-less multiplication.
1182-
//
1183-
// This operation is like long multiplication, but ignores all carries.
1184-
// That idea corresponds to the xor operator, which is used in the implementation.
1185-
//
1186-
// Wikipedia has an example https://en.wikipedia.org/wiki/Carry-less_product#Example
1187-
let mut result: u128 = 0;
1188-
1189-
for i in 0..64 {
1190-
// if the i-th bit in right is set
1191-
if (right & (1 << i)) != 0 {
1192-
// xor result with `left` shifted to the left by i positions
1193-
result ^= u128::from(left) << i;
1194-
}
1195-
}
1181+
let result = left.widening_carryless_mul(right);
11961182

11971183
let dest = ecx.project_index(&dest, i)?;
11981184
ecx.write_scalar(Scalar::from_u128(result), &dest)?;

0 commit comments

Comments
 (0)