-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm gc: implement intrinsics for Long and Class classes
- Loading branch information
1 parent
a97e657
commit 5eb1e7d
Showing
10 changed files
with
219 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/LongIntrinsic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm.intrinsics.gc; | ||
|
||
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; | ||
import org.teavm.backend.wasm.model.expression.WasmIntType; | ||
import org.teavm.model.MethodReference; | ||
|
||
public class LongIntrinsic implements WasmGCIntrinsic { | ||
private static final MethodReference COMPARE_UNSIGNED = new MethodReference(WasmRuntime.class, | ||
"compareUnsigned", long.class, long.class, int.class); | ||
|
||
@Override | ||
public WasmExpression apply(InvocationExpr invocation, WasmGCIntrinsicContext context) { | ||
switch (invocation.getMethod().getName()) { | ||
case "divideUnsigned": | ||
return new WasmIntBinary(WasmIntType.INT64, WasmIntBinaryOperation.DIV_UNSIGNED, | ||
context.generate(invocation.getArguments().get(0)), | ||
context.generate(invocation.getArguments().get(1))); | ||
case "remainderUnsigned": | ||
return new WasmIntBinary(WasmIntType.INT64, WasmIntBinaryOperation.REM_UNSIGNED, | ||
context.generate(invocation.getArguments().get(0)), | ||
context.generate(invocation.getArguments().get(1))); | ||
case "compareUnsigned": | ||
return new WasmCall(context.functions().forStaticMethod(COMPARE_UNSIGNED), | ||
context.generate(invocation.getArguments().get(0)), | ||
context.generate(invocation.getArguments().get(1))); | ||
default: | ||
throw new AssertionError(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
core/src/main/java/org/teavm/backend/wasm/intrinsics/gc/WasmRuntimeIntrinsic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2024 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm.intrinsics.gc; | ||
|
||
import org.teavm.ast.InvocationExpr; | ||
import org.teavm.backend.wasm.generate.WasmGeneratorUtil; | ||
import org.teavm.backend.wasm.model.WasmType; | ||
import org.teavm.backend.wasm.model.expression.WasmExpression; | ||
import org.teavm.backend.wasm.model.expression.WasmFloatBinary; | ||
import org.teavm.backend.wasm.model.expression.WasmFloatBinaryOperation; | ||
import org.teavm.backend.wasm.model.expression.WasmFloatType; | ||
import org.teavm.backend.wasm.model.expression.WasmIntBinary; | ||
import org.teavm.backend.wasm.model.expression.WasmIntBinaryOperation; | ||
import org.teavm.backend.wasm.model.expression.WasmIntType; | ||
|
||
public class WasmRuntimeIntrinsic implements WasmGCIntrinsic { | ||
@Override | ||
public WasmExpression apply(InvocationExpr invocation, WasmGCIntrinsicContext context) { | ||
switch (invocation.getMethod().getName()) { | ||
case "lt": | ||
return comparison(WasmIntBinaryOperation.LT_SIGNED, WasmFloatBinaryOperation.LT, | ||
invocation, context); | ||
case "gt": | ||
return comparison(WasmIntBinaryOperation.GT_SIGNED, WasmFloatBinaryOperation.GT, | ||
invocation, context); | ||
case "ltu": | ||
return comparison(WasmIntBinaryOperation.LT_UNSIGNED, WasmFloatBinaryOperation.LT, | ||
invocation, context); | ||
case "gtu": | ||
return comparison(WasmIntBinaryOperation.GT_UNSIGNED, WasmFloatBinaryOperation.GT, | ||
invocation, context); | ||
case "min": | ||
return comparison(WasmIntBinaryOperation.GT_SIGNED, WasmFloatBinaryOperation.MIN, | ||
invocation, context); | ||
case "max": | ||
return comparison(WasmIntBinaryOperation.GT_SIGNED, WasmFloatBinaryOperation.MAX, | ||
invocation, context); | ||
default: | ||
throw new IllegalArgumentException(invocation.getMethod().getName()); | ||
} | ||
} | ||
|
||
private static WasmExpression comparison(WasmIntBinaryOperation intOp, WasmFloatBinaryOperation floatOp, | ||
InvocationExpr invocation, WasmGCIntrinsicContext context) { | ||
var type = (WasmType.Number) WasmGeneratorUtil.mapType(invocation.getMethod().parameterType(0)); | ||
|
||
WasmExpression first = context.generate(invocation.getArguments().get(0)); | ||
WasmExpression second = context.generate(invocation.getArguments().get(1)); | ||
|
||
switch (type.number) { | ||
case INT32: | ||
return new WasmIntBinary(WasmIntType.INT32, intOp, first, second); | ||
case INT64: | ||
return new WasmIntBinary(WasmIntType.INT64, intOp, first, second); | ||
case FLOAT32: | ||
return new WasmFloatBinary(WasmFloatType.FLOAT32, floatOp, first, second); | ||
case FLOAT64: | ||
return new WasmFloatBinary(WasmFloatType.FLOAT64, floatOp, first, second); | ||
default: | ||
throw new IllegalArgumentException(type.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters