use crate::num::{as_cast, UnsignedInteger};
#[inline(always)]
pub fn mul<Full, Half>(x: Full, y: Full) -> (Full, Full)
where
    Full: UnsignedInteger,
    Half: UnsignedInteger,
{
    let x1 = x >> Half::BITS as i32;
    let x0 = x & as_cast(Half::MAX);
    let y1 = y >> Half::BITS as i32;
    let y0 = y & as_cast(Half::MAX);
    let w0 = x0 * y0;
    let tmp = (x1 * y0) + (w0 >> Half::BITS as i32);
    let w1 = tmp & as_cast(Half::MAX);
    let w2 = tmp >> Half::BITS as i32;
    let w1 = w1 + x0 * y1;
    let hi = (x1 * y1) + w2 + (w1 >> Half::BITS as i32);
    let lo = x.wrapping_mul(y);
    (hi, lo)
}
#[inline(always)]
pub fn mulhi<Full, Half>(x: Full, y: Full) -> Full
where
    Full: UnsignedInteger,
    Half: UnsignedInteger,
{
    let x1 = x >> Half::BITS as i32;
    let x0 = x & as_cast(Half::MAX);
    let y1 = y >> Half::BITS as i32;
    let y0 = y & as_cast(Half::MAX);
    let w0 = x0 * y0;
    let m = (x0 * y1) + (w0 >> Half::BITS as i32);
    let w1 = m & as_cast(Half::MAX);
    let w2 = m >> Half::BITS as i32;
    let w3 = (x1 * y0 + w1) >> Half::BITS as i32;
    x1 * y1 + w2 + w3
}