Skip to content
Open
Show file tree
Hide file tree
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 @@ -182,7 +182,44 @@ public final VectorMask<E> maskAll(boolean bit) {
final AbstractVector<?> asVectorRawTemplate(LaneType laneType) {
// NOTE: This assumes that convert0('X')
// respects REGISTER_ENDIAN order.
return convert0('X', vspecies().withLanes(laneType));
return convert0('X', vspecies().withLanes(laneType)).swapIfNeeded(vspecies());
}

@ForceInline
protected static <T> VectorShuffle<T> normalizeSubLanesForSpecies(AbstractSpecies<T> targetSpecies, int subLanesPerSrc) {
final int lanes = targetSpecies.laneCount();

if ((lanes % subLanesPerSrc) != 0) {
throw new IllegalArgumentException("laneCount " + lanes + " not divisible by subLanesPerSrc " + subLanesPerSrc);
}

// Each group corresponds to one source lane.
// For each group, reverse the lanes inside that group.
final int groups = lanes / subLanesPerSrc;
int[] map = new int[lanes];
for (int g = 0; g < groups; ++g) {
int base = g * subLanesPerSrc;
for (int j = 0; j < subLanesPerSrc; ++j) {
map[base + j] = base + (subLanesPerSrc - 1 - j);
}
}
return VectorShuffle.fromArray(targetSpecies, map, 0);
}

@ForceInline
protected final int subLanesToSwap(AbstractSpecies<?> srcSpecies) {
if (java.nio.ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) {
return -1;
}
int sBytes = srcSpecies.elementSize();
int tBytes = vspecies().elementSize();

// No lane reordering needed for same size or widening reinterprets
if (sBytes == tBytes || (sBytes % tBytes) != 0) {
return -1;
}
int subLanesPerSrc = sBytes / tBytes;
return subLanesPerSrc;
}

/*package-private*/
Expand Down Expand Up @@ -242,6 +279,9 @@ final VectorShuffle<E> iotaShuffleTemplate(int start, int step, boolean wrap) {
/*package-private*/
abstract AbstractVector<E> maybeSwap(ByteOrder bo);

/*package-private*/
abstract AbstractVector<?> swapIfNeeded(AbstractSpecies<?> srcSpecies);

/*package-private*/
@ForceInline
VectorShuffle<Byte> swapBytesShuffle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4071,6 +4071,14 @@ ByteVector maybeSwap(ByteOrder bo) {
return this;
}

/*package-private*/
@Override
@ForceInline
final
ByteVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
return this;
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BYTE_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,18 @@ DoubleVector maybeSwap(ByteOrder bo) {
return this;
}

@Override
@ForceInline
final
DoubleVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
int subLanesPerSrc = subLanesToSwap(srcSpecies);
if (subLanesPerSrc < 0) {
return this;
}
VectorShuffle<Double> shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc);
return (DoubleVector) this.rearrange(shuffle);
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_DOUBLE_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3562,6 +3562,18 @@ FloatVector maybeSwap(ByteOrder bo) {
return this;
}

@Override
@ForceInline
final
FloatVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
int subLanesPerSrc = subLanesToSwap(srcSpecies);
if (subLanesPerSrc < 0) {
return this;
}
VectorShuffle<Float> shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc);
return (FloatVector) this.rearrange(shuffle);
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_FLOAT_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,18 @@ IntVector maybeSwap(ByteOrder bo) {
return this;
}

@Override
@ForceInline
final
IntVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
int subLanesPerSrc = subLanesToSwap(srcSpecies);
if (subLanesPerSrc < 0) {
return this;
}
VectorShuffle<Integer> shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc);
return (IntVector) this.rearrange(shuffle);
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_INT_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,18 @@ LongVector maybeSwap(ByteOrder bo) {
return this;
}

@Override
@ForceInline
final
LongVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
int subLanesPerSrc = subLanesToSwap(srcSpecies);
if (subLanesPerSrc < 0) {
return this;
}
VectorShuffle<Long> shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc);
return (LongVector) this.rearrange(shuffle);
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4062,6 +4062,18 @@ ShortVector maybeSwap(ByteOrder bo) {
return this;
}

@Override
@ForceInline
final
ShortVector swapIfNeeded(AbstractSpecies<?> srcSpecies) {
int subLanesPerSrc = subLanesToSwap(srcSpecies);
if (subLanesPerSrc < 0) {
return this;
}
VectorShuffle<Short> shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc);
return (ShortVector) this.rearrange(shuffle);
}

static final int ARRAY_SHIFT =
31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE);
static final long ARRAY_BASE =
Expand Down