Created
May 19, 2020 21:20
-
-
Save loredanacirstea/1589c00d473e025df7a0ccb72172d5d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==== original source ==== | |
object "TestWasm9" { | |
code { | |
let _calldata := 96 | |
calldatacopy(_calldata, 0, calldatasize()) | |
let addr := mslice(_calldata, 20) | |
let input_ptr := add(_calldata, 20) | |
// callStatic | |
let success := staticcall(gas(), addr, input_ptr, 4, 0, 0) | |
mstore(0, success) | |
return (0, 32) | |
function mslice(position, length) -> result { | |
if gt(length, 32) { revert(0, 0) } | |
result := div(mload(position), exp(2, sub(256, mul(length, 8)))) | |
} | |
} | |
} | |
======= ./tests/contracts/c9.yul (Ewasm) ======= | |
Pretty printed source: | |
object "TestWasm9" { | |
code { | |
{ | |
calldatacopy(96, 0, calldatasize()) | |
mstore(0, staticcall(gas(), div(mload(96), 0x01000000000000000000000000), 116, 4, 0, 0)) | |
return(0, 32) | |
} | |
} | |
} | |
========================== | |
Translated source: | |
object "TestWasm9" { | |
code { | |
function main() | |
{ | |
let _1 := i64.extend_i32_u(eth.getCallDataSize()) | |
let _2 := 0 | |
let _3:i32 := u256_to_i32(_2, _2, _2, _1) | |
let _4:i32 := u256_to_i32(_2, _2, _2, _2) | |
let p:i32 := u256_to_i32(_2, _2, _2, 96) | |
let r:i32 := i32.add(p, 64:i32) | |
if i32.lt_u(r, p) { unreachable() } | |
eth.callDataCopy(r, _4, _3) | |
let p_1:i32 := u256_to_i32(_2, _2, _2, 96) | |
let r_1:i32 := i32.add(p_1, 64:i32) | |
if i32.lt_u(r_1, p_1) { unreachable() } | |
let z1 := endian_swap(i64.load(r_1)) | |
let z2 := endian_swap(i64.load(i32.add(r_1, 8:i32))) | |
let z3 := endian_swap(i64.load(i32.add(r_1, 16:i32))) | |
let _5, _6, _7, _8 := div(z1, z2, z3, endian_swap(i64.load(i32.add(r_1, 24:i32))), _2, _2, 4294967296, _2) | |
let z4 := eth.getGasLeft() | |
mstore_address(0:i32, _5, _6, _7, _8) | |
mstore(_2, _2, _2, _2, _2, _2, _2, i64.extend_i32_u(eth.callStatic(u256_to_i64(_2, _2, _2, z4), 12:i32, to_internal_i32ptr(_2, _2, _2, 116), u256_to_i32(_2, _2, _2, 4)))) | |
return(_2, _2, _2, _2, _2, _2, _2, 32) | |
} | |
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 t := i64.add(x4, y4) | |
r4 := i64.add(t, 0) | |
let r3_1, carry := add_carry(x3, y3, i64.extend_i32_u(i32.or(i64.lt_u(t, x4), i64.lt_u(r4, t)))) | |
r3 := r3_1 | |
let r2_1, carry_1 := add_carry(x2, y2, carry) | |
r2 := r2_1 | |
let r1_1, carry_2 := add_carry(x1, y1, carry_1) | |
r1 := r1_1 | |
} | |
function sub(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 | |
{ | |
let _1 := 0xffffffffffffffff | |
let t := i64.add(x4, i64.xor(y4, _1)) | |
r4 := i64.add(t, 1) | |
let r3_1, carry := add_carry(x3, i64.xor(y3, _1), i64.extend_i32_u(i32.or(i64.lt_u(t, x4), i64.lt_u(r4, t)))) | |
r3 := r3_1 | |
let r2_1, carry_1 := add_carry(x2, i64.xor(y2, _1), carry) | |
r2 := r2_1 | |
let r1_1, carry_2 := add_carry(x1, i64.xor(y1, _1), carry_1) | |
r1 := r1_1 | |
} | |
function shl_internal(amount, x1, x2, x3, x4) -> r1, r2, r3, r4 | |
{ | |
let _1 := i64.sub(64, amount) | |
r1 := i64.add(i64.shl(x1, amount), i64.shr_u(x2, _1)) | |
r2 := i64.add(i64.shl(x2, amount), i64.shr_u(x3, _1)) | |
r3 := i64.add(i64.shl(x3, amount), i64.shr_u(x4, _1)) | |
r4 := i64.shl(x4, amount) | |
} | |
function shr_internal(amount, x1, x2, x3, x4) -> r1, r2, r3, r4 | |
{ | |
let _1 := i64.sub(64, amount) | |
r4 := i64.add(i64.shr_u(x4, amount), i64.shl(x3, _1)) | |
r3 := i64.add(i64.shr_u(x3, amount), i64.shl(x2, _1)) | |
r2 := i64.add(i64.shr_u(x2, amount), i64.shl(x1, _1)) | |
r1 := i64.shr_u(x1, amount) | |
} | |
function div(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 | |
{ | |
if i64.eqz(i64.or(i64.or(y1, y2), i64.or(y3, y4))) { leave } | |
let m1 := 0 | |
let m2 := m1 | |
let m3 := m1 | |
let m4 := 1 | |
for { } true { } | |
{ | |
if i32.or(i64.eqz(i64.clz(y1)), i32.eqz(lt_256x256_64(y1, y2, y3, y4, x1, x2, x3, x4))) { break } | |
let y1_1, y2_1, y3_1, y4_1 := shl_internal(1, y1, y2, y3, y4) | |
y1 := y1_1 | |
y2 := y2_1 | |
y3 := y3_1 | |
y4 := y4_1 | |
let m1_1, m2_1, m3_1, m4_1 := shl_internal(1, m1, m2, m3, m4) | |
m1 := m1_1 | |
m2 := m2_1 | |
m3 := m3_1 | |
m4 := m4_1 | |
} | |
for { } | |
i32.eqz(i64.eqz(i64.or(i64.or(m1, m2), i64.or(m3, m4)))) | |
{ } | |
{ | |
if i32.eqz(lt_256x256_64(x1, x2, x3, x4, y1, y2, y3, y4)) | |
{ | |
let x1_1, x2_1, x3_1, x4_1 := sub(x1, x2, x3, x4, y1, y2, y3, y4) | |
x1 := x1_1 | |
x2 := x2_1 | |
x3 := x3_1 | |
x4 := x4_1 | |
let r1_1, r2_1, r3_1, r4_1 := add(r1, r2, r3, r4, m1, m2, m3, m4) | |
r1 := r1_1 | |
r2 := r2_1 | |
r3 := r3_1 | |
r4 := r4_1 | |
} | |
let y1_2, y2_2, y3_2, y4_2 := shr_internal(1, y1, y2, y3, y4) | |
y1 := y1_2 | |
y2 := y2_2 | |
y3 := y3_2 | |
y4 := y4_2 | |
let m1_2, m2_2, m3_2, m4_2 := shr_internal(1, m1, m2, m3, m4) | |
m1 := m1_2 | |
m2 := m2_2 | |
m3 := m3_2 | |
m4 := m4_2 | |
} | |
} | |
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_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 u256_to_i64(x1, x2, x3, x4) -> v | |
{ | |
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { unreachable() } | |
v := x4 | |
} | |
function u256_to_i32(x1, x2, x3, x4) -> v:i32 | |
{ | |
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { unreachable() } | |
if i64.ne(0, i64.shr_u(x4, 32)) { unreachable() } | |
v := i32.wrap_i64(x4) | |
} | |
function to_internal_i32ptr(x1, x2, x3, x4) -> r:i32 | |
{ | |
let p:i32 := u256_to_i32(x1, x2, x3, x4) | |
r := i32.add(p, 64:i32) | |
if i32.lt_u(r, p) { unreachable() } | |
} | |
function endian_swap_16(x) -> y | |
{ | |
y := i64.or(i64.and(i64.shl(x, 8), 0xff00), i64.and(i64.shr_u(x, 8), 0xff)) | |
} | |
function endian_swap_32(x) -> y | |
{ | |
let hi := i64.shl(endian_swap_16(x), 16) | |
y := i64.or(hi, endian_swap_16(i64.shr_u(x, 16))) | |
} | |
function endian_swap(x) -> y | |
{ | |
let hi := i64.shl(endian_swap_32(x), 32) | |
y := i64.or(hi, endian_swap_32(i64.shr_u(x, 32))) | |
} | |
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) | |
{ | |
if i64.ne(0, a1) { unreachable() } | |
if i64.ne(0, i64.shr_u(a2, 32)) { unreachable() } | |
mstore_internal(pos, 0, a2, a3, a4) | |
} | |
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)) | |
} | |
} | |
} | |
Binary representation: | |
0061736d0100000001610e6000006000017e6000017f60017e017e60027e7e017e60037e7e7e017e60047e7e7e7e017e60057e7e7e7e7e0060057e7e7e7e7e017e60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60047e7f7f7f017f60027f7f0060037f7f7f0002720508657468657265756d0f67657443616c6c4461746153697a65000208657468657265756d0a63616c6c537461746963000b08657468657265756d0a6765744761734c656674000108657468657265756d0666696e697368000c08657468657265756d0c63616c6c44617461436f7079000d03141300050a0a08080a040a0606060303030907070905030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00050ac30d13b80201107e1000ada7ad2100420021012001200120012000100f21022001200120012001100f210320012001200142e000100f21042004a742c000a76aad21052005a72004a749ad4200520440000b2005a72003a72002a7100420012001200142e000100f21062006a742c000a76aad21072007a72006a749ad4200520440000b2007a7290300101321082007a74208a76aada7290300101321092007a74210a76aada72903001013210a024020082009200a2007a74218a76aada72903001013200120014280808080102001100b210b2300210c2301210d2302210e0b1002210f4200200b200c200d200e10162001200120012001200120012001200120012001200f100e420ca720012001200142f4001010a72001200120014204100fa71001ada7ad10142001200120012001200120012001422010170b2c01037e200020017c2105200520027c21032005200054ada72003200554ada772ada7ad21042004240020030b6f010b7e200320077c210c200c42007c210b024020022006200c200354ada7200b200c54ada772ada7ad1006210d2300210e0b200d210a024020012005200e1006210f230021100b200f2109024020002004201010062111230021120b2011210820092400200a2401200b240220080b7f010c7e427f210c20032007200c857c210d200d42017c210b024020022006200c85200d200354ada7200b200d54ada772ada7ad1006210e2300210f0b200e210a024020012005200c85200f10062110230021110b20102109024020002004200c85201110062112230021130b2012210820092400200a2401200b240220080b4801057e42c00020007d2109200120008620022009887c2105200220008620032009887c2106200320008620042009887c21072004200086210820062400200724012008240220050b4801057e42c00020007d2109200420008820032009867c2108200320008820022009867c2107200220008820012009867c21062001200088210520062400200724012008240220050bbb0301207e200420058420062007848450ad42005204400f0b4200210c200c210d200c210e4201210f024003404201500d01024020047950ada720042005200620072000200120022003100da745ada772ad42005204400c030b024042012004200520062007100921102300211123012112230221130b2010210420112105201221062013210702404201200c200d200e200f100921142300211523012116230221170b2014210c2015210d2016210e2017210f0b0b0b02400340200c200d84200e200f848450ada745ad500d01024020002001200220032004200520062007100da745ad420052044002402000200120022003200420052006200710082118230021192301211a2302211b0b2018210020192101201a2102201b2103024020082009200a200b200c200d200e200f1007211c2300211d2301211e2302211f0b201c2108201d2109201e210a201f210b0b024042012004200520062007100a21202300212123012122230221230b2020210420212105202221062023210702404201200c200d200e200f100a21242300212523012126230221270b2024210c2025210d2026210e2027210f0b0b0b20092400200a2401200b240220080b2a01027e02402000200154ad21032003420151044042ffffffff0f2102052000200152ad21020b0b20020b7d01047e024020002004100c210920094200510440024020012005100c210a200a4200510440024020022006100c210b200b42005104402003200754ad210805200b42015104404200210805420121080b0b0b05200a42015104404200210805420121080b0b0b05200942015104404200210805420121080b0b0b20080b1d01017e4200200020018420028452ad4200520440000b2003210420040b2f01017e4200200020018420028452ad4200520440000b4200200342208852ad4200520440000b2003a7ad210420040b2c01027e2000200120022003100f21052005a742c000a76aad21042004a72005a749ad4200520440000b20040b1c01017e20004208864280fe0383200042088842ff018384210120010b1b01027e20001011421086210220022000421088101184210120010b1b01027e20001012422086210220022000422088101284210120010b1801007e20002001200220031010200420052006200710150b3e01007e2000a7200110133703002000a74208a76aada7200210133703002000a74210a76aada7200310133703002000a74218a76aada7200410133703000b2d01007e4200200152ad4200520440000b4200200242208852ad4200520440000b2000420020022003200410150b1c01007e20002001200220031010a72004200520062007100fa710030b | |
Text representation: | |
(module | |
(import "ethereum" "getCallDataSize" (func $eth.getCallDataSize (result i32))) | |
(import "ethereum" "callStatic" (func $eth.callStatic (param i64 i32 i32 i32) (result i32))) | |
(import "ethereum" "getGasLeft" (func $eth.getGasLeft (result i64))) | |
(import "ethereum" "finish" (func $eth.finish (param i32 i32))) | |
(import "ethereum" "callDataCopy" (func $eth.callDataCopy (param i32 i32 i32))) | |
(memory $memory (export "memory") 1) | |
(export "main" (func $main)) | |
(global $global_ (mut i64) (i64.const 0)) | |
(global $global__1 (mut i64) (i64.const 0)) | |
(global $global__2 (mut i64) (i64.const 0)) | |
(func $main | |
(local $_1 i64) | |
(local $_2 i64) | |
(local $_3 i64) | |
(local $_4 i64) | |
(local $p i64) | |
(local $r i64) | |
(local $p_1 i64) | |
(local $r_1 i64) | |
(local $z1 i64) | |
(local $z2 i64) | |
(local $z3 i64) | |
(local $_5 i64) | |
(local $_6 i64) | |
(local $_7 i64) | |
(local $_8 i64) | |
(local $z4 i64) | |
(local.set $_1 (i64.extend_i32_u (i32.wrap_i64 (i64.extend_i32_u (call $eth.getCallDataSize))))) | |
(local.set $_2 (i64.const 0)) | |
(local.set $_3 (call $u256_to_i32 (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_1))) | |
(local.set $_4 (call $u256_to_i32 (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2))) | |
(local.set $p (call $u256_to_i32 (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 96))) | |
(local.set $r (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $p)) (i32.wrap_i64 (i64.const 64))))) | |
(if (i64.ne (i64.extend_i32_u (i32.lt_u (i32.wrap_i64 (local.get $r)) (i32.wrap_i64 (local.get $p)))) (i64.const 0)) (then | |
(unreachable))) | |
(call $eth.callDataCopy (i32.wrap_i64 (local.get $r)) (i32.wrap_i64 (local.get $_4)) (i32.wrap_i64 (local.get $_3))) | |
(local.set $p_1 (call $u256_to_i32 (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 96))) | |
(local.set $r_1 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $p_1)) (i32.wrap_i64 (i64.const 64))))) | |
(if (i64.ne (i64.extend_i32_u (i32.lt_u (i32.wrap_i64 (local.get $r_1)) (i32.wrap_i64 (local.get $p_1)))) (i64.const 0)) (then | |
(unreachable))) | |
(local.set $z1 (call $endian_swap (i64.load (i32.wrap_i64 (local.get $r_1))))) | |
(local.set $z2 (call $endian_swap (i64.load (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $r_1)) (i32.wrap_i64 (i64.const 8)))))))) | |
(local.set $z3 (call $endian_swap (i64.load (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $r_1)) (i32.wrap_i64 (i64.const 16)))))))) | |
(block | |
(local.set $_5 (call $div (local.get $z1) (local.get $z2) (local.get $z3) (call $endian_swap (i64.load (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $r_1)) (i32.wrap_i64 (i64.const 24))))))) (local.get $_2) (local.get $_2) (i64.const 4294967296) (local.get $_2))) | |
(local.set $_6 (global.get $global_)) | |
(local.set $_7 (global.get $global__1)) | |
(local.set $_8 (global.get $global__2)) | |
) | |
(local.set $z4 (call $eth.getGasLeft)) | |
(call $mstore_address (i64.const 0) (local.get $_5) (local.get $_6) (local.get $_7) (local.get $_8)) | |
(call $mstore (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (i64.extend_i32_u (i32.wrap_i64 (i64.extend_i32_u (call $eth.callStatic (call $u256_to_i64 (local.get $_2) (local.get $_2) (local.get $_2) (local.get $z4)) (i32.wrap_i64 (i64.const 12)) (i32.wrap_i64 (call $to_internal_i32ptr (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 116))) (i32.wrap_i64 (call $u256_to_i32 (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 4)))))))) | |
(call $return (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 32)) | |
) | |
(func $add_carry | |
(param $x i64) | |
(param $y i64) | |
(param $c i64) | |
(result i64) | |
(local $r i64) | |
(local $r_c i64) | |
(local $t i64) | |
(local.set $t (i64.add (local.get $x) (local.get $y))) | |
(local.set $r (i64.add (local.get $t) (local.get $c))) | |
(local.set $r_c (i64.extend_i32_u (i32.wrap_i64 (i64.extend_i32_u (i32.or (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $t) (local.get $x)))) (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $r) (local.get $t))))))))) | |
(global.set $global_ (local.get $r_c)) | |
(local.get $r) | |
) | |
(func $add | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(result i64) | |
(local $r1 i64) | |
(local $r2 i64) | |
(local $r3 i64) | |
(local $r4 i64) | |
(local $t i64) | |
(local $r3_1 i64) | |
(local $carry i64) | |
(local $r2_1 i64) | |
(local $carry_1 i64) | |
(local $r1_1 i64) | |
(local $carry_2 i64) | |
(local.set $t (i64.add (local.get $x4) (local.get $y4))) | |
(local.set $r4 (i64.add (local.get $t) (i64.const 0))) | |
(block | |
(local.set $r3_1 (call $add_carry (local.get $x3) (local.get $y3) (i64.extend_i32_u (i32.wrap_i64 (i64.extend_i32_u (i32.or (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $t) (local.get $x4)))) (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $r4) (local.get $t)))))))))) | |
(local.set $carry (global.get $global_)) | |
) | |
(local.set $r3 (local.get $r3_1)) | |
(block | |
(local.set $r2_1 (call $add_carry (local.get $x2) (local.get $y2) (local.get $carry))) | |
(local.set $carry_1 (global.get $global_)) | |
) | |
(local.set $r2 (local.get $r2_1)) | |
(block | |
(local.set $r1_1 (call $add_carry (local.get $x1) (local.get $y1) (local.get $carry_1))) | |
(local.set $carry_2 (global.get $global_)) | |
) | |
(local.set $r1 (local.get $r1_1)) | |
(global.set $global_ (local.get $r2)) | |
(global.set $global__1 (local.get $r3)) | |
(global.set $global__2 (local.get $r4)) | |
(local.get $r1) | |
) | |
(func $sub | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(result i64) | |
(local $r1 i64) | |
(local $r2 i64) | |
(local $r3 i64) | |
(local $r4 i64) | |
(local $_1 i64) | |
(local $t i64) | |
(local $r3_1 i64) | |
(local $carry i64) | |
(local $r2_1 i64) | |
(local $carry_1 i64) | |
(local $r1_1 i64) | |
(local $carry_2 i64) | |
(local.set $_1 (i64.const 18446744073709551615)) | |
(local.set $t (i64.add (local.get $x4) (i64.xor (local.get $y4) (local.get $_1)))) | |
(local.set $r4 (i64.add (local.get $t) (i64.const 1))) | |
(block | |
(local.set $r3_1 (call $add_carry (local.get $x3) (i64.xor (local.get $y3) (local.get $_1)) (i64.extend_i32_u (i32.wrap_i64 (i64.extend_i32_u (i32.or (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $t) (local.get $x4)))) (i32.wrap_i64 (i64.extend_i32_u (i64.lt_u (local.get $r4) (local.get $t)))))))))) | |
(local.set $carry (global.get $global_)) | |
) | |
(local.set $r3 (local.get $r3_1)) | |
(block | |
(local.set $r2_1 (call $add_carry (local.get $x2) (i64.xor (local.get $y2) (local.get $_1)) (local.get $carry))) | |
(local.set $carry_1 (global.get $global_)) | |
) | |
(local.set $r2 (local.get $r2_1)) | |
(block | |
(local.set $r1_1 (call $add_carry (local.get $x1) (i64.xor (local.get $y1) (local.get $_1)) (local.get $carry_1))) | |
(local.set $carry_2 (global.get $global_)) | |
) | |
(local.set $r1 (local.get $r1_1)) | |
(global.set $global_ (local.get $r2)) | |
(global.set $global__1 (local.get $r3)) | |
(global.set $global__2 (local.get $r4)) | |
(local.get $r1) | |
) | |
(func $shl_internal | |
(param $amount i64) | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(result i64) | |
(local $r1 i64) | |
(local $r2 i64) | |
(local $r3 i64) | |
(local $r4 i64) | |
(local $_1 i64) | |
(local.set $_1 (i64.sub (i64.const 64) (local.get $amount))) | |
(local.set $r1 (i64.add (i64.shl (local.get $x1) (local.get $amount)) (i64.shr_u (local.get $x2) (local.get $_1)))) | |
(local.set $r2 (i64.add (i64.shl (local.get $x2) (local.get $amount)) (i64.shr_u (local.get $x3) (local.get $_1)))) | |
(local.set $r3 (i64.add (i64.shl (local.get $x3) (local.get $amount)) (i64.shr_u (local.get $x4) (local.get $_1)))) | |
(local.set $r4 (i64.shl (local.get $x4) (local.get $amount))) | |
(global.set $global_ (local.get $r2)) | |
(global.set $global__1 (local.get $r3)) | |
(global.set $global__2 (local.get $r4)) | |
(local.get $r1) | |
) | |
(func $shr_internal | |
(param $amount i64) | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(result i64) | |
(local $r1 i64) | |
(local $r2 i64) | |
(local $r3 i64) | |
(local $r4 i64) | |
(local $_1 i64) | |
(local.set $_1 (i64.sub (i64.const 64) (local.get $amount))) | |
(local.set $r4 (i64.add (i64.shr_u (local.get $x4) (local.get $amount)) (i64.shl (local.get $x3) (local.get $_1)))) | |
(local.set $r3 (i64.add (i64.shr_u (local.get $x3) (local.get $amount)) (i64.shl (local.get $x2) (local.get $_1)))) | |
(local.set $r2 (i64.add (i64.shr_u (local.get $x2) (local.get $amount)) (i64.shl (local.get $x1) (local.get $_1)))) | |
(local.set $r1 (i64.shr_u (local.get $x1) (local.get $amount))) | |
(global.set $global_ (local.get $r2)) | |
(global.set $global__1 (local.get $r3)) | |
(global.set $global__2 (local.get $r4)) | |
(local.get $r1) | |
) | |
(func $div | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(result i64) | |
(local $r1 i64) | |
(local $r2 i64) | |
(local $r3 i64) | |
(local $r4 i64) | |
(local $m1 i64) | |
(local $m2 i64) | |
(local $m3 i64) | |
(local $m4 i64) | |
(local $y1_1 i64) | |
(local $y2_1 i64) | |
(local $y3_1 i64) | |
(local $y4_1 i64) | |
(local $m1_1 i64) | |
(local $m2_1 i64) | |
(local $m3_1 i64) | |
(local $m4_1 i64) | |
(local $x1_1 i64) | |
(local $x2_1 i64) | |
(local $x3_1 i64) | |
(local $x4_1 i64) | |
(local $r1_1 i64) | |
(local $r2_1 i64) | |
(local $r3_1 i64) | |
(local $r4_1 i64) | |
(local $y1_2 i64) | |
(local $y2_2 i64) | |
(local $y3_2 i64) | |
(local $y4_2 i64) | |
(local $m1_2 i64) | |
(local $m2_2 i64) | |
(local $m3_2 i64) | |
(local $m4_2 i64) | |
(if (i64.ne (i64.extend_i32_u (i64.eqz (i64.or (i64.or (local.get $y1) (local.get $y2)) (i64.or (local.get $y3) (local.get $y4))))) (i64.const 0)) (then | |
(return) | |
)) | |
(local.set $m1 (i64.const 0)) | |
(local.set $m2 (local.get $m1)) | |
(local.set $m3 (local.get $m1)) | |
(local.set $m4 (i64.const 1)) | |
(block $label_ | |
(loop | |
(br_if $label_ (i64.eqz (i64.const 1))) | |
(block $label__3 | |
(if (i64.ne (i64.extend_i32_u (i32.or (i32.wrap_i64 (i64.extend_i32_u (i64.eqz (i64.clz (local.get $y1))))) (i32.wrap_i64 (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (call $lt_256x256_64 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4) (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)))))))) (i64.const 0)) (then | |
(br $label_) | |
)) | |
(block | |
(local.set $y1_1 (call $shl_internal (i64.const 1) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))) | |
(local.set $y2_1 (global.get $global_)) | |
(local.set $y3_1 (global.get $global__1)) | |
(local.set $y4_1 (global.get $global__2)) | |
) | |
(local.set $y1 (local.get $y1_1)) | |
(local.set $y2 (local.get $y2_1)) | |
(local.set $y3 (local.get $y3_1)) | |
(local.set $y4 (local.get $y4_1)) | |
(block | |
(local.set $m1_1 (call $shl_internal (i64.const 1) (local.get $m1) (local.get $m2) (local.get $m3) (local.get $m4))) | |
(local.set $m2_1 (global.get $global_)) | |
(local.set $m3_1 (global.get $global__1)) | |
(local.set $m4_1 (global.get $global__2)) | |
) | |
(local.set $m1 (local.get $m1_1)) | |
(local.set $m2 (local.get $m2_1)) | |
(local.set $m3 (local.get $m3_1)) | |
(local.set $m4 (local.get $m4_1)) | |
) | |
) | |
) | |
(block $label__4 | |
(loop | |
(br_if $label__4 (i64.eqz (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (i64.extend_i32_u (i64.eqz (i64.or (i64.or (local.get $m1) (local.get $m2)) (i64.or (local.get $m3) (local.get $m4)))))))))) | |
(block $label__5 | |
(if (i64.ne (i64.extend_i32_u (i32.eqz (i32.wrap_i64 (call $lt_256x256_64 (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))))) (i64.const 0)) (then | |
(block | |
(local.set $x1_1 (call $sub (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))) | |
(local.set $x2_1 (global.get $global_)) | |
(local.set $x3_1 (global.get $global__1)) | |
(local.set $x4_1 (global.get $global__2)) | |
) | |
(local.set $x1 (local.get $x1_1)) | |
(local.set $x2 (local.get $x2_1)) | |
(local.set $x3 (local.get $x3_1)) | |
(local.set $x4 (local.get $x4_1)) | |
(block | |
(local.set $r1_1 (call $add (local.get $r1) (local.get $r2) (local.get $r3) (local.get $r4) (local.get $m1) (local.get $m2) (local.get $m3) (local.get $m4))) | |
(local.set $r2_1 (global.get $global_)) | |
(local.set $r3_1 (global.get $global__1)) | |
(local.set $r4_1 (global.get $global__2)) | |
) | |
(local.set $r1 (local.get $r1_1)) | |
(local.set $r2 (local.get $r2_1)) | |
(local.set $r3 (local.get $r3_1)) | |
(local.set $r4 (local.get $r4_1)) | |
)) | |
(block | |
(local.set $y1_2 (call $shr_internal (i64.const 1) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))) | |
(local.set $y2_2 (global.get $global_)) | |
(local.set $y3_2 (global.get $global__1)) | |
(local.set $y4_2 (global.get $global__2)) | |
) | |
(local.set $y1 (local.get $y1_2)) | |
(local.set $y2 (local.get $y2_2)) | |
(local.set $y3 (local.get $y3_2)) | |
(local.set $y4 (local.get $y4_2)) | |
(block | |
(local.set $m1_2 (call $shr_internal (i64.const 1) (local.get $m1) (local.get $m2) (local.get $m3) (local.get $m4))) | |
(local.set $m2_2 (global.get $global_)) | |
(local.set $m3_2 (global.get $global__1)) | |
(local.set $m4_2 (global.get $global__2)) | |
) | |
(local.set $m1 (local.get $m1_2)) | |
(local.set $m2 (local.get $m2_2)) | |
(local.set $m3 (local.get $m3_2)) | |
(local.set $m4 (local.get $m4_2)) | |
) | |
) | |
) | |
(global.set $global_ (local.get $r2)) | |
(global.set $global__1 (local.get $r3)) | |
(global.set $global__2 (local.get $r4)) | |
(local.get $r1) | |
) | |
(func $cmp | |
(param $a i64) | |
(param $b i64) | |
(result i64) | |
(local $r i64) | |
(local $condition i64) | |
(block | |
(local.set $condition (i64.extend_i32_u (i64.lt_u (local.get $a) (local.get $b)))) | |
(if (i64.eq (local.get $condition) (i64.const 1)) (then | |
(local.set $r (i64.const 4294967295)) | |
)(else | |
(local.set $r (i64.extend_i32_u (i64.ne (local.get $a) (local.get $b)))) | |
)) | |
) | |
(local.get $r) | |
) | |
(func $lt_256x256_64 | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(result i64) | |
(local $z i64) | |
(local $condition_6 i64) | |
(local $condition_7 i64) | |
(local $condition_8 i64) | |
(block | |
(local.set $condition_6 (call $cmp (local.get $x1) (local.get $y1))) | |
(if (i64.eq (local.get $condition_6) (i64.const 0)) (then | |
(block | |
(local.set $condition_7 (call $cmp (local.get $x2) (local.get $y2))) | |
(if (i64.eq (local.get $condition_7) (i64.const 0)) (then | |
(block | |
(local.set $condition_8 (call $cmp (local.get $x3) (local.get $y3))) | |
(if (i64.eq (local.get $condition_8) (i64.const 0)) (then | |
(local.set $z (i64.extend_i32_u (i64.lt_u (local.get $x4) (local.get $y4)))) | |
)(else | |
(if (i64.eq (local.get $condition_8) (i64.const 1)) (then | |
(local.set $z (i64.const 0)) | |
)(else | |
(local.set $z (i64.const 1)) | |
)) | |
)) | |
) | |
)(else | |
(if (i64.eq (local.get $condition_7) (i64.const 1)) (then | |
(local.set $z (i64.const 0)) | |
)(else | |
(local.set $z (i64.const 1)) | |
)) | |
)) | |
) | |
)(else | |
(if (i64.eq (local.get $condition_6) (i64.const 1)) (then | |
(local.set $z (i64.const 0)) | |
)(else | |
(local.set $z (i64.const 1)) | |
)) | |
)) | |
) | |
(local.get $z) | |
) | |
(func $u256_to_i64 | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(result i64) | |
(local $v i64) | |
(if (i64.ne (i64.extend_i32_u (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3)))) (i64.const 0)) (then | |
(unreachable))) | |
(local.set $v (local.get $x4)) | |
(local.get $v) | |
) | |
(func $u256_to_i32 | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(result i64) | |
(local $v i64) | |
(if (i64.ne (i64.extend_i32_u (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3)))) (i64.const 0)) (then | |
(unreachable))) | |
(if (i64.ne (i64.extend_i32_u (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32)))) (i64.const 0)) (then | |
(unreachable))) | |
(local.set $v (i64.extend_i32_u (i32.wrap_i64 (local.get $x4)))) | |
(local.get $v) | |
) | |
(func $to_internal_i32ptr | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(result i64) | |
(local $r i64) | |
(local $p i64) | |
(local.set $p (call $u256_to_i32 (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4))) | |
(local.set $r (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $p)) (i32.wrap_i64 (i64.const 64))))) | |
(if (i64.ne (i64.extend_i32_u (i32.lt_u (i32.wrap_i64 (local.get $r)) (i32.wrap_i64 (local.get $p)))) (i64.const 0)) (then | |
(unreachable))) | |
(local.get $r) | |
) | |
(func $endian_swap_16 | |
(param $x i64) | |
(result i64) | |
(local $y i64) | |
(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) | |
(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) | |
(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 | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(call $mstore_internal (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) | |
) | |
(func $mstore_internal | |
(param $pos i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(i64.store (i32.wrap_i64 (local.get $pos)) (call $endian_swap (local.get $y1))) | |
(i64.store (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $pos)) (i32.wrap_i64 (i64.const 8))))) (call $endian_swap (local.get $y2))) | |
(i64.store (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $pos)) (i32.wrap_i64 (i64.const 16))))) (call $endian_swap (local.get $y3))) | |
(i64.store (i32.wrap_i64 (i64.extend_i32_u (i32.add (i32.wrap_i64 (local.get $pos)) (i32.wrap_i64 (i64.const 24))))) (call $endian_swap (local.get $y4))) | |
) | |
(func $mstore_address | |
(param $pos i64) | |
(param $a1 i64) | |
(param $a2 i64) | |
(param $a3 i64) | |
(param $a4 i64) | |
(if (i64.ne (i64.extend_i32_u (i64.ne (i64.const 0) (local.get $a1))) (i64.const 0)) (then | |
(unreachable))) | |
(if (i64.ne (i64.extend_i32_u (i64.ne (i64.const 0) (i64.shr_u (local.get $a2) (i64.const 32)))) (i64.const 0)) (then | |
(unreachable))) | |
(call $mstore_internal (local.get $pos) (i64.const 0) (local.get $a2) (local.get $a3) (local.get $a4)) | |
) | |
(func $return | |
(param $x1 i64) | |
(param $x2 i64) | |
(param $x3 i64) | |
(param $x4 i64) | |
(param $y1 i64) | |
(param $y2 i64) | |
(param $y3 i64) | |
(param $y4 i64) | |
(call $eth.finish (i32.wrap_i64 (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4))) (i32.wrap_i64 (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)))) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment