mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
SIGEXTEND: first try [#81700414]
This commit is contained in:
parent
af0530ba3d
commit
007641a84b
1 changed files with 33 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue