From 2f8f82c1c717435c37bfcd568596a8363f63c5c2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 12:49:25 -0700 Subject: [PATCH 1/6] waka --- src/library.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/library.js b/src/library.js index 8dc36d39ecca6..1de5dd96b26c2 100644 --- a/src/library.js +++ b/src/library.js @@ -3158,6 +3158,7 @@ mergeInto(LibraryManager.library, { #endif if (args && args.length) { // j (64-bit integer) must be passed in as two numbers [low 32, high 32]. + throw 'waka waka'; assert(args.length === sig.substring(1).replace(/j/g, '--').length); } else { assert(sig.length == 1); From 8eab1f5a0b99f4db2016f5e727fa9ae6766fd177 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 14:46:04 -0700 Subject: [PATCH 2/6] fix --- src/library.js | 8 +++++- test/core/dyncall_specific.c | 52 +++++++++++++++++++++++++++++----- test/core/dyncall_specific.out | 3 +- test/test_core.py | 4 ++- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/library.js b/src/library.js index 1de5dd96b26c2..4ef958dd1f806 100644 --- a/src/library.js +++ b/src/library.js @@ -3157,9 +3157,15 @@ mergeInto(LibraryManager.library, { assert(('dynCall_' + sig) in Module, `bad function pointer type - dynCall function not found for sig '${sig}'`); #endif if (args && args.length) { +#if WASM_BIGINT + // j (64-bit integer) is fine, and is implemented as a BigInt. Without + // legalization, the number of parameters should match (j is not expanded + // into two i's). + assert(args.length === sig.length - 1); +#else // j (64-bit integer) must be passed in as two numbers [low 32, high 32]. - throw 'waka waka'; assert(args.length === sig.substring(1).replace(/j/g, '--').length); +#endif } else { assert(sig.length == 1); } diff --git a/test/core/dyncall_specific.c b/test/core/dyncall_specific.c index 52c0ed1eef58d..9e409ae5018ec 100644 --- a/test/core/dyncall_specific.c +++ b/test/core/dyncall_specific.c @@ -5,17 +5,27 @@ * found in the LICENSE file. */ +#include #include #include #include int waka(int w, long long xy, int z) { +#ifndef WASM_BIGINT // xy should be 0xffff_ffff_0000_0004 - int x = (int) xy; // should be 4 - int y = xy >> 32; // should be -1 - EM_ASM({ - out('received ' + [$0, $1, $2, $3] + '.'); - }, w, x, y, z); + int x = (int) xy; + int y = xy >> 32; + assert(w == 1); + assert(x == 4); + assert(y == -1); + assert(z == 9); +#else + // With WASM_BIGINT things are straightforward: the 64-bit value just arrives + // with the expected value of 4. + assert(w == 1); + assert(xy == 4); + assert(z == 9); +#endif return 42; } @@ -23,8 +33,9 @@ EM_JS_DEPS(main, "$dynCall"); int main() { EM_ASM({ - // Note that these would need to use BigInts if the file were built with - // -sWASM_BIGINT + +#ifndef WASM_BIGINT + #if DIRECT console.log('Received ' + dynCall_iiji($0, 1, 4, 0xffffffff, 9)); return; @@ -45,6 +56,33 @@ int main() { eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, 4, 0xffffffff, 9))"); return; #endif + +#else // WASM_BIGINT + +#if DIRECT + console.log('Received ' + dynCall_iiji($0, 1, BigInt(4), 9)); + return; +#endif +#if DYNAMIC_SIG + console.log('Received ' + dynCall('iiji', $0, [1, BigInt(4), 9])); + return; +#endif +#if EXPORTED + console.log('Received ' + Module['dynCall_iiji']($0, 1, BigInt(4), 9)); + return; +#endif +#if EXPORTED_DYNAMIC_SIG + console.log('Received ' + Module['dynCall']('iiji', $0, [1, BigInt(4), 9])); + return; +#endif +#if FROM_OUTSIDE + eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, BigInt(4), 9))"); + return; +#endif + +#endif + + // We should have run the test and returned before we get here. throw "no test mode"; }, &waka); } diff --git a/test/core/dyncall_specific.out b/test/core/dyncall_specific.out index b3911f38b37b2..665f2d084a1d8 100644 --- a/test/core/dyncall_specific.out +++ b/test/core/dyncall_specific.out @@ -1,2 +1 @@ -received 1,4,-1,9. -Received 42 \ No newline at end of file +Received 42 diff --git a/test/test_core.py b/test/test_core.py index 835fac77de60d..4717baa68e534 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7209,8 +7209,10 @@ def test_EXPORTED_RUNTIME_METHODS(self): 'minimal_runtime': ['-sMINIMAL_RUNTIME=1'] }) def test_dyncall_specific(self, *args): - if self.get_setting('WASM_BIGINT') or self.get_setting('MEMORY64'): + if self.get_setting('MEMORY64'): self.skipTest('not compatible with WASM_BIGINT') + if self.get_setting('WASM_BIGINT'): + args = list(args) + ['-sDYNCALLS=1', '-DWASM_BIGINT'] cases = [ ('DIRECT', []), ('DYNAMIC_SIG', ['-sDYNCALLS=1']), From c93f72f94a8741906a1d7ba7c66eadf843ccfa55 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 14:48:49 -0700 Subject: [PATCH 3/6] comment --- test/test_core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_core.py b/test/test_core.py index 4717baa68e534..292b81bd14085 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7212,6 +7212,9 @@ def test_dyncall_specific(self, *args): if self.get_setting('MEMORY64'): self.skipTest('not compatible with WASM_BIGINT') if self.get_setting('WASM_BIGINT'): + # define DYNCALLS because this test does test calling them directly, and + # in WASM_BIGINT mode we do not enable them by default (since we can do + # more without them - we don't need to legalize) args = list(args) + ['-sDYNCALLS=1', '-DWASM_BIGINT'] cases = [ ('DIRECT', []), From 568ee4076338310e7f3d74845a8ab2e5a0de2d2b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 14:53:07 -0700 Subject: [PATCH 4/6] fix --- test/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_core.py b/test/test_core.py index 292b81bd14085..24ea055461910 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7210,7 +7210,7 @@ def test_EXPORTED_RUNTIME_METHODS(self): }) def test_dyncall_specific(self, *args): if self.get_setting('MEMORY64'): - self.skipTest('not compatible with WASM_BIGINT') + self.skipTest('not compatible with MEMORY64') if self.get_setting('WASM_BIGINT'): # define DYNCALLS because this test does test calling them directly, and # in WASM_BIGINT mode we do not enable them by default (since we can do From fe12dc03d9e574a3d984ee688ceae145a4efb7a6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 15:36:50 -0700 Subject: [PATCH 5/6] flip --- test/core/dyncall_specific.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/core/dyncall_specific.c b/test/core/dyncall_specific.c index 9e409ae5018ec..9b7045e872aa4 100644 --- a/test/core/dyncall_specific.c +++ b/test/core/dyncall_specific.c @@ -11,7 +11,13 @@ #include int waka(int w, long long xy, int z) { -#ifndef WASM_BIGINT +#ifdef WASM_BIGINT + // With WASM_BIGINT things are straightforward: the 64-bit value just arrives + // with the expected value of 4. + assert(w == 1); + assert(xy == 4); + assert(z == 9); +#else // xy should be 0xffff_ffff_0000_0004 int x = (int) xy; int y = xy >> 32; @@ -19,12 +25,6 @@ int waka(int w, long long xy, int z) { assert(x == 4); assert(y == -1); assert(z == 9); -#else - // With WASM_BIGINT things are straightforward: the 64-bit value just arrives - // with the expected value of 4. - assert(w == 1); - assert(xy == 4); - assert(z == 9); #endif return 42; } @@ -34,49 +34,49 @@ EM_JS_DEPS(main, "$dynCall"); int main() { EM_ASM({ -#ifndef WASM_BIGINT +#ifdef WASM_BIGINT #if DIRECT - console.log('Received ' + dynCall_iiji($0, 1, 4, 0xffffffff, 9)); + console.log('Received ' + dynCall_iiji($0, 1, BigInt(4), 9)); return; #endif #if DYNAMIC_SIG - console.log('Received ' + dynCall('iiji', $0, [1, 4, 0xffffffff, 9])); + console.log('Received ' + dynCall('iiji', $0, [1, BigInt(4), 9])); return; #endif #if EXPORTED - console.log('Received ' + Module['dynCall_iiji']($0, 1, 4, 0xffffffff, 9)); + console.log('Received ' + Module['dynCall_iiji']($0, 1, BigInt(4), 9)); return; #endif #if EXPORTED_DYNAMIC_SIG - console.log('Received ' + Module['dynCall']('iiji', $0, [1, 4, 0xffffffff, 9])); + console.log('Received ' + Module['dynCall']('iiji', $0, [1, BigInt(4), 9])); return; #endif #if FROM_OUTSIDE - eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, 4, 0xffffffff, 9))"); + eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, BigInt(4), 9))"); return; #endif #else // WASM_BIGINT #if DIRECT - console.log('Received ' + dynCall_iiji($0, 1, BigInt(4), 9)); + console.log('Received ' + dynCall_iiji($0, 1, 4, 0xffffffff, 9)); return; #endif #if DYNAMIC_SIG - console.log('Received ' + dynCall('iiji', $0, [1, BigInt(4), 9])); + console.log('Received ' + dynCall('iiji', $0, [1, 4, 0xffffffff, 9])); return; #endif #if EXPORTED - console.log('Received ' + Module['dynCall_iiji']($0, 1, BigInt(4), 9)); + console.log('Received ' + Module['dynCall_iiji']($0, 1, 4, 0xffffffff, 9)); return; #endif #if EXPORTED_DYNAMIC_SIG - console.log('Received ' + Module['dynCall']('iiji', $0, [1, BigInt(4), 9])); + console.log('Received ' + Module['dynCall']('iiji', $0, [1, 4, 0xffffffff, 9])); return; #endif #if FROM_OUTSIDE - eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, BigInt(4), 9))"); + eval("console.log('Received ' + Module['dynCall_iiji'](" + $0 + ", 1, 4, 0xffffffff, 9))"); return; #endif From a42cb9ec11808dde768df46bae7d6bfef2fccdeb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 22 Jun 2023 15:37:54 -0700 Subject: [PATCH 6/6] remove =1s --- test/test_core.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index 24ea055461910..a1ba088731bbf 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7215,17 +7215,17 @@ def test_dyncall_specific(self, *args): # define DYNCALLS because this test does test calling them directly, and # in WASM_BIGINT mode we do not enable them by default (since we can do # more without them - we don't need to legalize) - args = list(args) + ['-sDYNCALLS=1', '-DWASM_BIGINT'] + args = list(args) + ['-sDYNCALLS', '-DWASM_BIGINT'] cases = [ ('DIRECT', []), - ('DYNAMIC_SIG', ['-sDYNCALLS=1']), + ('DYNAMIC_SIG', ['-sDYNCALLS']), ] if '-sMINIMAL_RUNTIME=1' in args: self.emcc_args += ['--pre-js', test_file('minimal_runtime_exit_handling.js')] else: cases += [ ('EXPORTED', []), - ('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS=1', '-sEXPORTED_RUNTIME_METHODS=dynCall']), + ('EXPORTED_DYNAMIC_SIG', ['-sDYNCALLS', '-sEXPORTED_RUNTIME_METHODS=dynCall']), ('FROM_OUTSIDE', ['-sEXPORTED_RUNTIME_METHODS=dynCall_iiji']) ]