Skip to content

Commit

Permalink
8265128: [REDO] Optimize Vector API slice and unslice operations
Browse files Browse the repository at this point in the history
Reviewed-by: psandoz, vlivanov
  • Loading branch information
Sandhya Viswanathan committed May 10, 2021
1 parent e5d3ee3 commit 23446f1
Show file tree
Hide file tree
Showing 43 changed files with 363 additions and 709 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -387,14 +387,7 @@ public Byte128Vector slice(int origin, Vector<Byte> v) {
@Override
@ForceInline
public Byte128Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte128Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte128Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -415,14 +408,7 @@ public Byte128Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<By
@Override
@ForceInline
public Byte128Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte128Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((byte)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte128Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -387,14 +387,7 @@ public Byte256Vector slice(int origin, Vector<Byte> v) {
@Override
@ForceInline
public Byte256Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte256Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte256Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -415,14 +408,7 @@ public Byte256Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<By
@Override
@ForceInline
public Byte256Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte256Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((byte)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte256Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -387,14 +387,7 @@ public Byte512Vector slice(int origin, Vector<Byte> v) {
@Override
@ForceInline
public Byte512Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte512Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte512Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -415,14 +408,7 @@ public Byte512Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<By
@Override
@ForceInline
public Byte512Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte512Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((byte)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte512Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -387,14 +387,7 @@ public Byte64Vector slice(int origin, Vector<Byte> v) {
@Override
@ForceInline
public Byte64Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte64Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte64Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -415,14 +408,7 @@ public Byte64Vector unslice(int origin, Vector<Byte> w, int part, VectorMask<Byt
@Override
@ForceInline
public Byte64Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Byte64Shuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((byte)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Byte64Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -387,14 +387,7 @@ public ByteMaxVector slice(int origin, Vector<Byte> v) {
@Override
@ForceInline
public ByteMaxVector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
ByteMaxShuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (ByteMaxVector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -415,14 +408,7 @@ public ByteMaxVector unslice(int origin, Vector<Byte> w, int part, VectorMask<By
@Override
@ForceInline
public ByteMaxVector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
ByteMaxShuffle Iota = iotaShuffle();
VectorMask<Byte> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((byte)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (ByteMaxVector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1981,14 +1981,11 @@ public final ByteVector blend(long e,
ByteVector sliceTemplate(int origin, Vector<Byte> v1) {
ByteVector that = (ByteVector) v1;
that.check(this);
byte[] a0 = this.vec();
byte[] a1 = that.vec();
byte[] res = new byte[a0.length];
int vlen = res.length;
int firstPart = vlen - origin;
System.arraycopy(a0, origin, res, 0, firstPart);
System.arraycopy(a1, 0, res, firstPart, origin);
return vectorFactory(res);
Objects.checkIndex(origin, length() + 1);
VectorShuffle<Byte> iota = iotaShuffle();
VectorMask<Byte> blendMask = iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(length() - origin))));
iota = iotaShuffle(origin, 1, true);
return that.rearrange(iota).blend(this.rearrange(iota), blendMask);
}

/**
Expand All @@ -2010,6 +2007,17 @@ ByteVector slice(int origin,
public abstract
ByteVector slice(int origin);

/*package-private*/
final
@ForceInline
ByteVector sliceTemplate(int origin) {
Objects.checkIndex(origin, length() + 1);
VectorShuffle<Byte> iota = iotaShuffle();
VectorMask<Byte> blendMask = iota.toVector().compare(VectorOperators.LT, (broadcast((byte)(length() - origin))));
iota = iotaShuffle(origin, 1, true);
return vspecies().zero().blend(this.rearrange(iota), blendMask);
}

/**
* {@inheritDoc} <!--workaround-->
*/
Expand All @@ -2024,21 +2032,12 @@ ByteVector slice(int origin,
unsliceTemplate(int origin, Vector<Byte> w, int part) {
ByteVector that = (ByteVector) w;
that.check(this);
byte[] slice = this.vec();
byte[] res = that.vec().clone();
int vlen = res.length;
int firstPart = vlen - origin;
switch (part) {
case 0:
System.arraycopy(slice, 0, res, origin, firstPart);
break;
case 1:
System.arraycopy(slice, firstPart, res, 0, origin);
break;
default:
throw wrongPartForSlice(part);
}
return vectorFactory(res);
Objects.checkIndex(origin, length() + 1);
VectorShuffle<Byte> iota = iotaShuffle();
VectorMask<Byte> blendMask = iota.toVector().compare((part == 0) ? VectorOperators.GE : VectorOperators.LT,
(broadcast((byte)(origin))));
iota = iotaShuffle(-origin, 1, true);
return that.blend(this.rearrange(iota), blendMask);
}

/*package-private*/
Expand Down Expand Up @@ -2068,6 +2067,19 @@ ByteVector slice(int origin,
public abstract
ByteVector unslice(int origin);

/*package-private*/
final
@ForceInline
ByteVector
unsliceTemplate(int origin) {
Objects.checkIndex(origin, length() + 1);
VectorShuffle<Byte> iota = iotaShuffle();
VectorMask<Byte> blendMask = iota.toVector().compare(VectorOperators.GE,
(broadcast((byte)(origin))));
iota = iotaShuffle(-origin, 1, true);
return vspecies().zero().blend(this.rearrange(iota), blendMask);
}

private ArrayIndexOutOfBoundsException
wrongPartForSlice(int part) {
String msg = String.format("bad part number %d for slice operation",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -381,14 +381,7 @@ public Double128Vector slice(int origin, Vector<Double> v) {
@Override
@ForceInline
public Double128Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double128Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((double)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double128Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -409,14 +402,7 @@ public Double128Vector unslice(int origin, Vector<Double> w, int part, VectorMas
@Override
@ForceInline
public Double128Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double128Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((double)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double128Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -381,14 +381,7 @@ public Double256Vector slice(int origin, Vector<Double> v) {
@Override
@ForceInline
public Double256Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double256Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((double)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double256Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -409,14 +402,7 @@ public Double256Vector unslice(int origin, Vector<Double> w, int part, VectorMas
@Override
@ForceInline
public Double256Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double256Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((double)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double256Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -381,14 +381,7 @@ public Double512Vector slice(int origin, Vector<Double> v) {
@Override
@ForceInline
public Double512Vector slice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double512Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.LT, (broadcast((double)(VLENGTH-origin))));
Iota = iotaShuffle(origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double512Vector) super.sliceTemplate(origin); // specialize
}

@Override
Expand All @@ -409,14 +402,7 @@ public Double512Vector unslice(int origin, Vector<Double> w, int part, VectorMas
@Override
@ForceInline
public Double512Vector unslice(int origin) {
if ((origin < 0) || (origin >= VLENGTH)) {
throw new ArrayIndexOutOfBoundsException("Index " + origin + " out of bounds for vector length " + VLENGTH);
} else {
Double512Shuffle Iota = iotaShuffle();
VectorMask<Double> BlendMask = Iota.toVector().compare(VectorOperators.GE, (broadcast((double)(origin))));
Iota = iotaShuffle(-origin, 1, true);
return ZERO.blend(this.rearrange(Iota), BlendMask);
}
return (Double512Vector) super.unsliceTemplate(origin); // specialize
}

@Override
Expand Down
Loading

1 comment on commit 23446f1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.