cubecl_core/frontend/element/
bool.rs1use cubecl_ir::{ConstantScalarValue, ExpandElement, Scope, StorageType};
2
3use crate::frontend::{CubePrimitive, CubeType};
4use crate::ir::ElemType;
5
6use super::{
7 ExpandElementIntoMut, ExpandElementTyped, IntoMut, IntoRuntime, into_mut_expand_element,
8};
9
10pub trait BoolOps {
12 #[allow(clippy::new_ret_no_self)]
13 fn new(value: bool) -> bool {
14 value
15 }
16 fn __expand_new(
17 _scope: &mut Scope,
18 value: ExpandElementTyped<bool>,
19 ) -> ExpandElementTyped<bool> {
20 ExpandElement::Plain(ElemType::Bool.from_constant(*value.expand)).into()
21 }
22}
23
24impl BoolOps for bool {}
25
26impl CubeType for bool {
27 type ExpandType = ExpandElementTyped<Self>;
28}
29
30impl CubePrimitive for bool {
31 fn as_type_native() -> Option<StorageType> {
32 Some(StorageType::Scalar(ElemType::Bool))
33 }
34
35 fn from_const_value(value: ConstantScalarValue) -> Self {
36 let ConstantScalarValue::Bool(value) = value else {
37 unreachable!()
38 };
39 value
40 }
41}
42
43impl IntoRuntime for bool {
44 fn __expand_runtime_method(self, scope: &mut Scope) -> ExpandElementTyped<Self> {
45 let expand: ExpandElementTyped<Self> = self.into();
46 IntoMut::into_mut(expand, scope)
47 }
48}
49
50impl ExpandElementIntoMut for bool {
51 fn elem_into_mut(scope: &mut Scope, elem: ExpandElement) -> ExpandElement {
52 into_mut_expand_element(scope, elem)
53 }
54}