Search in sources :

Example 11 with LLVMMemory

use of com.oracle.truffle.llvm.runtime.memory.LLVMMemory in project graal by oracle.

the class NativeMemSetNode method nativeInJavaMemset.

@Specialization(guards = "length <= MAX_JAVA_LEN")
protected void nativeInJavaMemset(LLVMNativePointer object, byte value, long length, @Cached("createToNativeWithTarget()") LLVMToNativeNode globalAccess) {
    LLVMMemory memory = getLanguage().getLLVMMemory();
    long current = globalAccess.executeWithTarget(object).asNative();
    long i64ValuesToWrite = length >> 3;
    if (CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, i64ValuesToWrite > 0)) {
        long v16 = ((((long) value) & 0xFF) << 8) | ((long) value & 0xFF);
        long v32 = v16 << 16 | v16;
        long v64 = v32 << 32 | v32;
        for (long i = 0; CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, i < i64ValuesToWrite); i++) {
            memory.putI64(this, current, v64);
            current += 8;
        }
    }
    long i8ValuesToWrite = length & 0x07;
    for (long i = 0; CompilerDirectives.injectBranchProbability(CompilerDirectives.LIKELY_PROBABILITY, i < i8ValuesToWrite); i++) {
        memory.putI8(this, current, value);
        current++;
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 12 with LLVMMemory

use of com.oracle.truffle.llvm.runtime.memory.LLVMMemory in project graal by oracle.

the class LLVMStoreVectorNode method writeVector.

@Specialization(guards = "!isAutoDerefHandle(address)")
@ExplodeLoop
protected void writeVector(LLVMNativePointer address, LLVMFloatVector vector) {
    assert vector.getLength() == getVectorLength();
    LLVMMemory memory = getLanguage().getLLVMMemory();
    long currentPtr = address.asNative();
    for (int i = 0; i < getVectorLength(); i++) {
        memory.putFloat(this, currentPtr, vector.getValue(i));
        currentPtr += FLOAT_SIZE_IN_BYTES;
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 13 with LLVMMemory

use of com.oracle.truffle.llvm.runtime.memory.LLVMMemory in project graal by oracle.

the class LLVMStoreVectorNode method writeVector.

@Specialization(guards = "!isAutoDerefHandle(address)")
@ExplodeLoop
protected void writeVector(LLVMNativePointer address, LLVMI1Vector vector) {
    assert vector.getLength() == getVectorLength();
    LLVMMemory memory = getLanguage().getLLVMMemory();
    long basePtr = address.asNative();
    for (int byteOffset = 0; byteOffset < (getVectorLength() / 8) + 1; byteOffset++) {
        long byteAddr = basePtr + byteOffset;
        int b = memory.getI8(this, byteAddr);
        for (int bitOffset = 0; bitOffset < 8 && ((byteOffset * 8) + bitOffset) < getVectorLength(); bitOffset++) {
            int mask = (1 << bitOffset) & 0xFF;
            int maskInvert = (~mask) & 0xFF;
            int v = vector.getValue((byteOffset * 8) + bitOffset) ? 1 : 0;
            b = (b & maskInvert) | ((v << bitOffset) & mask);
        }
        memory.putI8(this, byteAddr, (byte) b);
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory) Specialization(com.oracle.truffle.api.dsl.Specialization) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 14 with LLVMMemory

use of com.oracle.truffle.llvm.runtime.memory.LLVMMemory in project graal by oracle.

the class LLVMGlobalContainer method toNative.

@TruffleBoundary
@ExportMessage
public void toNative(@Cached LLVMToNativeNode toNative) {
    if (address == 0) {
        LLVMMemory memory = LLVMLanguage.get(null).getLLVMMemory();
        LLVMNativePointer pointer = memory.allocateMemory(toNative, 8);
        address = pointer.asNative();
        long value;
        Object global = getFallback();
        if (global instanceof Number) {
            value = ((Number) global).longValue();
        } else {
            value = toNative.executeWithTarget(global).asNative();
        }
        memory.putI64(toNative, pointer, value);
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory) LLVMNativePointer(com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer) LLVMInternalTruffleObject(com.oracle.truffle.llvm.runtime.interop.LLVMInternalTruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 15 with LLVMMemory

use of com.oracle.truffle.llvm.runtime.memory.LLVMMemory in project graal by oracle.

the class LLVMGlobalContainer method dispose.

public void dispose() {
    if (address != 0) {
        LLVMMemory memory = LLVMLanguage.get(null).getLLVMMemory();
        memory.free(null, address);
        address = 0;
    }
}
Also used : LLVMMemory(com.oracle.truffle.llvm.runtime.memory.LLVMMemory)

Aggregations

LLVMMemory (com.oracle.truffle.llvm.runtime.memory.LLVMMemory)15 Specialization (com.oracle.truffle.api.dsl.Specialization)11 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)7 LLVMNativePointer (com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 ExportMessage (com.oracle.truffle.api.library.ExportMessage)1 LLVMInternalTruffleObject (com.oracle.truffle.llvm.runtime.interop.LLVMInternalTruffleObject)1