1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use core::fmt::Display;
use enumset::{EnumSet, EnumSetType};
use crate::{Instruction, Operation, TypeHash};
use crate::{OperationCode, OperationReflect};
use super::Variable;
/// Operations that don't change the semantics of the kernel. In other words, operations that do not
/// perform any computation, if they run at all. i.e. `println`, comments and debug symbols.
///
/// Can be safely removed or ignored without changing the kernel result.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, TypeHash, PartialEq, Eq, Hash, OperationCode)]
#[operation(opcode_name = MarkerOpCode)]
pub enum Marker {
/// Frees a shared memory, allowing reuse in later blocks.
Free(Variable),
}
impl OperationReflect for Marker {
type OpCode = MarkerOpCode;
fn op_code(&self) -> Self::OpCode {
self.__match_opcode()
}
}
impl Display for Marker {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Marker::Free(var) => write!(f, "free({var})"),
}
}
}
impl From<Marker> for Instruction {
fn from(value: Marker) -> Self {
Instruction::no_out(Operation::Marker(value))
}
}
/// Unchecked optimizations for float operations. May cause precision differences, or undefined
/// behaviour if the relevant conditions are not followed.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Hash, TypeHash, EnumSetType)]
pub enum FastMath {
/// Assume values are never `NaN`. If they are, the result is considered undefined behaviour.
NotNaN,
/// Assume values are never `Inf`/`-Inf`. If they are, the result is considered undefined
/// behaviour.
NotInf,
/// Ignore sign on zero values.
UnsignedZero,
/// Allow swapping float division with a reciprocal, even if that swap would change precision.
AllowReciprocal,
/// Allow contracting float operations into fewer operations, even if the precision could
/// change.
AllowContraction,
/// Allow reassociation for float operations, even if the precision could change.
AllowReassociation,
/// Allow all mathematical transformations for float operations, including contraction and
/// reassociation, even if the precision could change.
AllowTransform,
/// Allow using lower precision intrinsics
ReducedPrecision,
}
impl FastMath {
pub const fn all() -> EnumSet<FastMath> {
EnumSet::all()
}
}