Search in sources :

Example 1 with AMD64Assembler

use of org.graalvm.compiler.asm.amd64.AMD64Assembler in project graal by oracle.

the class BitOpsTest method tzcntlMemTest.

@Test
public void tzcntlMemTest() {
    if (tzcntSupported) {
        CodeGenTest test = new CodeGenTest() {

            @Override
            public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) {
                AMD64Assembler asm = new AMD64Assembler(target);
                Register ret = registerConfig.getReturnRegister(JavaKind.Int);
                try {
                    Field f = IntField.class.getDeclaredField("x");
                    AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f));
                    TZCNT.emit(asm, DWORD, ret, arg);
                    asm.ret(0);
                    return asm.close(true);
                } catch (Exception e) {
                    throw new RuntimeException("exception while trying to generate field access:", e);
                }
            }
        };
        assertReturn("intFieldStub", test, 31, new IntField(0x8000_0000));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Field(java.lang.reflect.Field) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) CompilationResult(org.graalvm.compiler.code.CompilationResult) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Example 2 with AMD64Assembler

use of org.graalvm.compiler.asm.amd64.AMD64Assembler in project graal by oracle.

the class BitOpsTest method tzcntqTest.

@Test
public void tzcntqTest() {
    if (tzcntSupported) {
        CodeGenTest test = new CodeGenTest() {

            @Override
            public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) {
                AMD64Assembler asm = new AMD64Assembler(target);
                Register ret = registerConfig.getReturnRegister(JavaKind.Int);
                Register arg = asRegister(cc.getArgument(0));
                TZCNT.emit(asm, QWORD, ret, arg);
                asm.ret(0);
                return asm.close(true);
            }
        };
        assertReturn("longStub", test, 63, 0x8000_0000_0000_0000L);
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) CompilationResult(org.graalvm.compiler.code.CompilationResult) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Example 3 with AMD64Assembler

use of org.graalvm.compiler.asm.amd64.AMD64Assembler in project graal by oracle.

the class BitOpsTest method lzcntlTest.

@Test
public void lzcntlTest() {
    if (lzcntSupported) {
        CodeGenTest test = new CodeGenTest() {

            @Override
            public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) {
                AMD64Assembler asm = new AMD64Assembler(target);
                Register ret = registerConfig.getReturnRegister(JavaKind.Int);
                Register arg = asRegister(cc.getArgument(0));
                LZCNT.emit(asm, DWORD, ret, arg);
                asm.ret(0);
                return asm.close(true);
            }
        };
        assertReturn("intStub", test, 31, 1);
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) CompilationResult(org.graalvm.compiler.code.CompilationResult) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Example 4 with AMD64Assembler

use of org.graalvm.compiler.asm.amd64.AMD64Assembler in project graal by oracle.

the class BitOpsTest method lzcntlMemTest.

@Test
public void lzcntlMemTest() {
    if (lzcntSupported) {
        CodeGenTest test = new CodeGenTest() {

            @Override
            public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) {
                AMD64Assembler asm = new AMD64Assembler(target);
                Register ret = registerConfig.getReturnRegister(JavaKind.Int);
                try {
                    Field f = IntField.class.getDeclaredField("x");
                    AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f));
                    LZCNT.emit(asm, DWORD, ret, arg);
                    asm.ret(0);
                    return asm.close(true);
                } catch (Exception e) {
                    throw new RuntimeException("exception while trying to generate field access:", e);
                }
            }
        };
        assertReturn("intFieldStub", test, 31, new IntField(1));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Field(java.lang.reflect.Field) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) CompilationResult(org.graalvm.compiler.code.CompilationResult) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Example 5 with AMD64Assembler

use of org.graalvm.compiler.asm.amd64.AMD64Assembler in project graal by oracle.

the class AMD64HotSpotFrameOmissionTest method testHelper.

private void testHelper(String name, CodeGenerator gen) {
    ResolvedJavaMethod javaMethod = getResolvedJavaMethod(name);
    InstalledCode installedCode = getCode(javaMethod);
    TargetDescription target = getCodeCache().getTarget();
    AMD64Assembler asm = new AMD64Assembler(target);
    gen.generateCode(asm);
    byte[] expectedCode = asm.close(true);
    // Only compare up to expectedCode.length bytes to ignore
    // padding instructions adding during code installation
    byte[] actualCode = Arrays.copyOf(installedCode.getCode(), expectedCode.length);
    Assert.assertArrayEquals(expectedCode, actualCode);
}
Also used : AMD64Assembler(org.graalvm.compiler.asm.amd64.AMD64Assembler) TargetDescription(jdk.vm.ci.code.TargetDescription) InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

TargetDescription (jdk.vm.ci.code.TargetDescription)10 AMD64Assembler (org.graalvm.compiler.asm.amd64.AMD64Assembler)10 CallingConvention (jdk.vm.ci.code.CallingConvention)9 Register (jdk.vm.ci.code.Register)9 RegisterConfig (jdk.vm.ci.code.RegisterConfig)9 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)9 CompilationResult (org.graalvm.compiler.code.CompilationResult)9 Test (org.junit.Test)9 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)8 Field (java.lang.reflect.Field)4 AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)4 InstalledCode (jdk.vm.ci.code.InstalledCode)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1