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++;
}
}
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;
}
}
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);
}
}
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);
}
}
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;
}
}
Aggregations