mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use native shift instructions in ABIFunctions on Constantinople
This commit is contained in:
parent
22bfd3da41
commit
c3608eaf90
@ -1401,9 +1401,26 @@ string ABIFunctions::copyToMemoryFunction(bool _fromCalldata)
|
|||||||
|
|
||||||
string ABIFunctions::shiftLeftFunction(size_t _numBits)
|
string ABIFunctions::shiftLeftFunction(size_t _numBits)
|
||||||
{
|
{
|
||||||
string functionName = "shift_left_" + to_string(_numBits);
|
|
||||||
return createFunction(functionName, [&]() {
|
|
||||||
solAssert(_numBits < 256, "");
|
solAssert(_numBits < 256, "");
|
||||||
|
|
||||||
|
string functionName = "shift_left_" + to_string(_numBits);
|
||||||
|
if (m_evmVersion.hasBitwiseShifting())
|
||||||
|
{
|
||||||
|
return createFunction(functionName, [&]() {
|
||||||
|
return
|
||||||
|
Whiskers(R"(
|
||||||
|
function <functionName>(value) -> newValue {
|
||||||
|
newValue := shl(<numBits>, value)
|
||||||
|
}
|
||||||
|
)")
|
||||||
|
("functionName", functionName)
|
||||||
|
("numBits", to_string(_numBits))
|
||||||
|
.render();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return createFunction(functionName, [&]() {
|
||||||
return
|
return
|
||||||
Whiskers(R"(
|
Whiskers(R"(
|
||||||
function <functionName>(value) -> newValue {
|
function <functionName>(value) -> newValue {
|
||||||
@ -1414,13 +1431,32 @@ string ABIFunctions::shiftLeftFunction(size_t _numBits)
|
|||||||
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
||||||
.render();
|
.render();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
|
string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
|
||||||
{
|
{
|
||||||
string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned");
|
|
||||||
return createFunction(functionName, [&]() {
|
|
||||||
solAssert(_numBits < 256, "");
|
solAssert(_numBits < 256, "");
|
||||||
|
|
||||||
|
string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned");
|
||||||
|
if (m_evmVersion.hasBitwiseShifting())
|
||||||
|
{
|
||||||
|
return createFunction(functionName, [&]() {
|
||||||
|
return
|
||||||
|
Whiskers(R"(
|
||||||
|
function <functionName>(value) -> newValue {
|
||||||
|
newValue := <shiftOp>(<numBits>, value)
|
||||||
|
}
|
||||||
|
)")
|
||||||
|
("functionName", functionName)
|
||||||
|
("shiftOp", _signed ? "sar" : "shr")
|
||||||
|
("numBits", to_string(_numBits))
|
||||||
|
.render();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return createFunction(functionName, [&]() {
|
||||||
return
|
return
|
||||||
Whiskers(R"(
|
Whiskers(R"(
|
||||||
function <functionName>(value) -> newValue {
|
function <functionName>(value) -> newValue {
|
||||||
@ -1432,6 +1468,7 @@ string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
|
|||||||
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
||||||
.render();
|
.render();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string ABIFunctions::roundUpFunction()
|
string ABIFunctions::roundUpFunction()
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <libsolidity/interface/EVMVersion.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/ASTForward.h>
|
#include <libsolidity/ast/ASTForward.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -48,6 +50,8 @@ using TypePointers = std::vector<TypePointer>;
|
|||||||
class ABIFunctions
|
class ABIFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
explicit ABIFunctions(EVMVersion _evmVersion = EVMVersion{}) : m_evmVersion(_evmVersion) {}
|
||||||
|
|
||||||
/// @returns name of an assembly function to ABI-encode values of @a _givenTypes
|
/// @returns name of an assembly function to ABI-encode values of @a _givenTypes
|
||||||
/// into memory, converting the types to @a _targetTypes on the fly.
|
/// into memory, converting the types to @a _targetTypes on the fly.
|
||||||
/// Parameters are: <headStart> <value_n> ... <value_1>, i.e.
|
/// Parameters are: <headStart> <value_n> ... <value_1>, i.e.
|
||||||
@ -225,6 +229,8 @@ private:
|
|||||||
|
|
||||||
/// Map from function name to code for a multi-use function.
|
/// Map from function name to code for a multi-use function.
|
||||||
std::map<std::string, std::string> m_requestedFunctions;
|
std::map<std::string, std::string> m_requestedFunctions;
|
||||||
|
|
||||||
|
EVMVersion m_evmVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,8 @@ public:
|
|||||||
explicit CompilerContext(EVMVersion _evmVersion = EVMVersion{}, CompilerContext* _runtimeContext = nullptr):
|
explicit CompilerContext(EVMVersion _evmVersion = EVMVersion{}, CompilerContext* _runtimeContext = nullptr):
|
||||||
m_asm(std::make_shared<eth::Assembly>()),
|
m_asm(std::make_shared<eth::Assembly>()),
|
||||||
m_evmVersion(_evmVersion),
|
m_evmVersion(_evmVersion),
|
||||||
m_runtimeContext(_runtimeContext)
|
m_runtimeContext(_runtimeContext),
|
||||||
|
m_abiFunctions(m_evmVersion)
|
||||||
{
|
{
|
||||||
if (m_runtimeContext)
|
if (m_runtimeContext)
|
||||||
m_runtimeSub = size_t(m_asm->newSub(m_runtimeContext->m_asm).data());
|
m_runtimeSub = size_t(m_asm->newSub(m_runtimeContext->m_asm).data());
|
||||||
|
Loading…
Reference in New Issue
Block a user