mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
Merge branch 'more-integer-intrinsics' into eagler-r1
This commit is contained in:
commit
6bd8a5bc01
|
@ -115,6 +115,7 @@ import org.teavm.backend.wasm.render.WasmBinaryWriter;
|
||||||
import org.teavm.backend.wasm.render.WasmCRenderer;
|
import org.teavm.backend.wasm.render.WasmCRenderer;
|
||||||
import org.teavm.backend.wasm.render.WasmRenderer;
|
import org.teavm.backend.wasm.render.WasmRenderer;
|
||||||
import org.teavm.backend.wasm.runtime.WasmSupport;
|
import org.teavm.backend.wasm.runtime.WasmSupport;
|
||||||
|
import org.teavm.backend.wasm.transformation.BaseClassesTransformation;
|
||||||
import org.teavm.backend.wasm.transformation.IndirectCallTraceTransformation;
|
import org.teavm.backend.wasm.transformation.IndirectCallTraceTransformation;
|
||||||
import org.teavm.backend.wasm.transformation.MemoryAccessTraceTransformation;
|
import org.teavm.backend.wasm.transformation.MemoryAccessTraceTransformation;
|
||||||
import org.teavm.backend.wasm.transformation.WasiFileSystemProviderTransformer;
|
import org.teavm.backend.wasm.transformation.WasiFileSystemProviderTransformer;
|
||||||
|
@ -241,6 +242,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
public List<ClassHolderTransformer> getTransformers() {
|
public List<ClassHolderTransformer> getTransformers() {
|
||||||
List<ClassHolderTransformer> transformers = new ArrayList<>();
|
List<ClassHolderTransformer> transformers = new ArrayList<>();
|
||||||
transformers.add(new ClassPatch());
|
transformers.add(new ClassPatch());
|
||||||
|
transformers.add(new BaseClassesTransformation());
|
||||||
transformers.add(new WasmDependencyListener());
|
transformers.add(new WasmDependencyListener());
|
||||||
if (runtimeType == WasmRuntimeType.WASI) {
|
if (runtimeType == WasmRuntimeType.WASI) {
|
||||||
transformers.add(new WasiSupportClassTransformer());
|
transformers.add(new WasiSupportClassTransformer());
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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.transformation;
|
||||||
|
|
||||||
|
import org.teavm.model.ClassHolder;
|
||||||
|
import org.teavm.model.ClassHolderTransformer;
|
||||||
|
import org.teavm.model.ClassHolderTransformerContext;
|
||||||
|
import org.teavm.model.ElementModifier;
|
||||||
|
|
||||||
|
public class BaseClassesTransformation implements ClassHolderTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) {
|
||||||
|
if (cls.getName().equals("java.lang.Integer") || cls.getName().equals("java.lang.Long")) {
|
||||||
|
for (var method : cls.getMethods()) {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "numberOfLeadingZeros":
|
||||||
|
case "numberOfTrailingZeros":
|
||||||
|
case "bitCount":
|
||||||
|
method.setProgram(null);
|
||||||
|
method.getModifiers().add(ElementModifier.NATIVE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -121,6 +121,17 @@ public class BaseClassesTransformation implements ClassHolderTransformer {
|
||||||
var clear = cls.getMethod(new MethodDescriptor("clear", void.class));
|
var clear = cls.getMethod(new MethodDescriptor("clear", void.class));
|
||||||
clear.getModifiers().add(ElementModifier.NATIVE);
|
clear.getModifiers().add(ElementModifier.NATIVE);
|
||||||
clear.setProgram(null);
|
clear.setProgram(null);
|
||||||
|
} else if (cls.getName().equals("java.lang.Integer") || cls.getName().equals("java.lang.Long")) {
|
||||||
|
for (var method : cls.getMethods()) {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "numberOfLeadingZeros":
|
||||||
|
case "numberOfTrailingZeros":
|
||||||
|
case "bitCount":
|
||||||
|
method.setProgram(null);
|
||||||
|
method.getModifiers().add(ElementModifier.NATIVE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,35 @@ public class LongTest {
|
||||||
assertEquals(0xF63BA00000000000L, Long.reverse(0x5DC6F));
|
assertEquals(0xF63BA00000000000L, Long.reverse(0x5DC6F));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void numberOfLeadingZerosComputed() {
|
||||||
|
assertEquals(0, Long.numberOfLeadingZeros(-1L));
|
||||||
|
assertEquals(1, Long.numberOfLeadingZeros(0x4000000000000000L));
|
||||||
|
assertEquals(1, Long.numberOfLeadingZeros(0x4000000000000123L));
|
||||||
|
assertEquals(1, Long.numberOfLeadingZeros(0x7FFFFFFFFFFFFFFFL));
|
||||||
|
assertEquals(63, Long.numberOfLeadingZeros(1L));
|
||||||
|
assertEquals(62, Long.numberOfLeadingZeros(2L));
|
||||||
|
assertEquals(62, Long.numberOfLeadingZeros(3L));
|
||||||
|
assertEquals(0, Long.numberOfLeadingZeros(0x8000000000000000L));
|
||||||
|
assertEquals(0, Long.numberOfLeadingZeros(0x8000000000000123L));
|
||||||
|
assertEquals(0, Long.numberOfLeadingZeros(0xFFFFFFFFFFFFFFFFL));
|
||||||
|
assertEquals(64, Long.numberOfLeadingZeros(0L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void numberOfTrailingZerosComputed() {
|
||||||
|
assertEquals(1, Long.numberOfTrailingZeros(0xFFFFFFFFFFFFFFFEL));
|
||||||
|
assertEquals(1, Long.numberOfTrailingZeros(0x4000000000000002L));
|
||||||
|
assertEquals(1, Long.numberOfTrailingZeros(0x0000000000000002L));
|
||||||
|
assertEquals(63, Long.numberOfTrailingZeros(0x8000000000000000L));
|
||||||
|
assertEquals(62, Long.numberOfTrailingZeros(0x4000000000000000L));
|
||||||
|
assertEquals(62, Long.numberOfTrailingZeros(0xC000000000000000L));
|
||||||
|
assertEquals(0, Long.numberOfTrailingZeros(0x0000000000000001L));
|
||||||
|
assertEquals(0, Long.numberOfTrailingZeros(0x1230000000000003L));
|
||||||
|
assertEquals(0, Long.numberOfTrailingZeros(0xFFFFFFFFFFFFFFFFL));
|
||||||
|
assertEquals(64, Long.numberOfTrailingZeros(0L));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void highestOneBit() {
|
public void highestOneBit() {
|
||||||
assertEquals(1L << 63, Long.highestOneBit(-1L));
|
assertEquals(1L << 63, Long.highestOneBit(-1L));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user