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

8267190: Optimize Vector API test operations #4039

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 3 additions & 2 deletions src/hotspot/share/opto/vectorIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,10 @@ bool LibraryCallKit::inline_vector_convert() {
return false; // should be primitive type
}
BasicType elem_bt_to = elem_type_to->basic_type();
if (is_mask && elem_bt_from != elem_bt_to) {
return false; // type mismatch
if (is_mask && (type2aelembytes(elem_bt_from) != type2aelembytes(elem_bt_to))) {
return false; // elem size mismatch
}

int num_elem_from = vlen_from->get_con();
int num_elem_to = vlen_to->get_con();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,31 +599,43 @@ Byte128Vector toVector() {
return (Byte128Vector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new Byte128Vector.Byte128Mask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new Short128Vector.Short128Mask(maskArray).check(dsp);
case LaneType.SK_INT -> new Int128Vector.Int128Mask(maskArray).check(dsp);
case LaneType.SK_LONG -> new Long128Vector.Long128Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new Float128Vector.Float128Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new Double128Vector.Double128Mask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte128Vector.Byte128Mask(maskArray).check(species);
case LaneType.SK_SHORT:
return new Short128Vector.Short128Mask(maskArray).check(species);
case LaneType.SK_INT:
return new Int128Vector.Int128Mask(maskArray).check(species);
case LaneType.SK_LONG:
return new Long128Vector.Long128Mask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new Float128Vector.Float128Mask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new Double128Vector.Double128Mask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
Byte128Mask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,31 +631,43 @@ Byte256Vector toVector() {
return (Byte256Vector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new Byte256Vector.Byte256Mask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new Short256Vector.Short256Mask(maskArray).check(dsp);
case LaneType.SK_INT -> new Int256Vector.Int256Mask(maskArray).check(dsp);
case LaneType.SK_LONG -> new Long256Vector.Long256Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new Float256Vector.Float256Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new Double256Vector.Double256Mask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte256Vector.Byte256Mask(maskArray).check(species);
case LaneType.SK_SHORT:
return new Short256Vector.Short256Mask(maskArray).check(species);
case LaneType.SK_INT:
return new Int256Vector.Int256Mask(maskArray).check(species);
case LaneType.SK_LONG:
return new Long256Vector.Long256Mask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new Float256Vector.Float256Mask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new Double256Vector.Double256Mask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
Byte256Mask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,31 +695,43 @@ Byte512Vector toVector() {
return (Byte512Vector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new Byte512Vector.Byte512Mask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new Short512Vector.Short512Mask(maskArray).check(dsp);
case LaneType.SK_INT -> new Int512Vector.Int512Mask(maskArray).check(dsp);
case LaneType.SK_LONG -> new Long512Vector.Long512Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new Float512Vector.Float512Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new Double512Vector.Double512Mask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte512Vector.Byte512Mask(maskArray).check(species);
case LaneType.SK_SHORT:
return new Short512Vector.Short512Mask(maskArray).check(species);
case LaneType.SK_INT:
return new Int512Vector.Int512Mask(maskArray).check(species);
case LaneType.SK_LONG:
return new Long512Vector.Long512Mask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new Float512Vector.Float512Mask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new Double512Vector.Double512Mask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
Byte512Mask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,31 +583,43 @@ Byte64Vector toVector() {
return (Byte64Vector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new Byte64Vector.Byte64Mask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new Short64Vector.Short64Mask(maskArray).check(dsp);
case LaneType.SK_INT -> new Int64Vector.Int64Mask(maskArray).check(dsp);
case LaneType.SK_LONG -> new Long64Vector.Long64Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new Float64Vector.Float64Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new Double64Vector.Double64Mask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte64Vector.Byte64Mask(maskArray).check(species);
case LaneType.SK_SHORT:
return new Short64Vector.Short64Mask(maskArray).check(species);
case LaneType.SK_INT:
return new Int64Vector.Int64Mask(maskArray).check(species);
case LaneType.SK_LONG:
return new Long64Vector.Long64Mask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new Float64Vector.Float64Mask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new Double64Vector.Double64Mask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
Byte64Mask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,31 +569,43 @@ ByteMaxVector toVector() {
return (ByteMaxVector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new ByteMaxVector.ByteMaxMask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new ShortMaxVector.ShortMaxMask(maskArray).check(dsp);
case LaneType.SK_INT -> new IntMaxVector.IntMaxMask(maskArray).check(dsp);
case LaneType.SK_LONG -> new LongMaxVector.LongMaxMask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new FloatMaxVector.FloatMaxMask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new DoubleMaxVector.DoubleMaxMask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new ByteMaxVector.ByteMaxMask(maskArray).check(species);
case LaneType.SK_SHORT:
return new ShortMaxVector.ShortMaxMask(maskArray).check(species);
case LaneType.SK_INT:
return new IntMaxVector.IntMaxMask(maskArray).check(species);
case LaneType.SK_LONG:
return new LongMaxVector.LongMaxMask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new FloatMaxVector.FloatMaxMask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new DoubleMaxVector.DoubleMaxMask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
ByteMaxMask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,31 +567,43 @@ Double128Vector toVector() {
return (Double128Vector) super.toVectorTemplate(); // specialize
}

/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
return switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE -> new Byte128Vector.Byte128Mask(maskArray).check(dsp);
case LaneType.SK_SHORT -> new Short128Vector.Short128Mask(maskArray).check(dsp);
case LaneType.SK_INT -> new Int128Vector.Int128Mask(maskArray).check(dsp);
case LaneType.SK_LONG -> new Long128Vector.Long128Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT -> new Float128Vector.Float128Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE -> new Double128Vector.Double128Mask(maskArray).check(dsp);
default -> throw new AssertionError(dsp);
};
}

@Override
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
public <E> VectorMask<E> cast(VectorSpecies<E> dsp) {
AbstractSpecies<E> species = (AbstractSpecies<E>) dsp;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
boolean[] maskArray = toArray();
// enum-switches don't optimize properly JDK-8161245
switch (species.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte128Vector.Byte128Mask(maskArray).check(species);
case LaneType.SK_SHORT:
return new Short128Vector.Short128Mask(maskArray).check(species);
case LaneType.SK_INT:
return new Int128Vector.Int128Mask(maskArray).check(species);
case LaneType.SK_LONG:
return new Long128Vector.Long128Mask(maskArray).check(species);
case LaneType.SK_FLOAT:
return new Float128Vector.Float128Mask(maskArray).check(species);
case LaneType.SK_DOUBLE:
return new Double128Vector.Double128Mask(maskArray).check(species);
if (VSIZE == species.vectorBitSize()) {
Class<?> dtype = species.elementType();
Class<?> dmtype = species.maskType();
return VectorSupport.convert(VectorSupport.VECTOR_OP_REINTERPRET,
this.getClass(), ETYPE, VLENGTH,
dmtype, dtype, VLENGTH,
this, species,
Double128Mask::defaultMaskCast);
}

// Should not reach here.
throw new AssertionError(species);
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Loading