Skip to content

Commit 2d72c4d

Browse files
authored
[Wasm64] Fix EM_ASM for addresses >4GB addresses (#19980)
This change use makeGetValue helper macros to avoid direct heap access. This does come with a 6 byte code size cost (I measured the size of the JS code generated for wasm64.test_em_asm with -O2 going from 9275 to 9281).
1 parent e1a7c13 commit 2d72c4d

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ jobs:
617617
test_targets: "
618618
wasm64
619619
wasm64_4gb.test_hello_world
620+
wasm64_4gb.test_em_asm
620621
wasm64l.test_bigswitch
621622
other.test_memory64_proxies
622623
other.test_failing_growth_wasm64"

src/library.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -2869,7 +2869,6 @@ addToLibrary({
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,22 +2884,22 @@ addToLibrary({
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 != {{{ charCode('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;
28912890
readEmAsmArgsArray.push(
2892-
ch == {{{ charCode('i') }}} ? HEAP32[buf] :
28932891
#if MEMORY64
28942892
// Special case for pointers under wasm64 which we read as int53 Numbers.
2895-
ch == {{{ charCode('p') }}} ? {{{ makeGetValue('buf++ << 2', 0, '*') }}} :
2893+
ch == {{{ charCode('p') }}} ? {{{ makeGetValue('buf', 0, '*') }}} :
28962894
#endif
28972895
#if WASM_BIGINT
2898-
(ch == {{{ charCode('j') }}} ? HEAP64 : HEAPF64)[buf++ >> 1]
2899-
#else
2900-
HEAPF64[buf++ >> 1]
2896+
ch == {{{ charCode('j') }}} ? {{{ makeGetValue('buf', 0, 'i64') }}} :
29012897
#endif
2898+
ch == {{{ charCode('i') }}} ?
2899+
{{{ makeGetValue('buf', 0, 'i32') }}} :
2900+
{{{ makeGetValue('buf', 0, 'double') }}}
29022901
);
2903-
++buf;
2902+
buf += ch == {{{ charCode('i') }}} ? 4 : 8;
29042903
}
29052904
return readEmAsmArgsArray;
29062905
},

test/runner.py

+1-1
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

0 commit comments

Comments
 (0)