Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8265128: [REDO] Optimize Vector API slice and unslice operations #3804

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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);
}

/**
@@ -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-->
*/
@@ -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*/
@@ -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",
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Loading