Skip to content

Commit

Permalink
[Backport] 8267190: Optimize Vector API test operations
Browse files Browse the repository at this point in the history
Summary: [Backport] 8267190: Optimize Vector API test operations

Test Plan: ci jtreg

Reviewed-by: JoshuaZhuwj

Issue: #591
  • Loading branch information
JinZhonghui authored and JoshuaZhuwj committed Nov 13, 2023
1 parent 74f32cc commit 77aecab
Show file tree
Hide file tree
Showing 32 changed files with 1,212 additions and 622 deletions.
5 changes: 3 additions & 2 deletions src/hotspot/share/opto/vectorIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,9 +1441,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,50 @@ Byte128Vector toVector() {
return (Byte128Vector) super.toVectorTemplate(); // specialize
}

@Override
/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
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);
switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte128Vector.Byte128Mask(maskArray).check(dsp);
case LaneType.SK_SHORT:
return new Short128Vector.Short128Mask(maskArray).check(dsp);
case LaneType.SK_INT:
return new Int128Vector.Int128Mask(maskArray).check(dsp);
case LaneType.SK_LONG:
return new Long128Vector.Long128Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT:
return new Float128Vector.Float128Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE:
return new Double128Vector.Double128Mask(maskArray).check(dsp);
default:
throw new AssertionError(dsp);
}
}

// Should not reach here.
throw new AssertionError(species);
@Override
@ForceInline
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");
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);
}
return this.defaultMaskCast(species);
}

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

@Override
/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
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);
switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte256Vector.Byte256Mask(maskArray).check(dsp);
case LaneType.SK_SHORT:
return new Short256Vector.Short256Mask(maskArray).check(dsp);
case LaneType.SK_INT:
return new Int256Vector.Int256Mask(maskArray).check(dsp);
case LaneType.SK_LONG:
return new Long256Vector.Long256Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT:
return new Float256Vector.Float256Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE:
return new Double256Vector.Double256Mask(maskArray).check(dsp);
default:
throw new AssertionError(dsp);
}
}

// Should not reach here.
throw new AssertionError(species);
@Override
@ForceInline
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");
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);
}
return this.defaultMaskCast(species);
}

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

@Override
/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
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);
switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte512Vector.Byte512Mask(maskArray).check(dsp);
case LaneType.SK_SHORT:
return new Short512Vector.Short512Mask(maskArray).check(dsp);
case LaneType.SK_INT:
return new Int512Vector.Int512Mask(maskArray).check(dsp);
case LaneType.SK_LONG:
return new Long512Vector.Long512Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT:
return new Float512Vector.Float512Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE:
return new Double512Vector.Double512Mask(maskArray).check(dsp);
default:
throw new AssertionError(dsp);
}
}

// Should not reach here.
throw new AssertionError(species);
@Override
@ForceInline
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");
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);
}
return this.defaultMaskCast(species);
}

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

@Override
/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
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);
switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE:
return new Byte64Vector.Byte64Mask(maskArray).check(dsp);
case LaneType.SK_SHORT:
return new Short64Vector.Short64Mask(maskArray).check(dsp);
case LaneType.SK_INT:
return new Int64Vector.Int64Mask(maskArray).check(dsp);
case LaneType.SK_LONG:
return new Long64Vector.Long64Mask(maskArray).check(dsp);
case LaneType.SK_FLOAT:
return new Float64Vector.Float64Mask(maskArray).check(dsp);
case LaneType.SK_DOUBLE:
return new Double64Vector.Double64Mask(maskArray).check(dsp);
default:
throw new AssertionError(dsp);
}
}

// Should not reach here.
throw new AssertionError(species);
@Override
@ForceInline
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");
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);
}
return this.defaultMaskCast(species);
}

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

@Override
/**
* Helper function for lane-wise mask conversions.
* This function kicks in after intrinsic failure.
*/
@ForceInline
public <E> VectorMask<E> cast(VectorSpecies<E> s) {
AbstractSpecies<E> species = (AbstractSpecies<E>) s;
if (length() != species.laneCount())
throw new IllegalArgumentException("VectorMask length and species length differ");
private final <E>
VectorMask<E> defaultMaskCast(AbstractSpecies<E> dsp) {
assert(length() == dsp.laneCount());
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);
switch (dsp.laneType.switchKey) {
case LaneType.SK_BYTE:
return new ByteMaxVector.ByteMaxMask(maskArray).check(dsp);
case LaneType.SK_SHORT:
return new ShortMaxVector.ShortMaxMask(maskArray).check(dsp);
case LaneType.SK_INT:
return new IntMaxVector.IntMaxMask(maskArray).check(dsp);
case LaneType.SK_LONG:
return new LongMaxVector.LongMaxMask(maskArray).check(dsp);
case LaneType.SK_FLOAT:
return new FloatMaxVector.FloatMaxMask(maskArray).check(dsp);
case LaneType.SK_DOUBLE:
return new DoubleMaxVector.DoubleMaxMask(maskArray).check(dsp);
default:
throw new AssertionError(dsp);
}
}

// Should not reach here.
throw new AssertionError(species);
@Override
@ForceInline
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");
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);
}
return this.defaultMaskCast(species);
}

// Unary operations
Expand Down
Loading

0 comments on commit 77aecab

Please sign in to comment.