Skip to content

Commit 8d03d35

Browse files
committed
[emscripten] Remove -sWASM_BIGINT flag
This flag has been enabled by default in emscripten for a while now so I don't think we need this here anymore. The main user-visible effect of this change is that it makes the `module.i64.const` JS method now simply take a single bigint rather than a pair numbers.
1 parent 23f7af1 commit 8d03d35

File tree

8 files changed

+94
-141
lines changed

8 files changed

+94
-141
lines changed

CMakeLists.txt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,6 @@ else() # MSVC
297297
endif()
298298

299299
if(EMSCRIPTEN)
300-
# Note: to debug with DWARF you will usually want to enable BIGINT support, as
301-
# that helps avoid running Binaryen on the wasm after link. Binaryen's DWARF
302-
# rewriting has known limitations, so avoiding it during link is recommended
303-
# where possible (like local debugging).
304-
#
305-
# Note that this is debug info for Binaryen itself, that is, when you are
306-
# debugging Binaryen source code. This flag has no impact on what Binaryen
307-
# does when run on wasm files.
308-
option(ENABLE_BIGINT "Enable wasm BigInt support" OFF)
309-
if(ENABLE_BIGINT)
310-
add_link_flag("-sWASM_BIGINT")
311-
else()
312-
add_link_flag("-sWASM_BIGINT=0")
313-
endif()
314-
315300
if("${CMAKE_BUILD_TYPE}" MATCHES "Release")
316301
# Extra check that cmake has set -O3 in its release flags.
317302
# This is really as an assertion that cmake is behaving as we expect.

scripts/test/shared.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def is_exe(fpath):
195195
which('gcc') or which('clang'))
196196
NATIVEXX = (os.environ.get('CXX') or which('mingw32-g++') or
197197
which('g++') or which('clang++'))
198-
NODEJS = os.environ.get('NODE') or which('node') or which('nodejs')
198+
NODEJS = os.environ.get('NODE') or os.environ.get('EMSDK_NODE') or which('node') or which('nodejs')
199199
MOZJS = which('mozjs') or which('spidermonkey')
200200

201201
V8 = os.environ.get('V8') or which('v8') or which('d8')
@@ -264,9 +264,8 @@ def has_shell_timeout():
264264

265265
try:
266266
if NODEJS is not None:
267-
subprocess.check_call([NODEJS, '--version'],
268-
stdout=subprocess.PIPE,
269-
stderr=subprocess.PIPE)
267+
version = subprocess.check_output([NODEJS, '--version'])
268+
print(f'Using node ({NODEJS}) version: {version.strip()}')
270269
except (OSError, subprocess.CalledProcessError):
271270
NODEJS = None
272271
if NODEJS is None:

src/binaryen-c.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,34 +2763,6 @@ void BinaryenConstSetValueI64(BinaryenExpressionRef expr, int64_t value) {
27632763
assert(expression->is<Const>());
27642764
static_cast<Const*>(expression)->value = Literal(value);
27652765
}
2766-
int32_t BinaryenConstGetValueI64Low(BinaryenExpressionRef expr) {
2767-
auto* expression = (Expression*)expr;
2768-
assert(expression->is<Const>());
2769-
return (int32_t)(static_cast<Const*>(expression)->value.geti64() &
2770-
0xffffffff);
2771-
}
2772-
void BinaryenConstSetValueI64Low(BinaryenExpressionRef expr, int32_t valueLow) {
2773-
auto* expression = (Expression*)expr;
2774-
assert(expression->is<Const>());
2775-
auto& value = static_cast<Const*>(expression)->value;
2776-
int64_t valueI64 = value.type == Type::i64 ? value.geti64() : 0;
2777-
static_cast<Const*>(expression)->value =
2778-
Literal((valueI64 & ~0xffffffff) | (int64_t(valueLow) & 0xffffffff));
2779-
}
2780-
int32_t BinaryenConstGetValueI64High(BinaryenExpressionRef expr) {
2781-
auto* expression = (Expression*)expr;
2782-
assert(expression->is<Const>());
2783-
return (int32_t)(static_cast<Const*>(expression)->value.geti64() >> 32);
2784-
}
2785-
void BinaryenConstSetValueI64High(BinaryenExpressionRef expr,
2786-
int32_t valueHigh) {
2787-
auto* expression = (Expression*)expr;
2788-
assert(expression->is<Const>());
2789-
auto& value = static_cast<Const*>(expression)->value;
2790-
int64_t valueI64 = value.type == Type::i64 ? value.geti64() : 0;
2791-
static_cast<Const*>(expression)->value =
2792-
Literal((int64_t(valueHigh) << 32) | (valueI64 & 0xffffffff));
2793-
}
27942766
float BinaryenConstGetValueF32(BinaryenExpressionRef expr) {
27952767
auto* expression = (Expression*)expr;
27962768
assert(expression->is<Const>());

src/binaryen-c.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,20 +1614,6 @@ BINARYEN_API int64_t BinaryenConstGetValueI64(BinaryenExpressionRef expr);
16141614
// Sets the 64-bit integer value of an `i64.const` expression.
16151615
BINARYEN_API void BinaryenConstSetValueI64(BinaryenExpressionRef expr,
16161616
int64_t value);
1617-
// Gets the low 32-bits of the 64-bit integer value of an `i64.const`
1618-
// expression.
1619-
BINARYEN_API int32_t BinaryenConstGetValueI64Low(BinaryenExpressionRef expr);
1620-
// Sets the low 32-bits of the 64-bit integer value of an `i64.const`
1621-
// expression.
1622-
BINARYEN_API void BinaryenConstSetValueI64Low(BinaryenExpressionRef expr,
1623-
int32_t valueLow);
1624-
// Gets the high 32-bits of the 64-bit integer value of an `i64.const`
1625-
// expression.
1626-
BINARYEN_API int32_t BinaryenConstGetValueI64High(BinaryenExpressionRef expr);
1627-
// Sets the high 32-bits of the 64-bit integer value of an `i64.const`
1628-
// expression.
1629-
BINARYEN_API void BinaryenConstSetValueI64High(BinaryenExpressionRef expr,
1630-
int32_t valueHigh);
16311617
// Gets the 32-bit float value of a `f32.const` expression.
16321618
BINARYEN_API float BinaryenConstGetValueF32(BinaryenExpressionRef expr);
16331619
// Sets the 32-bit float value of a `f32.const` expression.

src/js/binaryen.js-post.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#preprocess
2+
13
// export friendly API methods
24
function preserveStack(func) {
35
try {
@@ -1090,10 +1092,17 @@ function wrapModule(module, self = {}) {
10901092
'store32'(offset, align, ptr, value, name) {
10911093
return preserveStack(() => Module['_BinaryenStore'](module, 4, offset, align, ptr, value, Module['i64'], strToStack(name)));
10921094
},
1093-
'const'(x, y) {
1095+
'const'(x, y = undefined) {
10941096
return preserveStack(() => {
10951097
const tempLiteral = stackAlloc(sizeOfLiteral);
1098+
#if WASM_BIGINT
1099+
assert(typeof y == 'undefined', 'i64.const now take a single argument (which can be a bigint)');
1100+
// We insert a cast to BigInt here in an attempt to be backwards
1101+
// compatible with callers to passed a single number here.
1102+
Module['_BinaryenLiteralInt64'](tempLiteral, BigInt(x));
1103+
#else
10961104
Module['_BinaryenLiteralInt64'](tempLiteral, x, y);
1105+
#endif
10971106
return Module['_BinaryenConst'](module, tempLiteral);
10981107
});
10991108
},
@@ -1507,10 +1516,15 @@ function wrapModule(module, self = {}) {
15071516
return Module['_BinaryenConst'](module, tempLiteral);
15081517
});
15091518
},
1510-
'const_bits'(x, y) {
1519+
'const_bits'(x, y = undefined) {
15111520
return preserveStack(() => {
15121521
const tempLiteral = stackAlloc(sizeOfLiteral);
1522+
#if WASM_BIGINT
1523+
assert(typeof y == 'undefined', 'f64.const_bits now take a single argument (which can be a bigint)');
1524+
Module['_BinaryenLiteralFloat64Bits'](tempLiteral, BigInt(x));
1525+
#else
15131526
Module['_BinaryenLiteralFloat64Bits'](tempLiteral, x, y);
1527+
#endif
15141528
return Module['_BinaryenConst'](module, tempLiteral);
15151529
});
15161530
},
@@ -3063,10 +3077,7 @@ Module['getExpressionInfo'] = function(expr) {
30633077
case Module['ConstId']:
30643078
switch (type) {
30653079
case Module['i32']: info.value = Module['_BinaryenConstGetValueI32'](expr); break;
3066-
case Module['i64']: info.value = {
3067-
'low': Module['_BinaryenConstGetValueI64Low'](expr),
3068-
'high': Module['_BinaryenConstGetValueI64High'](expr)
3069-
}; break;
3080+
case Module['i64']: info.value = Module['_BinaryenConstGetValueI64'](expr); break;
30703081
case Module['f32']: info.value = Module['_BinaryenConstGetValueF32'](expr); break;
30713082
case Module['f64']: info.value = Module['_BinaryenConstGetValueF64'](expr); break;
30723083
case Module['v128']: {
@@ -3992,17 +4003,11 @@ Module['Const'] = makeExpressionWrapper(Module['_BinaryenConstId'](), {
39924003
'setValueI32'(expr, value) {
39934004
Module['_BinaryenConstSetValueI32'](expr, value);
39944005
},
3995-
'getValueI64Low'(expr) {
3996-
return Module['_BinaryenConstGetValueI64Low'](expr);
3997-
},
3998-
'setValueI64Low'(expr, value) {
3999-
Module['_BinaryenConstSetValueI64Low'](expr, value);
4000-
},
4001-
'getValueI64High'(expr) {
4002-
return Module['_BinaryenConstGetValueI64High'](expr);
4006+
'getValueI64'(expr) {
4007+
return Module['_BinaryenConstGetValueI64'](expr);
40034008
},
4004-
'setValueI64High'(expr, value) {
4005-
Module['_BinaryenConstSetValueI64High'](expr, value);
4009+
'setValueI64'(expr, value) {
4010+
Module['_BinaryenConstSetValueI64'](expr, BigInt(value));
40064011
},
40074012
'getValueF32'(expr) {
40084013
return Module['_BinaryenConstGetValueF32'](expr);

test/binaryen.js/expressions.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -832,17 +832,14 @@ console.log("# Const");
832832
assert(info.type === theConst.type);
833833
assert(info.value === theConst.valueI32);
834834

835-
theConst.valueI64Low = 3;
836-
assert(theConst.valueI64Low === 3);
837-
theConst.valueI64High = 4;
838-
assert(theConst.valueI64High === 4);
835+
theConst.valueI64 = 3;
836+
assert(theConst.valueI64 == 3);
839837
theConst.finalize();
840838
assert(theConst.type == binaryen.i64);
841839

842840
info = binaryen.getExpressionInfo(theConst);
843841
assert(info.type === theConst.type);
844-
assert(info.value.low === theConst.valueI64Low);
845-
assert(info.value.high === theConst.valueI64High);
842+
assert(info.value === theConst.valueI64);
846843

847844
theConst.valueF32 = 5;
848845
assert(theConst.valueF32 === 5);

test/binaryen.js/kitchen-sink.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function makeFloat32(x) {
2424
return module.f32.const(x);
2525
}
2626

27-
function makeInt64(l, h) {
28-
return module.i64.const(l, h);
27+
function makeInt64(x) {
28+
return module.i64.const(x);
2929
}
3030

3131
function makeFloat64(x) {
@@ -214,7 +214,7 @@ function test_core() {
214214
constF32 = module.f32.const(3.14),
215215
constF64 = module.f64.const(2.1828),
216216
constF32Bits = module.f32.const_bits(0xffff1234),
217-
constF64Bits = module.f64.const_bits(0x5678abcd, 0xffff1234);
217+
constF64Bits = module.f64.const_bits(0xffff1234_5678abcdn);
218218

219219
var iIfF = binaryen.createType([binaryen.i32, binaryen.i64, binaryen.f32, binaryen.f64])
220220

@@ -233,7 +233,7 @@ function test_core() {
233233
var valueList = [
234234
// Unary
235235
module.i32.clz(module.i32.const(-10)),
236-
module.i64.ctz(module.i64.const(-22, -1)),
236+
module.i64.ctz(module.i64.const(-23)),
237237
module.i32.popcnt(module.i32.const(-10)),
238238
module.f32.neg(module.f32.const(-33.612)),
239239
module.f64.abs(module.f64.const(-9005.841)),
@@ -245,7 +245,7 @@ function test_core() {
245245
module.i32.eqz(module.i32.const(-10)),
246246
module.i64.extend_s(module.i32.const(-10)),
247247
module.i64.extend_u(module.i32.const(-10)),
248-
module.i32.wrap(module.i64.const(-22, -1)),
248+
module.i32.wrap(module.i64.const(-23)),
249249
module.i32.trunc_s.f32(module.f32.const(-33.612)),
250250
module.i64.trunc_s.f32(module.f32.const(-33.612)),
251251
module.i32.trunc_u.f32(module.f32.const(-33.612)),
@@ -268,18 +268,18 @@ function test_core() {
268268
module.f64.convert_s.i32(module.i32.const(-10)),
269269
module.f32.convert_u.i32(module.i32.const(-10)),
270270
module.f64.convert_u.i32(module.i32.const(-10)),
271-
module.f32.convert_s.i64(module.i64.const(-22, -1)),
272-
module.f64.convert_s.i64(module.i64.const(-22, -1)),
273-
module.f32.convert_u.i64(module.i64.const(-22, -1)),
274-
module.f64.convert_u.i64(module.i64.const(-22, -1)),
271+
module.f32.convert_s.i64(module.i64.const(-23)),
272+
module.f64.convert_s.i64(module.i64.const(-23)),
273+
module.f32.convert_u.i64(module.i64.const(-23)),
274+
module.f64.convert_u.i64(module.i64.const(-23)),
275275
module.f64.promote(module.f32.const(-33.612)),
276276
module.f32.demote(module.f64.const(-9005.841)),
277277
module.f32.reinterpret(module.i32.const(-10)),
278-
module.f64.reinterpret(module.i64.const(-22, -1)),
278+
module.f64.reinterpret(module.i64.const(-23)),
279279
module.i8x16.splat(module.i32.const(42)),
280280
module.i16x8.splat(module.i32.const(42)),
281281
module.i32x4.splat(module.i32.const(42)),
282-
module.i64x2.splat(module.i64.const(123, 456)),
282+
module.i64x2.splat(module.i64.const(1_000_000_000_123n)),
283283
module.f32x4.splat(module.f32.const(42.0)),
284284
module.f64x2.splat(module.f64.const(42.0)),
285285
module.v128.not(module.v128.const(v128_bytes)),
@@ -337,31 +337,31 @@ function test_core() {
337337
module.i32.add(module.i32.const(-10), module.i32.const(-11)),
338338
module.f64.sub(module.f64.const(-9005.841), module.f64.const(-9007.333)),
339339
module.i32.div_s(module.i32.const(-10), module.i32.const(-11)),
340-
module.i64.div_u(module.i64.const(-22, 0), module.i64.const(-23, 0)),
341-
module.i64.rem_s(module.i64.const(-22, 0), module.i64.const(-23, 0)),
340+
module.i64.div_u(module.i64.const(-22), module.i64.const(-23)),
341+
module.i64.rem_s(module.i64.const(-22), module.i64.const(-23)),
342342
module.i32.rem_u(module.i32.const(-10), module.i32.const(-11)),
343343
module.i32.and(module.i32.const(-10), module.i32.const(-11)),
344-
module.i64.or(module.i64.const(-22, 0), module.i64.const(-23, 0)),
344+
module.i64.or(module.i64.const(-22), module.i64.const(-23)),
345345
module.i32.xor(module.i32.const(-10), module.i32.const(-11)),
346-
module.i64.shl(module.i64.const(-22, 0), module.i64.const(-23, 0)),
347-
module.i64.shr_u(module.i64.const(-22, 0), module.i64.const(-23, 0)),
346+
module.i64.shl(module.i64.const(-22), module.i64.const(-23)),
347+
module.i64.shr_u(module.i64.const(-22), module.i64.const(-23)),
348348
module.i32.shr_s(module.i32.const(-10), module.i32.const(-11)),
349349
module.i32.rotl(module.i32.const(-10), module.i32.const(-11)),
350-
module.i64.rotr(module.i64.const(-22, 0), module.i64.const(-23, 0)),
350+
module.i64.rotr(module.i64.const(-22), module.i64.const(-23)),
351351
module.f32.div(module.f32.const(-33.612), module.f32.const(-62.5)),
352352
module.f64.copysign(module.f64.const(-9005.841), module.f64.const(-9007.333)),
353353
module.f32.min(module.f32.const(-33.612), module.f32.const(-62.5)),
354354
module.f64.max(module.f64.const(-9005.841), module.f64.const(-9007.333)),
355355
module.i32.eq(module.i32.const(-10), module.i32.const(-11)),
356356
module.f32.ne(module.f32.const(-33.612), module.f32.const(-62.5)),
357357
module.i32.lt_s(module.i32.const(-10), module.i32.const(-11)),
358-
module.i64.lt_u(module.i64.const(-22, 0), module.i64.const(-23, 0)),
359-
module.i64.le_s(module.i64.const(-22, 0), module.i64.const(-23, 0)),
358+
module.i64.lt_u(module.i64.const(-22), module.i64.const(-23)),
359+
module.i64.le_s(module.i64.const(-22), module.i64.const(-23)),
360360
module.i32.le_u(module.i32.const(-10), module.i32.const(-11)),
361-
module.i64.gt_s(module.i64.const(-22, 0), module.i64.const(-23, 0)),
361+
module.i64.gt_s(module.i64.const(-23), module.i64.const(-23)),
362362
module.i32.gt_u(module.i32.const(-10), module.i32.const(-11)),
363363
module.i32.ge_s(module.i32.const(-10), module.i32.const(-11)),
364-
module.i64.ge_u(module.i64.const(-22, 0), module.i64.const(-23, 0)),
364+
module.i64.ge_u(module.i64.const(-22), module.i64.const(-23)),
365365
module.f32.lt(module.f32.const(-33.612), module.f32.const(-62.5)),
366366
module.f64.le(module.f64.const(-9005.841), module.f64.const(-9007.333)),
367367
module.f64.gt(module.f64.const(-9005.841), module.f64.const(-9007.333)),
@@ -506,7 +506,7 @@ function test_core() {
506506
module.i16x8.replace_lane(module.v128.const(v128_bytes), 1, module.i32.const(42)),
507507
module.i8x16.replace_lane(module.v128.const(v128_bytes), 1, module.i32.const(42)),
508508
module.i32x4.replace_lane(module.v128.const(v128_bytes), 1, module.i32.const(42)),
509-
module.i64x2.replace_lane(module.v128.const(v128_bytes), 1, module.i64.const(42, 43)),
509+
module.i64x2.replace_lane(module.v128.const(v128_bytes), 1, module.i64.const(42)),
510510
module.f32x4.replace_lane(module.v128.const(v128_bytes), 1, module.f32.const(42)),
511511
module.f64x2.replace_lane(module.v128.const(v128_bytes), 1, module.f64.const(42)),
512512
// SIMD shift
@@ -698,15 +698,24 @@ function test_core() {
698698
}
699699
}
700700

701-
console.log("getExpressionInfo(i32.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.i32.const(5))));
702-
console.log("getExpressionInfo(i64.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.i64.const(6, 7))));
703-
console.log("getExpressionInfo(f32.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.f32.const(8.5))));
704-
console.log("getExpressionInfo(f64.const)=" + JSON.stringify(binaryen.getExpressionInfo(module.f64.const(9.5))));
701+
function infoToString(info) {
702+
// BigInt values cannot be pass through JSON.stringify so convert
703+
// them to strings first.
704+
if (typeof info.value === 'bigint') {
705+
info.value = info.value.toString();
706+
}
707+
return JSON.stringify(info);
708+
}
709+
710+
console.log("getExpressionInfo(i32.const)=" + infoToString(binaryen.getExpressionInfo(module.i32.const(5))));
711+
console.log("getExpressionInfo(i64.const)=" + infoToString(binaryen.getExpressionInfo(module.i64.const(6))));
712+
console.log("getExpressionInfo(f32.const)=" + infoToString(binaryen.getExpressionInfo(module.f32.const(8.5))));
713+
console.log("getExpressionInfo(f64.const)=" + infoToString(binaryen.getExpressionInfo(module.f64.const(9.5))));
705714
var elements = binaryen.getExpressionInfo(
706715
module.tuple.make([ makeInt32(13), makeInt64(37, 0), makeFloat32(1.3), makeFloat64(3.7) ])
707716
).operands;
708717
for (var i = 0; i < elements.length; i++) {
709-
console.log("getExpressionInfo(tuple[" + i + "])=" + JSON.stringify(binaryen.getExpressionInfo(elements[i])));
718+
console.log("getExpressionInfo(tuple[" + i + "])=" + infoToString(binaryen.getExpressionInfo(elements[i])));
710719
}
711720

712721
// Make the main body of the function. and one block with a return value, one without

0 commit comments

Comments
 (0)