/* * Copyright (c) 2017, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have * questions. */ package jdk.incubator.vector; import jdk.internal.vm.annotation.ForceInline; import java.nio.ByteBuffer; import java.nio.ByteOrder; #if[!byte] import java.nio.$Type$Buffer; #end[!byte] import java.util.Objects; import java.util.concurrent.ThreadLocalRandom; /** * A specialized {@link Vector} representing an ordered immutable sequence of * {@code $type$} values. * * @param the type of shape of this vector */ @SuppressWarnings("cast") public abstract class $abstractvectortype$ extends Vector<$Boxtype$,S> { $abstractvectortype$() {} // Unary operator interface FUnOp { $type$ apply(int i, $type$ a); } abstract $abstractvectortype$ uOp(FUnOp f); abstract $abstractvectortype$ uOp(Mask<$Boxtype$, S> m, FUnOp f); // Binary operator interface FBinOp { $type$ apply(int i, $type$ a, $type$ b); } abstract $abstractvectortype$ bOp(Vector<$Boxtype$,S> v, FBinOp f); abstract $abstractvectortype$ bOp(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m, FBinOp f); // Trinary operator interface FTriOp { $type$ apply(int i, $type$ a, $type$ b, $type$ c); } abstract $abstractvectortype$ tOp(Vector<$Boxtype$,S> v1, Vector<$Boxtype$,S> v2, FTriOp f); abstract $abstractvectortype$ tOp(Vector<$Boxtype$,S> v1, Vector<$Boxtype$,S> v2, Mask<$Boxtype$, S> m, FTriOp f); // Reduction operator abstract $type$ rOp($type$ v, FBinOp f); // Binary test interface FBinTest { boolean apply(int i, $type$ a, $type$ b); } abstract Mask<$Boxtype$, S> bTest(Vector<$Boxtype$,S> v, FBinTest f); // Foreach interface FUnCon { void apply(int i, $type$ a); } abstract void forEach(FUnCon f); abstract void forEach(Mask<$Boxtype$, S> m, FUnCon f); // @Override public abstract $abstractvectortype$ add(Vector<$Boxtype$,S> v); /** * Adds this vector to the broadcast of an input scalar. *

