Skip to content

Commit 1ea6452

Browse files
committed
Better documentation of polynomial division mod 2
1 parent e229837 commit 1ea6452

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/shims/x86/sse42.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,25 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
458458
};
459459

460460
// Perform polynomial division modulo 2.
461+
// The algorithm for the division is an adapted version of the
462+
// schoolbook division algorithm used for normal integer or polynomial
463+
// division. In this context, the quotient is not calculated, since
464+
// only the remainder is needed.
465+
//
466+
// The algorithm works as follows:
467+
// 1. Pull down digits until division can be performed. In the context of division
468+
// modulo 2 it means locating the most significant digit of the dividend and shifting
469+
// the divisor such that the position of the divisors most significand digit and the
470+
// dividends most significand digit match.
471+
// 2. Perform a division and determine the remainder. Since it is arithmetic modulo 2,
472+
// this operation is a simple bitwise exclusive or.
473+
// 3. Repeat steps 1. and 2. until the full remainder is calculated. This is the case
474+
// once the degree of the remainder polynomial is smaller than the degree of the
475+
// divisor polynomial. In other words, the number of leading zeros of the remainder
476+
// is larger than the number of leading zeros of the divisor. It is important to
477+
// note that standard arithmetic comparison is not applicable here:
478+
// 0b10011 / 0b11111 = 0b01100 is a valid division, even though the dividend is
479+
// smaller than the divisor.
461480
let mut dividend = (crc << bit_size) ^ (v << 32);
462481
const POLYNOMIAL: u128 = 0x11EDC6F41;
463482
while dividend.leading_zeros() <= POLYNOMIAL.leading_zeros() {

0 commit comments

Comments
 (0)