Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serkan-ozal's 5th submission: #648

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public class CalculateAverage_serkan_ozal {
? ByteVector.SPECIES_128
: ByteVector.SPECIES_64;
private static final int BYTE_SPECIES_SIZE = BYTE_SPECIES.vectorByteSize();

private static final MemorySegment ALL = MemorySegment.NULL.reinterpret(Long.MAX_VALUE);
private static final ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder();

private static final char NEW_LINE_SEPARATOR = '\n';
private static final char KEY_VALUE_SEPARATOR = ';';
private static final int MAX_LINE_LENGTH = 128;
Expand Down Expand Up @@ -341,7 +342,7 @@ private void doProcessRegion(MemorySegment region, long regionAddress, long regi

// Read and process region - main
for (regionPtr = regionStart; regionPtr < regionMainLimit;) {
regionPtr = doProcessLine(region, regionAddress, regionPtr, vectorSize);
regionPtr = doProcessLine(regionPtr, vectorSize);
}

// Read and process region - tail
Expand All @@ -358,13 +359,14 @@ private void doProcessRegion(MemorySegment region, long regionAddress, long regi
}
}

private long doProcessLine(MemorySegment region, long regionAddress, long regionPtr, int vectorSize) {
private long doProcessLine(long regionPtr, int vectorSize) {
// Find key/value separator
////////////////////////////////////////////////////////////////////////////////////////////////////////
long keyStartPtr = regionPtr;

// Vectorized search for key/value separator
ByteVector keyVector = ByteVector.fromMemorySegment(BYTE_SPECIES, region, regionPtr - regionAddress, NATIVE_BYTE_ORDER);
ByteVector keyVector = ByteVector.fromMemorySegment(BYTE_SPECIES, ALL, regionPtr, NATIVE_BYTE_ORDER);

int keyLength = keyVector.compare(VectorOperators.EQ, KEY_VALUE_SEPARATOR).firstTrue();
// Check whether key/value separator is found in the first vector (city name is <= vector size)
if (keyLength != vectorSize) {
Expand Down
Loading