Merge branch 'more-integer-intrinsics' into eagler-r1

This commit is contained in:
lax1dude 2024-11-30 14:20:45 -08:00
commit b47bbcbc02
4 changed files with 42 additions and 0 deletions

View File

@ -22,6 +22,8 @@ import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
import org.teavm.backend.wasm.model.expression.WasmIntType;
import org.teavm.backend.wasm.model.expression.WasmIntUnary;
import org.teavm.backend.wasm.model.expression.WasmIntUnaryOperation;
import org.teavm.model.MethodReference;
public class IntegerIntrinsic implements WasmIntrinsic {
@ -38,6 +40,9 @@ public class IntegerIntrinsic implements WasmIntrinsic {
case "divideUnsigned":
case "remainderUnsigned":
case "compareUnsigned":
case "numberOfLeadingZeros":
case "numberOfTrailingZeros":
case "bitCount":
return true;
default:
return false;
@ -59,6 +64,15 @@ public class IntegerIntrinsic implements WasmIntrinsic {
return new WasmCall(manager.getFunctions().forStaticMethod(COMPARE_UNSIGNED),
manager.generate(invocation.getArguments().get(0)),
manager.generate(invocation.getArguments().get(1)));
case "numberOfLeadingZeros":
return new WasmIntUnary(WasmIntType.INT32, WasmIntUnaryOperation.CLZ,
manager.generate(invocation.getArguments().get(0)));
case "numberOfTrailingZeros":
return new WasmIntUnary(WasmIntType.INT32, WasmIntUnaryOperation.CTZ,
manager.generate(invocation.getArguments().get(0)));
case "bitCount":
return new WasmIntUnary(WasmIntType.INT32, WasmIntUnaryOperation.POPCNT,
manager.generate(invocation.getArguments().get(0)));
default:
throw new AssertionError();
}

View File

@ -22,6 +22,8 @@ import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
import org.teavm.backend.wasm.model.expression.WasmIntType;
import org.teavm.backend.wasm.model.expression.WasmIntUnary;
import org.teavm.backend.wasm.model.expression.WasmIntUnaryOperation;
import org.teavm.model.MethodReference;
public class LongIntrinsic implements WasmIntrinsic {
@ -38,6 +40,9 @@ public class LongIntrinsic implements WasmIntrinsic {
case "divideUnsigned":
case "remainderUnsigned":
case "compareUnsigned":
case "numberOfLeadingZeros":
case "numberOfTrailingZeros":
case "bitCount":
return true;
default:
return false;
@ -59,6 +64,15 @@ public class LongIntrinsic implements WasmIntrinsic {
return new WasmCall(manager.getFunctions().forStaticMethod(COMPARE_UNSIGNED),
manager.generate(invocation.getArguments().get(0)),
manager.generate(invocation.getArguments().get(1)));
case "numberOfLeadingZeros":
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CLZ,
manager.generate(invocation.getArguments().get(0)));
case "numberOfTrailingZeros":
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CTZ,
manager.generate(invocation.getArguments().get(0)));
case "bitCount":
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.POPCNT,
manager.generate(invocation.getArguments().get(0)));
default:
throw new AssertionError();
}

View File

@ -22,6 +22,8 @@ import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
import org.teavm.backend.wasm.model.expression.WasmIntType;
import org.teavm.backend.wasm.model.expression.WasmIntUnary;
import org.teavm.backend.wasm.model.expression.WasmIntUnaryOperation;
import org.teavm.model.MethodReference;
public class IntNumIntrinsic implements WasmGCIntrinsic {
@ -48,6 +50,15 @@ public class IntNumIntrinsic implements WasmGCIntrinsic {
return new WasmCall(context.functions().forStaticMethod(compareUnsigned),
context.generate(invocation.getArguments().get(0)),
context.generate(invocation.getArguments().get(1)));
case "numberOfLeadingZeros":
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.CLZ,
context.generate(invocation.getArguments().get(0)));
case "numberOfTrailingZeros":
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.CTZ,
context.generate(invocation.getArguments().get(0)));
case "bitCount":
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.POPCNT,
context.generate(invocation.getArguments().get(0)));
default:
throw new AssertionError();
}

View File

@ -133,6 +133,9 @@ public class WasmGCIntrinsics implements WasmGCIntrinsicProvider {
add(new MethodReference(wrapperClass, "divideUnsigned", javaClass, javaClass, javaClass), intrinsic);
add(new MethodReference(wrapperClass, "remainderUnsigned", javaClass, javaClass, javaClass), intrinsic);
add(new MethodReference(wrapperClass, "compareUnsigned", javaClass, javaClass, int.class), intrinsic);
add(new MethodReference(wrapperClass, "numberOfLeadingZeros", javaClass, int.class), intrinsic);
add(new MethodReference(wrapperClass, "numberOfTrailingZeros", javaClass, int.class), intrinsic);
add(new MethodReference(wrapperClass, "bitCount", javaClass, int.class), intrinsic);
}
private void fillFloat() {