Skip to content

Commit 4da1745

Browse files
author
Xiaohong Gong
committed
8291118: [vectorapi] Optimize the implementation of lanewise FIRST_NONZERO
Reviewed-by: eliu, psandoz
1 parent 38a8191 commit 4da1745

File tree

7 files changed

+48
-77
lines changed

7 files changed

+48
-77
lines changed

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,9 @@ ByteVector lanewiseTemplate(VectorOperators.Binary op,
759759

760760
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
761761
if (op == FIRST_NONZERO) {
762-
// FIXME: Support this in the JIT.
763-
VectorMask<Byte> thisNZ
764-
= this.viewAsIntegralLanes().compare(NE, (byte) 0);
765-
that = that.blend((byte) 0, thisNZ.cast(vspecies()));
766-
op = OR_UNCHECKED;
762+
VectorMask<Byte> mask
763+
= this.compare(EQ, (byte) 0);
764+
return this.blend(that, mask);
767765
}
768766
if (opKind(op, VO_SHIFT)) {
769767
// As per shift specification for Java, mask the shift count.
@@ -809,11 +807,9 @@ ByteVector lanewiseTemplate(VectorOperators.Binary op,
809807

810808
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
811809
if (op == FIRST_NONZERO) {
812-
// FIXME: Support this in the JIT.
813-
VectorMask<Byte> thisNZ
814-
= this.viewAsIntegralLanes().compare(NE, (byte) 0);
815-
that = that.blend((byte) 0, thisNZ.cast(vspecies()));
816-
op = OR_UNCHECKED;
810+
VectorMask<Byte> mask
811+
= this.compare(EQ, (byte) 0, m);
812+
return this.blend(that, mask);
817813
}
818814
if (opKind(op, VO_SHIFT)) {
819815
// As per shift specification for Java, mask the shift count.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,9 @@ DoubleVector lanewiseTemplate(VectorOperators.Binary op,
764764

765765
if (opKind(op, VO_SPECIAL )) {
766766
if (op == FIRST_NONZERO) {
767-
// FIXME: Support this in the JIT.
768-
VectorMask<Long> thisNZ
769-
= this.viewAsIntegralLanes().compare(NE, (long) 0);
770-
that = that.blend((double) 0, thisNZ.cast(vspecies()));
771-
op = OR_UNCHECKED;
772-
// FIXME: Support OR_UNCHECKED on float/double also!
773-
return this.viewAsIntegralLanes()
774-
.lanewise(op, that.viewAsIntegralLanes())
775-
.viewAsFloatingLanes();
767+
VectorMask<Long> mask
768+
= this.viewAsIntegralLanes().compare(EQ, (long) 0);
769+
return this.blend(that, mask.cast(vspecies()));
776770
}
777771
}
778772

@@ -803,7 +797,10 @@ DoubleVector lanewiseTemplate(VectorOperators.Binary op,
803797

804798
if (opKind(op, VO_SPECIAL )) {
805799
if (op == FIRST_NONZERO) {
806-
return blend(lanewise(op, v), m);
800+
LongVector bits = this.viewAsIntegralLanes();
801+
VectorMask<Long> mask
802+
= bits.compare(EQ, (long) 0, m.cast(bits.vspecies()));
803+
return this.blend(that, mask.cast(vspecies()));
807804
}
808805
}
809806

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,9 @@ FloatVector lanewiseTemplate(VectorOperators.Binary op,
764764

765765
if (opKind(op, VO_SPECIAL )) {
766766
if (op == FIRST_NONZERO) {
767-
// FIXME: Support this in the JIT.
768-
VectorMask<Integer> thisNZ
769-
= this.viewAsIntegralLanes().compare(NE, (int) 0);
770-
that = that.blend((float) 0, thisNZ.cast(vspecies()));
771-
op = OR_UNCHECKED;
772-
// FIXME: Support OR_UNCHECKED on float/double also!
773-
return this.viewAsIntegralLanes()
774-
.lanewise(op, that.viewAsIntegralLanes())
775-
.viewAsFloatingLanes();
767+
VectorMask<Integer> mask
768+
= this.viewAsIntegralLanes().compare(EQ, (int) 0);
769+
return this.blend(that, mask.cast(vspecies()));
776770
}
777771
}
778772

@@ -803,7 +797,10 @@ FloatVector lanewiseTemplate(VectorOperators.Binary op,
803797

804798
if (opKind(op, VO_SPECIAL )) {
805799
if (op == FIRST_NONZERO) {
806-
return blend(lanewise(op, v), m);
800+
IntVector bits = this.viewAsIntegralLanes();
801+
VectorMask<Integer> mask
802+
= bits.compare(EQ, (int) 0, m.cast(bits.vspecies()));
803+
return this.blend(that, mask.cast(vspecies()));
807804
}
808805
}
809806

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,9 @@ IntVector lanewiseTemplate(VectorOperators.Binary op,
759759

760760
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
761761
if (op == FIRST_NONZERO) {
762-
// FIXME: Support this in the JIT.
763-
VectorMask<Integer> thisNZ
764-
= this.viewAsIntegralLanes().compare(NE, (int) 0);
765-
that = that.blend((int) 0, thisNZ.cast(vspecies()));
766-
op = OR_UNCHECKED;
762+
VectorMask<Integer> mask
763+
= this.compare(EQ, (int) 0);
764+
return this.blend(that, mask);
767765
}
768766
if (opKind(op, VO_SHIFT)) {
769767
// As per shift specification for Java, mask the shift count.
@@ -809,11 +807,9 @@ IntVector lanewiseTemplate(VectorOperators.Binary op,
809807

810808
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
811809
if (op == FIRST_NONZERO) {
812-
// FIXME: Support this in the JIT.
813-
VectorMask<Integer> thisNZ
814-
= this.viewAsIntegralLanes().compare(NE, (int) 0);
815-
that = that.blend((int) 0, thisNZ.cast(vspecies()));
816-
op = OR_UNCHECKED;
810+
VectorMask<Integer> mask
811+
= this.compare(EQ, (int) 0, m);
812+
return this.blend(that, mask);
817813
}
818814
if (opKind(op, VO_SHIFT)) {
819815
// As per shift specification for Java, mask the shift count.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,9 @@ LongVector lanewiseTemplate(VectorOperators.Binary op,
717717

718718
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
719719
if (op == FIRST_NONZERO) {
720-
// FIXME: Support this in the JIT.
721-
VectorMask<Long> thisNZ
722-
= this.viewAsIntegralLanes().compare(NE, (long) 0);
723-
that = that.blend((long) 0, thisNZ.cast(vspecies()));
724-
op = OR_UNCHECKED;
720+
VectorMask<Long> mask
721+
= this.compare(EQ, (long) 0);
722+
return this.blend(that, mask);
725723
}
726724
if (opKind(op, VO_SHIFT)) {
727725
// As per shift specification for Java, mask the shift count.
@@ -767,11 +765,9 @@ LongVector lanewiseTemplate(VectorOperators.Binary op,
767765

768766
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
769767
if (op == FIRST_NONZERO) {
770-
// FIXME: Support this in the JIT.
771-
VectorMask<Long> thisNZ
772-
= this.viewAsIntegralLanes().compare(NE, (long) 0);
773-
that = that.blend((long) 0, thisNZ.cast(vspecies()));
774-
op = OR_UNCHECKED;
768+
VectorMask<Long> mask
769+
= this.compare(EQ, (long) 0, m);
770+
return this.blend(that, mask);
775771
}
776772
if (opKind(op, VO_SHIFT)) {
777773
// As per shift specification for Java, mask the shift count.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,9 @@ ShortVector lanewiseTemplate(VectorOperators.Binary op,
759759

760760
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
761761
if (op == FIRST_NONZERO) {
762-
// FIXME: Support this in the JIT.
763-
VectorMask<Short> thisNZ
764-
= this.viewAsIntegralLanes().compare(NE, (short) 0);
765-
that = that.blend((short) 0, thisNZ.cast(vspecies()));
766-
op = OR_UNCHECKED;
762+
VectorMask<Short> mask
763+
= this.compare(EQ, (short) 0);
764+
return this.blend(that, mask);
767765
}
768766
if (opKind(op, VO_SHIFT)) {
769767
// As per shift specification for Java, mask the shift count.
@@ -809,11 +807,9 @@ ShortVector lanewiseTemplate(VectorOperators.Binary op,
809807

810808
if (opKind(op, VO_SPECIAL | VO_SHIFT)) {
811809
if (op == FIRST_NONZERO) {
812-
// FIXME: Support this in the JIT.
813-
VectorMask<Short> thisNZ
814-
= this.viewAsIntegralLanes().compare(NE, (short) 0);
815-
that = that.blend((short) 0, thisNZ.cast(vspecies()));
816-
op = OR_UNCHECKED;
810+
VectorMask<Short> mask
811+
= this.compare(EQ, (short) 0, m);
812+
return this.blend(that, mask);
817813
}
818814
if (opKind(op, VO_SHIFT)) {
819815
// As per shift specification for Java, mask the shift count.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template

+10-17
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
839839

840840
if (opKind(op, VO_SPECIAL {#if[!FP]? | VO_SHIFT})) {
841841
if (op == FIRST_NONZERO) {
842-
// FIXME: Support this in the JIT.
843-
VectorMask<$Boxbitstype$> thisNZ
844-
= this.viewAsIntegralLanes().compare(NE, ($bitstype$) 0);
845-
that = that.blend(($type$) 0, thisNZ.cast(vspecies()));
846-
op = OR_UNCHECKED;
847-
#if[FP]
848-
// FIXME: Support OR_UNCHECKED on float/double also!
849-
return this.viewAsIntegralLanes()
850-
.lanewise(op, that.viewAsIntegralLanes())
851-
.viewAsFloatingLanes();
852-
#end[FP]
842+
VectorMask<$Boxbitstype$> mask
843+
= this{#if[FP]?.viewAsIntegralLanes()}.compare(EQ, ($bitstype$) 0);
844+
return this.blend(that, mask{#if[FP]?.cast(vspecies())});
853845
}
854846
#if[BITWISE]
855847
#if[!FP]
@@ -900,13 +892,14 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
900892
if (opKind(op, VO_SPECIAL {#if[!FP]? | VO_SHIFT})) {
901893
if (op == FIRST_NONZERO) {
902894
#if[FP]
903-
return blend(lanewise(op, v), m);
895+
$Bitstype$Vector bits = this.viewAsIntegralLanes();
896+
VectorMask<$Boxbitstype$> mask
897+
= bits.compare(EQ, ($bitstype$) 0, m.cast(bits.vspecies()));
898+
return this.blend(that, mask.cast(vspecies()));
904899
#else[FP]
905-
// FIXME: Support this in the JIT.
906-
VectorMask<$Boxbitstype$> thisNZ
907-
= this.viewAsIntegralLanes().compare(NE, ($bitstype$) 0);
908-
that = that.blend(($type$) 0, thisNZ.cast(vspecies()));
909-
op = OR_UNCHECKED;
900+
VectorMask<$Boxtype$> mask
901+
= this.compare(EQ, ($type$) 0, m);
902+
return this.blend(that, mask);
910903
#end[FP]
911904
}
912905
#if[BITWISE]

0 commit comments

Comments
 (0)