From 6ff0052fc0e92153678870c9c33bd046f3c72136 Mon Sep 17 00:00:00 2001 From: gcolvin Date: Sun, 1 Oct 2017 22:45:26 -0600 Subject: [PATCH] SAR via explicit bit twiddling --- libevm/VM.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libevm/VM.cpp b/libevm/VM.cpp index adfab982c35..b549e08a7f5 100755 --- a/libevm/VM.cpp +++ b/libevm/VM.cpp @@ -654,16 +654,24 @@ void VM::interpretCases() { ON_OP(); updateIOGas(); + + static u256 const hibit = u256(1) << 255; + static u256 const allbits = + u256("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - s256 shiftee = m_SP[1]; + u256 shiftee = m_SP[1]; if (m_SP[0] >= 256) { - if (shiftee < 0) - m_SPP[0] = u256(-1); + if (shiftee & hibit) + m_SPP[0] = allbits; + else + m_SPP[0] = 0; } else { - m_SPP[0] = u256(shiftee >> uint64_t(m_SP[0])); + uint64_t amount = uint64_t(m_SP[0]); + m_SPP[0] = shiftee >> amount; + m_SPP[0] |= allbits << (256 - amount); } } NEXT