Skip to content

Commit 32234e4

Browse files
authored
Merge pull request #116 from AluVM/feat/rm-bytecount
Remove bytecount method from Bytecode trait
2 parents d18ea84 + a02daa5 commit 32234e4

File tree

1 file changed

+0
-140
lines changed

1 file changed

+0
-140
lines changed

src/isa/bytecode.rs

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ impl ::std::error::Error for BytecodeError {
6767
/// bound by u16), (3) it provides too many fails in situations when we can't
6868
/// fail because of `u16`-bounding and exclusive in-memory encoding handling.
6969
pub trait Bytecode {
70-
/// Returns number of bytes which instruction and its argument occupies
71-
fn byte_count(&self) -> u16;
72-
7370
/// Returns range of instruction btecodes covered by a set of operations
7471
fn instr_range() -> RangeInclusive<u8>;
7572

@@ -106,26 +103,6 @@ impl<Extension> Bytecode for Instr<Extension>
106103
where
107104
Extension: InstructionSet,
108105
{
109-
fn byte_count(&self) -> u16 {
110-
match self {
111-
Instr::ControlFlow(instr) => instr.byte_count(),
112-
Instr::Put(instr) => instr.byte_count(),
113-
Instr::Move(instr) => instr.byte_count(),
114-
Instr::Cmp(instr) => instr.byte_count(),
115-
Instr::Arithmetic(instr) => instr.byte_count(),
116-
Instr::Bitwise(instr) => instr.byte_count(),
117-
Instr::Bytes(instr) => instr.byte_count(),
118-
Instr::Digest(instr) => instr.byte_count(),
119-
#[cfg(feature = "secp256k1")]
120-
Instr::Secp256k1(instr) => instr.byte_count(),
121-
#[cfg(feature = "curve25519")]
122-
Instr::Curve25519(instr) => instr.byte_count(),
123-
Instr::ExtensionCodes(instr) => instr.byte_count(),
124-
Instr::ReservedInstruction(instr) => instr.byte_count(),
125-
Instr::Nop => 1,
126-
}
127-
}
128-
129106
#[inline]
130107
fn instr_range() -> RangeInclusive<u8> { 0..=u8::MAX }
131108

@@ -235,17 +212,6 @@ where
235212
}
236213

237214
impl Bytecode for ControlFlowOp {
238-
fn byte_count(&self) -> u16 {
239-
match self {
240-
ControlFlowOp::Fail | ControlFlowOp::Succ => 1,
241-
ControlFlowOp::Jmp(_) | ControlFlowOp::Jif(_) => 3,
242-
ControlFlowOp::Routine(_) => 3,
243-
ControlFlowOp::Call(_) => 4,
244-
ControlFlowOp::Exec(_) => 4,
245-
ControlFlowOp::Ret => 1,
246-
}
247-
}
248-
249215
#[inline]
250216
fn instr_range() -> RangeInclusive<u8> { INSTR_FAIL..=INSTR_RET }
251217

@@ -308,17 +274,6 @@ impl Bytecode for ControlFlowOp {
308274
}
309275

310276
impl Bytecode for PutOp {
311-
fn byte_count(&self) -> u16 {
312-
match self {
313-
PutOp::ClrA(_, _) | PutOp::ClrF(_, _) | PutOp::ClrR(_, _) => 2,
314-
PutOp::PutA(_, _, _)
315-
| PutOp::PutIfA(_, _, _)
316-
| PutOp::PutF(_, _, _)
317-
| PutOp::PutR(_, _, _)
318-
| PutOp::PutIfR(_, _, _) => 3,
319-
}
320-
}
321-
322277
#[inline]
323278
fn instr_range() -> RangeInclusive<u8> { INSTR_CLRA..=INSTR_PUTIFR }
324279

@@ -437,9 +392,6 @@ impl Bytecode for PutOp {
437392
}
438393

439394
impl Bytecode for MoveOp {
440-
#[inline]
441-
fn byte_count(&self) -> u16 { 3 }
442-
443395
#[inline]
444396
fn instr_range() -> RangeInclusive<u8> { INSTR_MOV..=INSTR_CFA }
445397

@@ -604,23 +556,6 @@ impl Bytecode for MoveOp {
604556
}
605557

606558
impl Bytecode for CmpOp {
607-
fn byte_count(&self) -> u16 {
608-
match self {
609-
CmpOp::GtA(_, _, _, _)
610-
| CmpOp::LtA(_, _, _, _)
611-
| CmpOp::GtF(_, _, _, _)
612-
| CmpOp::LtF(_, _, _, _)
613-
| CmpOp::GtR(_, _, _)
614-
| CmpOp::LtR(_, _, _)
615-
| CmpOp::EqA(_, _, _, _)
616-
| CmpOp::EqF(_, _, _, _)
617-
| CmpOp::EqR(_, _, _, _) => 3,
618-
CmpOp::IfZA(_, _) | CmpOp::IfZR(_, _) | CmpOp::IfNA(_, _) | CmpOp::IfNR(_, _) => 2,
619-
CmpOp::St(_, _, _) => 2,
620-
CmpOp::StInv => 1,
621-
}
622-
}
623-
624559
#[inline]
625560
fn instr_range() -> RangeInclusive<u8> { INSTR_LGT..=INSTR_STINV }
626561

@@ -775,22 +710,6 @@ impl Bytecode for CmpOp {
775710
}
776711

777712
impl Bytecode for ArithmeticOp {
778-
fn byte_count(&self) -> u16 {
779-
match self {
780-
ArithmeticOp::AddA(_, _, _, _)
781-
| ArithmeticOp::AddF(_, _, _, _)
782-
| ArithmeticOp::SubA(_, _, _, _)
783-
| ArithmeticOp::SubF(_, _, _, _)
784-
| ArithmeticOp::MulA(_, _, _, _)
785-
| ArithmeticOp::MulF(_, _, _, _)
786-
| ArithmeticOp::DivA(_, _, _, _)
787-
| ArithmeticOp::DivF(_, _, _, _)
788-
| ArithmeticOp::Rem(_, _, _, _)
789-
| ArithmeticOp::Stp(_, _, _) => 3,
790-
ArithmeticOp::Neg(_, _) | ArithmeticOp::Abs(_, _) => 2,
791-
}
792-
}
793-
794713
#[inline]
795714
fn instr_range() -> RangeInclusive<u8> { INSTR_ADD..=INSTR_REM }
796715

@@ -898,23 +817,6 @@ impl Bytecode for ArithmeticOp {
898817
}
899818

900819
impl Bytecode for BitwiseOp {
901-
fn byte_count(&self) -> u16 {
902-
match self {
903-
BitwiseOp::And(_, _, _, _) | BitwiseOp::Or(_, _, _, _) | BitwiseOp::Xor(_, _, _, _) => {
904-
3
905-
}
906-
BitwiseOp::Not(_, _) => 2,
907-
908-
BitwiseOp::Shl(_, _, _, _)
909-
| BitwiseOp::ShrA(_, _, _, _, _)
910-
| BitwiseOp::ShrR(_, _, _, _)
911-
| BitwiseOp::Scl(_, _, _, _)
912-
| BitwiseOp::Scr(_, _, _, _) => 3,
913-
914-
BitwiseOp::RevA(_, _) | BitwiseOp::RevR(_, _) => 2,
915-
}
916-
}
917-
918820
#[inline]
919821
fn instr_range() -> RangeInclusive<u8> { INSTR_AND..=INSTR_REVR }
920822

@@ -1071,24 +973,6 @@ impl Bytecode for BitwiseOp {
1071973
}
1072974

1073975
impl Bytecode for BytesOp {
1074-
fn byte_count(&self) -> u16 {
1075-
match self {
1076-
BytesOp::Put(_, _, _) => 6,
1077-
BytesOp::Mov(_, _) | BytesOp::Swp(_, _) => 2,
1078-
BytesOp::Fill(_, _, _, _, _) => 3,
1079-
BytesOp::Len(_, _, _) | BytesOp::Cnt(_, _, _) => 3,
1080-
BytesOp::Eq(_, _) => 2,
1081-
BytesOp::Con(_, _, _, _, _) => 4,
1082-
BytesOp::Find(_, _) => 2,
1083-
BytesOp::Extr(_, _, _, _) | BytesOp::Inj(_, _, _, _) => 3,
1084-
BytesOp::Join(_, _, _) => 3,
1085-
BytesOp::Splt(_, _, _, _, _) => 4,
1086-
BytesOp::Ins(_, _, _, _) => 3,
1087-
BytesOp::Del(_, _, _, _, _, _, _, _, _) => 4,
1088-
BytesOp::Rev(_, _) => 2,
1089-
}
1090-
}
1091-
1092976
#[inline]
1093977
fn instr_range() -> RangeInclusive<u8> { INSTR_PUT..=INSTR_REV }
1094978

@@ -1288,9 +1172,6 @@ impl Bytecode for BytesOp {
12881172
}
12891173

12901174
impl Bytecode for DigestOp {
1291-
#[inline]
1292-
fn byte_count(&self) -> u16 { 3 }
1293-
12941175
#[inline]
12951176
fn instr_range() -> RangeInclusive<u8> { INSTR_RIPEMD..=INSTR_SHA512 }
12961177

@@ -1338,15 +1219,6 @@ impl Bytecode for DigestOp {
13381219
}
13391220

13401221
impl Bytecode for Secp256k1Op {
1341-
fn byte_count(&self) -> u16 {
1342-
match self {
1343-
Secp256k1Op::Gen(_, _) => 2,
1344-
Secp256k1Op::Mul(_, _, _, _) => 3,
1345-
Secp256k1Op::Add(_, _) => 2,
1346-
Secp256k1Op::Neg(_, _) => 2,
1347-
}
1348-
}
1349-
13501222
#[inline]
13511223
fn instr_range() -> RangeInclusive<u8> { INSTR_SECP_GEN..=INSTR_SECP_NEG }
13521224

@@ -1406,15 +1278,6 @@ impl Bytecode for Secp256k1Op {
14061278
}
14071279

14081280
impl Bytecode for Curve25519Op {
1409-
fn byte_count(&self) -> u16 {
1410-
match self {
1411-
Curve25519Op::Gen(_, _) => 2,
1412-
Curve25519Op::Mul(_, _, _, _) => 3,
1413-
Curve25519Op::Add(_, _, _, _) => 3,
1414-
Curve25519Op::Neg(_, _) => 2,
1415-
}
1416-
}
1417-
14181281
#[inline]
14191282
fn instr_range() -> RangeInclusive<u8> { INSTR_ED_GEN..=INSTR_ED_NEG }
14201283

@@ -1481,9 +1344,6 @@ impl Bytecode for Curve25519Op {
14811344
}
14821345

14831346
impl Bytecode for ReservedOp {
1484-
#[inline]
1485-
fn byte_count(&self) -> u16 { 1 }
1486-
14871347
#[inline]
14881348
fn instr_range() -> RangeInclusive<u8> { INSTR_RESV_FROM..=INSTR_ISAE_TO }
14891349

0 commit comments

Comments
 (0)