mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Split ewasm polyfill functions into different files.
This commit is contained in:
parent
db264d9e65
commit
19f764bf65
13
cmake/templates/ewasm_polyfill.in
Normal file
13
cmake/templates/ewasm_polyfill.in
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// The generation of this file is defined in libyul/CMakeLists.txt.
|
||||||
|
// This file was generated by using the content of libyul/backends/wasm/polyfill/@EWASM_POLYFILL_NAME@.yul.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace solidity::yul::wasm::polyfill
|
||||||
|
{
|
||||||
|
|
||||||
|
static char const @EWASM_POLYFILL_NAME@[] = {
|
||||||
|
@EWASM_POLYFILL_CONTENT@, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace solidity::yul::wasm::polyfill
|
@ -61,6 +61,14 @@ add_library(yul
|
|||||||
backends/wasm/WasmObjectCompiler.h
|
backends/wasm/WasmObjectCompiler.h
|
||||||
backends/wasm/WordSizeTransform.cpp
|
backends/wasm/WordSizeTransform.cpp
|
||||||
backends/wasm/WordSizeTransform.h
|
backends/wasm/WordSizeTransform.h
|
||||||
|
backends/wasm/polyfill/Arithmetic.yul
|
||||||
|
backends/wasm/polyfill/Bitwise.yul
|
||||||
|
backends/wasm/polyfill/Comparison.yul
|
||||||
|
backends/wasm/polyfill/Conversion.yul
|
||||||
|
backends/wasm/polyfill/Interface.yul
|
||||||
|
backends/wasm/polyfill/Keccak.yul
|
||||||
|
backends/wasm/polyfill/Logical.yul
|
||||||
|
backends/wasm/polyfill/Memory.yul
|
||||||
optimiser/ASTCopier.cpp
|
optimiser/ASTCopier.cpp
|
||||||
optimiser/ASTCopier.h
|
optimiser/ASTCopier.h
|
||||||
optimiser/ASTWalker.cpp
|
optimiser/ASTWalker.cpp
|
||||||
@ -179,4 +187,15 @@ add_library(yul
|
|||||||
optimiser/VarNameCleaner.h
|
optimiser/VarNameCleaner.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(POLYFILLS Arithmetic Bitwise Comparison Conversion Interface Keccak Logical Memory)
|
||||||
|
foreach(polyfill IN LISTS POLYFILLS)
|
||||||
|
set(POLYFILL_FILE ${CMAKE_SOURCE_DIR}/libyul/backends/wasm/polyfill/${polyfill}.yul)
|
||||||
|
file(READ ${POLYFILL_FILE} EWASM_POLYFILL_CONTENT HEX)
|
||||||
|
string(REGEX MATCHALL ".." EWASM_POLYFILL_CONTENT "${EWASM_POLYFILL_CONTENT}")
|
||||||
|
string(REGEX REPLACE ";" ",\n\t0x" EWASM_POLYFILL_CONTENT "${EWASM_POLYFILL_CONTENT}")
|
||||||
|
set(EWASM_POLYFILL_CONTENT "0x${EWASM_POLYFILL_CONTENT}")
|
||||||
|
set(EWASM_POLYFILL_NAME ${polyfill})
|
||||||
|
configure_file("${CMAKE_SOURCE_DIR}/cmake/templates/ewasm_polyfill.in" ${CMAKE_BINARY_DIR}/include/ewasmPolyfills/${polyfill}.h @ONLY)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
target_link_libraries(yul PUBLIC evmasm solutil langutil smtutil)
|
target_link_libraries(yul PUBLIC evmasm solutil langutil smtutil)
|
File diff suppressed because it is too large
Load Diff
396
libyul/backends/wasm/polyfill/Arithmetic.yul
Normal file
396
libyul/backends/wasm/polyfill/Arithmetic.yul
Normal file
@ -0,0 +1,396 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Arithmetic.h`.
|
||||||
|
|
||||||
|
// returns a + y + c plus carry value on 64 bit values.
|
||||||
|
// c should be at most 1
|
||||||
|
function add_carry(x, y, c) -> r, r_c {
|
||||||
|
let t := i64.add(x, y)
|
||||||
|
r := i64.add(t, c)
|
||||||
|
r_c := i64.extend_i32_u(i32.or(
|
||||||
|
i64.lt_u(t, x),
|
||||||
|
i64.lt_u(r, t)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
function add(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
let carry
|
||||||
|
r4, carry := add_carry(x4, y4, 0)
|
||||||
|
r3, carry := add_carry(x3, y3, carry)
|
||||||
|
r2, carry := add_carry(x2, y2, carry)
|
||||||
|
r1, carry := add_carry(x1, y1, carry)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// x - y = x + (~y + 1)
|
||||||
|
let carry
|
||||||
|
r4, carry := add_carry(x4, bit_negate(y4), 1)
|
||||||
|
r3, carry := add_carry(x3, bit_negate(y3), carry)
|
||||||
|
r2, carry := add_carry(x2, bit_negate(y2), carry)
|
||||||
|
r1, carry := add_carry(x1, bit_negate(y1), carry)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub320(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5) -> r1, r2, r3, r4, r5 {
|
||||||
|
// x - y = x + (~y + 1)
|
||||||
|
let carry
|
||||||
|
r5, carry := add_carry(x5, bit_negate(y5), 1)
|
||||||
|
r4, carry := add_carry(x4, bit_negate(y4), carry)
|
||||||
|
r3, carry := add_carry(x3, bit_negate(y3), carry)
|
||||||
|
r2, carry := add_carry(x2, bit_negate(y2), carry)
|
||||||
|
r1, carry := add_carry(x1, bit_negate(y1), carry)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub512(x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8) -> r1, r2, r3, r4, r5, r6, r7, r8 {
|
||||||
|
// x - y = x + (~y + 1)
|
||||||
|
let carry
|
||||||
|
r8, carry := add_carry(x8, bit_negate(y8), 1)
|
||||||
|
r7, carry := add_carry(x7, bit_negate(y7), carry)
|
||||||
|
r6, carry := add_carry(x6, bit_negate(y6), carry)
|
||||||
|
r5, carry := add_carry(x5, bit_negate(y5), carry)
|
||||||
|
r4, carry := add_carry(x4, bit_negate(y4), carry)
|
||||||
|
r3, carry := add_carry(x3, bit_negate(y3), carry)
|
||||||
|
r2, carry := add_carry(x2, bit_negate(y2), carry)
|
||||||
|
r1, carry := add_carry(x1, bit_negate(y1), carry)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplies two 64 bit values resulting in a 128 bit
|
||||||
|
// value split into two 64 bit values.
|
||||||
|
function mul_64x64_128(x, y) -> hi, lo {
|
||||||
|
let xh, xl := split(x)
|
||||||
|
let yh, yl := split(y)
|
||||||
|
let t0 := i64.mul(xl, yl)
|
||||||
|
let t1 := i64.mul(xh, yl)
|
||||||
|
let t2 := i64.mul(xl, yh)
|
||||||
|
let t3 := i64.mul(xh, yh)
|
||||||
|
let t0h, t0l := split(t0)
|
||||||
|
let u1 := i64.add(t1, t0h)
|
||||||
|
let u1h, u1l := split(u1)
|
||||||
|
let u2 := i64.add(t2, u1l)
|
||||||
|
lo := i64.or(i64.shl(u2, 32), t0l)
|
||||||
|
hi := i64.add(t3, i64.add(i64.shr_u(u2, 32), u1h))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplies two 128 bit values resulting in a 256 bit
|
||||||
|
// value split into four 64 bit values.
|
||||||
|
function mul_128x128_256(x1, x2, y1, y2) -> r1, r2, r3, r4 {
|
||||||
|
let ah, al := mul_64x64_128(x1, y1)
|
||||||
|
let bh, bl := mul_64x64_128(x1, y2)
|
||||||
|
let ch, cl := mul_64x64_128(x2, y1)
|
||||||
|
let dh, dl := mul_64x64_128(x2, y2)
|
||||||
|
r4 := dl
|
||||||
|
let carry1, carry2
|
||||||
|
let t1, t2
|
||||||
|
r3, carry1 := add_carry(bl, cl, 0)
|
||||||
|
r3, carry2 := add_carry(r3, dh, 0)
|
||||||
|
t1, carry1 := add_carry(bh, ch, carry1)
|
||||||
|
r2, carry2 := add_carry(t1, al, carry2)
|
||||||
|
r1 := i64.add(i64.add(ah, carry1), carry2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplies two 256 bit values resulting in a 512 bit
|
||||||
|
// value split into eight 64 bit values.
|
||||||
|
function mul_256x256_512(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4, r5, r6, r7, r8 {
|
||||||
|
let a1, a2, a3, a4 := mul_128x128_256(x1, x2, y1, y2)
|
||||||
|
let b1, b2, b3, b4 := mul_128x128_256(x1, x2, y3, y4)
|
||||||
|
let c1, c2, c3, c4 := mul_128x128_256(x3, x4, y1, y2)
|
||||||
|
let d1, d2, d3, d4 := mul_128x128_256(x3, x4, y3, y4)
|
||||||
|
r8 := d4
|
||||||
|
r7 := d3
|
||||||
|
let carry1, carry2
|
||||||
|
let t1, t2
|
||||||
|
r6, carry1 := add_carry(b4, c4, 0)
|
||||||
|
r6, carry2 := add_carry(r6, d2, 0)
|
||||||
|
r5, carry1 := add_carry(b3, c3, carry1)
|
||||||
|
r5, carry2 := add_carry(r5, d1, carry2)
|
||||||
|
r4, carry1 := add_carry(a4, b2, carry1)
|
||||||
|
r4, carry2 := add_carry(r4, c2, carry2)
|
||||||
|
r3, carry1 := add_carry(a3, b1, carry1)
|
||||||
|
r3, carry2 := add_carry(r3, c1, carry2)
|
||||||
|
r2, carry1 := add_carry(a2, carry1, carry2)
|
||||||
|
r1 := i64.add(a1, carry1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// TODO it would actually suffice to have mul_128x128_128 for the first two.
|
||||||
|
let b1, b2, b3, b4 := mul_128x128_256(x3, x4, y1, y2)
|
||||||
|
let c1, c2, c3, c4 := mul_128x128_256(x1, x2, y3, y4)
|
||||||
|
let d1, d2, d3, d4 := mul_128x128_256(x3, x4, y3, y4)
|
||||||
|
r4 := d4
|
||||||
|
r3 := d3
|
||||||
|
let t1, t2
|
||||||
|
t1, t2, r1, r2 := add(0, 0, b3, b4, 0, 0, c3, c4)
|
||||||
|
t1, t2, r1, r2 := add(0, 0, r1, r2, 0, 0, d1, d2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function div(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/DIV.wast
|
||||||
|
if iszero256(y1, y2, y3, y4) {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
|
||||||
|
let m1 := 0
|
||||||
|
let m2 := 0
|
||||||
|
let m3 := 0
|
||||||
|
let m4 := 1
|
||||||
|
|
||||||
|
for {} true {} {
|
||||||
|
if i32.or(i64.eqz(i64.clz(y1)), gte_256x256_64(y1, y2, y3, y4, x1, x2, x3, x4)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
y1, y2, y3, y4 := shl_internal(1, y1, y2, y3, y4)
|
||||||
|
m1, m2, m3, m4 := shl_internal(1, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {} or_bool(m1, m2, m3, m4) {} {
|
||||||
|
if gte_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
x1, x2, x3, x4 := sub(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
r1, r2, r3, r4 := add(r1, r2, r3, r4, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
y1, y2, y3, y4 := shr_internal(1, y1, y2, y3, y4)
|
||||||
|
m1, m2, m3, m4 := shr_internal(1, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sdiv(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/SDIV.wast
|
||||||
|
|
||||||
|
let sign:i32 := i32.wrap_i64(i64.shr_u(i64.xor(x1, y1), 63))
|
||||||
|
|
||||||
|
if i64.eqz(i64.clz(x1)) {
|
||||||
|
x1, x2, x3, x4 := xor(
|
||||||
|
x1, x2, x3, x4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
x1, x2, x3, x4 := add(x1, x2, x3, x4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if i64.eqz(i64.clz(y1)) {
|
||||||
|
y1, y2, y3, y4 := xor(
|
||||||
|
y1, y2, y3, y4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
y1, y2, y3, y4 := add(y1, y2, y3, y4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
r1, r2, r3, r4 := div(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
|
||||||
|
if sign {
|
||||||
|
r1, r2, r3, r4 := xor(
|
||||||
|
r1, r2, r3, r4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
r1, r2, r3, r4 := add(r1, r2, r3, r4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mod(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/MOD.wast
|
||||||
|
if iszero256(y1, y2, y3, y4) {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
|
||||||
|
r1 := x1
|
||||||
|
r2 := x2
|
||||||
|
r3 := x3
|
||||||
|
r4 := x4
|
||||||
|
|
||||||
|
let m1 := 0
|
||||||
|
let m2 := 0
|
||||||
|
let m3 := 0
|
||||||
|
let m4 := 1
|
||||||
|
|
||||||
|
for {} true {} {
|
||||||
|
if i32.or(i64.eqz(i64.clz(y1)), gte_256x256_64(y1, y2, y3, y4, r1, r2, r3, r4)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
y1, y2, y3, y4 := shl_internal(1, y1, y2, y3, y4)
|
||||||
|
m1, m2, m3, m4 := shl_internal(1, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {} or_bool(m1, m2, m3, m4) {} {
|
||||||
|
if gte_256x256_64(r1, r2, r3, r4, y1, y2, y3, y4) {
|
||||||
|
r1, r2, r3, r4 := sub(r1, r2, r3, r4, y1, y2, y3, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
y1, y2, y3, y4 := shr_internal(1, y1, y2, y3, y4)
|
||||||
|
m1, m2, m3, m4 := shr_internal(1, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mod320(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5) -> r1, r2, r3, r4, r5 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/mod_320.wast
|
||||||
|
if iszero320(y1, y2, y3, y4, y5) {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
|
||||||
|
let m1 := 0
|
||||||
|
let m2 := 0
|
||||||
|
let m3 := 0
|
||||||
|
let m4 := 0
|
||||||
|
let m5 := 1
|
||||||
|
|
||||||
|
r1 := x1
|
||||||
|
r2 := x2
|
||||||
|
r3 := x3
|
||||||
|
r4 := x4
|
||||||
|
r5 := x5
|
||||||
|
|
||||||
|
for {} true {} {
|
||||||
|
if i32.or(i64.eqz(i64.clz(y1)), gte_320x320_64(y1, y2, y3, y4, y5, r1, r2, r3, r4, r5)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
y1, y2, y3, y4, y5 := shl320_internal(1, y1, y2, y3, y4, y5)
|
||||||
|
m1, m2, m3, m4, m5 := shl320_internal(1, m1, m2, m3, m4, m5)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {} or_bool_320(m1, m2, m3, m4, m5) {} {
|
||||||
|
if gte_320x320_64(r1, r2, r3, r4, r5, y1, y2, y3, y4, y5) {
|
||||||
|
r1, r2, r3, r4, r5 := sub320(r1, r2, r3, r4, r5, y1, y2, y3, y4, y5)
|
||||||
|
}
|
||||||
|
|
||||||
|
y1, y2, y3, y4, y5 := shr320_internal(1, y1, y2, y3, y4, y5)
|
||||||
|
m1, m2, m3, m4, m5 := shr320_internal(1, m1, m2, m3, m4, m5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mod512(x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8) -> r1, r2, r3, r4, r5, r6, r7, r8 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/mod_512.wast
|
||||||
|
if iszero512(y1, y2, y3, y4, y5, y6, y7, y8) {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
|
||||||
|
let m1 := 0
|
||||||
|
let m2 := 0
|
||||||
|
let m3 := 0
|
||||||
|
let m4 := 0
|
||||||
|
let m5 := 0
|
||||||
|
let m6 := 0
|
||||||
|
let m7 := 0
|
||||||
|
let m8 := 1
|
||||||
|
|
||||||
|
r1 := x1
|
||||||
|
r2 := x2
|
||||||
|
r3 := x3
|
||||||
|
r4 := x4
|
||||||
|
r5 := x5
|
||||||
|
r6 := x6
|
||||||
|
r7 := x7
|
||||||
|
r8 := x8
|
||||||
|
|
||||||
|
for {} true {} {
|
||||||
|
if i32.or(
|
||||||
|
i64.eqz(i64.clz(y1)),
|
||||||
|
gte_512x512_64(y1, y2, y3, y4, y5, y6, y7, y8, r1, r2, r3, r4, r5, r6, r7, r8)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
break
|
||||||
|
}
|
||||||
|
y1, y2, y3, y4, y5, y6, y7, y8 := shl512_internal(1, y1, y2, y3, y4, y5, y6, y7, y8)
|
||||||
|
m1, m2, m3, m4, m5, m6, m7, m8 := shl512_internal(1, m1, m2, m3, m4, m5, m6, m7, m8)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {} or_bool_512(m1, m2, m3, m4, m5, m6, m7, m8) {} {
|
||||||
|
if gte_512x512_64(r1, r2, r3, r4, r5, r6, r7, r8, y1, y2, y3, y4, y5, y6, y7, y8) {
|
||||||
|
r1, r2, r3, r4, r5, r6, r7, r8 := sub512(r1, r2, r3, r4, r5, r6, r7, r8, y1, y2, y3, y4, y5, y6, y7, y8)
|
||||||
|
}
|
||||||
|
|
||||||
|
y1, y2, y3, y4, y5, y6, y7, y8 := shr512_internal(1, y1, y2, y3, y4, y5, y6, y7, y8)
|
||||||
|
m1, m2, m3, m4, m5, m6, m7, m8 := shr512_internal(1, m1, m2, m3, m4, m5, m6, m7, m8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function smod(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
// Based on https://github.com/ewasm/evm2wasm/blob/master/wasm/SMOD.wast
|
||||||
|
let m1 := 0
|
||||||
|
let m2 := 0
|
||||||
|
let m3 := 0
|
||||||
|
let m4 := 1
|
||||||
|
|
||||||
|
let sign:i32 := i32.wrap_i64(i64.shr_u(x1, 63))
|
||||||
|
|
||||||
|
if i64.eqz(i64.clz(x1)) {
|
||||||
|
x1, x2, x3, x4 := xor(
|
||||||
|
x1, x2, x3, x4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
x1, x2, x3, x4 := add(x1, x2, x3, x4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if i64.eqz(i64.clz(y1)) {
|
||||||
|
y1, y2, y3, y4 := xor(
|
||||||
|
y1, y2, y3, y4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
y1, y2, y3, y4 := add(y1, y2, y3, y4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
r1, r2, r3, r4 := mod(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
|
||||||
|
if sign {
|
||||||
|
r1, r2, r3, r4 := xor(
|
||||||
|
r1, r2, r3, r4,
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
r1, r2, r3, r4 := add(r1, r2, r3, r4, 0, 0, 0, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function exp(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
r4 := 1
|
||||||
|
for {} or_bool(y1, y2, y3, y4) {} {
|
||||||
|
if i32.wrap_i64(i64.and(y4, 1)) {
|
||||||
|
r1, r2, r3, r4 := mul(r1, r2, r3, r4, x1, x2, x3, x4)
|
||||||
|
}
|
||||||
|
x1, x2, x3, x4 := mul(x1, x2, x3, x4, x1, x2, x3, x4)
|
||||||
|
y1, y2, y3, y4 := shr_internal(1, y1, y2, y3, y4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addmod(x1, x2, x3, x4, y1, y2, y3, y4, m1, m2, m3, m4) -> z1, z2, z3, z4 {
|
||||||
|
let carry
|
||||||
|
z4, carry := add_carry(x4, y4, 0)
|
||||||
|
z3, carry := add_carry(x3, y3, carry)
|
||||||
|
z2, carry := add_carry(x2, y2, carry)
|
||||||
|
z1, carry := add_carry(x1, y1, carry)
|
||||||
|
|
||||||
|
let z0
|
||||||
|
z0, z1, z2, z3, z4 := mod320(carry, z1, z2, z3, z4, 0, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mulmod(x1, x2, x3, x4, y1, y2, y3, y4, m1, m2, m3, m4) -> z1, z2, z3, z4 {
|
||||||
|
let r1, r2, r3, r4, r5, r6, r7, r8 := mul_256x256_512(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
let t1
|
||||||
|
let t2
|
||||||
|
let t3
|
||||||
|
let t4
|
||||||
|
t1, t2, t3, t4, z1, z2, z3, z4 := mod512(r1, r2, r3, r4, r5, r6, r7, r8, 0, 0, 0, 0, m1, m2, m3, m4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function signextend(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
z1 := y1
|
||||||
|
z2 := y2
|
||||||
|
z3 := y3
|
||||||
|
z4 := y4
|
||||||
|
if lt_256x256_64(x1, x2, x3, x4, 0, 0, 0, 32) {
|
||||||
|
let d := i64.mul(i64.sub(31, x4), 8)
|
||||||
|
z1, z2, z3, z4 := shl(0, 0, 0, d, z1, z2, z3, z4)
|
||||||
|
z1, z2, z3, z4 := sar(0, 0, 0, d, z1, z2, z3, z4)
|
||||||
|
}
|
||||||
|
}
|
222
libyul/backends/wasm/polyfill/Bitwise.yul
Normal file
222
libyul/backends/wasm/polyfill/Bitwise.yul
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Bitwise.h`.
|
||||||
|
|
||||||
|
function bit_negate(x) -> y {
|
||||||
|
y := i64.xor(x, 0xffffffffffffffff)
|
||||||
|
}
|
||||||
|
|
||||||
|
function split(x) -> hi, lo {
|
||||||
|
hi := i64.shr_u(x, 32)
|
||||||
|
lo := i64.and(x, 0xffffffff)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shl_internal(amount, x1, x2, x3, x4) -> r1, r2, r3, r4 {
|
||||||
|
// amount < 64
|
||||||
|
r1 := i64.add(i64.shl(x1, amount), i64.shr_u(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shl(x2, amount), i64.shr_u(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shl(x3, amount), i64.shr_u(x4, i64.sub(64, amount)))
|
||||||
|
r4 := i64.shl(x4, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shr_internal(amount, x1, x2, x3, x4) -> r1, r2, r3, r4 {
|
||||||
|
// amount < 64
|
||||||
|
r4 := i64.add(i64.shr_u(x4, amount), i64.shl(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shr_u(x3, amount), i64.shl(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shr_u(x2, amount), i64.shl(x1, i64.sub(64, amount)))
|
||||||
|
r1 := i64.shr_u(x1, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shl320_internal(amount, x1, x2, x3, x4, x5) -> r1, r2, r3, r4, r5 {
|
||||||
|
// amount < 64
|
||||||
|
r1 := i64.add(i64.shl(x1, amount), i64.shr_u(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shl(x2, amount), i64.shr_u(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shl(x3, amount), i64.shr_u(x4, i64.sub(64, amount)))
|
||||||
|
r4 := i64.add(i64.shl(x4, amount), i64.shr_u(x5, i64.sub(64, amount)))
|
||||||
|
r5 := i64.shl(x5, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shr320_internal(amount, x1, x2, x3, x4, x5) -> r1, r2, r3, r4, r5 {
|
||||||
|
// amount < 64
|
||||||
|
r5 := i64.add(i64.shr_u(x5, amount), i64.shl(x4, i64.sub(64, amount)))
|
||||||
|
r4 := i64.add(i64.shr_u(x4, amount), i64.shl(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shr_u(x3, amount), i64.shl(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shr_u(x2, amount), i64.shl(x1, i64.sub(64, amount)))
|
||||||
|
r1 := i64.shr_u(x1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shl512_internal(amount, x1, x2, x3, x4, x5, x6, x7, x8) -> r1, r2, r3, r4, r5, r6, r7, r8 {
|
||||||
|
// amount < 64
|
||||||
|
r1 := i64.add(i64.shl(x1, amount), i64.shr_u(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shl(x2, amount), i64.shr_u(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shl(x3, amount), i64.shr_u(x4, i64.sub(64, amount)))
|
||||||
|
r4 := i64.add(i64.shl(x4, amount), i64.shr_u(x5, i64.sub(64, amount)))
|
||||||
|
r5 := i64.add(i64.shl(x5, amount), i64.shr_u(x6, i64.sub(64, amount)))
|
||||||
|
r6 := i64.add(i64.shl(x6, amount), i64.shr_u(x7, i64.sub(64, amount)))
|
||||||
|
r7 := i64.add(i64.shl(x7, amount), i64.shr_u(x8, i64.sub(64, amount)))
|
||||||
|
r8 := i64.shl(x8, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shr512_internal(amount, x1, x2, x3, x4, x5, x6, x7, x8) -> r1, r2, r3, r4, r5, r6, r7, r8 {
|
||||||
|
// amount < 64
|
||||||
|
r8 := i64.add(i64.shr_u(x8, amount), i64.shl(x7, i64.sub(64, amount)))
|
||||||
|
r7 := i64.add(i64.shr_u(x7, amount), i64.shl(x6, i64.sub(64, amount)))
|
||||||
|
r6 := i64.add(i64.shr_u(x6, amount), i64.shl(x5, i64.sub(64, amount)))
|
||||||
|
r5 := i64.add(i64.shr_u(x5, amount), i64.shl(x4, i64.sub(64, amount)))
|
||||||
|
r4 := i64.add(i64.shr_u(x4, amount), i64.shl(x3, i64.sub(64, amount)))
|
||||||
|
r3 := i64.add(i64.shr_u(x3, amount), i64.shl(x2, i64.sub(64, amount)))
|
||||||
|
r2 := i64.add(i64.shr_u(x2, amount), i64.shl(x1, i64.sub(64, amount)))
|
||||||
|
r1 := i64.shr_u(x1, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
if i64.eqz(i64.or(i64.or(x1, x2), x3)) {
|
||||||
|
let component
|
||||||
|
switch i64.div_u(x4, 8)
|
||||||
|
case 0 { component := y1 }
|
||||||
|
case 1 { component := y2 }
|
||||||
|
case 2 { component := y3 }
|
||||||
|
case 3 { component := y4 }
|
||||||
|
x4 := i64.mul(i64.rem_u(x4, 8), 8)
|
||||||
|
r4 := i64.shr_u(component, i64.sub(56, x4))
|
||||||
|
r4 := i64.and(0xff, r4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function xor(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
r1 := i64.xor(x1, y1)
|
||||||
|
r2 := i64.xor(x2, y2)
|
||||||
|
r3 := i64.xor(x3, y3)
|
||||||
|
r4 := i64.xor(x4, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function or(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
r1 := i64.or(x1, y1)
|
||||||
|
r2 := i64.or(x2, y2)
|
||||||
|
r3 := i64.or(x3, y3)
|
||||||
|
r4 := i64.or(x4, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function and(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
r1 := i64.and(x1, y1)
|
||||||
|
r2 := i64.and(x2, y2)
|
||||||
|
r3 := i64.and(x3, y3)
|
||||||
|
r4 := i64.and(x4, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function not(x1, x2, x3, x4) -> r1, r2, r3, r4 {
|
||||||
|
let mask := 0xffffffffffffffff
|
||||||
|
r1, r2, r3, r4 := xor(x1, x2, x3, x4, mask, mask, mask, mask)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shl_single(a, amount) -> x, y {
|
||||||
|
// amount < 64
|
||||||
|
x := i64.shr_u(a, i64.sub(64, amount))
|
||||||
|
y := i64.shl(a, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shl(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
if i32.and(i64.eqz(x1), i64.eqz(x2)) {
|
||||||
|
if i64.eqz(x3) {
|
||||||
|
if i64.lt_u(x4, 256) {
|
||||||
|
if i64.ge_u(x4, 128) {
|
||||||
|
y1 := y3
|
||||||
|
y2 := y4
|
||||||
|
y3 := 0
|
||||||
|
y4 := 0
|
||||||
|
x4 := i64.sub(x4, 128)
|
||||||
|
}
|
||||||
|
if i64.ge_u(x4, 64) {
|
||||||
|
y1 := y2
|
||||||
|
y2 := y3
|
||||||
|
y3 := y4
|
||||||
|
y4 := 0
|
||||||
|
x4 := i64.sub(x4, 64)
|
||||||
|
}
|
||||||
|
let t, r
|
||||||
|
t, z4 := shl_single(y4, x4)
|
||||||
|
r, z3 := shl_single(y3, x4)
|
||||||
|
z3 := i64.or(z3, t)
|
||||||
|
t, z2 := shl_single(y2, x4)
|
||||||
|
z2 := i64.or(z2, r)
|
||||||
|
r, z1 := shl_single(y1, x4)
|
||||||
|
z1 := i64.or(z1, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shr_single(a, amount) -> x, y {
|
||||||
|
// amount < 64
|
||||||
|
y := i64.shl(a, i64.sub(64, amount))
|
||||||
|
x := i64.shr_u(a, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shr(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
if i32.and(i64.eqz(x1), i64.eqz(x2)) {
|
||||||
|
if i64.eqz(x3) {
|
||||||
|
if i64.lt_u(x4, 256) {
|
||||||
|
if i64.ge_u(x4, 128) {
|
||||||
|
y4 := y2
|
||||||
|
y3 := y1
|
||||||
|
y2 := 0
|
||||||
|
y1 := 0
|
||||||
|
x4 := i64.sub(x4, 128)
|
||||||
|
}
|
||||||
|
if i64.ge_u(x4, 64) {
|
||||||
|
y4 := y3
|
||||||
|
y3 := y2
|
||||||
|
y2 := y1
|
||||||
|
y1 := 0
|
||||||
|
x4 := i64.sub(x4, 64)
|
||||||
|
}
|
||||||
|
let t
|
||||||
|
z4, t := shr_single(y4, x4)
|
||||||
|
z3, t := shr_single(y3, x4)
|
||||||
|
z4 := i64.or(z4, t)
|
||||||
|
z2, t := shr_single(y2, x4)
|
||||||
|
z3 := i64.or(z3, t)
|
||||||
|
z1, t := shr_single(y1, x4)
|
||||||
|
z2 := i64.or(z2, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sar(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
if i64.gt_u(i64.clz(y1), 0) {
|
||||||
|
z1, z2, z3, z4 := shr(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
|
||||||
|
if gte_256x256_64(x1, x2, x3, x4, 0, 0, 0, 256) {
|
||||||
|
z1 := 0xffffffffffffffff
|
||||||
|
z2 := 0xffffffffffffffff
|
||||||
|
z3 := 0xffffffffffffffff
|
||||||
|
z4 := 0xffffffffffffffff
|
||||||
|
}
|
||||||
|
if lt_256x256_64(x1, x2, x3, x4, 0, 0, 0, 256) {
|
||||||
|
y1, y2, y3, y4 := shr(0, 0, 0, x4, y1, y2, y3, y4)
|
||||||
|
z1, z2, z3, z4 := shl(
|
||||||
|
0, 0, 0, i64.sub(256, x4),
|
||||||
|
0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff
|
||||||
|
)
|
||||||
|
z1, z2, z3, z4 := or(y1, y2, y3, y4, z1, z2, z3, z4)
|
||||||
|
}
|
||||||
|
}
|
169
libyul/backends/wasm/polyfill/Comparison.yul
Normal file
169
libyul/backends/wasm/polyfill/Comparison.yul
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Comparison.h`.
|
||||||
|
|
||||||
|
function iszero(x1, x2, x3, x4) -> r1, r2, r3, r4 {
|
||||||
|
r4 := i64.extend_i32_u(iszero256(x1, x2, x3, x4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function iszero256(x1, x2, x3, x4) -> r:i32 {
|
||||||
|
r := i64.eqz(i64.or(i64.or(x1, x2), i64.or(x3, x4)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function iszero320(x1, x2, x3, x4, x5) -> r:i32 {
|
||||||
|
r := i64.eqz(i64.or(i64.or(i64.or(x1, x2), i64.or(x3, x4)), x5))
|
||||||
|
}
|
||||||
|
|
||||||
|
function iszero512(x1, x2, x3, x4, x5, x6, x7, x8) -> r:i32 {
|
||||||
|
r := i32.and(iszero256(x1, x2, x3, x4), iszero256(x5, x6, x7, x8))
|
||||||
|
}
|
||||||
|
|
||||||
|
function eq(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 {
|
||||||
|
if i64.eq(x1, y1) {
|
||||||
|
if i64.eq(x2, y2) {
|
||||||
|
if i64.eq(x3, y3) {
|
||||||
|
if i64.eq(x4, y4) {
|
||||||
|
r4 := 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns 0 if a == b, -1 if a < b and 1 if a > b
|
||||||
|
function cmp(a, b) -> r:i32 {
|
||||||
|
switch i64.lt_u(a, b)
|
||||||
|
case 1:i32 { r := 0xffffffff:i32 }
|
||||||
|
default {
|
||||||
|
r := i64.ne(a, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function lt_320x320_64(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5) -> z:i32 {
|
||||||
|
switch cmp(x1, y1)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x2, y2)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x3, y3)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x4, y4)
|
||||||
|
case 0:i32 {
|
||||||
|
z := i64.lt_u(x5, y5)
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
|
||||||
|
function lt_512x512_64(x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8) -> z:i32 {
|
||||||
|
switch cmp(x1, y1)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x2, y2)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x3, y3)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x4, y4)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x5, y5)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x6, y6)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x7, y7)
|
||||||
|
case 0:i32 {
|
||||||
|
z := i64.lt_u(x8, y8)
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
|
||||||
|
function lt_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4) -> z:i32 {
|
||||||
|
switch cmp(x1, y1)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x2, y2)
|
||||||
|
case 0:i32 {
|
||||||
|
switch cmp(x3, y3)
|
||||||
|
case 0:i32 {
|
||||||
|
z := i64.lt_u(x4, y4)
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
case 1:i32 { z := 0:i32 }
|
||||||
|
default { z := 1:i32 }
|
||||||
|
}
|
||||||
|
|
||||||
|
function lt(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
z4 := i64.extend_i32_u(lt_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function gte_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4) -> z:i32 {
|
||||||
|
z := i32.eqz(lt_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function gte_320x320_64(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5) -> z:i32 {
|
||||||
|
z := i32.eqz(lt_320x320_64(x1, x2, x3, x4, x5, y1, y2, y3, y4, y5))
|
||||||
|
}
|
||||||
|
|
||||||
|
function gte_512x512_64(x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8) -> z:i32 {
|
||||||
|
z := i32.eqz(lt_512x512_64(x1, x2, x3, x4, x5, x6, x7, x8, y1, y2, y3, y4, y5, y6, y7, y8))
|
||||||
|
}
|
||||||
|
|
||||||
|
function gt(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
z1, z2, z3, z4 := lt(y1, y2, y3, y4, x1, x2, x3, x4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function slt(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
// TODO correct?
|
||||||
|
x1 := i64.add(x1, 0x8000000000000000)
|
||||||
|
y1 := i64.add(y1, 0x8000000000000000)
|
||||||
|
z1, z2, z3, z4 := lt(x1, x2, x3, x4, y1, y2, y3, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sgt(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
z1, z2, z3, z4 := slt(y1, y2, y3, y4, x1, x2, x3, x4)
|
||||||
|
}
|
78
libyul/backends/wasm/polyfill/Conversion.yul
Normal file
78
libyul/backends/wasm/polyfill/Conversion.yul
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Conversion.h`.
|
||||||
|
|
||||||
|
function u256_to_u128(x1, x2, x3, x4) -> v1, v2 {
|
||||||
|
if i64.ne(0, i64.or(x1, x2)) { invalid() }
|
||||||
|
v2 := x4
|
||||||
|
v1 := x3
|
||||||
|
}
|
||||||
|
|
||||||
|
function u256_to_i64(x1, x2, x3, x4) -> v {
|
||||||
|
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { invalid() }
|
||||||
|
v := x4
|
||||||
|
}
|
||||||
|
|
||||||
|
function u256_to_i32(x1, x2, x3, x4) -> v:i32 {
|
||||||
|
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { invalid() }
|
||||||
|
if i64.ne(0, i64.shr_u(x4, 32)) { invalid() }
|
||||||
|
v := i32.wrap_i64(x4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function u256_to_byte(x1, x2, x3, x4) -> v {
|
||||||
|
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { invalid() }
|
||||||
|
if i64.gt_u(x4, 255) { invalid() }
|
||||||
|
v := x4
|
||||||
|
}
|
||||||
|
|
||||||
|
function u256_to_i32ptr(x1, x2, x3, x4) -> v:i32 {
|
||||||
|
v := u256_to_i32(x1, x2, x3, x4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function to_internal_i32ptr(x1, x2, x3, x4) -> r:i32 {
|
||||||
|
let p:i32 := u256_to_i32ptr(x1, x2, x3, x4)
|
||||||
|
r := i32.add(p, 64:i32)
|
||||||
|
if i32.lt_u(r, p) { invalid() }
|
||||||
|
}
|
||||||
|
|
||||||
|
function u256_to_address(x1, x2, x3, x4) -> r1, r2, r3 {
|
||||||
|
if i64.ne(0, x1) { invalid() }
|
||||||
|
if i64.ne(0, i64.shr_u(x2, 32)) { invalid() }
|
||||||
|
r1 := x2
|
||||||
|
r2 := x3
|
||||||
|
r3 := x4
|
||||||
|
}
|
||||||
|
|
||||||
|
function endian_swap_16(x) -> y {
|
||||||
|
let hi := i64.and(i64.shl(x, 8), 0xff00)
|
||||||
|
let lo := i64.and(i64.shr_u(x, 8), 0xff)
|
||||||
|
y := i64.or(hi, lo)
|
||||||
|
}
|
||||||
|
|
||||||
|
function endian_swap_32(x) -> y {
|
||||||
|
let hi := i64.shl(endian_swap_16(x), 16)
|
||||||
|
let lo := endian_swap_16(i64.shr_u(x, 16))
|
||||||
|
y := i64.or(hi, lo)
|
||||||
|
}
|
||||||
|
|
||||||
|
function endian_swap(x) -> y {
|
||||||
|
let hi := i64.shl(endian_swap_32(x), 32)
|
||||||
|
let lo := endian_swap_32(i64.shr_u(x, 32))
|
||||||
|
y := i64.or(hi, lo)
|
||||||
|
}
|
411
libyul/backends/wasm/polyfill/Interface.yul
Normal file
411
libyul/backends/wasm/polyfill/Interface.yul
Normal file
@ -0,0 +1,411 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Interface.h`.
|
||||||
|
|
||||||
|
function address() -> z1, z2, z3, z4 {
|
||||||
|
eth.getAddress(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function balance(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
mstore_address(0:i32, x1, x2, x3, x4)
|
||||||
|
eth.getExternalBalance(12:i32, 48:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(32:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function selfbalance() -> z1, z2, z3, z4 {
|
||||||
|
// TODO: not part of current Ewasm spec
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function chainid() -> z1, z2, z3, z4 {
|
||||||
|
// TODO: not part of current Ewasm spec
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function origin() -> z1, z2, z3, z4 {
|
||||||
|
eth.getTxOrigin(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function caller() -> z1, z2, z3, z4 {
|
||||||
|
eth.getCaller(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function callvalue() -> z1, z2, z3, z4 {
|
||||||
|
eth.getCallValue(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calldataload(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
eth.callDataCopy(0:i32, u256_to_i32(x1, x2, x3, x4), 32:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calldatasize() -> z1, z2, z3, z4 {
|
||||||
|
z4 := i64.extend_i32_u(eth.getCallDataSize())
|
||||||
|
}
|
||||||
|
|
||||||
|
function calldatacopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4) {
|
||||||
|
eth.callDataCopy(
|
||||||
|
to_internal_i32ptr(x1, x2, x3, x4),
|
||||||
|
u256_to_i32(y1, y2, y3, y4),
|
||||||
|
u256_to_i32(z1, z2, z3, z4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needed?
|
||||||
|
function codesize() -> z1, z2, z3, z4 {
|
||||||
|
z4 := i64.extend_i32_u(eth.getCodeSize())
|
||||||
|
}
|
||||||
|
|
||||||
|
function codecopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4) {
|
||||||
|
eth.codeCopy(
|
||||||
|
to_internal_i32ptr(x1, x2, x3, x4),
|
||||||
|
u256_to_i32(y1, y2, y3, y4),
|
||||||
|
u256_to_i32(z1, z2, z3, z4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function datacopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4) {
|
||||||
|
// TODO correct?
|
||||||
|
codecopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function gasprice() -> z1, z2, z3, z4 {
|
||||||
|
eth.getTxGasPrice(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function extcodesize_internal(x1, x2, x3, x4) -> r:i32 {
|
||||||
|
mstore_address(0:i32, x1, x2, x3, x4)
|
||||||
|
r := eth.getExternalCodeSize(12:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function extcodesize(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
z4 := i64.extend_i32_u(extcodesize_internal(x1, x2, x3, x4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function extcodehash(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
// TODO: not part of current Ewasm spec
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function extcodecopy(a1, a2, a3, a4, p1, p2, p3, p4, o1, o2, o3, o4, l1, l2, l3, l4) {
|
||||||
|
mstore_address(0:i32, a1, a2, a3, a4)
|
||||||
|
let codeOffset:i32 := u256_to_i32(o1, o2, o3, o4)
|
||||||
|
let codeLength:i32 := u256_to_i32(l1, l2, l3, l4)
|
||||||
|
eth.externalCodeCopy(12:i32, to_internal_i32ptr(p1, p2, p3, p4), codeOffset, codeLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
function returndatasize() -> z1, z2, z3, z4 {
|
||||||
|
z4 := i64.extend_i32_u(eth.getReturnDataSize())
|
||||||
|
}
|
||||||
|
|
||||||
|
function returndatacopy(x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4) {
|
||||||
|
eth.returnDataCopy(
|
||||||
|
to_internal_i32ptr(x1, x2, x3, x4),
|
||||||
|
u256_to_i32(y1, y2, y3, y4),
|
||||||
|
u256_to_i32(z1, z2, z3, z4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function blockhash(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
let r:i32 := eth.getBlockHash(u256_to_i64(x1, x2, x3, x4), 0:i32)
|
||||||
|
if i32.eqz(r) {
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function coinbase() -> z1, z2, z3, z4 {
|
||||||
|
eth.getBlockCoinbase(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function timestamp() -> z1, z2, z3, z4 {
|
||||||
|
z4 := eth.getBlockTimestamp()
|
||||||
|
}
|
||||||
|
|
||||||
|
function number() -> z1, z2, z3, z4 {
|
||||||
|
z4 := eth.getBlockNumber()
|
||||||
|
}
|
||||||
|
|
||||||
|
function difficulty() -> z1, z2, z3, z4 {
|
||||||
|
eth.getBlockDifficulty(0:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(0:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function gaslimit() -> z1, z2, z3, z4 {
|
||||||
|
z4 := eth.getBlockGasLimit()
|
||||||
|
}
|
||||||
|
|
||||||
|
function mload(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
z1, z2, z3, z4 := mload_internal(to_internal_i32ptr(x1, x2, x3, x4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function mload_internal(pos:i32) -> z1, z2, z3, z4 {
|
||||||
|
z1 := endian_swap(i64.load(pos))
|
||||||
|
z2 := endian_swap(i64.load(i32.add(pos, 8:i32)))
|
||||||
|
z3 := endian_swap(i64.load(i32.add(pos, 16:i32)))
|
||||||
|
z4 := endian_swap(i64.load(i32.add(pos, 24:i32)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function mstore(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
mstore_internal(to_internal_i32ptr(x1, x2, x3, x4), y1, y2, y3, y4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mstore_internal(pos:i32, y1, y2, y3, y4) {
|
||||||
|
i64.store(pos, endian_swap(y1))
|
||||||
|
i64.store(i32.add(pos, 8:i32), endian_swap(y2))
|
||||||
|
i64.store(i32.add(pos, 16:i32), endian_swap(y3))
|
||||||
|
i64.store(i32.add(pos, 24:i32), endian_swap(y4))
|
||||||
|
}
|
||||||
|
|
||||||
|
function mstore_address(pos:i32, a1, a2, a3, a4) {
|
||||||
|
a1, a2, a3 := u256_to_address(a1, a2, a3, a4)
|
||||||
|
mstore_internal(pos, 0, a1, a2, a3)
|
||||||
|
}
|
||||||
|
|
||||||
|
function mstore8(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
let v := u256_to_byte(y1, y2, y3, y4)
|
||||||
|
i64.store8(to_internal_i32ptr(x1, x2, x3, x4), v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Needed?
|
||||||
|
function msize() -> z1, z2, z3, z4 {
|
||||||
|
// TODO implement
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function sload(x1, x2, x3, x4) -> z1, z2, z3, z4 {
|
||||||
|
mstore_internal(0:i32, x1, x2, x3, x4)
|
||||||
|
eth.storageLoad(0:i32, 32:i32)
|
||||||
|
z1, z2, z3, z4 := mload_internal(32:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sstore(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
mstore_internal(0:i32, x1, x2, x3, x4)
|
||||||
|
mstore_internal(32:i32, y1, y2, y3, y4)
|
||||||
|
eth.storageStore(0:i32, 32:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function gas() -> z1, z2, z3, z4 {
|
||||||
|
z4 := eth.getGasLeft()
|
||||||
|
}
|
||||||
|
|
||||||
|
function log0(p1, p2, p3, p4, s1, s2, s3, s4) {
|
||||||
|
eth.log(
|
||||||
|
to_internal_i32ptr(p1, p2, p3, p4),
|
||||||
|
u256_to_i32(s1, s2, s3, s4),
|
||||||
|
0:i32, 0:i32, 0:i32, 0:i32, 0:i32
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function log1(
|
||||||
|
p1, p2, p3, p4, s1, s2, s3, s4,
|
||||||
|
t1_1, t1_2, t1_3, t1_4
|
||||||
|
) {
|
||||||
|
eth.log(
|
||||||
|
to_internal_i32ptr(p1, p2, p3, p4),
|
||||||
|
u256_to_i32(s1, s2, s3, s4),
|
||||||
|
1:i32,
|
||||||
|
to_internal_i32ptr(t1_1, t1_2, t1_3, t1_4),
|
||||||
|
0:i32, 0:i32, 0:i32
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function log2(
|
||||||
|
p1, p2, p3, p4, s1, s2, s3, s4,
|
||||||
|
t1_1, t1_2, t1_3, t1_4,
|
||||||
|
t2_1, t2_2, t2_3, t2_4
|
||||||
|
) {
|
||||||
|
eth.log(
|
||||||
|
to_internal_i32ptr(p1, p2, p3, p4),
|
||||||
|
u256_to_i32(s1, s2, s3, s4),
|
||||||
|
2:i32,
|
||||||
|
to_internal_i32ptr(t1_1, t1_2, t1_3, t1_4),
|
||||||
|
to_internal_i32ptr(t2_1, t2_2, t2_3, t2_4),
|
||||||
|
0:i32, 0:i32
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function log3(
|
||||||
|
p1, p2, p3, p4, s1, s2, s3, s4,
|
||||||
|
t1_1, t1_2, t1_3, t1_4,
|
||||||
|
t2_1, t2_2, t2_3, t2_4,
|
||||||
|
t3_1, t3_2, t3_3, t3_4
|
||||||
|
) {
|
||||||
|
eth.log(
|
||||||
|
to_internal_i32ptr(p1, p2, p3, p4),
|
||||||
|
u256_to_i32(s1, s2, s3, s4),
|
||||||
|
3:i32,
|
||||||
|
to_internal_i32ptr(t1_1, t1_2, t1_3, t1_4),
|
||||||
|
to_internal_i32ptr(t2_1, t2_2, t2_3, t2_4),
|
||||||
|
to_internal_i32ptr(t3_1, t3_2, t3_3, t3_4),
|
||||||
|
0:i32
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function log4(
|
||||||
|
p1, p2, p3, p4, s1, s2, s3, s4,
|
||||||
|
t1_1, t1_2, t1_3, t1_4,
|
||||||
|
t2_1, t2_2, t2_3, t2_4,
|
||||||
|
t3_1, t3_2, t3_3, t3_4,
|
||||||
|
t4_1, t4_2, t4_3, t4_4,
|
||||||
|
) {
|
||||||
|
eth.log(
|
||||||
|
to_internal_i32ptr(p1, p2, p3, p4),
|
||||||
|
u256_to_i32(s1, s2, s3, s4),
|
||||||
|
4:i32,
|
||||||
|
to_internal_i32ptr(t1_1, t1_2, t1_3, t1_4),
|
||||||
|
to_internal_i32ptr(t2_1, t2_2, t2_3, t2_4),
|
||||||
|
to_internal_i32ptr(t3_1, t3_2, t3_3, t3_4),
|
||||||
|
to_internal_i32ptr(t4_1, t4_2, t4_3, t4_4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function create(
|
||||||
|
x1, x2, x3, x4,
|
||||||
|
y1, y2, y3, y4,
|
||||||
|
z1, z2, z3, z4
|
||||||
|
) -> a1, a2, a3, a4 {
|
||||||
|
let v1, v2 := u256_to_u128(x1, x2, x3, x4)
|
||||||
|
mstore_internal(0:i32, 0, 0, v1, v2)
|
||||||
|
|
||||||
|
let r:i32 := eth.create(0:i32, to_internal_i32ptr(y1, y2, y3, y4), u256_to_i32(z1, z2, z3, z4), 32:i32)
|
||||||
|
if i32.eqz(r) {
|
||||||
|
a1, a2, a3, a4 := mload_internal(32:i32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function call(
|
||||||
|
a1, a2, a3, a4,
|
||||||
|
b1, b2, b3, b4,
|
||||||
|
c1, c2, c3, c4,
|
||||||
|
d1, d2, d3, d4,
|
||||||
|
e1, e2, e3, e4,
|
||||||
|
f1, f2, f3, f4,
|
||||||
|
g1, g2, g3, g4
|
||||||
|
) -> x1, x2, x3, x4 {
|
||||||
|
let g := u256_to_i64(a1, a2, a3, a4)
|
||||||
|
mstore_address(0:i32, b1, b2, b3, b4)
|
||||||
|
|
||||||
|
let v1, v2 := u256_to_u128(c1, c2, c3, c4)
|
||||||
|
mstore_internal(32:i32, 0, 0, v1, v2)
|
||||||
|
|
||||||
|
x4 := i64.extend_i32_u(eth.call(g, 12:i32, 32:i32, to_internal_i32ptr(d1, d2, d3, d4), u256_to_i32(e1, e2, e3, e4)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function callcode(
|
||||||
|
a1, a2, a3, a4,
|
||||||
|
b1, b2, b3, b4,
|
||||||
|
c1, c2, c3, c4,
|
||||||
|
d1, d2, d3, d4,
|
||||||
|
e1, e2, e3, e4,
|
||||||
|
f1, f2, f3, f4,
|
||||||
|
g1, g2, g3, g4
|
||||||
|
) -> x1, x2, x3, x4 {
|
||||||
|
mstore_address(0:i32, b1, b2, b3, b4)
|
||||||
|
|
||||||
|
let v1, v2 := u256_to_u128(c1, c2, c3, c4)
|
||||||
|
mstore_internal(32:i32, 0, 0, v1, v2)
|
||||||
|
|
||||||
|
x4 := i64.extend_i32_u(eth.callCode(
|
||||||
|
u256_to_i64(a1, a2, a3, a4),
|
||||||
|
12:i32,
|
||||||
|
32:i32,
|
||||||
|
to_internal_i32ptr(d1, d2, d3, d4),
|
||||||
|
u256_to_i32(e1, e2, e3, e4)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
function delegatecall(
|
||||||
|
a1, a2, a3, a4,
|
||||||
|
b1, b2, b3, b4,
|
||||||
|
c1, c2, c3, c4,
|
||||||
|
d1, d2, d3, d4,
|
||||||
|
e1, e2, e3, e4,
|
||||||
|
f1, f2, f3, f4
|
||||||
|
) -> x1, x2, x3, x4 {
|
||||||
|
mstore_address(0:i32, b1, b2, b3, b4)
|
||||||
|
|
||||||
|
x4 := i64.extend_i32_u(eth.callDelegate(
|
||||||
|
u256_to_i64(a1, a2, a3, a4),
|
||||||
|
12:i32,
|
||||||
|
to_internal_i32ptr(c1, c2, c3, c4),
|
||||||
|
u256_to_i32(d1, d2, d3, d4)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
function staticcall(
|
||||||
|
a1, a2, a3, a4,
|
||||||
|
b1, b2, b3, b4,
|
||||||
|
c1, c2, c3, c4,
|
||||||
|
d1, d2, d3, d4,
|
||||||
|
e1, e2, e3, e4,
|
||||||
|
f1, f2, f3, f4
|
||||||
|
) -> x1, x2, x3, x4 {
|
||||||
|
mstore_address(0:i32, b1, b2, b3, b4)
|
||||||
|
|
||||||
|
x4 := i64.extend_i32_u(eth.callStatic(
|
||||||
|
u256_to_i64(a1, a2, a3, a4),
|
||||||
|
12:i32,
|
||||||
|
to_internal_i32ptr(c1, c2, c3, c4),
|
||||||
|
u256_to_i32(d1, d2, d3, d4)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
function create2(
|
||||||
|
a1, a2, a3, a4,
|
||||||
|
b1, b2, b3, b4,
|
||||||
|
c1, c2, c3, c4,
|
||||||
|
d1, d2, d3, d4
|
||||||
|
) -> x1, x2, x3, x4 {
|
||||||
|
// TODO: not part of current Ewasm spec
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function selfdestruct(a1, a2, a3, a4) {
|
||||||
|
mstore_address(0:i32, a1, a2, a3, a4)
|
||||||
|
// In EVM, addresses are padded to 32 bytes, so discard the first 12.
|
||||||
|
eth.selfDestruct(12:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function return(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
eth.finish(
|
||||||
|
to_internal_i32ptr(x1, x2, x3, x4),
|
||||||
|
u256_to_i32(y1, y2, y3, y4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function revert(x1, x2, x3, x4, y1, y2, y3, y4) {
|
||||||
|
eth.revert(
|
||||||
|
to_internal_i32ptr(x1, x2, x3, x4),
|
||||||
|
u256_to_i32(y1, y2, y3, y4)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function invalid() {
|
||||||
|
unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
eth.finish(0:i32, 0:i32)
|
||||||
|
}
|
24
libyul/backends/wasm/polyfill/Keccak.yul
Normal file
24
libyul/backends/wasm/polyfill/Keccak.yul
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Keccak.h`.
|
||||||
|
|
||||||
|
function keccak256(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 {
|
||||||
|
// TODO implement
|
||||||
|
unreachable()
|
||||||
|
}
|
31
libyul/backends/wasm/polyfill/Logical.yul
Normal file
31
libyul/backends/wasm/polyfill/Logical.yul
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Logical.h`.
|
||||||
|
|
||||||
|
function or_bool(a, b, c, d) -> r:i32 {
|
||||||
|
r := i32.eqz(i64.eqz(i64.or(i64.or(a, b), i64.or(c, d))))
|
||||||
|
}
|
||||||
|
|
||||||
|
function or_bool_320(a, b, c, d, e) -> r:i32 {
|
||||||
|
r := i32.or(or_bool(a, b, c, 0), or_bool(d, e, 0, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
function or_bool_512(a, b, c, d, e, f, g, h) -> r:i32 {
|
||||||
|
r := i32.or(or_bool(a, b, c, d), or_bool(e, f, g, h))
|
||||||
|
}
|
62
libyul/backends/wasm/polyfill/Memory.yul
Normal file
62
libyul/backends/wasm/polyfill/Memory.yul
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
This file is part of solidity.
|
||||||
|
|
||||||
|
solidity is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
solidity is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
// NOTE: This file is used to generate `ewasmPolyfills/Memory.h`.
|
||||||
|
|
||||||
|
function save_temp_mem_32() -> t1, t2, t3, t4 {
|
||||||
|
t1 := i64.load(0:i32)
|
||||||
|
t2 := i64.load(8:i32)
|
||||||
|
t3 := i64.load(16:i32)
|
||||||
|
t4 := i64.load(24:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function restore_temp_mem_32(t1, t2, t3, t4) {
|
||||||
|
i64.store(0:i32, t1)
|
||||||
|
i64.store(8:i32, t2)
|
||||||
|
i64.store(16:i32, t3)
|
||||||
|
i64.store(24:i32, t4)
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_temp_mem_64() -> t1, t2, t3, t4, t5, t6, t7, t8 {
|
||||||
|
t1 := i64.load(0:i32)
|
||||||
|
t2 := i64.load(8:i32)
|
||||||
|
t3 := i64.load(16:i32)
|
||||||
|
t4 := i64.load(24:i32)
|
||||||
|
t5 := i64.load(32:i32)
|
||||||
|
t6 := i64.load(40:i32)
|
||||||
|
t7 := i64.load(48:i32)
|
||||||
|
t8 := i64.load(54:i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
function restore_temp_mem_64(t1, t2, t3, t4, t5, t6, t7, t8) {
|
||||||
|
i64.store(0:i32, t1)
|
||||||
|
i64.store(8:i32, t2)
|
||||||
|
i64.store(16:i32, t3)
|
||||||
|
i64.store(24:i32, t4)
|
||||||
|
i64.store(32:i32, t5)
|
||||||
|
i64.store(40:i32, t6)
|
||||||
|
i64.store(48:i32, t7)
|
||||||
|
i64.store(54:i32, t8)
|
||||||
|
}
|
||||||
|
|
||||||
|
function pop(x1, x2, x3, x4) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function memoryguard(x:i64) -> y1, y2, y3, y4 {
|
||||||
|
y4 := x
|
||||||
|
}
|
@ -43,7 +43,7 @@ object "object" {
|
|||||||
x_7 := x_11
|
x_7 := x_11
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let _5, _6, _7, _8 := iszero_170_789(_1, _1, _1, lt_172(x_4, x_5, x_6, x_7, _1, _1, _1, 10))
|
let _5, _6, _7, _8 := iszero_169_788(_1, _1, _1, lt_171(x_4, x_5, x_6, x_7, _1, _1, _1, 10))
|
||||||
if i32.eqz(i64.eqz(i64.or(i64.or(_5, _6), i64.or(_7, _8)))) { break }
|
if i32.eqz(i64.eqz(i64.or(i64.or(_5, _6), i64.or(_7, _8)))) { break }
|
||||||
if i32.eqz(i64.eqz(i64.or(_3, i64.or(_1, eq(x_4, x_5, x_6, x_7, _1, _1, _1, 2))))) { break }
|
if i32.eqz(i64.eqz(i64.or(_3, i64.or(_1, eq(x_4, x_5, x_6, x_7, _1, _1, _1, 2))))) { break }
|
||||||
if i32.eqz(i64.eqz(i64.or(_3, i64.or(_1, eq(x_4, x_5, x_6, x_7, _1, _1, _1, 4))))) { continue }
|
if i32.eqz(i64.eqz(i64.or(_3, i64.or(_1, eq(x_4, x_5, x_6, x_7, _1, _1, _1, 4))))) { continue }
|
||||||
@ -67,7 +67,7 @@ object "object" {
|
|||||||
let r1_1, carry_2 := add_carry(x1, y1, carry_1)
|
let r1_1, carry_2 := add_carry(x1, y1, carry_1)
|
||||||
r1 := r1_1
|
r1 := r1_1
|
||||||
}
|
}
|
||||||
function iszero_170_789(x1, x2, x3, x4) -> r1, r2, r3, r4
|
function iszero_169_788(x1, x2, x3, x4) -> r1, r2, r3, r4
|
||||||
{
|
{
|
||||||
r4 := i64.extend_i32_u(i64.eqz(i64.or(i64.or(x1, x2), i64.or(x3, x4))))
|
r4 := i64.extend_i32_u(i64.eqz(i64.or(i64.or(x1, x2), i64.or(x3, x4))))
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ object "object" {
|
|||||||
case 1:i32 { r := 0xffffffff:i32 }
|
case 1:i32 { r := 0xffffffff:i32 }
|
||||||
default { r := i64.ne(a, b) }
|
default { r := i64.ne(a, b) }
|
||||||
}
|
}
|
||||||
function lt_172(x1, x2, x3, x4, y1, y2, y3, y4) -> z4
|
function lt_171(x1, x2, x3, x4, y1, y2, y3, y4) -> z4
|
||||||
{
|
{
|
||||||
let z:i32 := false
|
let z:i32 := false
|
||||||
switch cmp(x1, y1)
|
switch cmp(x1, y1)
|
||||||
@ -106,20 +106,6 @@ object "object" {
|
|||||||
default { z := 1:i32 }
|
default { z := 1:i32 }
|
||||||
z4 := i64.extend_i32_u(z)
|
z4 := i64.extend_i32_u(z)
|
||||||
}
|
}
|
||||||
function calldataload(x1, x2, x3, x4) -> z1, z2, z3, z4
|
|
||||||
{
|
|
||||||
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { unreachable() }
|
|
||||||
if i64.ne(0, i64.shr_u(x4, 32)) { unreachable() }
|
|
||||||
eth.callDataCopy(0:i32, i32.wrap_i64(x4), 32:i32)
|
|
||||||
let z1_1 := endian_swap(i64.load(0:i32))
|
|
||||||
let z2_1 := endian_swap(i64.load(i32.add(0:i32, 8:i32)))
|
|
||||||
let z3_1 := endian_swap(i64.load(i32.add(0:i32, 16:i32)))
|
|
||||||
let z4_1 := endian_swap(i64.load(i32.add(0:i32, 24:i32)))
|
|
||||||
z1 := z1_1
|
|
||||||
z2 := z2_1
|
|
||||||
z3 := z3_1
|
|
||||||
z4 := z4_1
|
|
||||||
}
|
|
||||||
function endian_swap_16(x) -> y
|
function endian_swap_16(x) -> y
|
||||||
{
|
{
|
||||||
y := i64.or(i64.and(i64.shl(x, 8), 0xff00), i64.and(i64.shr_u(x, 8), 0xff))
|
y := i64.or(i64.and(i64.shl(x, 8), 0xff00), i64.and(i64.shr_u(x, 8), 0xff))
|
||||||
@ -134,6 +120,20 @@ object "object" {
|
|||||||
let hi := i64.shl(endian_swap_32(x), 32)
|
let hi := i64.shl(endian_swap_32(x), 32)
|
||||||
y := i64.or(hi, endian_swap_32(i64.shr_u(x, 32)))
|
y := i64.or(hi, endian_swap_32(i64.shr_u(x, 32)))
|
||||||
}
|
}
|
||||||
|
function calldataload(x1, x2, x3, x4) -> z1, z2, z3, z4
|
||||||
|
{
|
||||||
|
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { unreachable() }
|
||||||
|
if i64.ne(0, i64.shr_u(x4, 32)) { unreachable() }
|
||||||
|
eth.callDataCopy(0:i32, i32.wrap_i64(x4), 32:i32)
|
||||||
|
let z1_1 := endian_swap(i64.load(0:i32))
|
||||||
|
let z2_1 := endian_swap(i64.load(i32.add(0:i32, 8:i32)))
|
||||||
|
let z3_1 := endian_swap(i64.load(i32.add(0:i32, 16:i32)))
|
||||||
|
let z4_1 := endian_swap(i64.load(i32.add(0:i32, 24:i32)))
|
||||||
|
z1 := z1_1
|
||||||
|
z2 := z2_1
|
||||||
|
z3 := z3_1
|
||||||
|
z4 := z4_1
|
||||||
|
}
|
||||||
function mstore_internal(pos:i32, y1, y2, y3, y4)
|
function mstore_internal(pos:i32, y1, y2, y3, y4)
|
||||||
{
|
{
|
||||||
i64.store(pos, endian_swap(y1))
|
i64.store(pos, endian_swap(y1))
|
||||||
@ -152,7 +152,7 @@ object "object" {
|
|||||||
|
|
||||||
|
|
||||||
Binary representation:
|
Binary representation:
|
||||||
0061736d0100000001480a60000060017e017e60027e7e017f60037e7e7e017e60047e7e7e7e017e60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60057f7e7e7e7e0060027f7f0060037f7f7f0002310208657468657265756d0c73746f7261676553746f7265000808657468657265756d0c63616c6c44617461436f70790009030e0d0003060406020604010101070505030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00020af0070da302030b7e017f087e02404200210002402000200020002000100921012300210223012103230221040b20012105200221062003210720042108420121092000200084210a200a200020098484504545210b02400340200b45450d01024002402000200020002005200620072008200020002000420a10081005210c2300210d2301210e2302210f0b200c200d84200e200f8484504504400c030b200a20002005200620072008200020002000420210068484504504400c030b200a20002005200620072008200020002000420410068484504504400c010b0b024020052006200720082000200020002009100421102300211123012112230221130b201021052011210620122107201321080c000b0b20002000200020002005200620072008100e0b0b2901037e0240200020017c2105200520027c21032005200054200320055472ad21040b2004240020030b6c010b7e0240200320077c210c200c42007c210b024020022006200c200354200b200c5472ad1003210d2300210e0b200d210a024020012005200e1003210f230021100b200f2109024020002004201010032111230021120b201121080b20092400200a2401200b240220080b2401047e0240200020018420022003848450ad21070b20052400200624012007240220040b2d01017e024020002004510440200120055104402002200651044020032007510440420121080b0b0b0b0b20080b2701027f024002402000200154210320034101460440417f210205200020015221020b0b0b20020b8a0102017e047f0240410021090240200020041007210a200a41004604400240200120051007210b200b41004604400240200220061007210c200c41004604402003200754210905200c41014604404100210905410121090b0b0b05200b41014604404100210905410121090b0b0b05200a41014604404100210905410121090b0b0b2009ad21080b20080b7601087e024042002000200184200284520440000b42002003422088520440000b41002003a7412010014100290000100c2108410041086a290000100c2109410041106a290000100c210a410041186a290000100c210b2008210420092105200a2106200b21070b20052400200624012007240220040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100a421086210220022000421088100a8421010b20010b1e01027e02402000100b422086210220022000422088100b8421010b20010b3200024020002001100c370000200041086a2002100c370000200041106a2003100c370000200041186a2004100c3700000b0b2300024041002000200120022003100d41202004200520062007100d4100412010000b0b
|
0061736d0100000001480a60000060017e017e60027e7e017f60037e7e7e017e60047e7e7e7e017e60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60057f7e7e7e7e0060027f7f0060037f7f7f0002310208657468657265756d0c73746f7261676553746f7265000808657468657265756d0c63616c6c44617461436f70790009030e0d0003060406020601010104070505030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00020af0070da302030b7e017f087e02404200210002402000200020002000100c21012300210223012103230221040b20012105200221062003210720042108420121092000200084210a200a200020098484504545210b02400340200b45450d01024002402000200020002005200620072008200020002000420a10081005210c2300210d2301210e2302210f0b200c200d84200e200f8484504504400c030b200a20002005200620072008200020002000420210068484504504400c030b200a20002005200620072008200020002000420410068484504504400c010b0b024020052006200720082000200020002009100421102300211123012112230221130b201021052011210620122107201321080c000b0b20002000200020002005200620072008100e0b0b2901037e0240200020017c2105200520027c21032005200054200320055472ad21040b2004240020030b6c010b7e0240200320077c210c200c42007c210b024020022006200c200354200b200c5472ad1003210d2300210e0b200d210a024020012005200e1003210f230021100b200f2109024020002004201010032111230021120b201121080b20092400200a2401200b240220080b2401047e0240200020018420022003848450ad21070b20052400200624012007240220040b2d01017e024020002004510440200120055104402002200651044020032007510440420121080b0b0b0b0b20080b2701027f024002402000200154210320034101460440417f210205200020015221020b0b0b20020b8a0102017e047f0240410021090240200020041007210a200a41004604400240200120051007210b200b41004604400240200220061007210c200c41004604402003200754210905200c41014604404100210905410121090b0b0b05200b41014604404100210905410121090b0b0b05200a41014604404100210905410121090b0b0b2009ad21080b20080b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100942108621022002200042108810098421010b20010b1e01027e02402000100a422086210220022000422088100a8421010b20010b7601087e024042002000200184200284520440000b42002003422088520440000b41002003a7412010014100290000100b2108410041086a290000100b2109410041106a290000100b210a410041186a290000100b210b2008210420092105200a2106200b21070b20052400200624012007240220040b3200024020002001100b370000200041086a2002100b370000200041106a2003100b370000200041186a2004100b3700000b0b2300024041002000200120022003100d41202004200520062007100d4100412010000b0b
|
||||||
|
|
||||||
Text representation:
|
Text representation:
|
||||||
(module
|
(module
|
||||||
@ -206,7 +206,7 @@ Text representation:
|
|||||||
(br_if $label__3 (i32.eqz (i32.eqz (local.get $_4))))
|
(br_if $label__3 (i32.eqz (i32.eqz (local.get $_4))))
|
||||||
(block $label__4
|
(block $label__4
|
||||||
(block
|
(block
|
||||||
(local.set $_5 (call $iszero_170_789 (local.get $_1) (local.get $_1) (local.get $_1) (call $lt_172 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 10))))
|
(local.set $_5 (call $iszero_169_788 (local.get $_1) (local.get $_1) (local.get $_1) (call $lt_171 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 10))))
|
||||||
(local.set $_6 (global.get $global_))
|
(local.set $_6 (global.get $global_))
|
||||||
(local.set $_7 (global.get $global__1))
|
(local.set $_7 (global.get $global__1))
|
||||||
(local.set $_8 (global.get $global__2))
|
(local.set $_8 (global.get $global__2))
|
||||||
@ -310,7 +310,7 @@ Text representation:
|
|||||||
(local.get $r1)
|
(local.get $r1)
|
||||||
)
|
)
|
||||||
|
|
||||||
(func $iszero_170_789
|
(func $iszero_169_788
|
||||||
(param $x1 i64)
|
(param $x1 i64)
|
||||||
(param $x2 i64)
|
(param $x2 i64)
|
||||||
(param $x3 i64)
|
(param $x3 i64)
|
||||||
@ -377,7 +377,7 @@ Text representation:
|
|||||||
(local.get $r)
|
(local.get $r)
|
||||||
)
|
)
|
||||||
|
|
||||||
(func $lt_172
|
(func $lt_171
|
||||||
(param $x1 i64)
|
(param $x1 i64)
|
||||||
(param $x2 i64)
|
(param $x2 i64)
|
||||||
(param $x3 i64)
|
(param $x3 i64)
|
||||||
@ -437,6 +437,43 @@ Text representation:
|
|||||||
(local.get $z4)
|
(local.get $z4)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(func $endian_swap_16
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(block $label__15
|
||||||
|
(local.set $y (i64.or (i64.and (i64.shl (local.get $x) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $x) (i64.const 8)) (i64.const 255))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func $endian_swap_32
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(local $hi i64)
|
||||||
|
(block $label__16
|
||||||
|
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $x)) (i64.const 16)))
|
||||||
|
(local.set $y (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $x) (i64.const 16)))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func $endian_swap
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(local $hi i64)
|
||||||
|
(block $label__17
|
||||||
|
(local.set $hi (i64.shl (call $endian_swap_32 (local.get $x)) (i64.const 32)))
|
||||||
|
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $x) (i64.const 32)))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
(func $calldataload
|
(func $calldataload
|
||||||
(param $x1 i64)
|
(param $x1 i64)
|
||||||
(param $x2 i64)
|
(param $x2 i64)
|
||||||
@ -451,7 +488,7 @@ Text representation:
|
|||||||
(local $z2_1 i64)
|
(local $z2_1 i64)
|
||||||
(local $z3_1 i64)
|
(local $z3_1 i64)
|
||||||
(local $z4_1 i64)
|
(local $z4_1 i64)
|
||||||
(block $label__15
|
(block $label__18
|
||||||
(if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then
|
(if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then
|
||||||
(unreachable)))
|
(unreachable)))
|
||||||
(if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then
|
(if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then
|
||||||
@ -473,43 +510,6 @@ Text representation:
|
|||||||
(local.get $z1)
|
(local.get $z1)
|
||||||
)
|
)
|
||||||
|
|
||||||
(func $endian_swap_16
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(block $label__16
|
|
||||||
(local.set $y (i64.or (i64.and (i64.shl (local.get $x) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $x) (i64.const 8)) (i64.const 255))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $endian_swap_32
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(local $hi i64)
|
|
||||||
(block $label__17
|
|
||||||
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $x)) (i64.const 16)))
|
|
||||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $x) (i64.const 16)))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $endian_swap
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(local $hi i64)
|
|
||||||
(block $label__18
|
|
||||||
(local.set $hi (i64.shl (call $endian_swap_32 (local.get $x)) (i64.const 32)))
|
|
||||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $x) (i64.const 32)))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $mstore_internal
|
(func $mstore_internal
|
||||||
(param $pos i32)
|
(param $pos i32)
|
||||||
(param $y1 i64)
|
(param $y1 i64)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d01000000013a0860000060017e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e00600c7e7e7e7e7e7e7e7e7e7e7e7e0060017f0060027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000708657468657265756d06726576657274000608657468657265756d0c67657443616c6c56616c7565000508657468657265756d0666696e6973680006030a090002020401010103030503010001060100071102066d656d6f72790200046d61696e0004009d030c435f325f6465706c6f7965640061736d0100000001160460000060017e017e60047e7e7e7e017f60027f7f0002130108657468657265756d067265766572740003030504000201010503010001060100071102066d656d6f72790200046d61696e00010ab60204ca0104017e027f057e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b20001003421086210320032000421088100384422086210420042000422088100484210520022005370000200241086a2005370000200241106a20053700004280011003421086210620064280014210881003844220862107200241186a2007428001422088100484370000200020002000200010022108200020002000200010022109200941c0006a210a200a2009490440000b200a200810000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100342108621022002200042108810038421010b20010b0aec0309dc0103017e027f057e02404200210020002000200042c00010052101200141c0006a210220022001490440000b2000100a210320022003370000200241086a2003370000200241106a2003370000200241186a428001100a370000410010024100290000100a2104410041086a290000100a2105410041106a290000100a210620042005842006410041186a290000100a84845045044020002000200020002000200020002000100c0b4290032107200020002000200020002000200042ce012000200020002007100720002000200020002000200020002007100b0b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310052105200541c0006a210420042005490440000b0b20040b25000240200020012002200310062004200520062007100520082009200a200b100510000b0b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100842108621022002200042108810088421010b20010b1e01027e02402000100942208621022002200042208810098421010b20010b1b000240200020012002200310062004200520062007100510030b0b1b000240200020012002200310062004200520062007100510010b0b","wast":"(module
|
{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d01000000013a0860000060017e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e00600c7e7e7e7e7e7e7e7e7e7e7e7e0060017f0060027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000708657468657265756d06726576657274000608657468657265756d0c67657443616c6c56616c7565000508657468657265756d0666696e6973680006030a090002020101010403030503010001060100071102066d656d6f72790200046d61696e0004009d030c435f325f6465706c6f7965640061736d0100000001160460000060017e017e60047e7e7e7e017f60027f7f0002130108657468657265756d067265766572740003030504000201010503010001060100071102066d656d6f72790200046d61696e00010ab60204ca0104017e027f057e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b20001003421086210320032000421088100384422086210420042000422088100484210520022005370000200241086a2005370000200241106a20053700004280011003421086210620064280014210881003844220862107200241186a2007428001422088100484370000200020002000200010022108200020002000200010022109200941c0006a210a200a2009490440000b200a200810000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100342108621022002200042108810038421010b20010b0aec0309dc0103017e027f057e02404200210020002000200042c00010052101200141c0006a210220022001490440000b20001009210320022003370000200241086a2003370000200241106a2003370000200241186a428001100937000041001002410029000010092104410041086a29000010092105410041106a2900001009210620042005842006410041186a290000100984845045044020002000200020002000200020002000100c0b4290032107200020002000200020002000200042ce012000200020002007100a20002000200020002000200020002007100b0b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310052105200541c0006a210420042005490440000b0b20040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100742108621022002200042108810078421010b20010b1e01027e02402000100842208621022002200042208810088421010b20010b25000240200020012002200310062004200520062007100520082009200a200b100510000b0b1b000240200020012002200310062004200520062007100510030b0b1b000240200020012002200310062004200520062007100510010b0b","wast":"(module
|
||||||
;; custom section for sub-module
|
;; custom section for sub-module
|
||||||
;; The Keccak-256 hash of the text representation of \"C_2_deployed\": f03f5b9154b9eb6803a947177e38e92e2860de95e90ba0e75eb71a58f18ed589
|
;; The Keccak-256 hash of the text representation of \"C_2_deployed\": f03f5b9154b9eb6803a947177e38e92e2860de95e90ba0e75eb71a58f18ed589
|
||||||
;; (@custom \"C_2_deployed\" \"0061736d0100000001160460000060017e017e60047e7e7e7e017f60027f7f0002130108657468657265756d067265766572740003030504000201010503010001060100071102066d656d6f72790200046d61696e00010ab60204ca0104017e027f057e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b20001003421086210320032000421088100384422086210420042000422088100484210520022005370000200241086a2005370000200241106a20053700004280011003421086210620064280014210881003844220862107200241186a2007428001422088100484370000200020002000200010022108200020002000200010022109200941c0006a210a200a2009490440000b200a200810000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100342108621022002200042108810038421010b20010b\")
|
;; (@custom \"C_2_deployed\" \"0061736d0100000001160460000060017e017e60047e7e7e7e017f60027f7f0002130108657468657265756d067265766572740003030504000201010503010001060100071102066d656d6f72790200046d61696e00010ab60204ca0104017e027f057e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b20001003421086210320032000421088100384422086210420042000422088100484210520022005370000200241086a2005370000200241106a20053700004280011003421086210620064280014210881003844220862107200241186a2007428001422088100484370000200020002000200010022108200020002000200010022109200941c0006a210a200a2009490440000b200a200810000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017e024020004208864280fe0383200042088842ff01838421010b20010b1e01027e02402000100342108621022002200042108810038421010b20010b\")
|
||||||
@ -77,6 +77,43 @@
|
|||||||
(local.get $r)
|
(local.get $r)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(func $endian_swap_16
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(block $label__3
|
||||||
|
(local.set $y (i64.or (i64.and (i64.shl (local.get $x) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $x) (i64.const 8)) (i64.const 255))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func $endian_swap_32
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(local $hi i64)
|
||||||
|
(block $label__4
|
||||||
|
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $x)) (i64.const 16)))
|
||||||
|
(local.set $y (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $x) (i64.const 16)))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
|
(func $endian_swap
|
||||||
|
(param $x i64)
|
||||||
|
(result i64)
|
||||||
|
(local $y i64)
|
||||||
|
(local $hi i64)
|
||||||
|
(block $label__5
|
||||||
|
(local.set $hi (i64.shl (call $endian_swap_32 (local.get $x)) (i64.const 32)))
|
||||||
|
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $x) (i64.const 32)))))
|
||||||
|
|
||||||
|
)
|
||||||
|
(local.get $y)
|
||||||
|
)
|
||||||
|
|
||||||
(func $codecopy
|
(func $codecopy
|
||||||
(param $x1 i64)
|
(param $x1 i64)
|
||||||
(param $x2 i64)
|
(param $x2 i64)
|
||||||
@ -90,48 +127,11 @@
|
|||||||
(param $z2 i64)
|
(param $z2 i64)
|
||||||
(param $z3 i64)
|
(param $z3 i64)
|
||||||
(param $z4 i64)
|
(param $z4 i64)
|
||||||
(block $label__3
|
(block $label__6
|
||||||
(call $eth.codeCopy (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) (call $u256_to_i32 (local.get $z1) (local.get $z2) (local.get $z3) (local.get $z4)))
|
(call $eth.codeCopy (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) (call $u256_to_i32 (local.get $z1) (local.get $z2) (local.get $z3) (local.get $z4)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
(func $endian_swap_16
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(block $label__4
|
|
||||||
(local.set $y (i64.or (i64.and (i64.shl (local.get $x) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $x) (i64.const 8)) (i64.const 255))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $endian_swap_32
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(local $hi i64)
|
|
||||||
(block $label__5
|
|
||||||
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $x)) (i64.const 16)))
|
|
||||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $x) (i64.const 16)))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $endian_swap
|
|
||||||
(param $x i64)
|
|
||||||
(result i64)
|
|
||||||
(local $y i64)
|
|
||||||
(local $hi i64)
|
|
||||||
(block $label__6
|
|
||||||
(local.set $hi (i64.shl (call $endian_swap_32 (local.get $x)) (i64.const 32)))
|
|
||||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $x) (i64.const 32)))))
|
|
||||||
|
|
||||||
)
|
|
||||||
(local.get $y)
|
|
||||||
)
|
|
||||||
|
|
||||||
(func $return
|
(func $return
|
||||||
(param $x1 i64)
|
(param $x1 i64)
|
||||||
(param $x2 i64)
|
(param $x2 i64)
|
||||||
|
Loading…
Reference in New Issue
Block a user