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