diff --git a/build-time-compiler/src/main/java/run/endive/build/time/compiler/Generator.java b/build-time-compiler/src/main/java/run/endive/build/time/compiler/Generator.java index d0a79f1c3..50d1cad40 100644 --- a/build-time-compiler/src/main/java/run/endive/build/time/compiler/Generator.java +++ b/build-time-compiler/src/main/java/run/endive/build/time/compiler/Generator.java @@ -139,7 +139,7 @@ public void generateModuleInterface(String moduleInterfaceName) throws IOExcepti public void generateMetaWasm(Set interpretedFunctions) throws IOException { byte[] wasmBytes = Files.readAllBytes(config.wasmFile()); - var module = Parser.builder().includeSectionId(SectionId.CODE).build().parse(wasmBytes); + var module = Parser.parse(wasmBytes); var writer = new WasmWriter(); Parser.parseWithoutDecoding( diff --git a/cli/src/main/java/run/endive/experimental/cli/Cli.java b/cli/src/main/java/run/endive/experimental/cli/Cli.java index fd80b33e9..eaa62b970 100644 --- a/cli/src/main/java/run/endive/experimental/cli/Cli.java +++ b/cli/src/main/java/run/endive/experimental/cli/Cli.java @@ -86,11 +86,7 @@ public void run() { var result = export.apply(params); if (result != null) { for (var r : result) { - if (result == null) { - System.out.println(0); - } else { - System.out.println(r); // Check floating point results - } + System.out.println(r); // Check floating point results } } } diff --git a/runtime/src/main/java/run/endive/runtime/InterpreterMachine.java b/runtime/src/main/java/run/endive/runtime/InterpreterMachine.java index a33bebcd1..a88ba1bca 100644 --- a/runtime/src/main/java/run/endive/runtime/InterpreterMachine.java +++ b/runtime/src/main/java/run/endive/runtime/InterpreterMachine.java @@ -1506,6 +1506,9 @@ private static void I32_SHR_S(MStack stack) { private static void I32_SHL(MStack stack) { var c = (int) stack.pop(); var v = (int) stack.pop(); + // Intentionally get the result as 32 bit `int` (despite it being converted to `long` when + // pushed to the stack) + //noinspection IntegerMultiplicationImplicitCastToLong stack.push(v << c); } diff --git a/simd/src/main/java/run/endive/simd/SimdInterpreterMachine.java b/simd/src/main/java/run/endive/simd/SimdInterpreterMachine.java index d39edffe4..3e22253ef 100644 --- a/simd/src/main/java/run/endive/simd/SimdInterpreterMachine.java +++ b/simd/src/main/java/run/endive/simd/SimdInterpreterMachine.java @@ -1369,8 +1369,6 @@ private static byte addSatU(byte a, byte b) { int result = Byte.toUnsignedInt(a) + Byte.toUnsignedInt(b); if (result >= 0xFF) { return (byte) 0xFF; - } else if (result < 0) { - return 0; } else { return (byte) result; } @@ -1736,53 +1734,23 @@ private static void BINOP( } private static boolean lt(float a, float b) { - if (Float.isNaN(b)) { - return false; - } else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) { - return false; - } else { - return Float.compare(a, b) < 0; - } + return a < b; } private static boolean le(float a, float b) { - if (Float.isNaN(b)) { - return false; - } else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) { - return true; - } else { - return Float.compare(a, b) <= 0; - } + return a <= b; } private static boolean gt(float a, float b) { - if (Float.isNaN(a)) { - return false; - } else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) { - return false; - } else { - return Float.compare(a, b) > 0; - } + return a > b; } private static boolean ge(float a, float b) { - if (Float.isNaN(a)) { - return false; - } else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) { - return true; - } else { - return Float.compare(a, b) >= 0; - } + return a >= b; } private static boolean equals(float a, float b) { - if (Float.isNaN(a) || Float.isNaN(b)) { - return false; - } else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) { - return true; - } else { - return Float.compare(a, b) == 0; - } + return a == b; } private static void F32x4(MStack stack, BiFunction fn) { @@ -1925,7 +1893,7 @@ private static void BITMASK(MStack stack, Function reduce) { var result = 0L; for (int i = 0; i < vals.length; i++) { if (vals[i] < 0) { - result |= 1 << i; + result |= 1L << i; } } @@ -2564,7 +2532,7 @@ private static void I64x2_EXTMUL_LOW_I32x4_S(MStack stack) { var res = new long[] { - v1[0] * v2[0], v1[1] * v2[1], + ((long) v1[0]) * v2[0], ((long) v1[1]) * v2[1], }; var result = Value.i64ToVec(res); System.arraycopy(result, 0, stack.array(), offset, 2); @@ -2587,7 +2555,7 @@ private static void I64x2_EXTMUL_HIGH_I32x4_S(MStack stack) { var res = new long[] { - v1[2] * v2[2], v1[3] * v2[3], + ((long) v1[2]) * v2[2], ((long) v1[3]) * v2[3], }; var result = Value.i64ToVec(res); System.arraycopy(result, 0, stack.array(), offset, 2); @@ -3007,7 +2975,7 @@ private static void I8x16_SWIZZLE(MStack stack) { if (id < 8) { base = (baseLow >> (id * 8)) & 0xFFL; } else if (id < 16) { - base = (baseHigh >> (id * 8)) & 0xFFL; + base = (baseHigh >> ((id - 8) * 8)) & 0xFFL; } else { base = 0x00L; } diff --git a/wasm/src/main/java/run/endive/wasm/Parser.java b/wasm/src/main/java/run/endive/wasm/Parser.java index 5c4293709..430f5d60a 100644 --- a/wasm/src/main/java/run/endive/wasm/Parser.java +++ b/wasm/src/main/java/run/endive/wasm/Parser.java @@ -1327,7 +1327,7 @@ private static Instruction parseInstruction(ByteBuffer buffer) { operands.add(n); for (var j = 0; j < n; j++) { var catchOp = readByte(buffer); - operands.add(0L | catchOp); + operands.add((long) catchOp); var catchOpcode = CatchOpCode.byOpCode(catchOp); switch (catchOpcode) { case CATCH: