mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Merge branch 'more-integer-intrinsics' into eagler-r1
This commit is contained in:
commit
d485be9fe9
|
@ -17,7 +17,9 @@ package org.teavm.backend.wasm.intrinsics;
|
||||||
|
|
||||||
import org.teavm.ast.InvocationExpr;
|
import org.teavm.ast.InvocationExpr;
|
||||||
import org.teavm.backend.wasm.WasmRuntime;
|
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.WasmCall;
|
||||||
|
import org.teavm.backend.wasm.model.expression.WasmConversion;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmExpression;
|
import org.teavm.backend.wasm.model.expression.WasmExpression;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
|
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
|
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(0)),
|
||||||
manager.generate(invocation.getArguments().get(1)));
|
manager.generate(invocation.getArguments().get(1)));
|
||||||
case "numberOfLeadingZeros":
|
case "numberOfLeadingZeros":
|
||||||
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CLZ,
|
return castToInt(new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CLZ,
|
||||||
manager.generate(invocation.getArguments().get(0)));
|
manager.generate(invocation.getArguments().get(0))));
|
||||||
case "numberOfTrailingZeros":
|
case "numberOfTrailingZeros":
|
||||||
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CTZ,
|
return castToInt(new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.CTZ,
|
||||||
manager.generate(invocation.getArguments().get(0)));
|
manager.generate(invocation.getArguments().get(0))));
|
||||||
case "bitCount":
|
case "bitCount":
|
||||||
return new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.POPCNT,
|
return castToInt(new WasmIntUnary(WasmIntType.INT64, WasmIntUnaryOperation.POPCNT,
|
||||||
manager.generate(invocation.getArguments().get(0)));
|
manager.generate(invocation.getArguments().get(0))));
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WasmExpression castToInt(WasmExpression expr) {
|
||||||
|
return new WasmConversion(WasmNumType.INT64, WasmNumType.INT32, false, expr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@ package org.teavm.backend.wasm.intrinsics.gc;
|
||||||
|
|
||||||
import org.teavm.ast.InvocationExpr;
|
import org.teavm.ast.InvocationExpr;
|
||||||
import org.teavm.backend.wasm.WasmRuntime;
|
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.WasmCall;
|
||||||
|
import org.teavm.backend.wasm.model.expression.WasmConversion;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmExpression;
|
import org.teavm.backend.wasm.model.expression.WasmExpression;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
|
import org.teavm.backend.wasm.model.expression.WasmIntBinary;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation;
|
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(0)),
|
||||||
context.generate(invocation.getArguments().get(1)));
|
context.generate(invocation.getArguments().get(1)));
|
||||||
case "numberOfLeadingZeros":
|
case "numberOfLeadingZeros":
|
||||||
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.CLZ,
|
return castToInt(new WasmIntUnary(wasmType, WasmIntUnaryOperation.CLZ,
|
||||||
context.generate(invocation.getArguments().get(0)));
|
context.generate(invocation.getArguments().get(0))));
|
||||||
case "numberOfTrailingZeros":
|
case "numberOfTrailingZeros":
|
||||||
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.CTZ,
|
return castToInt(new WasmIntUnary(wasmType, WasmIntUnaryOperation.CTZ,
|
||||||
context.generate(invocation.getArguments().get(0)));
|
context.generate(invocation.getArguments().get(0))));
|
||||||
case "bitCount":
|
case "bitCount":
|
||||||
return new WasmIntUnary(wasmType, WasmIntUnaryOperation.POPCNT,
|
return castToInt(new WasmIntUnary(wasmType, WasmIntUnaryOperation.POPCNT,
|
||||||
context.generate(invocation.getArguments().get(0)));
|
context.generate(invocation.getArguments().get(0))));
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WasmExpression castToInt(WasmExpression expr) {
|
||||||
|
if (wasmType == WasmIntType.INT64) {
|
||||||
|
return new WasmConversion(WasmNumType.INT64, WasmNumType.INT32, false, expr);
|
||||||
|
} else {
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user