Skip to content

Commit c5fcc8d

Browse files
committed
[Wasm64] Fix EM_ASM for addresses >4GB addresses
This change use makeGetValue helper macros to avoid direct heap access. This does come with a 14 byte code size cost (I measured the size of the JS code generated for core3.test_em_asm going from 15091 to 15105) but I think its useful enough to pay that price.
1 parent fa099c1 commit c5fcc8d

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ jobs:
608608
wasm64
609609
wasm64_4gb.test_hello_world
610610
wasm64l.test_bigswitch
611+
wasm64l.test_em_asm
611612
other.test_memory64_proxies
612613
other.test_failing_growth_wasm64"
613614
- upload-test-results

src/library.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,6 @@ mergeInto(LibraryManager.library, {
28692869
var ch;
28702870
// Most arguments are i32s, so shift the buffer pointer so it is a plain
28712871
// index into HEAP32.
2872-
buf >>= 2;
28732872
while (ch = HEAPU8[sigPtr++]) {
28742873
#if ASSERTIONS
28752874
var chr = String.fromCharCode(ch);
@@ -2885,24 +2884,30 @@ mergeInto(LibraryManager.library, {
28852884
#endif
28862885
assert(validChars.includes(chr), `Invalid character ${ch}("${chr}") in readEmAsmArgs! Use only [${validChars}], and do not specify "v" for void return argument.`);
28872886
#endif
2888-
// Floats are always passed as doubles, and doubles and int64s take up 8
2889-
// bytes (two 32-bit slots) in memory, align reads to these:
2890-
buf += (ch != 105/*i*/) & buf;
2887+
// Floats are always passed as doubles, so all types except for 'i'
2888+
// are 8 bytes and require alignment.
2889+
if (ch != {{{ charCode('i') }}}) {
28912890
#if MEMORY64
2892-
// Special case for pointers under wasm64 which we read as int53 Numbers.
2893-
if (ch == 112/*p*/) {
2894-
readEmAsmArgsArray.push(readI53FromI64(buf++ << 2));
2895-
} else
2891+
buf = Math.ceil(buf / 8) * 8;
2892+
#else
2893+
buf += buf & 0x7 ? 4 : 0;
28962894
#endif
2895+
}
28972896
readEmAsmArgsArray.push(
2898-
ch == 105/*i*/ ? HEAP32[buf] :
2897+
#if MEMORY64
2898+
// Special case for pointers under wasm64 which we read as int53 Numbers.
2899+
(ch == {{{ charCode('p') }}}) ?
2900+
arg = {{{ makeGetValue('buf', 0, '*') }}} :
2901+
#endif
28992902
#if WASM_BIGINT
2900-
(ch == 106/*j*/ ? HEAP64 : HEAPF64)[buf++ >> 1]
2901-
#else
2902-
HEAPF64[buf++ >> 1]
2903+
(ch == {{{ charCode('j') }}}) ?
2904+
{{{ makeGetValue('buf', 0, 'i64') }}} :
29032905
#endif
2906+
(ch == {{{ charCode('i') }}}) ?
2907+
{{{ makeGetValue('buf', 0, 'i32') }}} :
2908+
{{{ makeGetValue('buf', 0, 'double') }}}
29042909
);
2905-
++buf;
2910+
buf += ch == {{{ charCode('i') }}} ? 4 : 8;
29062911
}
29072912
return readEmAsmArgsArray;
29082913
},

test/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def load_test_suites(args, modules):
284284
for test in tests:
285285
suite.addTest(test)
286286
suites.append((m.__name__, suite))
287-
if total_tests == 1:
287+
if total_tests == 1 or parallel_testsuite.num_cores() == 1:
288288
common.EMTEST_SAVE_DIR = True
289289
return suites, unmatched_test_names
290290

test/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ def test_inlinejs4(self):
21442144
''', 'false', assert_returncode=NON_ZERO)
21452145

21462146
def test_em_asm(self):
2147+
self.maybe_closure()
21472148
self.do_core_test('test_em_asm.cpp')
21482149

21492150
def test_em_asm_c(self):

0 commit comments

Comments
 (0)