@onda-lang/binaryen-web 0.8.15 → 0.8.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/compiler/index.js +15 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onda-lang/binaryen-web",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Binaryen backend for versioned Onda MIR in browsers and Node.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"verify-mir": "node ./scripts/verify-mir.mjs"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@onda-lang/processor-abi": "0.8.
|
|
49
|
+
"@onda-lang/processor-abi": "0.8.17",
|
|
50
50
|
"binaryen": "130.0.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
package/src/compiler/index.js
CHANGED
|
@@ -1159,7 +1159,6 @@ export class MirCompiler extends MirCompilerLowering {
|
|
|
1159
1159
|
const scalar = data.args.length
|
|
1160
1160
|
? this.valueScalarType(data.args[0], context)
|
|
1161
1161
|
: expectedScalar;
|
|
1162
|
-
const args = data.args.map((value) => this.compileValue(value, context));
|
|
1163
1162
|
const isFloat = scalar === "f32" || scalar === "f64";
|
|
1164
1163
|
const isInteger = scalar === "i32" || scalar === "i64";
|
|
1165
1164
|
if (!isFloat && !isInteger) {
|
|
@@ -1212,37 +1211,45 @@ export class MirCompiler extends MirCompilerLowering {
|
|
|
1212
1211
|
const bits = scalar === "i64" ? 64n : 32n;
|
|
1213
1212
|
const width = upper - lower + 1n;
|
|
1214
1213
|
if (width === (1n << bits)) return arg(0);
|
|
1214
|
+
if (width === 1n) return arg(1);
|
|
1215
1215
|
const encodedWidth = BigInt.asIntN(Number(bits), width);
|
|
1216
|
-
const widthValue = scalar === "i64"
|
|
1216
|
+
const widthValue = () => scalar === "i64"
|
|
1217
1217
|
? this.module.i64.const(encodedWidth)
|
|
1218
1218
|
: this.module.i32.const(Number(encodedWidth));
|
|
1219
1219
|
const encodedSpan = BigInt.asIntN(Number(bits), width - 1n);
|
|
1220
|
-
const spanValue = scalar === "i64"
|
|
1220
|
+
const spanValue = () => scalar === "i64"
|
|
1221
1221
|
? this.module.i64.const(encodedSpan)
|
|
1222
1222
|
: this.module.i32.const(Number(encodedSpan));
|
|
1223
1223
|
const one = scalar === "i64"
|
|
1224
1224
|
? this.module.i64.const(1n)
|
|
1225
1225
|
: this.module.i32.const(1);
|
|
1226
|
+
const allOnes = scalar === "i64"
|
|
1227
|
+
? this.module.i64.const(-1n)
|
|
1228
|
+
: this.module.i32.const(-1);
|
|
1226
1229
|
const distanceFromLower = lower === 0n
|
|
1227
1230
|
? arg(0)
|
|
1228
1231
|
: wasm.sub(arg(0), arg(1));
|
|
1229
1232
|
return this.module.if(
|
|
1230
|
-
wasm.le_u(distanceFromLower, spanValue),
|
|
1233
|
+
wasm.le_u(distanceFromLower, spanValue()),
|
|
1231
1234
|
arg(0),
|
|
1232
1235
|
this.module.if(
|
|
1233
1236
|
wasm.lt_s(arg(0), arg(1)),
|
|
1234
1237
|
wasm.sub(
|
|
1235
1238
|
arg(2),
|
|
1236
1239
|
wasm.rem_u(
|
|
1237
|
-
|
|
1238
|
-
|
|
1240
|
+
// `lower - 1 - value` is the exact unsigned distance from
|
|
1241
|
+
// a value below the range. Express it as `lower + ~value`
|
|
1242
|
+
// so optimization preserves the source-width wrap instead
|
|
1243
|
+
// of reassociating subtraction across the unsigned modulo.
|
|
1244
|
+
wasm.add(arg(1), wasm.xor(arg(0), allOnes)),
|
|
1245
|
+
widthValue(),
|
|
1239
1246
|
),
|
|
1240
1247
|
),
|
|
1241
1248
|
wasm.add(
|
|
1242
1249
|
arg(1),
|
|
1243
1250
|
wasm.rem_u(
|
|
1244
1251
|
wasm.sub(arg(0), wasm.add(arg(2), one)),
|
|
1245
|
-
widthValue,
|
|
1252
|
+
widthValue(),
|
|
1246
1253
|
),
|
|
1247
1254
|
),
|
|
1248
1255
|
),
|
|
@@ -1253,6 +1260,7 @@ export class MirCompiler extends MirCompilerLowering {
|
|
|
1253
1260
|
}
|
|
1254
1261
|
}
|
|
1255
1262
|
|
|
1263
|
+
const args = data.args.map((value) => this.compileValue(value, context));
|
|
1256
1264
|
switch (data.intrinsic) {
|
|
1257
1265
|
case "sqrt": return wasm.sqrt(args[0]);
|
|
1258
1266
|
case "abs": return wasm.abs(args[0]);
|