@@ -458,6 +458,25 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
458
458
} ;
459
459
460
460
// 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.
461
480
let mut dividend = ( crc << bit_size) ^ ( v << 32 ) ;
462
481
const POLYNOMIAL : u128 = 0x11EDC6F41 ;
463
482
while dividend. leading_zeros ( ) <= POLYNOMIAL . leading_zeros ( ) {
0 commit comments