1use crate::jeff_capnp;
4
5use super::ConstArray;
6
7#[derive(Clone, Copy, Debug)]
9#[non_exhaustive]
10pub enum IntOp {
11 Const1(bool),
13 Const8(u8),
15 Const16(u16),
17 Const32(u32),
19 Const64(u64),
21 Add,
23 Sub,
25 Mul,
27 DivS,
29 DivU,
31 Pow,
33 And,
35 Or,
37 Xor,
39 Not,
41 MinS,
43 MinU,
45 MaxS,
47 MaxU,
49 Eq,
51 LtS,
53 LteS,
55 LtU,
57 LteU,
59 Abs,
61 RemS,
63 RemU,
65 Shl,
67 Shr,
69 Select,
71 ExtS,
73 ExtU,
75 Trunc,
77 ToFloatS,
79 ToFloatU,
81}
82
83#[derive(Clone, Copy, Debug)]
85#[non_exhaustive]
86pub enum IntArrayOp<'a> {
87 ConstArray1(ConstArray<'a, bool>),
89 ConstArray8(ConstArray<'a, u8>),
91 ConstArray16(ConstArray<'a, u16>),
93 ConstArray32(ConstArray<'a, u32>),
95 ConstArray64(ConstArray<'a, u64>),
97 Zero {
99 bits: u8,
101 },
102 GetIndex,
104 SetIndex,
106 Length,
108 Create,
110}
111
112impl IntOp {
113 pub(crate) fn read_capnp(int_op: jeff_capnp::int_op::Reader<'_>) -> Self {
115 match int_op.which().expect("Integer operation should be present") {
116 jeff_capnp::int_op::Which::Const1(val) => Self::Const1(val),
117 jeff_capnp::int_op::Which::Const8(val) => Self::Const8(val),
118 jeff_capnp::int_op::Which::Const16(val) => Self::Const16(val),
119 jeff_capnp::int_op::Which::Const32(val) => Self::Const32(val),
120 jeff_capnp::int_op::Which::Const64(val) => Self::Const64(val),
121 jeff_capnp::int_op::Which::Add(()) => Self::Add,
122 jeff_capnp::int_op::Which::Sub(()) => Self::Sub,
123 jeff_capnp::int_op::Which::Mul(()) => Self::Mul,
124 jeff_capnp::int_op::Which::DivS(()) => Self::DivS,
125 jeff_capnp::int_op::Which::DivU(()) => Self::DivU,
126 jeff_capnp::int_op::Which::Pow(()) => Self::Pow,
127 jeff_capnp::int_op::Which::And(()) => Self::And,
128 jeff_capnp::int_op::Which::Or(()) => Self::Or,
129 jeff_capnp::int_op::Which::Xor(()) => Self::Xor,
130 jeff_capnp::int_op::Which::Not(()) => Self::Not,
131 jeff_capnp::int_op::Which::MinS(()) => Self::MinS,
132 jeff_capnp::int_op::Which::MinU(()) => Self::MinU,
133 jeff_capnp::int_op::Which::MaxS(()) => Self::MaxS,
134 jeff_capnp::int_op::Which::MaxU(()) => Self::MaxU,
135 jeff_capnp::int_op::Which::Eq(()) => Self::Eq,
136 jeff_capnp::int_op::Which::LtS(()) => Self::LtS,
137 jeff_capnp::int_op::Which::LteS(()) => Self::LteS,
138 jeff_capnp::int_op::Which::LtU(()) => Self::LtU,
139 jeff_capnp::int_op::Which::LteU(()) => Self::LteU,
140 jeff_capnp::int_op::Which::Abs(()) => Self::Abs,
141 jeff_capnp::int_op::Which::RemS(()) => Self::RemS,
142 jeff_capnp::int_op::Which::RemU(()) => Self::RemU,
143 jeff_capnp::int_op::Which::Shl(()) => Self::Shl,
144 jeff_capnp::int_op::Which::Shr(()) => Self::Shr,
145 jeff_capnp::int_op::Which::Select(()) => Self::Select,
146 jeff_capnp::int_op::Which::ExtS(()) => Self::ExtS,
147 jeff_capnp::int_op::Which::ExtU(()) => Self::ExtU,
148 jeff_capnp::int_op::Which::Trunc(()) => Self::Trunc,
149 jeff_capnp::int_op::Which::ToFloatS(()) => Self::ToFloatS,
150 jeff_capnp::int_op::Which::ToFloatU(()) => Self::ToFloatU,
151 }
152 }
153}
154
155impl<'a> IntArrayOp<'a> {
156 pub(crate) fn read_capnp(int_array_op: jeff_capnp::int_array_op::Reader<'a>) -> Self {
158 match int_array_op
159 .which()
160 .expect("Integer array operation should be present")
161 {
162 jeff_capnp::int_array_op::Which::Const1(val) => Self::ConstArray1(
163 ConstArray::read_capnp(val.expect("Const1 should be present")),
164 ),
165 jeff_capnp::int_array_op::Which::Const8(val) => Self::ConstArray8(
166 ConstArray::read_capnp(val.expect("Const8 should be present")),
167 ),
168 jeff_capnp::int_array_op::Which::Const16(val) => Self::ConstArray16(
169 ConstArray::read_capnp(val.expect("Const16 should be present")),
170 ),
171 jeff_capnp::int_array_op::Which::Const32(val) => Self::ConstArray32(
172 ConstArray::read_capnp(val.expect("Const32 should be present")),
173 ),
174 jeff_capnp::int_array_op::Which::Const64(val) => Self::ConstArray64(
175 ConstArray::read_capnp(val.expect("Const64 should be present")),
176 ),
177 jeff_capnp::int_array_op::Which::Zero(val) => Self::Zero { bits: val },
178 jeff_capnp::int_array_op::Which::GetIndex(()) => Self::GetIndex,
179 jeff_capnp::int_array_op::Which::SetIndex(()) => Self::SetIndex,
180 jeff_capnp::int_array_op::Which::Length(()) => Self::Length,
181 jeff_capnp::int_array_op::Which::Create(()) => Self::Create,
182 }
183 }
184}