//! 512-bit unsigned integer type stored as eight `u64` limbs in little-endian
//! order: `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0` is the least
//! significant.

/// A 512-bit unsigned integer represented as eight 64-bit limbs in little-endian
/// order.
///
/// The internal layout is `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0`
/// contains the least significant 64 bits and `w7` contains the most
/// significant 64 bits. Used for full products of 256-bit multiplications
/// and other intermediate results in multi-precision arithmetic.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct U512(pub(crate) [u64; 8]);

impl PartialOrd for U512 {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for U512 {
    #[inline]
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        // Compare from MSB (index 7) to LSB (index 0) for correct numerical ordering.
        let mut i = 7;
        loop {
            match self.0[i].cmp(&other.0[i]) {
                core::cmp::Ordering::Equal => {}
                ord => return ord,
            }
            if i == 0 {
                return core::cmp::Ordering::Equal;
            }
            i -= 1;
        }
    }
}

mod bit_len;
mod checked_add;
mod checked_sub;
mod const_eq;
mod constants;
mod div_u256;
mod div_u64;
mod from_be_bytes;
mod from_be_limbs;
mod from_le_bytes;
mod from_le_limbs;
mod is_even;
mod is_odd;
mod is_zero;
mod leading_zero_bytes;
mod leading_zeros;
mod high_u256;
mod low_u256;
mod negate;
mod non_zero;
mod overflowing_add;
mod overflowing_sub;
mod shl_bits;
mod shr_bits;
mod sig_limbs;
mod sparse_reduce;
mod sparse_reduce_ct;
mod sparse_reduce_vt;
mod to_be_bytes;
mod to_be_limbs;
mod to_le_bytes;
mod to_le_limbs;
mod trailing_zeros;
mod undilate_even;
mod undilate_odd;
mod interleave;
mod deinterleave;

// Standard trait implementations
mod add;
mod bitand;
mod bitor;
mod bitxor;
mod default;
mod display;
mod from_limbs;
mod from_str;
mod from_u128;
mod from_u256;
mod from_u320;
mod from_u384;
mod from_u64;
mod into_be_bytes;
mod into_limbs;
mod lower_hex;
mod not;
mod shl;
mod shr;
mod sub;
mod upper_hex;
