< prev index next >

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

Print this page
rev 54658 : refactored mask and shuffle creation methods, moved classes to top-level
rev 54659 : changed VectorSpecies to interface and moved stuff to AbstractSpecies
rev 54660 : Javadoc changes

*** 29,39 **** import java.util.Objects; /** * A {@code VectorMask} represents an ordered immutable sequence of {@code boolean} ! * values. A VectorMask can be used with a mask accepting vector operation to * control the selection and operation of lane elements of input vectors. * <p> * The number of values in the sequence is referred to as the VectorMask * {@link #length() length}. The length also corresponds to the number of * VectorMask lanes. The lane element at lane index {@code N} (from {@code 0}, --- 29,39 ---- import java.util.Objects; /** * A {@code VectorMask} represents an ordered immutable sequence of {@code boolean} ! * values. Some vector operations accept masks to * control the selection and operation of lane elements of input vectors. * <p> * The number of values in the sequence is referred to as the VectorMask * {@link #length() length}. The length also corresponds to the number of * VectorMask lanes. The lane element at lane index {@code N} (from {@code 0},
*** 44,90 **** * <p> * A lane is said to be <em>set</em> if the lane element is {@code true}, * otherwise a lane is said to be <em>unset</em> if the lane element is * {@code false}. * <p> ! * VectorMask declares a limited set of unary, binary and reductive mask ! * operations. * <ul> * <li> ! * A mask unary operation (1-ary) operates on one input mask to produce a * result mask. * For each lane of the input mask the * lane element is operated on using the specified scalar unary operation and * the boolean result is placed into the mask result at the same lane. ! * The following pseudocode expresses the behaviour of this operation category: * * <pre>{@code * VectorMask<E> a = ...; * boolean[] ar = new boolean[a.length()]; * for (int i = 0; i < a.length(); i++) { ! * ar[i] = boolean_unary_op(a.isSet(i)); * } ! * VectorMask<E> r = VectorMask.fromArray(ar, 0); * }</pre> * * <li> ! * A mask binary operation (2-ary) operates on two input * masks to produce a result mask. ! * For each lane of the two input masks, ! * a and b say, the corresponding lane elements from a and b are operated on * using the specified scalar binary operation and the boolean result is placed * into the mask result at the same lane. ! * The following pseudocode expresses the behaviour of this operation category: * * <pre>{@code * VectorMask<E> a = ...; * VectorMask<E> b = ...; * boolean[] ar = new boolean[a.length()]; * for (int i = 0; i < a.length(); i++) { * ar[i] = scalar_binary_op(a.isSet(i), b.isSet(i)); * } ! * VectorMask<E> r = VectorMask.fromArray(ar, 0); * }</pre> * * </ul> * @param <E> the boxed element type of this mask */ --- 44,104 ---- * <p> * A lane is said to be <em>set</em> if the lane element is {@code true}, * otherwise a lane is said to be <em>unset</em> if the lane element is * {@code false}. * <p> ! * VectorMask declares a limited set of unary, binary and reduction operations. * <ul> * <li> ! * A lane-wise unary operation operates on one input mask and produces a * result mask. * For each lane of the input mask the * lane element is operated on using the specified scalar unary operation and * the boolean result is placed into the mask result at the same lane. ! * The following pseudocode expresses the behavior of this operation category: * * <pre>{@code * VectorMask<E> a = ...; * boolean[] ar = new boolean[a.length()]; * for (int i = 0; i < a.length(); i++) { ! * ar[i] = scalar_unary_op(a.isSet(i)); * } ! * VectorMask<E> r = VectorMask.fromArray(a.species(), ar, 0); * }</pre> * * <li> ! * A lane-wise binary operation operates on two input * masks to produce a result mask. ! * For each lane of the two input masks a and b, ! * the corresponding lane elements from a and b are operated on * using the specified scalar binary operation and the boolean result is placed * into the mask result at the same lane. ! * The following pseudocode expresses the behavior of this operation category: * * <pre>{@code * VectorMask<E> a = ...; * VectorMask<E> b = ...; * boolean[] ar = new boolean[a.length()]; * for (int i = 0; i < a.length(); i++) { * ar[i] = scalar_binary_op(a.isSet(i), b.isSet(i)); * } ! * VectorMask<E> r = VectorMask.fromArray(a.species(), ar, 0); ! * }</pre> ! * ! * <li> ! * A cross-lane reduction operation accepts an input mask and produces a scalar result. ! * For each lane of the input mask the lane element is operated on, together with a scalar accumulation value, ! * using the specified scalar binary operation. The scalar result is the final value of the accumulator. The ! * following pseudocode expresses the behaviour of this operation category: ! * ! * <pre>{@code ! * Mask<E> a = ...; ! * int acc = zero_for_scalar_binary_op; // 0, or 1 for & ! * for (int i = 0; i < a.length(); i++) { ! * acc = scalar_binary_op(acc, a.isSet(i) ? 1 : 0); // & | + ! * } ! * return acc; // maybe boolean (acc != 0) * }</pre> * * </ul> * @param <E> the boxed element type of this mask */
*** 130,152 **** * if the array element at index {@code ix + N} is {@code true} then the * mask lane at index {@code N} is set, otherwise it is unset. * * @param species mask species * @param bits the {@code boolean} array ! * @param ix the offset into the array * @return the mask loaded from a {@code boolean} array ! * @throws IndexOutOfBoundsException if {@code ix < 0}, or ! * {@code ix > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static <E> VectorMask<E> fromArray(VectorSpecies<E> species, boolean[] bits, int ix) { Objects.requireNonNull(bits); ! ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); return VectorIntrinsics.load((Class<VectorMask<E>>) species.maskType(), species.elementType(), species.length(), ! bits, (long) ix + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, ! bits, ix, species, (boolean[] c, int idx, VectorSpecies<E> s) -> ((AbstractSpecies<E>)s).opm(n -> c[idx + n])); } /** * Returns a mask where all lanes are set. --- 144,166 ---- * if the array element at index {@code ix + N} is {@code true} then the * mask lane at index {@code N} is set, otherwise it is unset. * * @param species mask species * @param bits the {@code boolean} array ! * @param offset the offset into the array * @return the mask loaded from a {@code boolean} array ! * @throws IndexOutOfBoundsException if {@code offset < 0}, or ! * {@code offset > bits.length - species.length()} */ @ForceInline @SuppressWarnings("unchecked") ! public static <E> VectorMask<E> fromArray(VectorSpecies<E> species, boolean[] bits, int offset) { Objects.requireNonNull(bits); ! offset = VectorIntrinsics.checkIndex(offset, bits.length, species.length()); return VectorIntrinsics.load((Class<VectorMask<E>>) species.maskType(), species.elementType(), species.length(), ! bits, (long) offset + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, ! bits, offset, species, (boolean[] c, int idx, VectorSpecies<E> s) -> ((AbstractSpecies<E>)s).opm(n -> c[idx + n])); } /** * Returns a mask where all lanes are set.
*** 231,245 **** * For each mask lane, where {@code N} is the mask lane index, * the lane element at index {@code N} is stored into the array at index * {@code i + N}. * * @param a the array ! * @param i the offset into the array ! * @throws IndexOutOfBoundsException if {@code i < 0}, or ! * {@code i > a.length - this.length()} */ ! public abstract void intoArray(boolean[] a, int i); /** * Returns {@code true} if any of the mask lanes are set. * * @return {@code true} if any of the mask lanes are set, otherwise --- 245,259 ---- * For each mask lane, where {@code N} is the mask lane index, * the lane element at index {@code N} is stored into the array at index * {@code i + N}. * * @param a the array ! * @param offset the offset into the array ! * @throws IndexOutOfBoundsException if {@code offset < 0}, or ! * {@code offset > a.length - this.length()} */ ! public abstract void intoArray(boolean[] a, int offset); /** * Returns {@code true} if any of the mask lanes are set. * * @return {@code true} if any of the mask lanes are set, otherwise
*** 263,296 **** public abstract int trueCount(); /** * Logically ands this mask with an input mask. * <p> ! * This is a mask binary operation where the logical and operation ! * ({@code &&} is applied to lane elements. * * @param o the input mask * @return the result of logically and'ing this mask with an input mask */ public abstract VectorMask<E> and(VectorMask<E> o); /** * Logically ors this mask with an input mask. * <p> ! * This is a mask binary operation where the logical or operation ! * ({@code ||} is applied to lane elements. * * @param o the input mask * @return the result of logically or'ing this mask with an input mask */ public abstract VectorMask<E> or(VectorMask<E> o); /** * Logically negates this mask. * <p> ! * This is a mask unary operation where the logical not operation ! * ({@code !} is applied to lane elements. * * @return the result of logically negating this mask. */ public abstract VectorMask<E> not(); --- 277,310 ---- public abstract int trueCount(); /** * Logically ands this mask with an input mask. * <p> ! * This is a lane-wise binary operation which applies the logical and operation ! * ({@code &&}) to each lane. * * @param o the input mask * @return the result of logically and'ing this mask with an input mask */ public abstract VectorMask<E> and(VectorMask<E> o); /** * Logically ors this mask with an input mask. * <p> ! * This is a lane-wise binary operation which applies the logical or operation ! * ({@code ||}) to each lane. * * @param o the input mask * @return the result of logically or'ing this mask with an input mask */ public abstract VectorMask<E> or(VectorMask<E> o); /** * Logically negates this mask. * <p> ! * This is a lane-wise unary operation which applies the logical not operation ! * ({@code !}) to each lane. * * @return the result of logically negating this mask. */ public abstract VectorMask<E> not();
*** 311,327 **** * Tests if the lane at index {@code i} is set * @param i the lane index * * @return true if the lane at index {@code i} is set, otherwise false */ ! public abstract boolean getElement(int i); /** * Tests if the lane at index {@code i} is set * @param i the lane index * @return true if the lane at index {@code i} is set, otherwise false ! * @see #getElement */ public boolean isSet(int i) { ! return getElement(i); } } --- 325,341 ---- * Tests if the lane at index {@code i} is set * @param i the lane index * * @return true if the lane at index {@code i} is set, otherwise false */ ! public abstract boolean lane(int i); /** * Tests if the lane at index {@code i} is set * @param i the lane index * @return true if the lane at index {@code i} is set, otherwise false ! * @see #lane */ public boolean isSet(int i) { ! return lane(i); } }
< prev index next >