|
|
@ -372,14 +372,14 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode, |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
/*case Instruction::NEG:
|
|
|
|
case Instruction::BNOT: |
|
|
|
{ |
|
|
|
auto top = stack.pop(); |
|
|
|
auto zero = Constant::get(0); |
|
|
|
auto res = m_builder.CreateSub(zero, top); |
|
|
|
auto allones = llvm::ConstantInt::get(Type::i256, llvm::APInt::getAllOnesValue(256)); |
|
|
|
auto res = m_builder.CreateXor(top, allones); |
|
|
|
stack.push(res); |
|
|
|
break; |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
case Instruction::LT: |
|
|
|
{ |
|
|
@ -505,6 +505,35 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode, |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Instruction::SIGNEXTEND: |
|
|
|
{ |
|
|
|
auto k = stack.pop(); |
|
|
|
auto b = stack.pop(); |
|
|
|
auto k32 = m_builder.CreateTrunc(k, m_builder.getIntNTy(5), "k_32"); |
|
|
|
auto k32ext = m_builder.CreateZExt(k32, Type::i256); |
|
|
|
auto k32x8 = m_builder.CreateMul(k32ext, Constant::get(8), "kx8"); |
|
|
|
|
|
|
|
// test for b >> (k * 8 + 7)
|
|
|
|
auto val = m_builder.CreateAdd(k32x8, llvm::ConstantInt::get(Type::i256, 7)); |
|
|
|
auto tmp = m_builder.CreateAShr(b, val); |
|
|
|
auto bitset = m_builder.CreateTrunc(tmp, m_builder.getInt1Ty()); |
|
|
|
|
|
|
|
// shift left by (31 - k) * 8 = (248 - k*8), then do arithmetic shr by the same amount.
|
|
|
|
auto shiftSize = m_builder.CreateSub(llvm::ConstantInt::get(Type::i256, 31 * 8), k32x8); |
|
|
|
auto bshl = m_builder.CreateShl(b, shiftSize); |
|
|
|
auto bshr = m_builder.CreateAShr(bshl, shiftSize); |
|
|
|
|
|
|
|
// bshr is our final value if 0 <= k <= 30 and bitset is true,
|
|
|
|
// otherwise we push back b unchanged
|
|
|
|
auto kInRange = m_builder.CreateICmpULE(k, llvm::ConstantInt::get(Type::i256, 30)); |
|
|
|
auto cond = m_builder.CreateAnd(kInRange, bitset); |
|
|
|
|
|
|
|
auto result = m_builder.CreateSelect(cond, bshr, b); |
|
|
|
stack.push(result); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case Instruction::SHA3: |
|
|
|
{ |
|
|
|
auto inOff = stack.pop(); |
|
|
|