use crate::frontend::UInt;
use crate::frontend::{CubeType, ExpandElement};
use crate::ir::{Elem, Variable};
use super::{ExpandElementTyped, Vectorized};
pub trait CubePrimitive:
CubeType<ExpandType = ExpandElementTyped<Self>>
+ Vectorized
+ core::cmp::Eq
+ core::cmp::PartialEq
+ Send
+ Sync
+ 'static
+ Clone
+ Copy
{
fn as_elem() -> Elem;
fn from_expand_elem(elem: ExpandElement) -> Self::ExpandType {
ExpandElementTyped::new(elem)
}
}
macro_rules! impl_into_expand_element {
($type:ty) => {
impl From<$type> for ExpandElement {
fn from(value: $type) -> Self {
ExpandElement::Plain(Variable::from(value))
}
}
};
}
impl_into_expand_element!(u32);
impl_into_expand_element!(usize);
impl_into_expand_element!(bool);
impl_into_expand_element!(f32);
impl_into_expand_element!(i32);
impl_into_expand_element!(i64);
impl From<UInt> for ExpandElement {
fn from(value: UInt) -> Self {
ExpandElement::Plain(crate::ir::Variable::ConstantScalar(
crate::ir::ConstantScalarValue::UInt(value.val as u64),
))
}
}