From 29ee636e56f22ed6e60f359d0dbd1f801f3eaca6 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 8 Mar 2018 12:38:31 +0100 Subject: [PATCH] core/vm: make slt/sgt cleaner --- core/vm/instructions.go | 58 ++++++++++++----------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 15ed643ce1..66e804fb7e 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -198,32 +198,19 @@ func opSlt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stac xSign := x.Cmp(tt255) ySign := y.Cmp(tt255) - if xSign >= 0 { - //x negative - if ySign < 0 { - // y positive - y.SetUint64(1) - return nil, nil - } - // Both negative + switch { + case xSign >= 0 && ySign < 0: + y.SetUint64(1) + + case xSign < 0 && ySign >= 0: + y.SetUint64(0) + + default: if x.Cmp(y) < 0 { y.SetUint64(1) } else { y.SetUint64(0) } - } else { - // x positive - if ySign >= 0 { - // y negative - y.SetUint64(0) - return nil, nil - } - // Both positive - if x.Cmp(y) >= 0 { - y.SetUint64(0) - } else { - y.SetUint64(1) - } } evm.interpreter.intPool.put(x) return nil, nil @@ -235,27 +222,14 @@ func opSgt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stac xSign := x.Cmp(tt255) ySign := y.Cmp(tt255) - if xSign >= 0 { - //x negative - if ySign < 0 { - // y positive - y.SetUint64(0) - return nil, nil - } - // Both negative (note: equality -> 0) - if x.Cmp(y) <= 0 { - y.SetUint64(0) - } else { - y.SetUint64(1) - } - } else { - // x positive - if ySign >= 0 { - // y negative - y.SetUint64(1) - return nil, nil - } - // Both positive + switch { + case xSign >= 0 && ySign < 0: + y.SetUint64(0) + + case xSign < 0 && ySign >= 0: + y.SetUint64(1) + + default: if x.Cmp(y) > 0 { y.SetUint64(1) } else {