Skip to content

Commit a5670d8

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 11 byte code size cost (I measured the size of the JS code generated for core3.test_em_asm going from 15091 to 15102) but I think its useful enough to pay that price.
1 parent bc55b54 commit a5670d8

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ jobs:
607607
test_targets: "
608608
wasm64
609609
wasm64_4gb.test_hello_world
610+
wasm64_4gb.test_em_asm
610611
wasm64l.test_bigswitch
611612
other.test_memory64_proxies
612613
other.test_failing_growth_wasm64"

src/library.js

Lines changed: 12 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,24 @@ 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+
buf += (ch != {{{ charCode('i') }}}) && buf % 8 ? 4 : 0;
2890+
readEmAsmArgsArray.push(
28912891
#if MEMORY64
28922892
// 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
2893+
(ch == {{{ charCode('p') }}}) ?
2894+
{{{ makeGetValue('buf', 0, '*') }}} :
28962895
#endif
2897-
readEmAsmArgsArray.push(
2898-
ch == 105/*i*/ ? HEAP32[buf] :
28992896
#if WASM_BIGINT
2900-
(ch == 106/*j*/ ? HEAP64 : HEAPF64)[buf++ >> 1]
2901-
#else
2902-
HEAPF64[buf++ >> 1]
2897+
(ch == {{{ charCode('j') }}}) ?
2898+
{{{ makeGetValue('buf', 0, 'i64') }}} :
29032899
#endif
2900+
(ch == {{{ charCode('i') }}}) ?
2901+
{{{ makeGetValue('buf', 0, 'i32') }}} :
2902+
{{{ makeGetValue('buf', 0, 'double') }}}
29042903
);
2905-
++buf;
2904+
buf += ch == {{{ charCode('i') }}} ? 4 : 8;
29062905
}
29072906
return readEmAsmArgsArray;
29082907
},

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)