use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method objectCopyForward.
private static void objectCopyForward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
UnsignedWord size = elementSize.multiply(length);
objectCopyForwardUninterruptibly(fromArray, fromOffset, toArray, toOffset, elementSize, size);
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class ArraycopySnippets method primitiveCopyForward.
private static void primitiveCopyForward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
UnsignedWord size = elementSize.multiply(length);
UnsignedWord i = WordFactory.zero();
if (size.and(1).notEqual(0)) {
ObjectAccess.writeByte(toArray, toOffset.add(i), ObjectAccess.readByte(fromArray, fromOffset.add(i)));
size = size.subtract(1);
i = i.add(1);
}
if (size.and(3).notEqual(0)) {
ObjectAccess.writeShort(toArray, toOffset.add(i), ObjectAccess.readShort(fromArray, fromOffset.add(i)));
size = size.subtract(2);
i = i.add(2);
}
if (size.and(7).notEqual(0)) {
ObjectAccess.writeInt(toArray, toOffset.add(i), ObjectAccess.readInt(fromArray, fromOffset.add(i)));
size = size.subtract(4);
i = i.add(4);
}
while (i.belowThan(size)) {
ObjectAccess.writeLong(toArray, toOffset.add(i), ObjectAccess.readLong(fromArray, fromOffset.add(i)));
i = i.add(8);
}
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class WordTest method cast.
@Snippet
public static long cast(long input) {
WordBase base = WordFactory.signed(input);
UnsignedWord unsigned = (UnsignedWord) base;
Pointer pointer = (Pointer) unsigned;
Word word = (Word) pointer;
return word.rawValue();
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class TruffleNFISupport method utf8ToJavaString.
@TruffleBoundary
static String utf8ToJavaString(CCharPointer str) {
if (str.equal(WordFactory.zero())) {
return null;
} else {
UnsignedWord len = SubstrateUtil.strlen(str);
ByteBuffer buffer = SubstrateUtil.wrapAsByteBuffer(str, (int) len.rawValue());
return UTF8.decode(buffer).toString();
}
}
use of org.graalvm.word.UnsignedWord in project graal by oracle.
the class PosixOSInterface method writeBytes0.
// @formatter:off
// @Override
// protected void writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) throws IOException {
// try (PinnedObject bytesPin = PinnedObject.open(bytes)) {
// CCharPointer curBuf = bytesPin.addressOfArrayElement(off);
// Unsigned curLen = Word.unsigned(len);
// while (curLen.notEqual(0)) {
// int fd = FileDescriptorAlias.getFD(descriptor);
// if (fd == -1) {
// throw new IOException("Stream Closed");
// }
//
// Signed n = write(fd, curBuf, curLen);
//
// if (n.equal(-1)) {
// throw new IOException(lastErrorString("Write error"));
// }
// curBuf = curBuf.addressOf(n);
// curLen = curLen.subtract((Unsigned) n);
// }
// }
// }
// @formatter:on
/*
* TODO Temporarily removed the pinning of 'bytes' to allow it to be region allocation. See
* above.
*/
@Override
protected boolean writeBytes0(FileDescriptor descriptor, byte[] bytes, int off, int len, boolean append) {
final DynamicHub hub = ObjectHeader.readDynamicHubFromObject(bytes);
final UnsignedWord offsetOfArrayElement = LayoutEncoding.getArrayElementOffset(hub.getLayoutEncoding(), off);
final UnsignedWord length = WordFactory.unsigned(len);
return writeBytes0Uninterruptibly(descriptor, bytes, length, offsetOfArrayElement);
}
Aggregations