openvm_native_compiler/ir/
select.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::ir::{Builder, Config, Ext, Felt, Var};

pub trait CanSelect<C: Config> {
    fn select(builder: &mut Builder<C>, cond: Var<C::N>, a: Self, b: Self) -> Self;
}

impl<C: Config> CanSelect<C> for Var<C::N> {
    fn select(builder: &mut Builder<C>, cond: Var<C::N>, a: Self, b: Self) -> Self {
        builder.select_v(cond, a, b)
    }
}

impl<C: Config> CanSelect<C> for Felt<C::F> {
    fn select(builder: &mut Builder<C>, cond: Var<C::N>, a: Self, b: Self) -> Self {
        builder.select_f(cond, a, b)
    }
}

impl<C: Config> CanSelect<C> for Ext<C::F, C::EF> {
    fn select(builder: &mut Builder<C>, cond: Var<C::N>, a: Self, b: Self) -> Self {
        builder.select_ef(cond, a, b)
    }
}