* This is a vector binary operation where the primitive addition operation * ({@code +}) is applied to lane elements. * * @param s the input scalar * @return the result of adding this vector to the broadcast of an input * scalar */ public abstract $abstractvectortype$ add($type$ s); @Override public abstract $abstractvectortype$ add(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Adds this vector to broadcast of an input scalar, * selecting lane elements controlled by a mask. *

* This is a vector binary operation where the primitive addition operation * ({@code +}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the result of adding this vector to the broadcast of an input * scalar */ public abstract $abstractvectortype$ add($type$ s, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ sub(Vector<$Boxtype$,S> v); /** * Subtracts the broadcast of an input scalar from this vector. *

* This is a vector binary operation where the primitive subtraction * operation ({@code -}) is applied to lane elements. * * @param s the input scalar * @return the result of subtracting the broadcast of an input * scalar from this vector */ public abstract $abstractvectortype$ sub($type$ s); @Override public abstract $abstractvectortype$ sub(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Subtracts the broadcast of an input scalar from this vector, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the primitive subtraction * operation ({@code -}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the result of subtracting the broadcast of an input * scalar from this vector */ public abstract $abstractvectortype$ sub($type$ s, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ mul(Vector<$Boxtype$,S> v); /** * Multiplies this vector with the broadcast of an input scalar. *

* This is a vector binary operation where the primitive multiplication * operation ({@code *}) is applied to lane elements. * * @param s the input scalar * @return the result of multiplying this vector with the broadcast of an * input scalar */ public abstract $abstractvectortype$ mul($type$ s); @Override public abstract $abstractvectortype$ mul(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Multiplies this vector with the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the primitive multiplication * operation ({@code *}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the result of multiplying this vector with the broadcast of an * input scalar */ public abstract $abstractvectortype$ mul($type$ s, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ neg(); @Override public abstract $abstractvectortype$ neg(Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ abs(); @Override public abstract $abstractvectortype$ abs(Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ min(Vector<$Boxtype$,S> v); /** * Returns the minimum of this vector and the broadcast of an input scalar. *

* This is a vector binary operation where the operation * {@code (a, b) -> a < b ? a : b} is applied to lane elements. * * @param s the input scalar * @return the minimum of this vector and the broadcast of an input scalar */ public abstract $abstractvectortype$ min($type$ s); @Override public abstract $abstractvectortype$ max(Vector<$Boxtype$,S> v); /** * Returns the maximum of this vector and the broadcast of an input scalar. *

* This is a vector binary operation where the operation * {@code (a, b) -> a > b ? a : b} is applied to lane elements. * * @param s the input scalar * @return the maximum of this vector and the broadcast of an input scalar */ public abstract $abstractvectortype$ max($type$ s); @Override public abstract Mask<$Boxtype$, S> equal(Vector<$Boxtype$,S> v); /** * Tests if this vector is equal to the broadcast of an input scalar. *

* This is a vector binary test operation where the primitive equals * operation ({@code ==}) is applied to lane elements. * * @param s the input scalar * @return the result mask of testing if this vector is equal to the * broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> equal($type$ s); @Override public abstract Mask<$Boxtype$, S> notEqual(Vector<$Boxtype$,S> v); /** * Tests if this vector is not equal to the broadcast of an input scalar. *

* This is a vector binary test operation where the primitive not equals * operation ({@code !=}) is applied to lane elements. * * @param s the input scalar * @return the result mask of testing if this vector is not equal to the * broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> notEqual($type$ s); @Override public abstract Mask<$Boxtype$, S> lessThan(Vector<$Boxtype$,S> v); /** * Tests if this vector is less than the broadcast of an input scalar. *

* This is a vector binary test operation where the primitive less than * operation ({@code <}) is applied to lane elements. * * @param s the input scalar * @return the mask result of testing if this vector is less than the * broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> lessThan($type$ s); @Override public abstract Mask<$Boxtype$, S> lessThanEq(Vector<$Boxtype$,S> v); /** * Tests if this vector is less or equal to the broadcast of an input scalar. *

* This is a vector binary test operation where the primitive less than * or equal to operation ({@code <=}) is applied to lane elements. * * @param s the input scalar * @return the mask result of testing if this vector is less than or equal * to the broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> lessThanEq($type$ s); @Override public abstract Mask<$Boxtype$, S> greaterThan(Vector<$Boxtype$,S> v); /** * Tests if this vector is greater than the broadcast of an input scalar. *

* This is a vector binary test operation where the primitive greater than * operation ({@code >}) is applied to lane elements. * * @param s the input scalar * @return the mask result of testing if this vector is greater than the * broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> greaterThan($type$ s); @Override public abstract Mask<$Boxtype$, S> greaterThanEq(Vector<$Boxtype$,S> v); /** * Tests if this vector is greater than or equal to the broadcast of an * input scalar. *

* This is a vector binary test operation where the primitive greater than * or equal to operation ({@code >=}) is applied to lane elements. * * @param s the input scalar * @return the mask result of testing if this vector is greater than or * equal to the broadcast of an input scalar */ public abstract Mask<$Boxtype$, S> greaterThanEq($type$ s); @Override public abstract $abstractvectortype$ blend(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Blends the lane elements of this vector with those of the broadcast of an * input scalar, selecting lanes controlled by a mask. *

* For each lane of the mask, at lane index {@code N}, if the mask lane * is set then the lane element at {@code N} from the input vector is * selected and placed into the resulting vector at {@code N}, * otherwise the the lane element at {@code N} from this input vector is * selected and placed into the resulting vector at {@code N}. * * @param s the input scalar * @param m the mask controlling lane selection * @return the result of blending the lane elements of this vector with * those of the broadcast of an input scalar */ public abstract $abstractvectortype$ blend($type$ s, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ rearrange(Vector<$Boxtype$, S> v, Shuffle<$Boxtype$, S> s, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ rearrange(Shuffle<$Boxtype$, S> m); @Override @ForceInline public $abstractvectortype$ resize(Species<$Boxtype$, T> species) { return ($abstractvectortype$) species.resize(this); } @Override public abstract $abstractvectortype$ rotateEL(int i); @Override public abstract $abstractvectortype$ rotateER(int i); @Override public abstract $abstractvectortype$ shiftEL(int i); @Override public abstract $abstractvectortype$ shiftER(int i); #if[FP] /** * Divides this vector by an input vector. *

* This is a vector binary operation where the primitive division * operation ({@code /}) is applied to lane elements. * * @param v the input vector * @return the result of dividing this vector by the input vector */ public abstract $abstractvectortype$ div(Vector<$Boxtype$,S> v); /** * Divides this vector by the broadcast of an input scalar. *

* This is a vector binary operation where the primitive division * operation ({@code /}) is applied to lane elements. * * @param v the input scalar * @return the result of dividing this vector by the broadcast of an input * scalar */ public abstract $abstractvectortype$ div($type$ s); /** * Divides this vector by an input vector, selecting lane elements * controlled by a mask. *

* This is a vector binary operation where the primitive division * operation ({@code /}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the result of dividing this vector by the input vector */ public abstract $abstractvectortype$ div(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Divides this vector by the broadcast of an input scalar, selecting lane * elements controlled by a mask. *

* This is a vector binary operation where the primitive division * operation ({@code /}) is applied to lane elements. * * @param v the input scalar * @param m the mask controlling lane selection * @return the result of dividing this vector by the broadcast of an input * scalar */ public abstract $abstractvectortype$ div($type$ s, Mask<$Boxtype$, S> m); // @@@ Many methods are refer to Math or StrictMath functions that only accept // double values, what should be the behaviour for lane elements of float // vectors? down and then upcast? Or will some numeric algorithms differ? // The answers might also depend if strict definitions are required // to ensure portability. // Leveraging the existing defintions in Math/StrictMath is very convenient // but its unclear if it is t /** * Calculates the square root of this vector. *

* This is a vector unary operation where the {@link Math#sqrt} operation * is applied to lane elements. * * @return the square root of this vector */ public abstract $abstractvectortype$ sqrt(); /** * Calculates the square root of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#sqrt} operation * ({@code -}) is applied to lane elements. * * @param m the mask controlling lane selection * @return the square root of this vector */ public $abstractvectortype$ sqrt(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.sqrt((double) a)); } /** * Calculates the trigonometric tangent of this vector. *

* This is a vector unary operation where the {@link Math#tan} operation * is applied to lane elements. * * @return the tangent of this vector */ public $abstractvectortype$ tan() { return uOp((i, a) -> ($type$) Math.tan((double) a)); } /** * Calculates the trigonometric tangent of this vector, selecting lane * elements controlled by a mask. *

* This is a vector unary operation where the {@link Math#tan} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the tangent of this vector */ public $abstractvectortype$ tan(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.tan((double) a)); } /** * Calculates the hyperbolic tangent of this vector. *

* This is a vector unary operation where the {@link Math#tanh} operation * is applied to lane elements. * * @return the hyperbolic tangent of this vector */ public $abstractvectortype$ tanh() { return uOp((i, a) -> ($type$) Math.tanh((double) a)); } /** * Calculates the hyperbolic tangent of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#tanh} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the hyperbolic tangent of this vector */ public $abstractvectortype$ tanh(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.tanh((double) a)); } /** * Calculates the trigonometric sine of this vector. *

* This is a vector unary operation where the {@link Math#sin} operation * is applied to lane elements. * * @return the sine of this vector */ public $abstractvectortype$ sin() { return uOp((i, a) -> ($type$) Math.sin((double) a)); } /** * Calculates the trigonometric sine of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#sin} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the sine of this vector */ public $abstractvectortype$ sin(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.sin((double) a)); } /** * Calculates the hyperbolic sine of this vector. *

* This is a vector unary operation where the {@link Math#sinh} operation * is applied to lane elements. * * @return the hyperbolic sine of this vector */ public $abstractvectortype$ sinh() { return uOp((i, a) -> ($type$) Math.sinh((double) a)); } /** * Calculates the hyperbolic sine of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#sinh} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the hyperbolic sine of this vector */ public $abstractvectortype$ sinh(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.sinh((double) a)); } /** * Calculates the trigonometric cosine of this vector. *

* This is a vector unary operation where the {@link Math#cos} operation * is applied to lane elements. * * @return the cosine of this vector */ public $abstractvectortype$ cos() { return uOp((i, a) -> ($type$) Math.cos((double) a)); } /** * Calculates the trigonometric cosine of this vector, selecting lane * elements controlled by a mask. *

* This is a vector unary operation where the {@link Math#cos} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the cosine of this vector */ public $abstractvectortype$ cos(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.cos((double) a)); } /** * Calculates the hyperbolic cosine of this vector. *

* This is a vector unary operation where the {@link Math#cosh} operation * is applied to lane elements. * * @return the hyperbolic cosine of this vector */ public $abstractvectortype$ cosh() { return uOp((i, a) -> ($type$) Math.cosh((double) a)); } /** * Calculates the hyperbolic cosine of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#cosh} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the hyperbolic cosine of this vector */ public $abstractvectortype$ cosh(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.cosh((double) a)); } /** * Calculates the arc sine of this vector. *

* This is a vector unary operation where the {@link Math#asin} operation * is applied to lane elements. * * @return the arc sine of this vector */ public $abstractvectortype$ asin() { return uOp((i, a) -> ($type$) Math.asin((double) a)); } /** * Calculates the arc sine of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#asin} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the arc sine of this vector */ public $abstractvectortype$ asin(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.asin((double) a)); } /** * Calculates the arc cosine of this vector. *

* This is a vector unary operation where the {@link Math#acos} operation * is applied to lane elements. * * @return the arc cosine of this vector */ public $abstractvectortype$ acos() { return uOp((i, a) -> ($type$) Math.acos((double) a)); } /** * Calculates the arc cosine of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#acos} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the arc cosine of this vector */ public $abstractvectortype$ acos(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.acos((double) a)); } /** * Calculates the arc tangent of this vector. *

* This is a vector unary operation where the {@link Math#atan} operation * is applied to lane elements. * * @return the arc tangent of this vector */ public $abstractvectortype$ atan() { return uOp((i, a) -> ($type$) Math.atan((double) a)); } /** * Calculates the arc tangent of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#atan} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the arc tangent of this vector */ public $abstractvectortype$ atan(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.atan((double) a)); } /** * Calculates the arc tangent of this vector divided by an input vector. *

* This is a vector binary operation where the {@link Math#atan2} operation * is applied to lane elements. * * @param v the input vector * @return the arc tangent of this vector divided by the input vector */ public $abstractvectortype$ atan2(Vector<$Boxtype$,S> v) { return bOp(v, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b)); } /** * Calculates the arc tangent of this vector divided by the broadcast of an * an input scalar. *

* This is a vector binary operation where the {@link Math#atan2} operation * is applied to lane elements. * * @param s the input scalar * @return the arc tangent of this vector over the input vector */ public abstract $abstractvectortype$ atan2($type$ s); /** * Calculates the arc tangent of this vector divided by an input vector, * selecting lane elements controlled by a mask. *

* This is a vector binary operation where the {@link Math#atan2} operation * is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the arc tangent of this vector divided by the input vector */ public $abstractvectortype$ atan2(Vector<$Boxtype$,S> v, Mask<$Boxtype$,S> m) { return bOp(v, m, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b)); } /** * Calculates the arc tangent of this vector divided by the broadcast of an * an input scalar, selecting lane elements controlled by a mask. *

* This is a vector binary operation where the {@link Math#atan2} operation * is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the arc tangent of this vector over the input vector */ public abstract $abstractvectortype$ atan2($type$ s, Mask<$Boxtype$,S> m); /** * Calculates the cube root of this vector. *

* This is a vector unary operation where the {@link Math#cbrt} operation * is applied to lane elements. * * @return the cube root of this vector */ public $abstractvectortype$ cbrt() { return uOp((i, a) -> ($type$) Math.cbrt((double) a)); } /** * Calculates the cube root of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#cbrt} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the cube root of this vector */ public $abstractvectortype$ cbrt(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.cbrt((double) a)); } /** * Calculates the natural logarithm of this vector. *

* This is a vector unary operation where the {@link Math#log} operation * is applied to lane elements. * * @return the natural logarithm of this vector */ public $abstractvectortype$ log() { return uOp((i, a) -> ($type$) Math.log((double) a)); } /** * Calculates the natural logarithm of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#log} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the natural logarithm of this vector */ public $abstractvectortype$ log(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.log((double) a)); } /** * Calculates the base 10 logarithm of this vector. *

* This is a vector unary operation where the {@link Math#log10} operation * is applied to lane elements. * * @return the base 10 logarithm of this vector */ public $abstractvectortype$ log10() { return uOp((i, a) -> ($type$) Math.log10((double) a)); } /** * Calculates the base 10 logarithm of this vector, selecting lane elements * controlled by a mask. *

* This is a vector unary operation where the {@link Math#log10} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the base 10 logarithm of this vector */ public $abstractvectortype$ log10(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.log10((double) a)); } /** * Calculates the natural logarithm of the sum of this vector and the * broadcast of {@code 1}. *

* This is a vector unary operation where the {@link Math#log1p} operation * is applied to lane elements. * * @return the natural logarithm of the sum of this vector and the broadcast * of {@code 1} */ public $abstractvectortype$ log1p() { return uOp((i, a) -> ($type$) Math.log1p((double) a)); } /** * Calculates the natural logarithm of the sum of this vector and the * broadcast of {@code 1}, selecting lane elements controlled by a mask. *

* This is a vector unary operation where the {@link Math#log1p} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the natural logarithm of the sum of this vector and the broadcast * of {@code 1} */ public $abstractvectortype$ log1p(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.log1p((double) a)); } /** * Calculates this vector raised to the power of an input vector. *

* This is a vector binary operation where the {@link Math#pow} operation * is applied to lane elements. * * @param v the input vector * @return this vector raised to the power of an input vector */ public $abstractvectortype$ pow(Vector<$Boxtype$,S> v) { return bOp(v, (i, a, b) -> ($type$) Math.pow((double) a, (double) b)); } /** * Calculates this vector raised to the power of the broadcast of an input * scalar. *

* This is a vector binary operation where the {@link Math#pow} operation * is applied to lane elements. * * @param s the input scalar * @return this vector raised to the power of the broadcast of an input * scalar. */ public abstract $abstractvectortype$ pow($type$ s); /** * Calculates this vector raised to the power of an input vector, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the {@link Math#pow} operation * is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return this vector raised to the power of an input vector */ public $abstractvectortype$ pow(Vector<$Boxtype$,S> v, Mask<$Boxtype$,S> m) { return bOp(v, m, (i, a, b) -> ($type$) Math.pow((double) a, (double) b)); } /** * Calculates this vector raised to the power of the broadcast of an input * scalar, selecting lane elements controlled by a mask. *

* This is a vector binary operation where the {@link Math#pow} operation * is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return this vector raised to the power of the broadcast of an input * scalar. */ public abstract $abstractvectortype$ pow($type$ s, Mask<$Boxtype$,S> m); /** * Calculates the broadcast of Euler's number {@code e} raised to the power * of this vector. *

* This is a vector unary operation where the {@link Math#exp} operation * is applied to lane elements. * * @return the broadcast of Euler's number {@code e} raised to the power of * this vector */ public $abstractvectortype$ exp() { return uOp((i, a) -> ($type$) Math.exp((double) a)); } /** * Calculates the broadcast of Euler's number {@code e} raised to the power * of this vector, selecting lane elements controlled by a mask. *

* This is a vector unary operation where the {@link Math#exp} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the broadcast of Euler's number {@code e} raised to the power of * this vector */ public $abstractvectortype$ exp(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.exp((double) a)); } /** * Calculates the broadcast of Euler's number {@code e} raised to the power * of this vector minus the broadcast of {@code -1}. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.exp().sub(this.species().broadcast(1))
     * }
*

* This is a vector unary operation where the {@link Math#expm1} operation * is applied to lane elements. * * @return the broadcast of Euler's number {@code e} raised to the power of * this vector minus the broadcast of {@code -1} */ public $abstractvectortype$ expm1() { return uOp((i, a) -> ($type$) Math.expm1((double) a)); } /** * Calculates the broadcast of Euler's number {@code e} raised to the power * of this vector minus the broadcast of {@code -1}, selecting lane elements * controlled by a mask * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.exp(m).sub(this.species().broadcast(1), m)
     * }
*

* This is a vector unary operation where the {@link Math#expm1} operation * is applied to lane elements. * * @param m the mask controlling lane selection * @return the broadcast of Euler's number {@code e} raised to the power of * this vector minus the broadcast of {@code -1} */ public $abstractvectortype$ expm1(Mask<$Boxtype$,S> m) { return uOp(m, (i, a) -> ($type$) Math.expm1((double) a)); } /** * Calculates the product of this vector and a first input vector summed * with a second input vector. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(v1).add(v2)
     * }
*

* This is a vector ternary operation where the {@link Math#fma} operation * is applied to lane elements. * * @param v1 the first input vector * @param v2 the second input vector * @return the product of this vector and the first input vector summed with * the second input vector */ public abstract $abstractvectortype$ fma(Vector<$Boxtype$,S> v1, Vector<$Boxtype$,S> v2); /** * Calculates the product of this vector and the broadcast of a first input * scalar summed with the broadcast of a second input scalar. * More specifically as if the following: *

{@code
     *   this.fma(this.species().broadcast(s1), this.species().broadcast(s2))
     * }
*

* This is a vector ternary operation where the {@link Math#fma} operation * is applied to lane elements. * * @param s1 the first input scalar * @param s2 the second input scalar * @return the product of this vector and the broadcast of a first input * scalar summed with the broadcast of a second input scalar */ public abstract $abstractvectortype$ fma($type$ s1, $type$ s2); /** * Calculates the product of this vector and a first input vector summed * with a second input vector, selecting lane elements controlled by a mask. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(v1, m).add(v2, m)
     * }
*

* This is a vector ternary operation where the {@link Math#fma} operation * is applied to lane elements. * * @param v1 the first input vector * @param v2 the second input vector * @param m the mask controlling lane selection * @return the product of this vector and the first input vector summed with * the second input vector */ public $abstractvectortype$ fma(Vector<$Boxtype$,S> v1, Vector<$Boxtype$,S> v2, Mask<$Boxtype$,S> m) { return tOp(v1, v2, m, (i, a, b, c) -> Math.fma(a, b, c)); } /** * Calculates the product of this vector and the broadcast of a first input * scalar summed with the broadcast of a second input scalar, selecting lane * elements controlled by a mask * More specifically as if the following: *

{@code
     *   this.fma(this.species().broadcast(s1), this.species().broadcast(s2), m)
     * }
*

* This is a vector ternary operation where the {@link Math#fma} operation * is applied to lane elements. * * @param s1 the first input scalar * @param s2 the second input scalar * @param m the mask controlling lane selection * @return the product of this vector and the broadcast of a first input * scalar summed with the broadcast of a second input scalar */ public abstract $abstractvectortype$ fma($type$ s1, $type$ s2, Mask<$Boxtype$,S> m); // Computes the square root of the sum of the squares of x and y /** * Calculates square root of the sum of the squares of this vector and an * input vector. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(this).add(v.mul(v)).sqrt()
     * }
*

* This is a vector binary operation where the {@link Math#hypot} operation * is applied to lane elements. * * @param v the input vector * @return square root of the sum of the squares of this vector and an input * vector */ public $abstractvectortype$ hypot(Vector<$Boxtype$,S> v) { return bOp(v, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b)); } /** * Calculates square root of the sum of the squares of this vector and the * broadcast of an input scalar. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(this).add(this.species().broadcast(v * v)).sqrt()
     * }
*

* This is a vector binary operation where the {@link Math#hypot} operation * is applied to lane elements. * * @param s the input scalar * @return square root of the sum of the squares of this vector and the * broadcast of an input scalar */ public abstract $abstractvectortype$ hypot($type$ s); /** * Calculates square root of the sum of the squares of this vector and an * input vector, selecting lane elements controlled by a mask. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(this, m).add(v.mul(v), m).sqrt(m)
     * }
*

* This is a vector binary operation where the {@link Math#hypot} operation * is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return square root of the sum of the squares of this vector and an input * vector */ public $abstractvectortype$ hypot(Vector<$Boxtype$,S> v, Mask<$Boxtype$,S> m) { return bOp(v, m, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b)); } /** * Calculates square root of the sum of the squares of this vector and the * broadcast of an input scalar, selecting lane elements controlled by a * mask. * More specifically as if the following (ignoring any differences in * numerical accuracy): *

{@code
     *   this.mul(this, m).add(this.species().broadcast(v * v), m).sqrt(m)
     * }
*

* This is a vector binary operation where the {@link Math#hypot} operation * is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return square root of the sum of the squares of this vector and the * broadcast of an input scalar */ public abstract $abstractvectortype$ hypot($type$ s, Mask<$Boxtype$,S> m); #end[FP] #if[BITWISE] /** * Bitwise ANDs this vector with an input vector. *

* This is a vector binary operation where the primitive bitwise AND * operation ({@code &}) is applied to lane elements. * * @param v the input vector * @return the bitwise AND of this vector with the input vector */ public abstract $abstractvectortype$ and(Vector<$Boxtype$,S> v); /** * Bitwise ANDs this vector with the broadcast of an input scalar. *

* This is a vector binary operation where the primitive bitwise AND * operation ({@code &}) is applied to lane elements. * * @param s the input scalar * @return the bitwise AND of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ and($type$ s); /** * Bitwise ANDs this vector with an input vector, selecting lane elements * controlled by a mask. *

* This is a vector binary operation where the primitive bitwise AND * operation ({@code &}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the bitwise AND of this vector with the input vector */ public abstract $abstractvectortype$ and(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Bitwise ANDs this vector with the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the primitive bitwise AND * operation ({@code &}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the bitwise AND of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ and($type$ s, Mask<$Boxtype$, S> m); /** * Bitwise ORs this vector with an input vector. *

* This is a vector binary operation where the primitive bitwise OR * operation ({@code |}) is applied to lane elements. * * @param v the input vector * @return the bitwise OR of this vector with the input vector */ public abstract $abstractvectortype$ or(Vector<$Boxtype$,S> v); /** * Bitwise ORs this vector with the broadcast of an input scalar. *

* This is a vector binary operation where the primitive bitwise OR * operation ({@code |}) is applied to lane elements. * * @param s the input scalar * @return the bitwise OR of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ or($type$ s); /** * Bitwise ORs this vector with an input vector, selecting lane elements * controlled by a mask. *

* This is a vector binary operation where the primitive bitwise OR * operation ({@code |}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the bitwise OR of this vector with the input vector */ public abstract $abstractvectortype$ or(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Bitwise ORs this vector with the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the primitive bitwise OR * operation ({@code |}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the bitwise OR of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ or($type$ s, Mask<$Boxtype$, S> m); /** * Bitwise XORs this vector with an input vector. *

* This is a vector binary operation where the primitive bitwise XOR * operation ({@code ^}) is applied to lane elements. * * @param v the input vector * @return the bitwise XOR of this vector with the input vector */ public abstract $abstractvectortype$ xor(Vector<$Boxtype$,S> v); /** * Bitwise XORs this vector with the broadcast of an input scalar. *

* This is a vector binary operation where the primitive bitwise XOR * operation ({@code ^}) is applied to lane elements. * * @param s the input scalar * @return the bitwise XOR of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ xor($type$ s); /** * Bitwise XORs this vector with an input vector, selecting lane elements * controlled by a mask. *

* This is a vector binary operation where the primitive bitwise XOR * operation ({@code ^}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the bitwise XOR of this vector with the input vector */ public abstract $abstractvectortype$ xor(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m); /** * Bitwise XORs this vector with the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the primitive bitwise XOR * operation ({@code ^}) is applied to lane elements. * * @param s the input scalar * @param m the mask controlling lane selection * @return the bitwise XOR of this vector with the broadcast of an input * scalar */ public abstract $abstractvectortype$ xor($type$ s, Mask<$Boxtype$, S> m); /** * Bitwise NOTs this vector. *

* This is a vector unary operation where the primitive bitwise NOT * operation ({@code ~}) is applied to lane elements. * * @return the bitwise NOT of this vector */ public abstract $abstractvectortype$ not(); /** * Bitwise NOTs this vector, selecting lane elements controlled by a mask. *

* This is a vector unary operation where the primitive bitwise NOT * operation ({@code ~}) is applied to lane elements. * * @param m the mask controlling lane selection * @return the bitwise NOT of this vector */ public abstract $abstractvectortype$ not(Mask<$Boxtype$, S> m); /* @@@ Check the shift operations against the JLS definition and vector instructions. For int values the low 5 bits of s are used. For long values the low 6 bits of s are used. */ #if[intOrLong] /** * Logically left shifts this vector by the broadcast of an input scalar. *

* This is a vector binary operation where the primitive logical left shift * operation ({@code <<}) is applied to lane elements. * * @param s the input scalar; the number of the bits to left shift * @return the result of logically left shifting left this vector by the * broadcast of an input scalar */ public abstract $abstractvectortype$ shiftL(int s); /** * Logically left shifts this vector by the broadcast of an input scalar, * selecting lane elements controlled by a mask. *

* This is a vector binary operation where the primitive logical left shift * operation ({@code <<}) is applied to lane elements. * * @param s the input scalar; the number of the bits to left shift * @param m the mask controlling lane selection * @return the result of logically left shifting this vector by the * broadcast of an input scalar */ public $abstractvectortype$ shiftL(int s, Mask<$Boxtype$, S> m) { return uOp(m, (i, a) -> ($type$) (a << s)); } /** * Logically left shifts this vector by an input vector. *

* This is a vector binary operation where the primitive logical left shift * operation ({@code <<}) is applied to lane elements. * * @param v the input vector * @return the result of logically left shifting this vector by the input * vector */ public abstract $abstractvectortype$ shiftL(Vector<$Boxtype$,S> v); /** * Logically left shifts this vector by an input vector, selecting lane * elements controlled by a mask. *

* This is a vector binary operation where the primitive logical left shift * operation ({@code <<}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the result of logically left shifting this vector by the input * vector */ public $abstractvectortype$ shiftL(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m) { return bOp(v, m, (i, a, b) -> ($type$) (a << b)); } // logical, or unsigned, shift right /** * Logically right shifts (or unsigned right shifts) this vector by the * broadcast of an input scalar. *

* This is a vector binary operation where the primitive logical right shift * operation ({@code >>>}) is applied to lane elements. * * @param s the input scalar; the number of the bits to right shift * @return the result of logically right shifting this vector by the * broadcast of an input scalar */ public abstract $abstractvectortype$ shiftR(int s); /** * Logically right shifts (or unsigned right shifts) this vector by the * broadcast of an input scalar, selecting lane elements controlled by a * mask. *

* This is a vector binary operation where the primitive logical right shift * operation ({@code >>>}) is applied to lane elements. * * @param s the input scalar; the number of the bits to right shift * @return the result of logically right shifting this vector by the * broadcast of an input scalar */ public $abstractvectortype$ shiftR(int s, Mask<$Boxtype$, S> m) { return uOp(m, (i, a) -> ($type$) (a >>> s)); } /** * Logically right shifts (or unsigned right shifts) this vector by an * input vector. *

* This is a vector binary operation where the primitive logical right shift * operation ({@code >>>}) is applied to lane elements. * * @param v the input vector * @return the result of logically right shifting this vector by the * input vector */ public abstract $abstractvectortype$ shiftR(Vector<$Boxtype$,S> v); /** * Logically right shifts (or unsigned right shifts) this vector by an * input vector, selecting lane elements controlled by a mask. *

* This is a vector binary operation where the primitive logical right shift * operation ({@code >>>}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the result of logically right shifting this vector by the * input vector */ public $abstractvectortype$ shiftR(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m) { return bOp(v, m, (i, a, b) -> ($type$) (a >>> b)); } /** * Arithmetically right shifts (or signed right shifts) this vector by the * broadcast of an input scalar. *

* This is a vector binary operation where the primitive arithmetic right * shift operation ({@code >>}) is applied to lane elements. * * @param s the input scalar; the number of the bits to right shift * @return the result of arithmetically right shifting this vector by the * broadcast of an input scalar */ public abstract $abstractvectortype$ aShiftR(int s); /** * Arithmetically right shifts (or signed right shifts) this vector by the * broadcast of an input scalar, selecting lane elements controlled by a * mask. *

* This is a vector binary operation where the primitive arithmetic right * shift operation ({@code >>}) is applied to lane elements. * * @param s the input scalar; the number of the bits to right shift * @param m the mask controlling lane selection * @return the result of arithmetically right shifting this vector by the * broadcast of an input scalar */ public $abstractvectortype$ aShiftR(int s, Mask<$Boxtype$, S> m) { return uOp(m, (i, a) -> ($type$) (a >> s)); } /** * Arithmetically right shifts (or signed right shifts) this vector by an * input vector. *

* This is a vector binary operation where the primitive arithmetic right * shift operation ({@code >>}) is applied to lane elements. * * @param v the input vector * @return the result of arithmetically right shifting this vector by the * input vector */ public abstract $abstractvectortype$ aShiftR(Vector<$Boxtype$,S> v); /** * Arithmetically right shifts (or signed right shifts) this vector by an * input vector, selecting lane elements controlled by a mask. *

* This is a vector binary operation where the primitive arithmetic right * shift operation ({@code >>}) is applied to lane elements. * * @param v the input vector * @param m the mask controlling lane selection * @return the result of arithmetically right shifting this vector by the * input vector */ public $abstractvectortype$ aShiftR(Vector<$Boxtype$,S> v, Mask<$Boxtype$, S> m) { return bOp(v, m, (i, a, b) -> ($type$) (a >> b)); } /** * Rotates left this vector by the broadcast of an input scalar. *

* This is a vector binary operation where the operation * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where * lane elements of this vector apply to the first argument, and lane * elements of the broadcast vector apply to the second argument (the * rotation distance). * * @param s the input scalar; the number of the bits to rotate left * @return the result of rotating left this vector by the broadcast of an * input scalar */ @ForceInline public final $abstractvectortype$ rotateL(int s) { return shiftL(s).or(shiftR(-s)); } /** * Rotates left this vector by the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the operation * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where * lane elements of this vector apply to the first argument, and lane * elements of the broadcast vector apply to the second argument (the * rotation distance). * * @param s the input scalar; the number of the bits to rotate left * @param m the mask controlling lane selection * @return the result of rotating left this vector by the broadcast of an * input scalar */ @ForceInline public final $abstractvectortype$ rotateL(int s, Mask<$Boxtype$, S> m) { return shiftL(s, m).or(shiftR(-s, m), m); } /** * Rotates right this vector by the broadcast of an input scalar. *

* This is a vector binary operation where the operation * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where * lane elements of this vector apply to the first argument, and lane * elements of the broadcast vector apply to the second argument (the * rotation distance). * * @param s the input scalar; the number of the bits to rotate right * @return the result of rotating right this vector by the broadcast of an * input scalar */ @ForceInline public final $abstractvectortype$ rotateR(int s) { return shiftR(s).or(shiftL(-s)); } /** * Rotates right this vector by the broadcast of an input scalar, selecting * lane elements controlled by a mask. *

* This is a vector binary operation where the operation * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where * lane elements of this vector apply to the first argument, and lane * elements of the broadcast vector apply to the second argument (the * rotation distance). * * @param s the input scalar; the number of the bits to rotate right * @param m the mask controlling lane selection * @return the result of rotating right this vector by the broadcast of an * input scalar */ @ForceInline public final $abstractvectortype$ rotateR(int s, Mask<$Boxtype$, S> m) { return shiftR(s, m).or(shiftL(-s, m), m); } #end[intOrLong] #end[BITWISE] @Override public abstract void intoByteArray(byte[] a, int ix); @Override public abstract void intoByteArray(byte[] a, int ix, Mask<$Boxtype$, S> m); @Override public abstract void intoByteBuffer(ByteBuffer bb, int ix); @Override public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$, S> m); // Type specific horizontal reductions // @@@ For floating point vectors order matters for reproducibility // with equivalent sequential reduction. Some order needs to be specified // by default. If that default is sequential encounter order then there // could be a "go faster" option that is unspecified, essentially giving // implementation flexibility at the expense of reproducibility and/or // accuracy. // @@@ Mask versions? /** * Adds all lane elements of this vector. *

* This is an associative vector reduction operation where the addition * operation ({@code +}) is applied to lane elements, * and the identity value is {@code 0}. * * @return the addition of all the lane elements of this vector */ public abstract $type$ addAll(); /** * Adds all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the addition * operation ({@code +}) is applied to lane elements, * and the identity value is {@code 0}. * * @param m the mask controlling lane selection * @return the addition of all the lane elements of this vector */ public abstract $type$ addAll(Mask<$Boxtype$, S> m); /** * Subtracts all lane elements of this vector. *

* This is an associative vector reduction operation where the subtraction * operation ({@code -}) is applied to lane elements, * and the identity value is {@code 0}. * * @return the subtraction of all the lane elements of this vector */ public abstract $type$ subAll(); /** * Subtracts all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the subtraction * operation ({@code -}) is applied to lane elements, * and the identity value is {@code 0}. * * @param m the mask controlling lane selection * @return the subtraction of all the lane elements of this vector */ public abstract $type$ subAll(Mask<$Boxtype$, S> m); /** * Multiplies all lane elements of this vector. *

* This is an associative vector reduction operation where the * multiplication operation ({@code *}) is applied to lane elements, * and the identity value is {@code 1}. * * @return the multiplication of all the lane elements of this vector */ public abstract $type$ mulAll(); /** * Multiplies all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the * multiplication operation ({@code *}) is applied to lane elements, * and the identity value is {@code 1}. * * @param m the mask controlling lane selection * @return the multiplication of all the lane elements of this vector */ public abstract $type$ mulAll(Mask<$Boxtype$, S> m); /** * Returns the minimum lane element of this vector. *

* This is an associative vector reduction operation where the operation * {@code (a, b) -> a > b ? b : a} is applied to lane elements, * and the identity value is {@link $Boxtype$.MAX_VALUE}. * * @return the minimum lane element of this vector */ public abstract $type$ minAll(); /** * Returns the minimum lane element of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the operation * {@code (a, b) -> a > b ? b : a} is applied to lane elements, * and the identity value is {@link $Boxtype$.MAX_VALUE}. * * @param m the mask controlling lane selection * @return the minimum lane element of this vector */ public abstract $type$ minAll(Mask<$Boxtype$, S> m); /** * Returns the maximum lane element of this vector. *

* This is an associative vector reduction operation where the operation * {@code (a, b) -> a < b ? b : a} is applied to lane elements, * and the identity value is {@link $Boxtype$.MIN_VALUE}. * * @return the maximum lane element of this vector */ public abstract $type$ maxAll(); /** * Returns the maximum lane element of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the operation * {@code (a, b) -> a < b ? b : a} is applied to lane elements, * and the identity value is {@link $Boxtype$.MIN_VALUE}. * * @param m the mask controlling lane selection * @return the maximum lane element of this vector */ public abstract $type$ maxAll(Mask<$Boxtype$, S> m); #if[BITWISE] /** * Logically ORs all lane elements of this vector. *

* This is an associative vector reduction operation where the logical OR * operation ({@code |}) is applied to lane elements, * and the identity value is {@code 0}. * * @return the logical OR all the lane elements of this vector */ public abstract $type$ orAll(); /** * Logically ORs all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the logical OR * operation ({@code |}) is applied to lane elements, * and the identity value is {@code 0}. * * @param m the mask controlling lane selection * @return the logical OR all the lane elements of this vector */ public abstract $type$ orAll(Mask<$Boxtype$, S> m); /** * Logically ANDs all lane elements of this vector. *

* This is an associative vector reduction operation where the logical AND * operation ({@code |}) is applied to lane elements, * and the identity value is {@code -1}. * * @return the logical AND all the lane elements of this vector */ public abstract $type$ andAll(); /** * Logically ANDs all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the logical AND * operation ({@code |}) is applied to lane elements, * and the identity value is {@code -1}. * * @param m the mask controlling lane selection * @return the logical AND all the lane elements of this vector */ public abstract $type$ andAll(Mask<$Boxtype$, S> m); /** * Logically XORs all lane elements of this vector. *

* This is an associative vector reduction operation where the logical XOR * operation ({@code ^}) is applied to lane elements, * and the identity value is {@code 0}. * * @return the logical XOR all the lane elements of this vector */ public abstract $type$ xorAll(); /** * Logically XORs all lane elements of this vector, selecting lane elements * controlled by a mask. *

* This is an associative vector reduction operation where the logical XOR * operation ({@code ^}) is applied to lane elements, * and the identity value is {@code 0}. * * @param m the mask controlling lane selection * @return the logical XOR all the lane elements of this vector */ public abstract $type$ xorAll(Mask<$Boxtype$, S> m); #end[BITWISE] // Type specific accessors /** * Gets the lane element at lane index {@code i} * * @param i the lane index * @return the lane element at lane index {@code i} * @throws IllegalArgumentException if the index is is out of range * ({@code < 0 || >= length()}) */ public abstract $type$ get(int i); /** * Replaces the lane element of this vector at lane index {@code i} with * value {@code e}. *

* This is a cross-lane operation and behaves as if it returns the result * of blending this vector with an input vector that is the result of * broadcasting {@code e} and a mask that has only one lane set at lane * index {@code i}. * * @param i the lane index of the lane element to be replaced * @param e the value to be placed * @return the result of replacing the lane element of this vector at lane * index {@code i} with value {@code e}. * @throws IllegalArgumentException if the index is is out of range * ({@code < 0 || >= length()}) */ public abstract $abstractvectortype$ with(int i, $type$ e); // Type specific extractors /** * Returns an array containing the lane elements of this vector. *

* This method behaves as if it {@link #intoArray($type$[], int)} stores} * this vector into an allocated array and returns the array as follows: *

{@code
     *   $type$[] a = new $type$[this.length()];
     *   this.intoArray(a, 0);
     *   return a;
     * }
* * @return an array containing the the lane elements of this vector */ @ForceInline public final $type$[] toArray() { // @@@ could allocate without zeroing, see Unsafe.allocateUninitializedArray $type$[] a = new $type$[species().length()]; intoArray(a, 0); return a; } /** * Stores this vector into an array starting at offset. *

* For each vector lane, where {@code N} is the vector 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($type$[] a, int i); /** * Stores this vector into an array starting at offset and using a mask. *

* For each vector lane, where {@code N} is the vector lane index, * if the mask lane at index {@code N} is set then the lane element at * index {@code N} is stored into the array index {@code i + N}. * * @param a the array * @param i the offset into the array * @param m the mask * @throws IndexOutOfBoundsException if {@code i < 0}, or * for any vector lane index {@code N} where the mask at lane {@code N} * is set {@code i >= a.length - N} */ public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$, S> m); /** * Stores this vector into an array using indexes obtained from an index * map. *

* For each vector lane, where {@code N} is the vector lane index, the * lane element at index {@code N} is stored into the array at index * {@code i + indexMap[j + N]}. * * @param a the array * @param i the offset into the array, may be negative if relative * indexes in the index map compensate to produce a value within the * array bounds * @param indexMap the index map * @param j the offset into the index map * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ public void intoArray($type$[] a, int i, int[] indexMap, int j) { forEach((n, e) -> a[i + indexMap[j + n]] = e); } /** * Stores this vector into an array using indexes obtained from an index * map and using a mask. *

* For each vector lane, where {@code N} is the vector lane index, * if the mask lane at index {@code N} is set then the lane element at * index {@code N} is stored into the array at index * {@code i + indexMap[j + N]}. * * @param a the array * @param i the offset into the array, may be negative if relative * indexes in the index map compensate to produce a value within the * array bounds * @param m the mask * @param indexMap the index map * @param j the offset into the index map * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} where the mask at lane * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ public void intoArray($type$[] a, int i, Mask<$Boxtype$, S> m, int[] indexMap, int j) { forEach(m, (n, e) -> a[i + indexMap[j + n]] = e); } // Species @Override public abstract $Type$Species species(); /** * A specialized factory for creating {@link $Type$Vector} value of the same * shape, and a {@link Mask} and {@link Shuffle} values of the same shape * and {@code int} element type. * * @param the type of shape of this species */ public static abstract class $Type$Species extends Vector.Species<$Boxtype$, S> { interface FOp { $type$ apply(int i); } abstract $abstractvectortype$ op(FOp f); abstract $abstractvectortype$ op(Mask<$Boxtype$, S> m, FOp f); // Factories @Override public abstract $abstractvectortype$ zero(); /** * Returns a vector where all lane elements are set to the primitive * value {@code e}. * * @param e the value * @return a vector of vector where all lane elements are set to * the primitive value {@code e} */ public abstract $abstractvectortype$ broadcast($type$ e); /** * Returns a vector where the first lane element is set to the primtive * value {@code e}, all other lane elements are set to the default * value. * * @param e the value * @return a vector where the first lane element is set to the primitive * value {@code e} */ @ForceInline public final $abstractvectortype$ single($type$ e) { return zero().with(0, e); } /** * Returns a vector where each lane element is set to a randomly * generated primitive value. * @@@ what are the properties of the random number generator? * * @return a vector where each lane elements is set to a randomly * generated primitive value */ #if[intOrLong] public $abstractvectortype$ random() { ThreadLocalRandom r = ThreadLocalRandom.current(); return op(i -> r.next$Type$()); } #else[intOrLong] #if[FP] public $abstractvectortype$ random() { ThreadLocalRandom r = ThreadLocalRandom.current(); return op(i -> r.next$Type$()); } #else[FP] public $abstractvectortype$ random() { ThreadLocalRandom r = ThreadLocalRandom.current(); return op(i -> ($type$) r.nextInt()); } #end[FP] #end[intOrLong] /** * Returns a vector where each lane element is set to a given * primitive value. *

* For each vector lane, where {@code N} is the vector lane index, the * the primitive value at index {@code N} is placed into the resulting * vector at lane index {@code N}. * * @@@ What should happen if es.length < this.length() ? use the default * value or throw IndexOutOfBoundsException * * @param es the given primitive values * @return a vector where each lane element is set to a given primitive * value */ public abstract $abstractvectortype$ scalars($type$... es); /** * Loads a vector from an array starting at offset. *

* For each vector lane, where {@code N} is the vector lane index, the * array element at index {@code i + N} is placed into the * resulting vector at lane index {@code N}. * * @param a the array * @param i the offset into the array * @return the vector loaded from an array * @throws IndexOutOfBoundsException if {@code i < 0}, or * {@code i > a.length - this.length()} */ public abstract $abstractvectortype$ fromArray($type$[] a, int i); /** * Loads a vector from an array starting at offset and using a mask. *

* For each vector lane, where {@code N} is the vector lane index, * if the mask lane at index {@code N} is set then the array element at * index {@code i + N} is placed into the resulting vector at lane index * {@code N}, otherwise the default element value is placed into the * resulting vector at lane index {@code N}. * * @param a the array * @param i the offset into the array * @param m the mask * @return the vector loaded from an array * @throws IndexOutOfBoundsException if {@code i < 0}, or * for any vector lane index {@code N} where the mask at lane {@code N} * is set {@code i > a.length - N} */ public abstract $abstractvectortype$ fromArray($type$[] a, int i, Mask<$Boxtype$, S> m); /** * Loads a vector from an array using indexes obtained from an index * map. *

* For each vector lane, where {@code N} is the vector lane index, the * array element at index {@code i + indexMap[j + N]} is placed into the * resulting vector at lane index {@code N}. * * @param a the array * @param i the offset into the array, may be negative if relative * indexes in the index map compensate to produce a value within the * array bounds * @param indexMap the index map * @param j the offset into the index map * @return the vector loaded from an array * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} the result of * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} */ public $abstractvectortype$ fromArray($type$[] a, int i, int[] indexMap, int j) { return op(n -> a[i + indexMap[j + n]]); } /** * Loads a vector from an array using indexes obtained from an index * map and using a mask. *

* For each vector lane, where {@code N} is the vector lane index, * if the mask lane at index {@code N} is set then the array element at * index {@code i + indexMap[j + N]} is placed into the resulting vector * at lane index {@code N}. * * @param a the array * @param i the offset into the array, may be negative if relative * indexes in the index map compensate to produce a value within the * array bounds * @param indexMap the index map * @param j the offset into the index map * @return the vector loaded from an array * @throws IndexOutOfBoundsException if {@code j < 0}, or * {@code j > indexMap.length - this.length()}, * or for any vector lane index {@code N} where the mask at lane * {@code N} is set the result of {@code i + indexMap[j + N]} is * {@code < 0} or {@code >= a.length} */ public $abstractvectortype$ fromArray($type$[] a, int i, Mask<$Boxtype$, S> m, int[] indexMap, int j) { return op(m, n -> a[i + indexMap[j + n]]); } @Override public abstract $abstractvectortype$ fromByteArray(byte[] a, int ix); @Override public abstract $abstractvectortype$ fromByteArray(byte[] a, int ix, Mask<$Boxtype$, S> m); @Override public abstract $abstractvectortype$ fromByteBuffer(ByteBuffer bb, int ix); @Override public abstract $abstractvectortype$ fromByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$, S> m); @Override public $abstractvectortype$ reshape(Vector o) { int blen = Math.max(o.species().bitSize(), bitSize()) / Byte.SIZE; ByteBuffer bb = ByteBuffer.allocate(blen).order(ByteOrder.nativeOrder()); o.intoByteBuffer(bb, 0); return fromByteBuffer(bb, 0); } @Override public abstract $abstractvectortype$ rebracket(Vector o); @Override public abstract $abstractvectortype$ resize(Vector<$Boxtype$, T> o); @Override public abstract $abstractvectortype$ cast(Vector v); } /** * Finds the preferred species for an element type of {@code $type$}. *

* A preferred species is a species chosen by the platform that has a * shape of maximal bit size. A preferred species for different element * types will have the same shape, and therefore vectors, masks, and * shuffles created from such species will be shape compatible. * * @return the preferred species for an element type of {@code $type$} */ @SuppressWarnings("unchecked") public static $Type$Species preferredSpecies() { return ($Type$Species) Vector.preferredSpecies($type$.class); } /** * Finds a species for an element type of {@code $type$} and shape. * * @param s the shape * @param the type of shape * @return a species for an element type of {@code $type$} and shape * @throws IllegalArgumentException if no such species exists for the shape */ @SuppressWarnings("unchecked") public static $Type$Species species(S s) { Objects.requireNonNull(s); if (s == Shapes.S_64_BIT) { return ($Type$Species) $Type$64Vector.SPECIES; } else if (s == Shapes.S_128_BIT) { return ($Type$Species) $Type$128Vector.SPECIES; } else if (s == Shapes.S_256_BIT) { return ($Type$Species) $Type$256Vector.SPECIES; } else if (s == Shapes.S_512_BIT) { return ($Type$Species) $Type$512Vector.SPECIES; } else if (s == Shapes.S_Scalable_BIT) { return ($Type$Species) $Type$ScalableVector.SPECIES; } else { throw new IllegalArgumentException("Bad shape: " + s); } } }