//! F1 — Logic monomers: MC_08–MC_15
//!
//! Bitwise and boolean operations. All operations are total and deterministic.

/// MC_08 — AND8: Bitwise AND.
pub fn and8(a: u8, b: u8) -> u8 { a & b }

/// MC_09 — OR8: Bitwise OR.
pub fn or8(a: u8, b: u8) -> u8 { a | b }

/// MC_10 — XOR8: Bitwise XOR.
pub fn xor8(a: u8, b: u8) -> u8 { a ^ b }

/// MC_11 — NOT8: Bitwise NOT.
pub fn not8(a: u8) -> u8 { !a }

/// MC_12 — SHL8: Left shift, clamped to [0, 7].
///
/// Shift amounts >= 8 return 0.
///
/// ```
/// use brik64_core::mc::shl8;
/// assert_eq!(shl8(1, 3), 8);
/// assert_eq!(shl8(1, 8), 0); // safe
/// ```
pub fn shl8(a: u8, shift: u8) -> u8 {
    if shift >= 8 { 0 } else { a << shift }
}

/// MC_13 — SHR8: Right shift, clamped to [0, 7].
///
/// Shift amounts >= 8 return 0.
pub fn shr8(a: u8, shift: u8) -> u8 {
    if shift >= 8 { 0 } else { a >> shift }
}

/// MC_14 — BOOL_AND: Logical AND.
pub fn bool_and(a: bool, b: bool) -> bool { a && b }

/// MC_15 — BOOL_OR: Logical OR.
pub fn bool_or(a: bool, b: bool) -> bool { a || b }

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn bitwise() {
        assert_eq!(and8(0b1100, 0b1010), 0b1000);
        assert_eq!(xor8(0b1111, 0b1010), 0b0101);
        assert_eq!(shl8(1, 8), 0);
        assert_eq!(shr8(128, 8), 0);
    }
}
