Browse Source

Merge branch 'develop-evmcc' of github.com:imapp-pl/ethereum into develop-evmcc

cl-refactor
artur-zawlocki 10 years ago
parent
commit
58c5a4f0be
  1. 1
      libevmjit/BasicBlock.cpp
  2. 21
      libevmjit/Compiler.cpp
  3. 24
      libevmjit/Endianness.cpp
  4. 22
      libevmjit/Endianness.h

1
libevmjit/BasicBlock.cpp

@ -32,6 +32,7 @@ BasicBlock::BasicBlock(std::string _name, llvm::Function* _mainFunc) :
void BasicBlock::Stack::push(llvm::Value* _value)
{
assert(_value->getType() == Type::i256);
m_backend.push_back(_value);
}

21
libevmjit/Compiler.cpp

@ -15,6 +15,7 @@
#include "Ext.h"
#include "GasMeter.h"
#include "Utils.h"
#include "Endianness.h"
namespace dev
{
@ -420,21 +421,11 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
const auto byteNum = stack.pop();
auto value = stack.pop();
/*
if (byteNum < 32) - use select
{
value <<= byteNum*8
value >>= 31*8
push value
}
else push 0
*/
// TODO: Shifting by 0 gives wrong results as of this bug http://llvm.org/bugs/show_bug.cgi?id=16439
auto shbits = m_builder.CreateShl(byteNum, Constant::get(3));
value = m_builder.CreateShl(value, shbits);
value = m_builder.CreateLShr(value, Constant::get(31 * 8));
//
value = Endianness::toBE(m_builder, value);
auto bytes = m_builder.CreateBitCast(value, llvm::VectorType::get(Type::Byte, 32), "bytes");
auto byte = m_builder.CreateExtractElement(bytes, byteNum, "byte");
value = m_builder.CreateZExt(byte, Type::i256);
auto byteNumValid = m_builder.CreateICmpULT(byteNum, Constant::get(32));
value = m_builder.CreateSelect(byteNumValid, value, Constant::get(0));

24
libevmjit/Endianness.cpp

@ -0,0 +1,24 @@
#include "Endianness.h"
#include <llvm/IR/IntrinsicInst.h>
#include "Type.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
// TODO: Native is Little Endian
auto bswap = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::i256);
return _builder.CreateCall(bswap, _word);
}
}
}
}

22
libevmjit/Endianness.h

@ -0,0 +1,22 @@
#pragma once
#include <llvm/IR/IRBuilder.h>
namespace dev
{
namespace eth
{
namespace jit
{
class Endianness
{
public:
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}
Loading…
Cancel
Save