vyre-conform 0.1.0

Conformance suite for vyre backends — proves byte-identical output to CPU reference
Documentation
//! Hand-verified golden samples for every registered primitive.
//!
//! The conform primitive adapter generates `OpSpec`s through a macro
//! (see `src/specs/primitive/mod.rs`), so there is no per-op file the
//! codegen's discover_ops can scan for a `pub const GOLDEN`. This
//! aggregator file exists so `all_generated_golden_samples` picks up
//! one hand-verified sample per primitive — the `every_spec_has_
//! golden_sample` and `golden_sample_count` tests rely on these.
//!
//! Every sample is a fixed `(input, expected)` pair in little-endian
//! byte layout, derived from the op's mathematical definition — never
//! from re-running `cpu_fn`, which would be tautological. A future
//! refactor of `cpu_fn` that silently diverges from the spec will
//! cause the golden check to fail, surfacing the drift immediately.
//!
//! Location-agnostic (this module does not declare an OpMetadata
//! because the primitive ops already carry theirs through
//! `core::ops::primitive::*::SPEC`).

use vyre_spec::GoldenSample;

/// Hand-verified golden samples for every primitive. The codegen
/// discovers this constant via `discover_ops::has_non_empty_slice`
/// and wires it into `all_generated_golden_samples`.
pub const GOLDEN: &[GoldenSample] = &[
    // ── primitive.math ───────────────────────────────────────────
    GoldenSample {
        op_id: "primitive.math.add",
        input: &[0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00],
        expected: &[0x30, 0x00, 0x00, 0x00],
        reason: "16 + 32 = 48 (wrapping add)",
    },
    GoldenSample {
        op_id: "primitive.math.sub",
        input: &[0x20, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "32 - 16 = 16",
    },
    GoldenSample {
        op_id: "primitive.math.mul",
        input: &[0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00],
        expected: &[0x2A, 0x00, 0x00, 0x00],
        reason: "7 * 6 = 42",
    },
    GoldenSample {
        op_id: "primitive.math.div",
        input: &[0x2A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00],
        expected: &[0x0E, 0x00, 0x00, 0x00],
        reason: "42 / 3 = 14",
    },
    GoldenSample {
        op_id: "primitive.math.mod",
        input: &[0x2A, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00],
        expected: &[0x02, 0x00, 0x00, 0x00],
        reason: "42 % 5 = 2",
    },
    GoldenSample {
        op_id: "primitive.math.min",
        input: &[0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "min(16, 32) = 16",
    },
    GoldenSample {
        op_id: "primitive.math.max",
        input: &[0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00],
        expected: &[0x20, 0x00, 0x00, 0x00],
        reason: "max(16, 32) = 32",
    },
    GoldenSample {
        op_id: "primitive.math.abs_diff",
        input: &[0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "|16 - 32| = 16",
    },
    GoldenSample {
        op_id: "primitive.math.add_sat",
        input: &[0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00],
        expected: &[0xFF, 0xFF, 0xFF, 0xFF],
        reason: "u32::MAX + 1 saturates to u32::MAX",
    },
    GoldenSample {
        op_id: "primitive.math.sub_sat",
        input: &[0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00],
        expected: &[0x00, 0x00, 0x00, 0x00],
        reason: "0 - 1 saturates to 0",
    },
    GoldenSample {
        op_id: "primitive.math.abs",
        input: &[0xFF, 0xFF, 0xFF, 0xFF],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "abs(-1 as i32) = 1",
    },
    GoldenSample {
        op_id: "primitive.math.neg",
        input: &[0x05, 0x00, 0x00, 0x00],
        expected: &[0xFB, 0xFF, 0xFF, 0xFF],
        reason: "neg(5) = -5 (two's complement 0xFFFFFFFB)",
    },
    GoldenSample {
        op_id: "primitive.math.negate",
        input: &[0x05, 0x00, 0x00, 0x00],
        expected: &[0xFB, 0xFF, 0xFF, 0xFF],
        reason: "negate(5) = -5 (two's complement 0xFFFFFFFB)",
    },
    GoldenSample {
        op_id: "primitive.math.sign",
        input: &[0xFB, 0xFF, 0xFF, 0xFF],
        expected: &[0xFF, 0xFF, 0xFF, 0xFF],
        reason: "sign(-5 as i32) = -1 (0xFFFFFFFF)",
    },
    GoldenSample {
        op_id: "primitive.math.gcd",
        input: &[0x0C, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00],
        expected: &[0x04, 0x00, 0x00, 0x00],
        reason: "gcd(12, 8) = 4",
    },
    GoldenSample {
        op_id: "primitive.math.lcm",
        input: &[0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00],
        expected: &[0x0C, 0x00, 0x00, 0x00],
        reason: "lcm(4, 6) = 12",
    },
    GoldenSample {
        op_id: "primitive.math.clamp",
        input: &[
            0x05, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
        ],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "clamp(5, lo=16, hi=32) = 16",
    },
    // ── primitive.bitwise ────────────────────────────────────────
    GoldenSample {
        op_id: "primitive.bitwise.xor",
        input: &[0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55],
        expected: &[0xFF, 0xFF, 0xFF, 0xFF],
        reason: "0xAAAAAAAA ^ 0x55555555 = 0xFFFFFFFF",
    },
    GoldenSample {
        op_id: "primitive.bitwise.or",
        input: &[0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55],
        expected: &[0xFF, 0xFF, 0xFF, 0xFF],
        reason: "0xAAAAAAAA | 0x55555555 = 0xFFFFFFFF",
    },
    GoldenSample {
        op_id: "primitive.bitwise.not",
        input: &[0x00, 0x00, 0x00, 0x00],
        expected: &[0xFF, 0xFF, 0xFF, 0xFF],
        reason: "!0 = u32::MAX",
    },
    GoldenSample {
        op_id: "primitive.bitwise.shl",
        input: &[0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "1 << 4 = 16",
    },
    GoldenSample {
        op_id: "primitive.bitwise.shr",
        input: &[0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "128 >> 3 = 16",
    },
    GoldenSample {
        op_id: "primitive.bitwise.popcount",
        input: &[0xFF, 0x00, 0x00, 0x00],
        expected: &[0x08, 0x00, 0x00, 0x00],
        reason: "popcount(0xFF) = 8",
    },
    GoldenSample {
        op_id: "primitive.bitwise.popcount_sw",
        input: &[0xFF, 0x00, 0x00, 0x00],
        expected: &[0x08, 0x00, 0x00, 0x00],
        reason: "popcount_sw(0xFF) = 8 (SWAR matches hardware popcount)",
    },
    GoldenSample {
        op_id: "primitive.bitwise.clz",
        input: &[0x00, 0x00, 0x00, 0x80],
        expected: &[0x00, 0x00, 0x00, 0x00],
        reason: "clz(0x80000000) = 0 (top bit set)",
    },
    GoldenSample {
        op_id: "primitive.bitwise.ctz",
        input: &[0x00, 0x00, 0x00, 0x80],
        expected: &[0x1F, 0x00, 0x00, 0x00],
        reason: "ctz(0x80000000) = 31",
    },
    GoldenSample {
        op_id: "primitive.bitwise.reverse_bits",
        input: &[0x01, 0x00, 0x00, 0x00],
        expected: &[0x00, 0x00, 0x00, 0x80],
        reason: "reverse_bits(0x00000001) = 0x80000000",
    },
    GoldenSample {
        op_id: "primitive.bitwise.rotl",
        input: &[0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00],
        expected: &[0x10, 0x00, 0x00, 0x00],
        reason: "rotl(1, 4) = 16",
    },
    GoldenSample {
        op_id: "primitive.bitwise.rotr",
        input: &[0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "rotr(16, 4) = 1",
    },
    GoldenSample {
        op_id: "primitive.bitwise.and",
        input: &[0xFF, 0xFF, 0xFF, 0xFF, 0x55, 0x55, 0x55, 0x55],
        expected: &[0x55, 0x55, 0x55, 0x55],
        reason: "u32::MAX & 0x55555555 = 0x55555555 (identity on nonzero)",
    },
    GoldenSample {
        op_id: "primitive.bitwise.extract_bits",
        input: &[
            0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
        ],
        expected: &[0x00, 0x00, 0x00, 0x00],
        reason: "extract_bits(0, offset=4, count=4) = 0 (zero input yields zero extraction)",
    },
    GoldenSample {
        op_id: "primitive.bitwise.insert_bits",
        input: &[
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
            0x00, 0x00,
        ],
        expected: &[0x00, 0x00, 0x00, 0x00],
        reason: "insert_bits(0, value=0, offset=4, count=4) = 0 (zero value preserves zero source)",
    },
    // ── primitive.compare ────────────────────────────────────────
    GoldenSample {
        op_id: "primitive.compare.eq",
        input: &[0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "eq(5, 5) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.ne",
        input: &[0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "ne(5, 6) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.lt",
        input: &[0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "lt(5, 6) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.le",
        input: &[0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "le(5, 5) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.gt",
        input: &[0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "gt(6, 5) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.ge",
        input: &[0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "ge(5, 5) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.logical_not",
        input: &[0x00, 0x00, 0x00, 0x00],
        expected: &[0x01, 0x00, 0x00, 0x00],
        reason: "logical_not(0) = 1",
    },
    GoldenSample {
        op_id: "primitive.compare.select",
        input: &[0xAA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00],
        expected: &[0xAA, 0x00, 0x00, 0x00],
        reason: "select(value=0xAA, condition=1) = 0xAA (inputs are (value, condition))",
    },
    // ── primitive.float (f32 bits in LE) ─────────────────────────
    GoldenSample {
        op_id: "primitive.float.f32_add",
        input: &[0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x40],
        expected: &[0x00, 0x00, 0x40, 0x40],
        reason: "1.0 + 2.0 = 3.0 (IEEE-754 f32)",
    },
    GoldenSample {
        op_id: "primitive.float.f32_sub",
        input: &[0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x80, 0x3F],
        expected: &[0x00, 0x00, 0x00, 0x40],
        reason: "3.0 - 1.0 = 2.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_mul",
        input: &[0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40],
        expected: &[0x00, 0x00, 0xC0, 0x40],
        reason: "2.0 * 3.0 = 6.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_div",
        input: &[0x00, 0x00, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x40],
        expected: &[0x00, 0x00, 0x40, 0x40],
        reason: "6.0 / 2.0 = 3.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_neg",
        input: &[0x00, 0x00, 0x80, 0x3F],
        expected: &[0x00, 0x00, 0x80, 0xBF],
        reason: "-1.0 as f32 bits = 0xBF800000",
    },
    GoldenSample {
        op_id: "primitive.float.f32_abs",
        input: &[0x00, 0x00, 0x80, 0xBF],
        expected: &[0x00, 0x00, 0x80, 0x3F],
        reason: "abs(-1.0) = 1.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_sqrt",
        input: &[0x00, 0x00, 0x80, 0x40],
        expected: &[0x00, 0x00, 0x00, 0x40],
        reason: "sqrt(4.0) = 2.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_sin",
        input: &[0x00, 0x00, 0x00, 0x00],
        expected: &[0x00, 0x00, 0x00, 0x00],
        reason: "sin(0.0) = 0.0",
    },
    GoldenSample {
        op_id: "primitive.float.f32_cos",
        input: &[0x00, 0x00, 0x00, 0x00],
        expected: &[0x00, 0x00, 0x80, 0x3F],
        reason: "cos(0.0) = 1.0",
    },
];