Skip to content
Permalink
Browse files
8267190: Optimize Vector API test operations
Reviewed-by: psandoz, kvn
  • Loading branch information
Sandhya Viswanathan committed May 21, 2021
1 parent 94cfeb9 commit 8f10c5a8900517cfa04256eab909e18535086b98
Showing with 995 additions and 622 deletions.
  1. +3 −2 src/hotspot/share/opto/vectorIntrinsics.cpp
  2. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java
  3. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java
  4. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java
  5. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java
  6. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java
  7. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java
  8. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java
  9. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java
  10. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double64Vector.java
  11. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleMaxVector.java
  12. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float128Vector.java
  13. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float256Vector.java
  14. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float512Vector.java
  15. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float64Vector.java
  16. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatMaxVector.java
  17. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int128Vector.java
  18. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int256Vector.java
  19. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int512Vector.java
  20. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int64Vector.java
  21. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntMaxVector.java
  22. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long128Vector.java
  23. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long256Vector.java
  24. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java
  25. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java
  26. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongMaxVector.java
  27. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short128Vector.java
  28. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java
  29. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short512Vector.java
  30. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java
  31. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java
  32. +32 −20 src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template
@@ -1439,9 +1439,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();

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Loading

1 comment on commit 8f10c5a

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 8f10c5a May 21, 2021

Please sign in to comment.