Skip to main content

cubecl_core/frontend/element/
bool.rs

1use cubecl_ir::{ConstantValue, Scope, StorageType, Type};
2
3use crate::prelude::*;
4use crate::{ir::ElemType, prelude::Const};
5
6use super::{IntoRuntime, NativeAssign, NativeExpand};
7
8/// Extension trait for [bool].
9pub trait BoolOps {
10    #[allow(clippy::new_ret_no_self)]
11    fn new(value: bool) -> bool {
12        value
13    }
14    fn __expand_new(_scope: &Scope, value: NativeExpand<bool>) -> NativeExpand<bool> {
15        ElemType::Bool
16            .constant(value.expand.as_const().unwrap())
17            .into()
18    }
19}
20
21impl BoolOps for bool {}
22
23impl CubeType for bool {
24    type ExpandType = NativeExpand<Self>;
25}
26
27impl CubeDebug for bool {}
28impl Scalar for bool {}
29impl CubePrimitive for bool {
30    type Scalar = Self;
31    type Size = Const<1>;
32    type WithScalar<S: Scalar> = S;
33
34    fn as_type_native() -> Option<Type> {
35        Some(StorageType::Scalar(ElemType::Bool).into())
36    }
37
38    fn from_const_value(value: ConstantValue) -> Self {
39        let ConstantValue::Bool(value) = value else {
40            unreachable!()
41        };
42        value
43    }
44}
45
46impl IntoRuntime for bool {
47    fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
48        self.into()
49    }
50}
51
52impl IntoExpand for bool {
53    type Expand = NativeExpand<bool>;
54
55    fn into_expand(self, _: &Scope) -> Self::Expand {
56        self.into()
57    }
58}
59
60impl NativeAssign for bool {}