Skip to content

Commit 9735ad8

Browse files
committed
translate to C++ and make it pass tests
1 parent 5e95642 commit 9735ad8

File tree

8 files changed

+528
-849
lines changed

8 files changed

+528
-849
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "deps/evmc"]
1717
path = deps/evmc
1818
url = https://github.com/ethereum/evmc
19+
[submodule "src/native/intx"]
20+
path = src/native/intx
21+
url = https://github.com/chfast/intx

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ build_dir:
44
mkdir build
55

66
v2:
7-
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/v2/benchmark.yul 2>&1 | awk '/Binary representation:/ { getline; print $0 }' > build/v2-f6m_mul_bench.bin
8-
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/v2/test.yul 2>&1 | awk '/Binary representation:/ { getline; print $0 }' > build/v2-test.bin
7+
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/evm/v2/benchmark.yul 2>&1 | awk '/Binary representation:/ { getline; print $0 }' > build/v2-f6m_mul_bench.bin
8+
./deps/v2/solidity/build/solc/solc --strict-assembly --optimize src/evm/v2/test.yul 2>&1 | awk '/Binary representation:/ { getline; print $0 }' > build/v2-test.bin
99
v1:
1010
./deps/v1/solidity/build/solc/solc --strict-assembly --optimize src/v1/benchmark.yul 2>&1 | awk '/Binary representation:/ { getline; print $0 }' > build/v1-f6m_mul_bench.bin
1111

src/evm/v2/test.yul

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
// r <- x * y
2929
function f2m_mul(x, y, r, modulus, inv, mem) {
30-
3130
let tmp := add(mem, 64)
3231
let tmp2 := add(tmp, 64)
3332
let zero := add(tmp2, 64)
@@ -115,7 +114,7 @@
115114
// tmp3 <- tmp2 * tmp1
116115
f2m_mul(tmp2, tmp1, tmp3, modulus, inv, arena)
117116

118-
// tmp1 <- aA * bB
117+
// tmp1 <- aA + bB
119118
f2m_add(aA, add(aA, 64), bB, add(bB, 64), tmp1, add(tmp1, 64), modulus, arena)
120119

121120
// tmp2 <- tmp3 - tmp1
@@ -311,10 +310,10 @@
311310

312311
function test_f2m_mul() {
313312
/*
314-
8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940272d1c8c528a1ce3bcaa280a8e735aa0d992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7ee83b6e91c6550f5aceab102e88e918097299907146816f08c4c6a394e91374ed6ff3618a57358cfb124ee6ab4c560e5cac40700b41e2ee8674680728f0c5a618 *
315-
ecd347c808af644c7a3a971a556576f434e302b6b490004fb418a4a7da330a6743adeca931169b8b92e91df73ae1e11512a2829e11e843d764d5e3b80e75432d93f69b23ad79c38d43ebbc9bd2b17b9e903033351357b03602624762e5ad360dd7f9857dce663301f393f9fac66f5c49168494e0d20797a6c4f96327ed4fa47dd36d0078d217a712407d35046871d40f =
313+
8f2990f3e598f5b1b8f480a3c388306bc023fac151c0104d13ec3aa18159940272d1c8c528a1ce3bcaa280a8e735aa0d992d7a27906d4cd530b23a7e8c48c0778f8653fbc3332d63db24339d8bc65d7ee83b6e91c6550f5aceab102e88e91809 *
314+
ecd347c808af644c7a3a971a556576f434e302b6b490004fb418a4a7da330a6743adeca931169b8b92e91df73ae1e11512a2829e11e843d764d5e3b80e75432d93f69b23ad79c38d43ebbc9bd2b17b9e903033351357b03602624762e5ad360d =
316315
317-
1a984f235709ab3941e22b5e67d5ba892ce9242e227c0c6bb38aa1ace4d4b64aaba753d350d98f4c05570f525d67a901b1297e4e9ca0c757dfe693ea0d2f5216daeaa4ad06964e2f7c242200049d386d860b25d4718a2c4240fb89c90abe4e10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
316+
1a984f235709ab3941e22b5e67d5ba892ce9242e227c0c6bb38aa1ace4d4b64aaba753d350d98f4c05570f525d67a901b1297e4e9ca0c757dfe693ea0d2f5216daeaa4ad06964e2f7c242200049d386d860b25d4718a2c4240fb89c90abe4e10
318317
*/
319318
let mem := msize()
320319

src/native/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake_minimum_required (VERSION 3.0)
22
project (f6m_mul_native)
33

4-
add_executable(f6m_mul_native f6m_mul.c)
4+
include_directories(./intx/include)
5+
add_executable(f6m_mul_native f6m_mul.cpp)

0 commit comments

Comments
 (0)