Search in sources :

Example 21 with TargetDescription

use of jdk.vm.ci.code.TargetDescription in project graal by oracle.

the class AMD64HotSpotForeignCallsProvider method initialize.

@Override
public void initialize(HotSpotProviders providers, OptionValues options) {
    GraalHotSpotVMConfig config = runtime.getVMConfig();
    TargetDescription target = providers.getCodeCache().getTarget();
    PlatformKind word = target.arch.getWordKind();
    // The calling convention for the exception handler stub is (only?) defined in
    // TemplateInterpreterGenerator::generate_throw_exception()
    // in templateInterpreter_x86_64.cpp around line 1923
    RegisterValue exception = rax.asValue(LIRKind.reference(word));
    RegisterValue exceptionPc = rdx.asValue(LIRKind.value(word));
    CallingConvention exceptionCc = new CallingConvention(0, ILLEGAL, exception, exceptionPc);
    register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, exceptionCc, null, NOT_REEXECUTABLE, any()));
    register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, exceptionCc, null, NOT_REEXECUTABLE, any()));
    link(new AMD64MathStub(ARITHMETIC_LOG_STUB, options, providers, registerStubCall(ARITHMETIC_LOG_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_LOG10_STUB, options, providers, registerStubCall(ARITHMETIC_LOG10_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_SIN_STUB, options, providers, registerStubCall(ARITHMETIC_SIN_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_COS_STUB, options, providers, registerStubCall(ARITHMETIC_COS_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_TAN_STUB, options, providers, registerStubCall(ARITHMETIC_TAN_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_EXP_STUB, options, providers, registerStubCall(ARITHMETIC_EXP_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    link(new AMD64MathStub(ARITHMETIC_POW_STUB, options, providers, registerStubCall(ARITHMETIC_POW_STUB, REEXECUTABLE, LEAF, NO_LOCATIONS)));
    if (config.useCRC32Intrinsics) {
        // This stub does callee saving
        registerForeignCall(UPDATE_BYTES_CRC32, config.updateBytesCRC32Stub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, any());
    }
    if (config.useCRC32CIntrinsics) {
        registerForeignCall(UPDATE_BYTES_CRC32C, config.updateBytesCRC32C, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, any());
    }
    super.initialize(providers, options);
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterValue(jdk.vm.ci.code.RegisterValue) HotSpotForeignCallLinkageImpl(org.graalvm.compiler.hotspot.HotSpotForeignCallLinkageImpl) TargetDescription(jdk.vm.ci.code.TargetDescription) PlatformKind(jdk.vm.ci.meta.PlatformKind) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig)

Example 22 with TargetDescription

use of jdk.vm.ci.code.TargetDescription in project graal by oracle.

the class AArch64HotSpotForeignCallsProvider method initialize.

@Override
public void initialize(HotSpotProviders providers, OptionValues options) {
    GraalHotSpotVMConfig config = runtime.getVMConfig();
    TargetDescription target = providers.getCodeCache().getTarget();
    PlatformKind word = target.arch.getWordKind();
    // The calling convention for the exception handler stub is (only?) defined in
    // TemplateInterpreterGenerator::generate_throw_exception()
    RegisterValue exception = r0.asValue(LIRKind.reference(word));
    RegisterValue exceptionPc = r3.asValue(LIRKind.value(word));
    CallingConvention exceptionCc = new CallingConvention(0, ILLEGAL, exception, exceptionPc);
    register(new HotSpotForeignCallLinkageImpl(HotSpotBackend.EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF, exceptionCc, null, NOT_REEXECUTABLE, any()));
    register(new HotSpotForeignCallLinkageImpl(HotSpotBackend.EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF, exceptionCc, null, NOT_REEXECUTABLE, any()));
    // These stubs do callee saving
    if (config.useCRC32Intrinsics) {
        registerForeignCall(UPDATE_BYTES_CRC32, config.updateBytesCRC32Stub, NativeCall, PRESERVES_REGISTERS, LEAF, NOT_REEXECUTABLE, any());
    }
    if (config.useCRC32CIntrinsics) {
        registerForeignCall(UPDATE_BYTES_CRC32C, config.updateBytesCRC32C, NativeCall, PRESERVES_REGISTERS, LEAF, NOT_REEXECUTABLE, any());
    }
    super.initialize(providers, options);
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterValue(jdk.vm.ci.code.RegisterValue) HotSpotForeignCallLinkageImpl(org.graalvm.compiler.hotspot.HotSpotForeignCallLinkageImpl) TargetDescription(jdk.vm.ci.code.TargetDescription) PlatformKind(jdk.vm.ci.meta.PlatformKind) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig)

Example 23 with TargetDescription

use of jdk.vm.ci.code.TargetDescription 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)

Example 24 with TargetDescription

use of jdk.vm.ci.code.TargetDescription in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitNegate.

@Override
public Variable emitNegate(Value inputVal) {
    AllocatableValue input = getLIRGen().asAllocatable(inputVal);
    Variable result = getLIRGen().newVariable(LIRKind.combine(input));
    TargetDescription target = getLIRGen().target();
    boolean isAvx = ((AMD64) target.arch).getFeatures().contains(CPUFeature.AVX);
    switch((AMD64Kind) input.getPlatformKind()) {
        case DWORD:
            getLIRGen().append(new AMD64Unary.MOp(NEG, DWORD, result, input));
            break;
        case QWORD:
            getLIRGen().append(new AMD64Unary.MOp(NEG, QWORD, result, input));
            break;
        case SINGLE:
            if (isAvx) {
                getLIRGen().append(new AMD64Binary.DataThreeOp(AVXOp.XOR, PS, result, input, JavaConstant.forFloat(Float.intBitsToFloat(0x80000000)), 16));
            } else {
                getLIRGen().append(new AMD64Binary.DataTwoOp(SSEOp.XOR, PS, result, input, JavaConstant.forFloat(Float.intBitsToFloat(0x80000000)), 16));
            }
            break;
        case DOUBLE:
            if (isAvx) {
                getLIRGen().append(new AMD64Binary.DataThreeOp(AVXOp.XOR, PD, result, input, JavaConstant.forDouble(Double.longBitsToDouble(0x8000000000000000L)), 16));
            } else {
                getLIRGen().append(new AMD64Binary.DataTwoOp(SSEOp.XOR, PD, result, input, JavaConstant.forDouble(Double.longBitsToDouble(0x8000000000000000L)), 16));
            }
            break;
        default:
            throw GraalError.shouldNotReachHere(input.getPlatformKind().toString());
    }
    return result;
}
Also used : AMD64Unary(org.graalvm.compiler.lir.amd64.AMD64Unary) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) Variable(org.graalvm.compiler.lir.Variable) AMD64Binary(org.graalvm.compiler.lir.amd64.AMD64Binary) TargetDescription(jdk.vm.ci.code.TargetDescription) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 25 with TargetDescription

use of jdk.vm.ci.code.TargetDescription in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitAdd.

@Override
public Variable emitAdd(LIRKind resultKind, Value a, Value b, boolean setFlags) {
    TargetDescription target = getLIRGen().target();
    boolean isAvx = ((AMD64) target.arch).getFeatures().contains(CPUFeature.AVX);
    switch((AMD64Kind) a.getPlatformKind()) {
        case DWORD:
            if (isJavaConstant(b) && !setFlags) {
                long displacement = asJavaConstant(b).asLong();
                if (NumUtil.isInt(displacement) && displacement != 1 && displacement != -1) {
                    return emitBaseOffsetLea(resultKind, a, (int) displacement, OperandSize.DWORD);
                }
            }
            return emitBinary(resultKind, ADD, DWORD, true, a, b, setFlags);
        case QWORD:
            if (isJavaConstant(b) && !setFlags) {
                long displacement = asJavaConstant(b).asLong();
                if (NumUtil.isInt(displacement) && displacement != 1 && displacement != -1) {
                    return emitBaseOffsetLea(resultKind, a, (int) displacement, OperandSize.QWORD);
                }
            }
            return emitBinary(resultKind, ADD, QWORD, true, a, b, setFlags);
        case SINGLE:
            if (isAvx) {
                return emitBinary(resultKind, AVXOp.ADD, SS, true, a, b);
            } else {
                return emitBinary(resultKind, SSEOp.ADD, SS, true, a, b);
            }
        case DOUBLE:
            if (isAvx) {
                return emitBinary(resultKind, AVXOp.ADD, SD, true, a, b);
            } else {
                return emitBinary(resultKind, SSEOp.ADD, SD, true, a, b);
            }
        default:
            throw GraalError.shouldNotReachHere();
    }
}
Also used : AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) TargetDescription(jdk.vm.ci.code.TargetDescription)

Aggregations

TargetDescription (jdk.vm.ci.code.TargetDescription)41 CallingConvention (jdk.vm.ci.code.CallingConvention)14 Register (jdk.vm.ci.code.Register)14 RegisterConfig (jdk.vm.ci.code.RegisterConfig)12 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)11 CompilationResult (org.graalvm.compiler.code.CompilationResult)11 Test (org.junit.Test)11 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)10 AMD64Assembler (org.graalvm.compiler.asm.amd64.AMD64Assembler)10 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)8 GraalHotSpotVMConfig (org.graalvm.compiler.hotspot.GraalHotSpotVMConfig)7 LIRKind (org.graalvm.compiler.core.common.LIRKind)6 AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)5 Field (java.lang.reflect.Field)4 BytecodeProvider (org.graalvm.compiler.bytecode.BytecodeProvider)4 Value (jdk.vm.ci.meta.Value)3 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)3 HotSpotRegistersProvider (org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider)3 RegisterValue (jdk.vm.ci.code.RegisterValue)2 DataSectionReference (jdk.vm.ci.code.site.DataSectionReference)2