Skip to content
Permalink
Browse files
8268151: Vector API toShuffle optimization
Reviewed-by: psandoz, vlivanov
  • Loading branch information
Sandhya Viswanathan committed Jun 4, 2021
1 parent 64ec8b3 commit 20b631278c0c89ccd9c16f2a29d47eb8414aacd5
Showing 41 changed files with 202 additions and 234 deletions.
@@ -406,14 +406,10 @@ void PhaseVector::expand_vunbox_node(VectorUnboxNode* vec_unbox) {
const TypeVect* vt = vec_unbox->bottom_type()->is_vect();
BasicType bt = vt->element_basic_type();
BasicType masktype = bt;
BasicType elem_bt;

if (is_vector_mask(from_kls)) {
bt = T_BOOLEAN;
} else if (is_vector_shuffle(from_kls)) {
if (vec_unbox->is_shuffle_to_vector() == true) {
elem_bt = bt;
}
bt = T_BYTE;
}

@@ -459,13 +455,9 @@ void PhaseVector::expand_vunbox_node(VectorUnboxNode* vec_unbox) {

if (is_vector_mask(from_kls)) {
vec_val_load = gvn.transform(new VectorLoadMaskNode(vec_val_load, TypeVect::make(masktype, num_elem)));
} else if (is_vector_shuffle(from_kls)) {
if (vec_unbox->is_shuffle_to_vector() == false) {
assert(vec_unbox->bottom_type()->is_vect()->element_basic_type() == masktype, "expect shuffle type consistency");
vec_val_load = gvn.transform(new VectorLoadShuffleNode(vec_val_load, TypeVect::make(masktype, num_elem)));
} else {
vec_val_load = gvn.transform(VectorCastNode::make(Op_VectorCastB2X, vec_val_load, elem_bt, num_elem));
}
} else if (is_vector_shuffle(from_kls) && !vec_unbox->is_shuffle_to_vector()) {
assert(vec_unbox->bottom_type()->is_vect()->element_basic_type() == masktype, "expect shuffle type consistency");
vec_val_load = gvn.transform(new VectorLoadShuffleNode(vec_val_load, TypeVect::make(masktype, num_elem)));
}

gvn.hash_delete(vec_unbox);
@@ -578,7 +578,11 @@ bool LibraryCallKit::inline_vector_shuffle_to_vector() {
const TypeInstPtr* shuffle_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, sbox_klass);

// Unbox shuffle with true flag to indicate its load shuffle to vector
Node* shuffle_vec = unbox_vector(shuffle, shuffle_box_type, elem_bt, num_elem, true);
// shuffle is a byte array
Node* shuffle_vec = unbox_vector(shuffle, shuffle_box_type, T_BYTE, num_elem, true);

// cast byte to target element type
shuffle_vec = gvn().transform(VectorCastNode::make(cast_vopc, shuffle_vec, elem_bt, num_elem));

ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass();
const TypeInstPtr* vec_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass);
@@ -1588,7 +1592,7 @@ bool LibraryCallKit::inline_vector_convert() {

ciKlass* vbox_klass_from = vector_klass_from->const_oop()->as_instance()->java_lang_Class_klass();
ciKlass* vbox_klass_to = vector_klass_to->const_oop()->as_instance()->java_lang_Class_klass();
if (is_vector_shuffle(vbox_klass_from) || is_vector_shuffle(vbox_klass_to)) {
if (is_vector_shuffle(vbox_klass_from)) {
return false; // vector shuffles aren't supported
}
bool is_mask = is_vector_mask(vbox_klass_from);
@@ -1243,10 +1243,7 @@ Node* VectorUnboxNode::Ideal(PhaseGVN* phase, bool can_reshape) {
value = phase->transform(VectorStoreMaskNode::make(*phase, value, in_vt->element_basic_type(), in_vt->length()));
return new VectorLoadMaskNode(value, out_vt);
} else if (is_vector_shuffle) {
if (is_shuffle_to_vector()) {
// VectorUnbox (VectorBox vshuffle) ==> VectorCastB2X vshuffle
return new VectorCastB2XNode(value, out_vt);
} else {
if (!is_shuffle_to_vector()) {
// VectorUnbox (VectorBox vshuffle) ==> VectorLoadShuffle vshuffle
return new VectorLoadShuffleNode(value, out_vt);
}
@@ -330,15 +330,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Byte> toShuffle() {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Byte128Shuffle.class); // specialize
}

// Specialized unary testing
@@ -330,15 +330,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Byte> toShuffle() {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Byte256Shuffle.class); // specialize
}

// Specialized unary testing
@@ -330,15 +330,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Byte> toShuffle() {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Byte512Shuffle.class); // specialize
}

// Specialized unary testing
@@ -330,15 +330,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Byte> toShuffle() {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Byte64Shuffle.class); // specialize
}

// Specialized unary testing
@@ -330,15 +330,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Byte> toShuffle() {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(ByteMaxShuffle.class); // specialize
}

// Specialized unary testing
@@ -2166,6 +2166,29 @@ ByteVector rearrangeTemplate(Class<S> shuffletype,
return r1.blend(r0, valid);
}

@ForceInline
private final
VectorShuffle<Byte> toShuffle0(ByteSpecies dsp) {
byte[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(dsp, sa, 0);
}

/*package-private*/
@ForceInline
final
VectorShuffle<Byte> toShuffleTemplate(Class<?> shuffleType) {
ByteSpecies vsp = vspecies();
return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST,
getClass(), byte.class, length(),
shuffleType, byte.class, length(),
this, vsp,
ByteVector::toShuffle0);
}

/**
* {@inheritDoc} <!--workaround-->
*/
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Double> toShuffle() {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Double128Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Double> toShuffle() {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Double256Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Double> toShuffle() {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Double512Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Double> toShuffle() {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Double64Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Double> toShuffle() {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(DoubleMaxShuffle.class); // specialize
}

// Specialized unary testing
@@ -2073,6 +2073,29 @@ DoubleVector rearrangeTemplate(Class<S> shuffletype,
return r1.blend(r0, valid);
}

@ForceInline
private final
VectorShuffle<Double> toShuffle0(DoubleSpecies dsp) {
double[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(dsp, sa, 0);
}

/*package-private*/
@ForceInline
final
VectorShuffle<Double> toShuffleTemplate(Class<?> shuffleType) {
DoubleSpecies vsp = vspecies();
return VectorSupport.convert(VectorSupport.VECTOR_OP_CAST,
getClass(), double.class, length(),
shuffleType, byte.class, length(),
this, vsp,
DoubleVector::toShuffle0);
}

/**
* {@inheritDoc} <!--workaround-->
*/
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Float> toShuffle() {
float[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Float128Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Float> toShuffle() {
float[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Float256Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Float> toShuffle() {
float[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Float512Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Float> toShuffle() {
float[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(Float64Shuffle.class); // specialize
}

// Specialized unary testing
@@ -324,15 +324,9 @@ public final long reduceLanesToLong(VectorOperators.Associative op,
return (long) super.reduceLanesTemplate(op, m); // specialized
}

@Override
@ForceInline
public VectorShuffle<Float> toShuffle() {
float[] a = toArray();
int[] sa = new int[a.length];
for (int i = 0; i < a.length; i++) {
sa[i] = (int) a[i];
}
return VectorShuffle.fromArray(VSPECIES, sa, 0);
return super.toShuffleTemplate(FloatMaxShuffle.class); // specialize
}

// Specialized unary testing

0 comments on commit 20b6312

Please sign in to comment.