diff --git a/core/src/main/java/org/teavm/backend/wasm/intrinsics/IntegerIntrinsic.java b/core/src/main/java/org/teavm/backend/wasm/intrinsics/IntegerIntrinsic.java index 38cb6fd79..34b41b53b 100644 --- a/core/src/main/java/org/teavm/backend/wasm/intrinsics/IntegerIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/wasm/intrinsics/IntegerIntrinsic.java @@ -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(); } diff --git a/core/src/main/java/org/teavm/backend/wasm/intrinsics/LongIntrinsic.java b/core/src/main/java/org/teavm/backend/wasm/intrinsics/LongIntrinsic.java index 9b0f22f11..43ad044aa 100644 --- a/core/src/main/java/org/teavm/backend/wasm/intrinsics/LongIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/wasm/intrinsics/LongIntrinsic.java @@ -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(); } diff --git a/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/IntNumIntrinsic.java b/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/IntNumIntrinsic.java index eaed36989..db95b6189 100644 --- a/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/IntNumIntrinsic.java +++ b/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/IntNumIntrinsic.java @@ -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(); } diff --git a/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/WasmGCIntrinsics.java b/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/WasmGCIntrinsics.java index 00919cf13..08296f55d 100644 --- a/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/WasmGCIntrinsics.java +++ b/core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/WasmGCIntrinsics.java @@ -126,6 +126,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() {