diff --git a/src/parseTools.js b/src/parseTools.js index 20fda91a03ce8..c8df775eb3f61 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -211,7 +211,7 @@ function splitI64(value) { // // $1$0 = ~~$d >>> 0; // $1$1 = Math.abs($d) >= 1 ? ( - // $d > 0 ? Math.min(Math.floor(($d)/ 4294967296.0), 4294967295.0) + // $d > 0 ? Math.floor(($d)/ 4294967296.0) >>> 0, // : Math.ceil(Math.min(-4294967296.0, $d - $1$0)/ 4294967296.0) // ) : 0; // @@ -227,9 +227,8 @@ function splitI64(value) { const high = makeInlineCalculation( asmCoercion('Math.abs(VALUE)', 'double') + ' >= ' + asmEnsureFloat('1', 'double') + ' ? ' + '(VALUE > ' + asmEnsureFloat('0', 'double') + ' ? ' + - asmCoercion('Math.min(' + asmCoercion('Math.floor((VALUE)/' + - asmEnsureFloat(4294967296, 'double') + ')', 'double') + ', ' + - asmEnsureFloat(4294967295, 'double') + ')', 'i32') + '>>>0' + + asmCoercion('Math.floor((VALUE)/' + + asmEnsureFloat(4294967296, 'double') + ')', 'double') + '>>>0' + ' : ' + asmFloatToInt(asmCoercion('Math.ceil((VALUE - +((' + asmFloatToInt('VALUE') + ')>>>0))/' + asmEnsureFloat(4294967296, 'double') + ')', 'double')) + '>>>0' + @@ -364,12 +363,10 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, sep) { assert(typeof align === 'undefined', 'makeSetValue no longer supports align parameter'); assert(typeof noNeedFirst === 'undefined', 'makeSetValue no longer supports noNeedFirst parameter'); assert(typeof sep === 'undefined', 'makeSetValue no longer supports sep parameter'); - if (type == 'i64' && (!WASM_BIGINT || !MEMORY64)) { - // If we lack either BigInt support or Memory64 then we must fall back to an - // unaligned read of a 64-bit value: without BigInt we do not have HEAP64, - // and without Memory64 i64 fields are not guaranteed to be aligned to 64 - // bits, so HEAP64[ptr>>3] might be broken. - return '(tempI64 = [' + splitI64(value) + '],' + + if (type == 'i64' && !WASM_BIGINT) { + // If we lack either BigInt we must fall back to an reading a pair of I32 + // values. + return '(tempI64 = [' + splitI64(value) + '], ' + makeSetValue(ptr, pos, 'tempI64[0]', 'i32') + ',' + makeSetValue(ptr, getFastValue(pos, '+', getNativeTypeSize('i32')), 'tempI64[1]', 'i32') + ')'; } diff --git a/src/preamble.js b/src/preamble.js index b6cb5d2d2de56..55fb916518437 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -1156,9 +1156,11 @@ function createWasm() { #endif } +#if !WASM_BIGINT // Globals used by JS i64 conversions (see makeSetValue) var tempDouble; var tempI64; +#endif #include "runtime_debug.js" diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index dd67803067d5e..750374c76d04b 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -39,7 +39,7 @@ function abort(what) { throw {{{ ASSERTIONS ? 'new Error(what)' : 'what' }}}; } -#if SAFE_HEAP +#if SAFE_HEAP && !WASM_BIGINT // Globals used by JS i64 conversions (see makeSetValue) var tempDouble; var tempI64; diff --git a/test/other/metadce/test_metadce_cxx_ctors1.jssize b/test/other/metadce/test_metadce_cxx_ctors1.jssize index 49e2b95cc2ae9..cfd500263a04b 100644 --- a/test/other/metadce/test_metadce_cxx_ctors1.jssize +++ b/test/other/metadce/test_metadce_cxx_ctors1.jssize @@ -1 +1 @@ -25939 +25914 diff --git a/test/other/metadce/test_metadce_cxx_ctors2.jssize b/test/other/metadce/test_metadce_cxx_ctors2.jssize index 8c9d5517f8bda..ad29f7c112c4a 100644 --- a/test/other/metadce/test_metadce_cxx_ctors2.jssize +++ b/test/other/metadce/test_metadce_cxx_ctors2.jssize @@ -1 +1 @@ -25903 +25878 diff --git a/test/other/metadce/test_metadce_cxx_except.jssize b/test/other/metadce/test_metadce_cxx_except.jssize index ad26bc5dd957b..ab4fd0a0713ae 100644 --- a/test/other/metadce/test_metadce_cxx_except.jssize +++ b/test/other/metadce/test_metadce_cxx_except.jssize @@ -1 +1 @@ -30453 +30428 diff --git a/test/other/metadce/test_metadce_cxx_except_wasm.jssize b/test/other/metadce/test_metadce_cxx_except_wasm.jssize index 7b9c7d539c3a4..4cb8626753a4f 100644 --- a/test/other/metadce/test_metadce_cxx_except_wasm.jssize +++ b/test/other/metadce/test_metadce_cxx_except_wasm.jssize @@ -1 +1 @@ -25748 +25723 diff --git a/test/other/metadce/test_metadce_cxx_mangle.jssize b/test/other/metadce/test_metadce_cxx_mangle.jssize index b827c6486a83a..3a436364b573f 100644 --- a/test/other/metadce/test_metadce_cxx_mangle.jssize +++ b/test/other/metadce/test_metadce_cxx_mangle.jssize @@ -1 +1 @@ -30457 +30432 diff --git a/test/other/metadce/test_metadce_cxx_noexcept.jssize b/test/other/metadce/test_metadce_cxx_noexcept.jssize index 49e2b95cc2ae9..cfd500263a04b 100644 --- a/test/other/metadce/test_metadce_cxx_noexcept.jssize +++ b/test/other/metadce/test_metadce_cxx_noexcept.jssize @@ -1 +1 @@ -25939 +25914 diff --git a/test/other/test_parseTools.c b/test/other/test_parseTools.c index 42c27d097afec..724e9720ede07 100644 --- a/test/other/test_parseTools.c +++ b/test/other/test_parseTools.c @@ -7,7 +7,6 @@ void test_makeGetValue(int64_t* ptr); void test_makeSetValue(int64_t* ptr); int test_receiveI64ParamAsI53(int64_t arg1, int64_t arg2); int test_receiveI64ParamAsDouble(int64_t arg1, int64_t arg2); -void test_makeSetValue_unaligned(int64_t* ptr); #define MAX_SAFE_INTEGER (1ll << 53) #define MIN_SAFE_INTEGER (-MAX_SAFE_INTEGER) @@ -55,18 +54,6 @@ int main() { rtn = test_receiveI64ParamAsDouble(MIN_SAFE_INTEGER - 1, 0); printf("rtn = %d\n", rtn); - printf("\ntest_makeSetValue_unaligned\n"); - // Test an unaligned read of an i64 in JS. To do that, get an unaligned - // pointer. i64s are only 32-bit aligned, but we can't rely on the address to - // happen to be unaligned here, so actually force an unaligned address (one - // of the iterations will be unaligned). - char buffer[16]; - for (size_t i = 0; i < 8; i += 4) { - int64_t* unaligned_i64 = (int64_t*)(buffer + i); - test_makeSetValue_unaligned(unaligned_i64); - printf("i64 = 0x%llx\n", *unaligned_i64); - } - printf("\ndone\n"); return 0; } diff --git a/test/other/test_parseTools.js b/test/other/test_parseTools.js index a8da60869d042..6247abbfad7cf 100644 --- a/test/other/test_parseTools.js +++ b/test/other/test_parseTools.js @@ -106,12 +106,17 @@ mergeInto(LibraryManager.library, { {{{ makeSetValue('ptr', '0', 0x12345678AB, 'i64') }}}; _printI64(ptr); - // This value doesn't fit into i64. The current behaviour here is to - // truncate and round (see splitI16 in parseTools.js) + // This value doesn't fit into i64. The current behaviour truncate (i.e. + // ignore the upper bits), in the same way that `BigInt64Array[X] = Y` does. + // (see splitI16 in parseTools.js) _clearI64(ptr); {{{ makeSetValue('ptr', '0', 0x1122334455667788AA, 'i64') }}}; _printI64(ptr); + _clearI64(ptr); + {{{ makeSetValue('ptr', '0', -0x1122334455667788AA, 'i64') }}}; + _printI64(ptr); + _clearI64(ptr); {{{ makeSetValue('ptr', '0', 0x12345678AB, 'i53') }}}; _printI64(ptr); @@ -128,8 +133,4 @@ mergeInto(LibraryManager.library, { {{{ makeSetValue('ptr', '0', 0x12345678ab, 'i32') }}}; _printI64(ptr); }, - - test_makeSetValue_unaligned: function(ptr) { - {{{ makeSetValue('ptr', '0', 0x12345678AB, 'i64') }}}; - }, }); diff --git a/test/other/test_parseTools.out b/test/other/test_parseTools.out index c6c40feaad578..780e7f8f24733 100644 --- a/test/other/test_parseTools.out +++ b/test/other/test_parseTools.out @@ -19,7 +19,8 @@ ptr: edcba988 test_makeSetValue: printI64: 0x12345678ab -printI64: 0xffffffff66780000 +printI64: 0x2233445566780000 +printI64: 0xddccbbaa99880000 printI64: 0x12345678ab printI64: 0xffffffffffffffff printI64: 0xff @@ -61,8 +62,4 @@ arg1: -9007199254740992 arg2: 0 rtn = 0 -test_makeSetValue_unaligned -i64 = 0x12345678ab -i64 = 0x12345678ab - done diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index f44658ab30b09..8e0545a3a593b 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -59613 +59584 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index 684f212104582..2a7a3ea68f817 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -33284 +33255 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index cd1258f5c0977..32993c88f3353 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -58555 +58526