//! Knuth Algorithm D with MG10 reciprocal-based quotient estimation.
//!
//! Encapsulates the normalized divisor state and precomputed reciprocal
//! needed for multi-limb division. Used by [`U512::div_u256`](crate::u512::U512::div_u256)
//! to reduce 512-bit products modulo a 256-bit modulus.

/// Precomputed state for Knuth Algorithm D division.
///
/// Bundles a normalized little-endian divisor with its MG10 reciprocal
/// approximation. Constructed once per divisor, then reused across all
/// quotient digit iterations. All fields are read-only after construction.
///
/// # Invariants
///
/// - `vn[n-1]` has its most significant bit set (normalization guarantee).
/// - `d1 == vn[n-1]`, `d0 == vn[n-2]`, `d == (d1 << 64) | d0`.
/// - `v` is the MG10 reciprocal of `(d1, d0)`.
#[derive(Debug, Clone, Copy)]
pub(crate) struct KnuthD {
    /// Normalized divisor limbs in little-endian order.
    pub(crate) vn: [u64; 4],
    /// Top normalized limb (`vn[n-1]`), guaranteed `>= 2^63`.
    pub(crate) d1: u64,
    /// Second normalized limb (`vn[n-2]`).
    pub(crate) d0: u64,
    /// Combined top two limbs: `(d1 << 64) | d0`.
    pub(crate) d: u128,
    /// Precomputed MG10 reciprocal for `(d1, d0)`.
    pub(crate) v: u64,
    /// Number of significant limbs in the divisor (2–4).
    pub(crate) n: usize,
    /// Normalization left-shift amount (0–63).
    pub(crate) s: u32,
}

mod add_back;
mod consts;
mod div_3x2;
mod knuth_loop;
mod new;
mod normalize_dividend;
mod reciprocal_1;
mod reciprocal_2;
mod rem;
mod submul;
mod unnormalize;
