Remove unnecessary Wasm runtime imports, implement isFinite method

This commit is contained in:
Alexey Andreev 2022-11-11 09:38:21 +01:00
parent c52b71292d
commit 5fb83ca2ac
5 changed files with 22 additions and 21 deletions

View File

@ -1451,7 +1451,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
expr.getIndex().acceptVisitor(this);
}
private WasmExpression negate(WasmExpression expr) {
private static WasmExpression negate(WasmExpression expr) {
if (expr instanceof WasmIntBinary) {
WasmIntBinary binary = (WasmIntBinary) expr;
if (binary.getType() == WasmIntType.INT32 && binary.getOperation() == WasmIntBinaryOperation.XOR) {
@ -1478,11 +1478,11 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
return new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, expr, new WasmInt32Constant(0));
}
private boolean isOne(WasmExpression expression) {
private static boolean isOne(WasmExpression expression) {
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 1;
}
private boolean isZero(WasmExpression expression) {
private static boolean isZero(WasmExpression expression) {
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 0;
}
@ -1546,7 +1546,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
return expression;
}
private WasmIntBinaryOperation negate(WasmIntBinaryOperation op) {
private static WasmIntBinaryOperation negate(WasmIntBinaryOperation op) {
switch (op) {
case EQ:
return WasmIntBinaryOperation.NE;
@ -1573,7 +1573,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
}
}
private WasmFloatBinaryOperation negate(WasmFloatBinaryOperation op) {
private static WasmFloatBinaryOperation negate(WasmFloatBinaryOperation op) {
switch (op) {
case EQ:
return WasmFloatBinaryOperation.NE;

View File

@ -47,6 +47,7 @@ public class DoubleIntrinsic implements WasmIntrinsic {
case "getNaN":
case "isNaN":
case "isInfinite":
case "isFinite":
case "doubleToLongBits":
case "longBitsToDouble":
return true;
@ -65,7 +66,14 @@ public class DoubleIntrinsic implements WasmIntrinsic {
WasmIntBinaryOperation.NE);
case "isInfinite":
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
WasmIntBinaryOperation.EQ);
WasmIntBinaryOperation.NE);
case "isFinite": {
WasmExpression result = testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
WasmIntBinaryOperation.NE);
result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, result,
new WasmInt32Constant(0));
return result;
}
case "doubleToLongBits": {
WasmConversion conversion = new WasmConversion(WasmType.FLOAT64, WasmType.INT64, false,
manager.generate(invocation.getArguments().get(0)));

View File

@ -46,6 +46,7 @@ public class FloatIntrinsic implements WasmIntrinsic {
case "getNaN":
case "isNaN":
case "isInfinite":
case "isFinite":
case "floatToIntBits":
case "intBitsToFloat":
return true;
@ -65,6 +66,13 @@ public class FloatIntrinsic implements WasmIntrinsic {
case "isInfinite":
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
WasmIntBinaryOperation.EQ);
case "isFinite": {
WasmExpression result = testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
WasmIntBinaryOperation.EQ);
result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, result,
new WasmInt32Constant(0));
return result;
}
case "floatToIntBits": {
WasmConversion conversion = new WasmConversion(WasmType.FLOAT32, WasmType.INT32, false,
manager.generate(invocation.getArguments().get(0)));

View File

@ -16,9 +16,6 @@ float teavm_teavm_getNaN() {
return NAN;
}
#define teavm_isnan isnan
#define teavm_isinf isinf
#define teavm_isfinite isfinite
#define teavmMath_sin sin
#define teavmMath_cos cos
#define teavmMath_sqrt sqrt

View File

@ -39,12 +39,6 @@ TeaVM.wasm = function() {
putwchar(memory[buffer++]);
}
}
function towlower(code) {
return String.fromCharCode(code).toLowerCase().charCodeAt(0);
}
function towupper(code) {
return String.fromCharCode(code).toUpperCase().charCodeAt(0);
}
function currentTimeMillis() {
return new Date().getTime();
}
@ -94,14 +88,8 @@ TeaVM.wasm = function() {
obj.teavm = {
currentTimeMillis: currentTimeMillis,
nanoTime: function() { return performance.now(); },
isnan: isNaN,
teavm_getNaN: function() { return NaN; },
isinf: function(n) { return !isFinite(n) },
isfinite: isFinite,
putwcharsOut: (chars, count) => putwchars(controller, chars, count),
putwcharsErr: (chars, count) => putwchars(controller, chars, count),
towlower: towlower,
towupper: towupper,
getNativeOffset: getNativeOffset,
logString: string => logString(string, controller),
logInt: logInt,