Below code snippet is in test/micro/org/openjdk/bench/jdk/incubator/vector/MaskFromLongBenchmark.java
@Benchmark
public int microMaskFromLong_Byte64() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_64, val);
return mask.laneIsSet(1) ? 1 : 0;
}
After inlining laneIsSet, the VectorMaskToLong-VectorLongToMask pair would be optimized to nothing, thus this benchmark is actually to be zero cost.
Implementation of laneIsSet:
@Override
@ForceInline
public boolean laneIsSet(int i) {
int length = length();
Objects.checkIndex(i, length);
if (length <= Long.SIZE) {
return ((toLong() >>> i) & 1L) == 1;
} else {
return getBits()[i];
}
}
@Benchmark
public int microMaskFromLong_Byte64() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_64, val);
return mask.laneIsSet(1) ? 1 : 0;
}
After inlining laneIsSet, the VectorMaskToLong-VectorLongToMask pair would be optimized to nothing, thus this benchmark is actually to be zero cost.
Implementation of laneIsSet:
@Override
@ForceInline
public boolean laneIsSet(int i) {
int length = length();
Objects.checkIndex(i, length);
if (length <= Long.SIZE) {
return ((toLong() >>> i) & 1L) == 1;
} else {
return getBits()[i];
}
}