core/vm: make slt/sgt cleaner

This commit is contained in:
Martin Holst Swende 2018-03-08 12:38:31 +01:00
parent fb7c46e80e
commit 29ee636e56
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -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
switch {
case xSign >= 0 && ySign < 0:
y.SetUint64(1)
return nil, nil
}
// Both negative
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
switch {
case xSign >= 0 && ySign < 0:
y.SetUint64(0)
return nil, nil
}
// Both negative (note: equality -> 0)
if x.Cmp(y) <= 0 {
y.SetUint64(0)
} else {
case xSign < 0 && ySign >= 0:
y.SetUint64(1)
}
} else {
// x positive
if ySign >= 0 {
// y negative
y.SetUint64(1)
return nil, nil
}
// Both positive
default:
if x.Cmp(y) > 0 {
y.SetUint64(1)
} else {