mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-25 12:57:17 +00:00
Signextend
This commit is contained in:
parent
c8438979a9
commit
3f90f7c898
@ -34,6 +34,10 @@ func BigD(data []byte) *big.Int {
|
||||
return n
|
||||
}
|
||||
|
||||
func BitTest(num *big.Int, i int) bool {
|
||||
return num.Bit(i) > 0
|
||||
}
|
||||
|
||||
// To256
|
||||
//
|
||||
// "cast" the big int to a 256 big int (i.e., limit to)
|
||||
|
@ -392,6 +392,20 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
|
||||
self.Printf(" = %v", base)
|
||||
|
||||
stack.Push(base)
|
||||
case SIGNEXTEND:
|
||||
back := stack.Pop().Uint64()
|
||||
if back.Cmp(big.NewInt(31)) < 0 {
|
||||
bit := uint(back*8 + 7)
|
||||
num := stack.Pop()
|
||||
mask := new(big.Int).Lsh(ethutil.Big1, bit)
|
||||
mask.Sub(mask, ethutil.Big1)
|
||||
if ethutil.BitTest(num, int(bit)) {
|
||||
num.Or(num, mask.Not(mask))
|
||||
} else {
|
||||
num.And(num, mask)
|
||||
}
|
||||
stack.Push(num)
|
||||
}
|
||||
case NOT:
|
||||
base.Sub(Pow256, stack.Pop()).Sub(base, ethutil.Big1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user