Skip to content

Commit 7842962

Browse files
Marcono1234andreaTP
authored andcommitted
Fix potential bug IntelliJ warnings
1 parent 5787881 commit 7842962

5 files changed

Lines changed: 20 additions & 48 deletions

File tree

build-time-compiler/src/main/java/run/endive/build/time/compiler/Generator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.github.javaparser.ast.stmt.ThrowStmt;
2424
import com.github.javaparser.ast.stmt.TryStmt;
2525
import com.github.javaparser.utils.SourceRoot;
26+
import java.io.ByteArrayInputStream;
2627
import java.io.ByteArrayOutputStream;
2728
import java.io.IOException;
2829
import java.io.InputStream;
@@ -139,7 +140,11 @@ public void generateModuleInterface(String moduleInterfaceName) throws IOExcepti
139140

140141
public void generateMetaWasm(Set<Integer> interpretedFunctions) throws IOException {
141142
byte[] wasmBytes = Files.readAllBytes(config.wasmFile());
142-
var module = Parser.builder().includeSectionId(SectionId.CODE).build().parse(wasmBytes);
143+
var module =
144+
Parser.builder()
145+
.includeSectionId(SectionId.CODE)
146+
.build()
147+
.parse(() -> new ByteArrayInputStream(wasmBytes));
143148

144149
var writer = new WasmWriter();
145150
Parser.parseWithoutDecoding(

cli/src/main/java/run/endive/experimental/cli/Cli.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ public void run() {
8686
var result = export.apply(params);
8787
if (result != null) {
8888
for (var r : result) {
89-
if (result == null) {
90-
System.out.println(0);
91-
} else {
92-
System.out.println(r); // Check floating point results
93-
}
89+
System.out.println(r); // Check floating point results
9490
}
9591
}
9692
}

runtime/src/main/java/run/endive/runtime/InterpreterMachine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,9 @@ private static void I32_SHR_S(MStack stack) {
15061506
private static void I32_SHL(MStack stack) {
15071507
var c = (int) stack.pop();
15081508
var v = (int) stack.pop();
1509+
// Intentionally get the result as 32 bit `int` (despite it being converted to `long` when
1510+
// pushed to the stack)
1511+
//noinspection IntegerMultiplicationImplicitCastToLong
15091512
stack.push(v << c);
15101513
}
15111514

simd/src/main/java/run/endive/simd/SimdInterpreterMachine.java

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,6 @@ private static byte addSatU(byte a, byte b) {
13691369
int result = Byte.toUnsignedInt(a) + Byte.toUnsignedInt(b);
13701370
if (result >= 0xFF) {
13711371
return (byte) 0xFF;
1372-
} else if (result < 0) {
1373-
return 0;
13741372
} else {
13751373
return (byte) result;
13761374
}
@@ -1736,53 +1734,23 @@ private static void BINOP(
17361734
}
17371735

17381736
private static boolean lt(float a, float b) {
1739-
if (Float.isNaN(b)) {
1740-
return false;
1741-
} else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) {
1742-
return false;
1743-
} else {
1744-
return Float.compare(a, b) < 0;
1745-
}
1737+
return a <= b;
17461738
}
17471739

17481740
private static boolean le(float a, float b) {
1749-
if (Float.isNaN(b)) {
1750-
return false;
1751-
} else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) {
1752-
return true;
1753-
} else {
1754-
return Float.compare(a, b) <= 0;
1755-
}
1741+
return a <= b;
17561742
}
17571743

17581744
private static boolean gt(float a, float b) {
1759-
if (Float.isNaN(a)) {
1760-
return false;
1761-
} else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) {
1762-
return false;
1763-
} else {
1764-
return Float.compare(a, b) > 0;
1765-
}
1745+
return a > b;
17661746
}
17671747

17681748
private static boolean ge(float a, float b) {
1769-
if (Float.isNaN(a)) {
1770-
return false;
1771-
} else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) {
1772-
return true;
1773-
} else {
1774-
return Float.compare(a, b) >= 0;
1775-
}
1749+
return a >= b;
17761750
}
17771751

17781752
private static boolean equals(float a, float b) {
1779-
if (Float.isNaN(a) || Float.isNaN(b)) {
1780-
return false;
1781-
} else if ((a == 0.0f && b == -0.0f) || (a == -0.0f && b == 0.0f)) {
1782-
return true;
1783-
} else {
1784-
return Float.compare(a, b) == 0;
1785-
}
1753+
return a == b;
17861754
}
17871755

17881756
private static void F32x4(MStack stack, BiFunction<Float, Float, Long> fn) {
@@ -1925,7 +1893,7 @@ private static void BITMASK(MStack stack, Function<LongVector, long[]> reduce) {
19251893
var result = 0L;
19261894
for (int i = 0; i < vals.length; i++) {
19271895
if (vals[i] < 0) {
1928-
result |= 1 << i;
1896+
result |= 1L << i;
19291897
}
19301898
}
19311899

@@ -2564,7 +2532,7 @@ private static void I64x2_EXTMUL_LOW_I32x4_S(MStack stack) {
25642532

25652533
var res =
25662534
new long[] {
2567-
v1[0] * v2[0], v1[1] * v2[1],
2535+
((long) v1[0]) * v2[0], ((long) v1[1]) * v2[1],
25682536
};
25692537
var result = Value.i64ToVec(res);
25702538
System.arraycopy(result, 0, stack.array(), offset, 2);
@@ -2587,7 +2555,7 @@ private static void I64x2_EXTMUL_HIGH_I32x4_S(MStack stack) {
25872555

25882556
var res =
25892557
new long[] {
2590-
v1[2] * v2[2], v1[3] * v2[3],
2558+
((long) v1[2]) * v2[2], ((long) v1[3]) * v2[3],
25912559
};
25922560
var result = Value.i64ToVec(res);
25932561
System.arraycopy(result, 0, stack.array(), offset, 2);
@@ -3007,7 +2975,7 @@ private static void I8x16_SWIZZLE(MStack stack) {
30072975
if (id < 8) {
30082976
base = (baseLow >> (id * 8)) & 0xFFL;
30092977
} else if (id < 16) {
3010-
base = (baseHigh >> (id * 8)) & 0xFFL;
2978+
base = (baseHigh >> ((id - 8) * 8)) & 0xFFL;
30112979
} else {
30122980
base = 0x00L;
30132981
}

wasm/src/main/java/run/endive/wasm/Parser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ private static Instruction parseInstruction(ByteBuffer buffer) {
13271327
operands.add(n);
13281328
for (var j = 0; j < n; j++) {
13291329
var catchOp = readByte(buffer);
1330-
operands.add(0L | catchOp);
1330+
operands.add((long) catchOp);
13311331
var catchOpcode = CatchOpCode.byOpCode(catchOp);
13321332
switch (catchOpcode) {
13331333
case CATCH:

0 commit comments

Comments
 (0)