wasm: support Long.compareUnsigned

This commit is contained in:
Alexey Andreev 2023-08-22 17:11:26 +02:00
parent f6131a8248
commit e291128948

View File

@ -16,6 +16,8 @@
package org.teavm.backend.wasm.intrinsics;
import org.teavm.ast.InvocationExpr;
import org.teavm.backend.wasm.WasmRuntime;
import org.teavm.backend.wasm.model.expression.WasmCall;
import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
@ -23,6 +25,9 @@ import org.teavm.backend.wasm.model.expression.WasmIntType;
import org.teavm.model.MethodReference;
public class LongIntrinsic implements WasmIntrinsic {
private static final MethodReference COMPARE_UNSIGNED = new MethodReference(WasmRuntime.class,
"compareUnsigned", long.class, long.class, int.class);
@Override
public boolean isApplicable(MethodReference methodReference) {
if (!methodReference.getClassName().equals(Long.class.getName())) {
@ -32,6 +37,7 @@ public class LongIntrinsic implements WasmIntrinsic {
switch (methodReference.getName()) {
case "divideUnsigned":
case "remainderUnsigned":
case "compareUnsigned":
return true;
default:
return false;
@ -49,6 +55,10 @@ public class LongIntrinsic implements WasmIntrinsic {
return new WasmIntBinary(WasmIntType.INT64, WasmIntBinaryOperation.REM_UNSIGNED,
manager.generate(invocation.getArguments().get(0)),
manager.generate(invocation.getArguments().get(1)));
case "compareUnsigned":
return new WasmCall(manager.getNames().forMethod(COMPARE_UNSIGNED),
manager.generate(invocation.getArguments().get(0)),
manager.generate(invocation.getArguments().get(1)));
default:
throw new AssertionError();
}