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 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.
  • Loading branch information
sbc100 committed Aug 10, 2023
1 parent bc55b54 commit a5670d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 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
25 changes: 12 additions & 13 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,6 @@ mergeInto(LibraryManager.library, {
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,24 +2884,24 @@ mergeInto(LibraryManager.library, {
#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 != 105/*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(
#if MEMORY64
// Special case for pointers under wasm64 which we read as int53 Numbers.
if (ch == 112/*p*/) {
readEmAsmArgsArray.push(readI53FromI64(buf++ << 2));
} else
(ch == {{{ charCode('p') }}}) ?
{{{ makeGetValue('buf', 0, '*') }}} :
#endif
readEmAsmArgsArray.push(
ch == 105/*i*/ ? HEAP32[buf] :
#if WASM_BIGINT
(ch == 106/*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
1 change: 1 addition & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,7 @@ def test_inlinejs4(self):
''', 'false', assert_returncode=NON_ZERO)

def test_em_asm(self):
self.maybe_closure()
self.do_core_test('test_em_asm.cpp')

def test_em_asm_c(self):
Expand Down

0 comments on commit a5670d8

Please sign in to comment.