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 fn __expand_as_type(scope: &Scope) -> TypeHandle {
47 BoolType::get(scope.ctx()).into()
48 }
49}
50
51impl IntoRuntime for bool {
52 fn __expand_runtime_method(self, _scope: &Scope) -> NativeExpand<Self> {
53 self.into()
54 }
55}
56
57impl IntoExpand for bool {
58 type Expand = NativeExpand<bool>;
59
60 fn into_expand(self, _: &Scope) -> Self::Expand {
61 self.into()
62 }
63}
64
65impl NativeAssign for bool {}