aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-15 00:04:40 +0800
committerGitHub <noreply@github.com>2017-06-15 00:04:40 +0800
commitd693822a6fce5d1c853e50f4c7758bc003542644 (patch)
tree1444b123b9b2023881f7fbb813b3617e29711931
parent2491721d42e3d1ac94a323761da22f4b873c8bca (diff)
parent600e3ad240042a9673e4227e51cb96c4ec28d90a (diff)
downloaddexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar.gz
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar.bz2
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar.lz
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar.xz
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.tar.zst
dexon-solidity-d693822a6fce5d1c853e50f4c7758bc003542644.zip
Merge pull request #2394 from ethereum/lll-shifts
Support shl/shr in LLL
-rw-r--r--liblll/CompilerState.cpp3
-rw-r--r--test/liblll/EndToEndTest.cpp20
2 files changed, 23 insertions, 0 deletions
diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp
index b990ecac..c22242a3 100644
--- a/liblll/CompilerState.cpp
+++ b/liblll/CompilerState.cpp
@@ -74,6 +74,9 @@ void CompilerState::populateStandard()
"(def 'szabo 1000000000000)"
"(def 'finney 1000000000000000)"
"(def 'ether 1000000000000000000)"
+ // these could be replaced by native instructions once supported by EVM
+ "(def 'shl (val shift) (mul val (exp 2 shift)))"
+ "(def 'shr (val shift) (div val (exp 2 shift)))"
"}";
CodeFragment::compile(s, *this);
}
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp
index 7f1924c2..9021fa43 100644
--- a/test/liblll/EndToEndTest.cpp
+++ b/test/liblll/EndToEndTest.cpp
@@ -328,6 +328,26 @@ BOOST_AUTO_TEST_CASE(sha3_one_arg)
fromHex("b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6")));
}
+BOOST_AUTO_TEST_CASE(shift_left)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (return (shl 1 8)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(256)));
+}
+
+BOOST_AUTO_TEST_CASE(shift_right)
+{
+ char const* sourceCode = R"(
+ (returnlll
+ (return (shr 65536 8)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(256)));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}