@onda-lang/wasm-compiler 0.8.15 → 0.8.16

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.
@@ -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
- wasm.sub(wasm.sub(arg(1), one), arg(0)),
1238
- widthValue,
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]);
package/dist/build.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
- "ondaVersion": "0.8.15",
2
+ "ondaVersion": "0.8.16",
3
3
  "binaryenVersion": "130.0.0",
4
4
  "frontendPackage": "onda_compiler_web",
5
5
  "frontendOptimization": {
6
6
  "tool": "wasm-opt",
7
7
  "binaryenVersion": "130.0.0",
8
8
  "optimizeLevel": 4,
9
- "inputBytes": 10645365,
10
- "outputBytes": 7806612
9
+ "inputBytes": 10618636,
10
+ "outputBytes": 7782411
11
11
  }
12
12
  }
@@ -5,7 +5,7 @@
5
5
  "Francesco Cameli"
6
6
  ],
7
7
  "description": "Browser-safe Onda source-to-MIR compiler",
8
- "version": "0.8.15",
8
+ "version": "0.8.16",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -675,7 +675,7 @@ SOFTWARE.
675
675
  MIT License (MIT)
676
676
 
677
677
  Used by:
678
- - onda_compiler_web 0.8.15 (https://github.com/onda-lang/onda)
678
+ - onda_compiler_web 0.8.16 (https://github.com/onda-lang/onda)
679
679
 
680
680
  MIT License
681
681
 
@@ -704,13 +704,13 @@ SOFTWARE.
704
704
  MIT License (MIT)
705
705
 
706
706
  Used by:
707
- - onda_frontend 0.8.15
708
- - onda_host_protocol 0.8.15
709
- - onda_lsp 0.8.15
710
- - onda_mir 0.8.15
711
- - onda_processor_abi 0.8.15
712
- - onda_project 0.8.15
713
- - onda_semantics 0.8.15
707
+ - onda_frontend 0.8.16
708
+ - onda_host_protocol 0.8.16
709
+ - onda_lsp 0.8.16
710
+ - onda_mir 0.8.16
711
+ - onda_processor_abi 0.8.16
712
+ - onda_project 0.8.16
713
+ - onda_semantics 0.8.16
714
714
 
715
715
  MIT License
716
716
 
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const ONDA_VERSION = "0.8.15";
1
+ export const ONDA_VERSION = "0.8.16";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onda-lang/wasm-compiler",
3
- "version": "0.8.15",
3
+ "version": "0.8.16",
4
4
  "type": "module",
5
5
  "description": "Onda source-to-WebAssembly compiler for browsers and Node.js",
6
6
  "license": "MIT",
@@ -60,7 +60,7 @@
60
60
  "prepack": "npm run build && node ../../scripts/stage-web-api-docs.mjs"
61
61
  },
62
62
  "dependencies": {
63
- "@onda-lang/processor-abi": "0.8.15",
63
+ "@onda-lang/processor-abi": "0.8.16",
64
64
  "binaryen": "130.0.0"
65
65
  },
66
66
  "publishConfig": {