eva_asm/instruction/
bitwise.rs

1//! Comparison & Bitwise Logic Operations.
2
3use derive_more::Display;
4
5use crate::{
6    instruction::Instruction,
7    opcode::{Mnemonic, OpCode},
8};
9
10/// Less-than comparison.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
12#[display("{}", self.opcode())]
13pub struct Lt;
14
15impl Instruction for Lt {
16    fn opcode(&self) -> OpCode {
17        OpCode::Known(Mnemonic::LT)
18    }
19}
20
21/// Greater-than comparison.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
23#[display("{}", self.opcode())]
24pub struct Gt;
25
26impl Instruction for Gt {
27    fn opcode(&self) -> OpCode {
28        OpCode::Known(Mnemonic::GT)
29    }
30}
31
32/// Signed less-than comparison.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
34#[display("{}", self.opcode())]
35pub struct SLt;
36
37impl Instruction for SLt {
38    fn opcode(&self) -> OpCode {
39        OpCode::Known(Mnemonic::SLT)
40    }
41}
42
43/// Signed greater-than comparison.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
45#[display("{}", self.opcode())]
46pub struct SGt;
47
48impl Instruction for SGt {
49    fn opcode(&self) -> OpCode {
50        OpCode::Known(Mnemonic::SGT)
51    }
52}
53
54/// Equality comparison.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
56#[display("{}", self.opcode())]
57pub struct Eq;
58
59impl Instruction for Eq {
60    fn opcode(&self) -> OpCode {
61        OpCode::Known(Mnemonic::EQ)
62    }
63}
64
65/// Is-zero comparison.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
67#[display("{}", self.opcode())]
68pub struct IsZero;
69
70impl Instruction for IsZero {
71    fn opcode(&self) -> OpCode {
72        OpCode::Known(Mnemonic::ISZERO)
73    }
74}
75
76/// Bitwise AND operation.
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
78#[display("{}", self.opcode())]
79pub struct And;
80
81impl Instruction for And {
82    fn opcode(&self) -> OpCode {
83        OpCode::Known(Mnemonic::AND)
84    }
85}
86
87/// Bitwise OR operation.
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
89#[display("{}", self.opcode())]
90pub struct Or;
91
92impl Instruction for Or {
93    fn opcode(&self) -> OpCode {
94        OpCode::Known(Mnemonic::OR)
95    }
96}
97
98/// Bitwise XOR operation.
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
100#[display("{}", self.opcode())]
101pub struct Xor;
102
103impl Instruction for Xor {
104    fn opcode(&self) -> OpCode {
105        OpCode::Known(Mnemonic::XOR)
106    }
107}
108
109/// Bitwise NOT operation.
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
111#[display("{}", self.opcode())]
112pub struct Not;
113
114impl Instruction for Not {
115    fn opcode(&self) -> OpCode {
116        OpCode::Known(Mnemonic::NOT)
117    }
118}
119
120/// Retrieve single byte from word.
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
122#[display("{}", self.opcode())]
123pub struct Byte;
124
125impl Instruction for Byte {
126    fn opcode(&self) -> OpCode {
127        OpCode::Known(Mnemonic::BYTE)
128    }
129}
130
131/// Left shift operation.
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
133#[display("{}", self.opcode())]
134pub struct Shl;
135
136impl Instruction for Shl {
137    fn opcode(&self) -> OpCode {
138        OpCode::Known(Mnemonic::SHL)
139    }
140}
141
142/// Logical right shift operation.
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
144#[display("{}", self.opcode())]
145pub struct Shr;
146
147impl Instruction for Shr {
148    fn opcode(&self) -> OpCode {
149        OpCode::Known(Mnemonic::SHR)
150    }
151}
152
153/// Arithmetic (signed) right shift operation.
154#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
155#[display("{}", self.opcode())]
156pub struct Sar;
157
158impl Instruction for Sar {
159    fn opcode(&self) -> OpCode {
160        OpCode::Known(Mnemonic::SAR)
161    }
162}