1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Unsigned minimum of two u32 values.
use crate::ir::{Expr, Program};
use crate::ops::primitive;
use crate::ops::{AlgebraicLaw, OpSpec, U32_OUTPUTS, U32_U32_INPUTS};
pub const LAWS: &[AlgebraicLaw] = &[
AlgebraicLaw::Commutative,
AlgebraicLaw::Associative,
AlgebraicLaw::Identity { element: u32::MAX },
AlgebraicLaw::Idempotent,
AlgebraicLaw::Absorbing { element: 0 },
AlgebraicLaw::DistributiveOver {
over_op: "primitive.math.max",
},
AlgebraicLaw::LatticeAbsorption {
dual_op: "primitive.math.max",
},
];
/// Unsigned minimum operation.
#[derive(Debug, Clone, Copy, Default)]
pub struct Min;
impl Min {
/// Declarative operation specification.
///
/// Laws are declared as explicit `AlgebraicLaw` values on `SPEC`.
pub const SPEC: OpSpec = OpSpec::composition_inlinable(
"primitive.math.min",
U32_U32_INPUTS,
U32_OUTPUTS,
LAWS,
Self::program,
);
/// Build the canonical IR program.
///
/// # Examples
///
/// ```
/// use vyre::ir::Expr;
/// use vyre::ops::primitive::min::Min;
///
/// let _expr = Expr::select(Expr::le(Expr::u32(3), Expr::u32(7)), Expr::u32(3), Expr::u32(7));
/// let program = Min::program();
/// assert!(!program.entry().is_empty());
/// ```
#[must_use]
pub fn program() -> Program {
primitive::binary_u32_program(|a, b| Expr::select(Expr::le(a.clone(), b.clone()), a, b))
}
}