Fix 64 bit variants

This commit is contained in:
lax1dude 2024-11-30 14:34:16 -08:00
parent 739cb2ba7e
commit bfd8b7b631
2 changed files with 28 additions and 12 deletions

View File

@ -17,7 +17,9 @@ package org.teavm.backend.wasm.intrinsics;
import org.teavm.ast.InvocationExpr;
import org.teavm.backend.wasm.WasmRuntime;
import org.teavm.backend.wasm.model.WasmNumType;
import org.teavm.backend.wasm.model.expression.WasmCall;
import org.teavm.backend.wasm.model.expression.WasmConversion;
import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
@ -65,16 +67,20 @@ public class LongIntrinsic implements WasmIntrinsic {
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)));
return castToInt(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)));
return castToInt(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)));
return castToInt(new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.POPCNT,
manager.generate(invocation.getArguments().get(0))));
default:
throw new AssertionError();
}
}
private WasmExpression castToInt(WasmExpression expr) {
return new WasmConversion(WasmNumType.INT64, WasmNumType.INT32, false, expr);
}
}

View File

@ -17,7 +17,9 @@ package org.teavm.backend.wasm.intrinsics.gc;
import org.teavm.ast.InvocationExpr;
import org.teavm.backend.wasm.WasmRuntime;
import org.teavm.backend.wasm.model.WasmNumType;
import org.teavm.backend.wasm.model.expression.WasmCall;
import org.teavm.backend.wasm.model.expression.WasmConversion;
import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
@ -51,16 +53,24 @@ public class IntNumIntrinsic implements WasmGCIntrinsic {
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)));
return castToInt(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)));
return castToInt(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)));
return castToInt(new WasmIntUnary(wasmType, WasmIntUnaryOperation.POPCNT,
context.generate(invocation.getArguments().get(0))));
default:
throw new AssertionError();
}
}
private WasmExpression castToInt(WasmExpression expr) {
if (wasmType == WasmIntType.INT64) {
return new WasmConversion(WasmNumType.INT64, WasmNumType.INT32, false, expr);
} else {
return expr;
}
}
}