Skip to content

Commit

Permalink
[Wasm64] Fix EM_ASM for addresses >4GB addresses
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
sbc100 committed Aug 16, 2023
1 parent bd6f10b commit cc19139
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ jobs:
test_targets: "
wasm64
wasm64_4gb.test_hello_world
wasm64_4gb.test_em_asm
wasm64l.test_bigswitch
other.test_memory64_proxies
other.test_failing_growth_wasm64"
Expand Down
19 changes: 9 additions & 10 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,6 @@ addToLibrary({
var ch;
// Most arguments are i32s, so shift the buffer pointer so it is a plain
// index into HEAP32.
buf >>= 2;
while (ch = HEAPU8[sigPtr++]) {
#if ASSERTIONS
var chr = String.fromCharCode(ch);
Expand All @@ -2885,22 +2884,22 @@ addToLibrary({
#endif
assert(validChars.includes(chr), `Invalid character ${ch}("${chr}") in readEmAsmArgs! Use only [${validChars}], and do not specify "v" for void return argument.`);
#endif
// Floats are always passed as doubles, and doubles and int64s take up 8
// bytes (two 32-bit slots) in memory, align reads to these:
buf += (ch != {{{ charCode('i') }}}) & buf;
// Floats are always passed as doubles, so all types except for 'i'
// are 8 bytes and require alignment.
buf += (ch != {{{ charCode('i') }}}) && buf % 8 ? 4 : 0;
readEmAsmArgsArray.push(
ch == {{{ charCode('i') }}} ? HEAP32[buf] :
#if MEMORY64
// Special case for pointers under wasm64 which we read as int53 Numbers.
ch == {{{ charCode('p') }}} ? {{{ makeGetValue('buf++ << 2', 0, '*') }}} :
ch == {{{ charCode('p') }}} ? {{{ makeGetValue('buf', 0, '*') }}} :
#endif
#if WASM_BIGINT
(ch == {{{ charCode('j') }}} ? HEAP64 : HEAPF64)[buf++ >> 1]
#else
HEAPF64[buf++ >> 1]
ch == {{{ charCode('j') }}} ? {{{ makeGetValue('buf', 0, 'i64') }}} :
#endif
ch == {{{ charCode('i') }}} ?
{{{ makeGetValue('buf', 0, 'i32') }}} :
{{{ makeGetValue('buf', 0, 'double') }}}
);
++buf;
buf += ch == {{{ charCode('i') }}} ? 4 : 8;
}
return readEmAsmArgsArray;
},
Expand Down
2 changes: 1 addition & 1 deletion test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def load_test_suites(args, modules):
for test in tests:
suite.addTest(test)
suites.append((m.__name__, suite))
if total_tests == 1:
if total_tests == 1 or parallel_testsuite.num_cores() == 1:
common.EMTEST_SAVE_DIR = True
return suites, unmatched_test_names

Expand Down

0 comments on commit cc19139

Please sign in to comment.