1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have 23 * questions. 24 */ 25 package jdk.incubator.vector; 26 27 import java.nio.ByteBuffer; 28 #if[!byte] 29 import java.nio.$Type$Buffer; 30 #end[!byte] 31 import java.nio.ByteOrder; 32 import java.util.Objects; 33 import java.util.function.IntUnaryOperator; 34 import java.util.concurrent.ThreadLocalRandom; 35 36 import jdk.internal.misc.Unsafe; 37 import jdk.internal.vm.annotation.ForceInline; 38 import static jdk.incubator.vector.VectorIntrinsics.*; 39 40 41 /** 42 * A specialized {@link Vector} representing an ordered immutable sequence of 43 * {@code $type$} values. 44 */ 45 @SuppressWarnings("cast") 46 public abstract class $abstractvectortype$ extends Vector<$Boxtype$> { 47 48 $abstractvectortype$() {} 49 50 private static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_$TYPE$_INDEX_SCALE); 51 52 // Unary operator 53 54 interface FUnOp { 55 $type$ apply(int i, $type$ a); 56 } 57 58 abstract $abstractvectortype$ uOp(FUnOp f); 59 60 abstract $abstractvectortype$ uOp(Mask<$Boxtype$> m, FUnOp f); 61 62 // Binary operator 63 64 interface FBinOp { 65 $type$ apply(int i, $type$ a, $type$ b); 66 } 67 68 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, FBinOp f); 69 70 abstract $abstractvectortype$ bOp(Vector<$Boxtype$> v, Mask<$Boxtype$> m, FBinOp f); 71 72 // Trinary operator 73 74 interface FTriOp { 75 $type$ apply(int i, $type$ a, $type$ b, $type$ c); 76 } 77 78 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, FTriOp f); 79 80 abstract $abstractvectortype$ tOp(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, Mask<$Boxtype$> m, FTriOp f); 81 82 // Reduction operator 83 84 abstract $type$ rOp($type$ v, FBinOp f); 85 86 // Binary test 87 88 interface FBinTest { 89 boolean apply(int i, $type$ a, $type$ b); 90 } 91 92 abstract Mask<$Boxtype$> bTest(Vector<$Boxtype$> v, FBinTest f); 93 94 // Foreach 95 96 interface FUnCon { 97 void apply(int i, $type$ a); 98 } 99 100 abstract void forEach(FUnCon f); 101 102 abstract void forEach(Mask<$Boxtype$> m, FUnCon f); 103 104 // Static factories 105 106 /** 107 * Returns a vector where all lane elements are set to the default 108 * primitive value. 109 * 110 * @param species species of desired vector 111 * @return a zero vector of given species 112 */ 113 @ForceInline 114 @SuppressWarnings("unchecked") 115 public static $abstractvectortype$ zero($Type$Species species) { 116 return species.zero(); 117 } 118 119 /** 120 * Loads a vector from a byte array starting at an offset. 121 * <p> 122 * Bytes are composed into primitive lane elements according to the 123 * native byte order of the underlying platform 124 * <p> 125 * This method behaves as if it returns the result of calling the 126 * byte buffer, offset, and mask accepting 127 * {@link #fromByteBuffer($Type$Species, ByteBuffer, int, Mask) method} as follows: 128 * <pre>{@code 129 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, this.maskAllTrue()); 130 * }</pre> 131 * 132 * @param species species of desired vector 133 * @param a the byte array 134 * @param ix the offset into the array 135 * @return a vector loaded from a byte array 136 * @throws IndexOutOfBoundsException if {@code i < 0} or 137 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} 138 */ 139 @ForceInline 140 @SuppressWarnings("unchecked") 141 public static $abstractvectortype$ fromByteArray($Type$Species species, byte[] a, int ix) { 142 Objects.requireNonNull(a); 143 ix = VectorIntrinsics.checkIndex(ix, a.length, species.bitSize() / Byte.SIZE); 144 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), 145 a, ((long) ix) + Unsafe.ARRAY_BYTE_BASE_OFFSET, 146 a, ix, species, 147 (c, idx, s) -> { 148 ByteBuffer bbc = ByteBuffer.wrap(c, idx, a.length - idx).order(ByteOrder.nativeOrder()); 149 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();} 150 return (($Type$Species)s).op(i -> tb.get()); 151 }); 152 } 153 154 /** 155 * Loads a vector from a byte array starting at an offset and using a 156 * mask. 157 * <p> 158 * Bytes are composed into primitive lane elements according to the 159 * native byte order of the underlying platform. 160 * <p> 161 * This method behaves as if it returns the result of calling the 162 * byte buffer, offset, and mask accepting 163 * {@link #fromByteBuffer($Type$Species, ByteBuffer, int, Mask) method} as follows: 164 * <pre>{@code 165 * return this.fromByteBuffer(ByteBuffer.wrap(a), i, m); 166 * }</pre> 167 * 168 * @param species species of desired vector 169 * @param a the byte array 170 * @param ix the offset into the array 171 * @param m the mask 172 * @return a vector loaded from a byte array 173 * @throws IndexOutOfBoundsException if {@code i < 0} or 174 * {@code i > a.length - (this.length() * this.elementSize() / Byte.SIZE)} 175 * @throws IndexOutOfBoundsException if the offset is {@code < 0}, 176 * or {@code > a.length}, 177 * for any vector lane index {@code N} where the mask at lane {@code N} 178 * is set 179 * {@code i >= a.length - (N * this.elementSize() / Byte.SIZE)} 180 */ 181 @ForceInline 182 public static $abstractvectortype$ fromByteArray($Type$Species species, byte[] a, int ix, Mask<$Boxtype$> m) { 183 return zero(species).blend(fromByteArray(species, a, ix), m); 184 } 185 186 /** 187 * Loads a vector from an array starting at offset. 188 * <p> 189 * For each vector lane, where {@code N} is the vector lane index, the 190 * array element at index {@code i + N} is placed into the 191 * resulting vector at lane index {@code N}. 192 * 193 * @param species species of desired vector 194 * @param a the array 195 * @param i the offset into the array 196 * @return the vector loaded from an array 197 * @throws IndexOutOfBoundsException if {@code i < 0}, or 198 * {@code i > a.length - this.length()} 199 */ 200 @ForceInline 201 @SuppressWarnings("unchecked") 202 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i){ 203 Objects.requireNonNull(a); 204 i = VectorIntrinsics.checkIndex(i, a.length, species.length()); 205 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), 206 a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_$TYPE$_BASE_OFFSET, 207 a, i, species, 208 (c, idx, s) -> (($Type$Species)s).op(n -> c[idx + n])); 209 } 210 211 212 /** 213 * Loads a vector from an array starting at offset and using a mask. 214 * <p> 215 * For each vector lane, where {@code N} is the vector lane index, 216 * if the mask lane at index {@code N} is set then the array element at 217 * index {@code i + N} is placed into the resulting vector at lane index 218 * {@code N}, otherwise the default element value is placed into the 219 * resulting vector at lane index {@code N}. 220 * 221 * @param species species of desired vector 222 * @param a the array 223 * @param i the offset into the array 224 * @param m the mask 225 * @return the vector loaded from an array 226 * @throws IndexOutOfBoundsException if {@code i < 0}, or 227 * for any vector lane index {@code N} where the mask at lane {@code N} 228 * is set {@code i > a.length - N} 229 */ 230 @ForceInline 231 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> m) { 232 return zero(species).blend(fromArray(species, a, i), m); 233 } 234 235 /** 236 * Loads a vector from an array using indexes obtained from an index 237 * map. 238 * <p> 239 * For each vector lane, where {@code N} is the vector lane index, the 240 * array element at index {@code i + indexMap[j + N]} is placed into the 241 * resulting vector at lane index {@code N}. 242 * 243 * @param species species of desired vector 244 * @param a the array 245 * @param i the offset into the array, may be negative if relative 246 * indexes in the index map compensate to produce a value within the 247 * array bounds 248 * @param indexMap the index map 249 * @param j the offset into the index map 250 * @return the vector loaded from an array 251 * @throws IndexOutOfBoundsException if {@code j < 0}, or 252 * {@code j > indexMap.length - this.length()}, 253 * or for any vector lane index {@code N} the result of 254 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} 255 */ 256 #if[byteOrShort] 257 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, int[] indexMap, int j) { 258 return species.op(n -> a[i + indexMap[j + n]]); 259 } 260 #else[byteOrShort] 261 @ForceInline 262 @SuppressWarnings("unchecked") 263 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, int[] indexMap, int j) { 264 Objects.requireNonNull(a); 265 Objects.requireNonNull(indexMap); 266 267 #if[longOrDouble] 268 if (species.length() == 1) { 269 return $abstractvectortype$.fromArray(species, a, i + indexMap[j]); 270 } 271 #end[longOrDouble] 272 273 // Index vector: vix[0:n] = k -> i + indexMap[j + i] 274 IntVector vix = IntVector.fromArray(species.indexSpecies(), indexMap, j).add(i); 275 276 vix = VectorIntrinsics.checkIndex(vix, a.length); 277 278 return VectorIntrinsics.loadWithMap((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), 279 species.indexSpecies().vectorType(), a, Unsafe.ARRAY_$TYPE$_BASE_OFFSET, vix, 280 a, i, indexMap, j, species, 281 (c, idx, iMap, idy, s) -> (($Type$Species)s).op(n -> c[idx + iMap[idy+n]])); 282 } 283 284 #end[byteOrShort] 285 /** 286 * Loads a vector from an array using indexes obtained from an index 287 * map and using a mask. 288 * <p> 289 * For each vector lane, where {@code N} is the vector lane index, 290 * if the mask lane at index {@code N} is set then the array element at 291 * index {@code i + indexMap[j + N]} is placed into the resulting vector 292 * at lane index {@code N}. 293 * 294 * @param species species of desired vector 295 * @param a the array 296 * @param i the offset into the array, may be negative if relative 297 * indexes in the index map compensate to produce a value within the 298 * array bounds 299 * @param m the mask 300 * @param indexMap the index map 301 * @param j the offset into the index map 302 * @return the vector loaded from an array 303 * @throws IndexOutOfBoundsException if {@code j < 0}, or 304 * {@code j > indexMap.length - this.length()}, 305 * or for any vector lane index {@code N} where the mask at lane 306 * {@code N} is set the result of {@code i + indexMap[j + N]} is 307 * {@code < 0} or {@code >= a.length} 308 */ 309 #if[byteOrShort] 310 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) { 311 return species.op(m, n -> a[i + indexMap[j + n]]); 312 } 313 #else[byteOrShort] 314 @ForceInline 315 @SuppressWarnings("unchecked") 316 public static $abstractvectortype$ fromArray($Type$Species species, $type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) { 317 // @@@ This can result in out of bounds errors for unset mask lanes 318 return zero(species).blend(fromArray(species, a, i, indexMap, j), m); 319 } 320 321 #end[byteOrShort] 322 323 /** 324 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an 325 * offset into the byte buffer. 326 * <p> 327 * Bytes are composed into primitive lane elements according to the 328 * native byte order of the underlying platform. 329 * <p> 330 * This method behaves as if it returns the result of calling the 331 * byte buffer, offset, and mask accepting 332 * {@link #fromByteBuffer($Type$Species, ByteBuffer, int, Mask)} method} as follows: 333 * <pre>{@code 334 * return this.fromByteBuffer(b, i, this.maskAllTrue()) 335 * }</pre> 336 * 337 * @param species species of desired vector 338 * @param bb the byte buffer 339 * @param ix the offset into the byte buffer 340 * @return a vector loaded from a byte buffer 341 * @throws IndexOutOfBoundsException if the offset is {@code < 0}, 342 * or {@code > b.limit()}, 343 * or if there are fewer than 344 * {@code this.length() * this.elementSize() / Byte.SIZE} bytes 345 * remaining in the byte buffer from the given offset 346 */ 347 @ForceInline 348 @SuppressWarnings("unchecked") 349 public static $abstractvectortype$ fromByteBuffer($Type$Species species, ByteBuffer bb, int ix) { 350 if (bb.order() != ByteOrder.nativeOrder()) { 351 throw new IllegalArgumentException(); 352 } 353 ix = VectorIntrinsics.checkIndex(ix, bb.limit(), species.bitSize() / Byte.SIZE); 354 return VectorIntrinsics.load((Class<$abstractvectortype$>) species.boxType(), $type$.class, species.length(), 355 U.getReference(bb, BYTE_BUFFER_HB), U.getLong(bb, BUFFER_ADDRESS) + ix, 356 bb, ix, species, 357 (c, idx, s) -> { 358 ByteBuffer bbc = c.duplicate().position(idx).order(ByteOrder.nativeOrder()); 359 $Type$Buffer tb = bbc{#if[byte]?;:.as$Type$Buffer();} 360 return (($Type$Species)s).op(i -> tb.get()); 361 }); 362 } 363 364 /** 365 * Loads a vector from a {@link ByteBuffer byte buffer} starting at an 366 * offset into the byte buffer and using a mask. 367 * <p> 368 * This method behaves as if the byte buffer is viewed as a primitive 369 * {@link java.nio.Buffer buffer} for the primitive element type, 370 * according to the native byte order of the underlying platform, and 371 * the returned vector is loaded with a mask from a primitive array 372 * obtained from the primitive buffer. 373 * The following pseudocode expresses the behaviour, where 374 * {@coce EBuffer} is the primitive buffer type, {@code e} is the 375 * primitive element type, and {@code ESpecies<S>} is the primitive 376 * species for {@code e}: 377 * <pre>{@code 378 * EBuffer eb = b.duplicate(). 379 * order(ByteOrder.nativeOrder()).position(i). 380 * asEBuffer(); 381 * e[] es = new e[this.length()]; 382 * for (int n = 0; n < t.length; n++) { 383 * if (m.isSet(n)) 384 * es[n] = eb.get(n); 385 * } 386 * Vector<E> r = ((ESpecies<S>)this).fromArray(es, 0, m); 387 * }</pre> 388 * 389 * @param species species of desired vector 390 * @param bb the byte buffer 391 * @param ix the offset into the byte buffer 392 * @param m the mask 393 * @return a vector loaded from a byte buffer 394 * @throws IndexOutOfBoundsException if the offset is {@code < 0}, 395 * or {@code > b.limit()}, 396 * for any vector lane index {@code N} where the mask at lane {@code N} 397 * is set 398 * {@code i >= b.limit() - (N * this.elementSize() / Byte.SIZE)} 399 */ 400 @ForceInline 401 public static $abstractvectortype$ fromByteBuffer($Type$Species species, ByteBuffer bb, int ix, Mask<$Boxtype$> m) { 402 return zero(species).blend(fromByteBuffer(species, bb, ix), m); 403 } 404 405 /** 406 * Returns a mask where each lane is set or unset according to given 407 * {@code boolean} values 408 * <p> 409 * For each mask lane, where {@code N} is the mask lane index, 410 * if the given {@code boolean} value at index {@code N} is {@code true} 411 * then the mask lane at index {@code N} is set, otherwise it is unset. 412 * 413 * @param species mask species 414 * @param bits the given {@code boolean} values 415 * @return a mask where each lane is set or unset according to the given {@code boolean} value 416 * @throws IndexOutOfBoundsException if {@code bits.length < species.length()} 417 */ 418 @ForceInline 419 public static Mask<$Boxtype$> maskFromValues($Type$Species species, boolean... bits) { 420 if (species.boxType() == $Type$MaxVector.class) 421 return new $Type$MaxVector.$Type$MaxMask(bits); 422 switch (species.bitSize()) { 423 case 64: return new $Type$64Vector.$Type$64Mask(bits); 424 case 128: return new $Type$128Vector.$Type$128Mask(bits); 425 case 256: return new $Type$256Vector.$Type$256Mask(bits); 426 case 512: return new $Type$512Vector.$Type$512Mask(bits); 427 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 428 } 429 } 430 431 // @@@ This is a bad implementation -- makes lambdas capturing -- fix this 432 static Mask<$Boxtype$> trueMask($Type$Species species) { 433 if (species.boxType() == $Type$MaxVector.class) 434 return $Type$MaxVector.$Type$MaxMask.TRUE_MASK; 435 switch (species.bitSize()) { 436 case 64: return $Type$64Vector.$Type$64Mask.TRUE_MASK; 437 case 128: return $Type$128Vector.$Type$128Mask.TRUE_MASK; 438 case 256: return $Type$256Vector.$Type$256Mask.TRUE_MASK; 439 case 512: return $Type$512Vector.$Type$512Mask.TRUE_MASK; 440 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 441 } 442 } 443 444 static Mask<$Boxtype$> falseMask($Type$Species species) { 445 if (species.boxType() == $Type$MaxVector.class) 446 return $Type$MaxVector.$Type$MaxMask.FALSE_MASK; 447 switch (species.bitSize()) { 448 case 64: return $Type$64Vector.$Type$64Mask.FALSE_MASK; 449 case 128: return $Type$128Vector.$Type$128Mask.FALSE_MASK; 450 case 256: return $Type$256Vector.$Type$256Mask.FALSE_MASK; 451 case 512: return $Type$512Vector.$Type$512Mask.FALSE_MASK; 452 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 453 } 454 } 455 456 /** 457 * Loads a mask from a {@code boolean} array starting at an offset. 458 * <p> 459 * For each mask lane, where {@code N} is the mask lane index, 460 * if the array element at index {@code ix + N} is {@code true} then the 461 * mask lane at index {@code N} is set, otherwise it is unset. 462 * 463 * @param species mask species 464 * @param bits the {@code boolean} array 465 * @param ix the offset into the array 466 * @return the mask loaded from a {@code boolean} array 467 * @throws IndexOutOfBoundsException if {@code ix < 0}, or 468 * {@code ix > bits.length - species.length()} 469 */ 470 @ForceInline 471 @SuppressWarnings("unchecked") 472 public static Mask<$Boxtype$> maskFromArray($Type$Species species, boolean[] bits, int ix) { 473 Objects.requireNonNull(bits); 474 ix = VectorIntrinsics.checkIndex(ix, bits.length, species.length()); 475 return VectorIntrinsics.load((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), 476 bits, (((long) ix) << ARRAY_SHIFT) + Unsafe.ARRAY_BOOLEAN_BASE_OFFSET, 477 bits, ix, species, 478 (c, idx, s) -> (Mask<$Boxtype$>) (($Type$Species)s).opm(n -> c[idx + n])); 479 } 480 481 /** 482 * Returns a mask where all lanes are set. 483 * 484 * @param species mask species 485 * @return a mask where all lanes are set 486 */ 487 @ForceInline 488 @SuppressWarnings("unchecked") 489 public static Mask<$Boxtype$> maskAllTrue($Type$Species species) { 490 return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), 491 ($bitstype$)-1, species, 492 ((z, s) -> trueMask(($Type$Species)s))); 493 } 494 495 /** 496 * Returns a mask where all lanes are unset. 497 * 498 * @param species mask species 499 * @return a mask where all lanes are unset 500 */ 501 @ForceInline 502 @SuppressWarnings("unchecked") 503 public static Mask<$Boxtype$> maskAllFalse($Type$Species species) { 504 return VectorIntrinsics.broadcastCoerced((Class<Mask<$Boxtype$>>) species.maskType(), $bitstype$.class, species.length(), 505 0, species, 506 ((z, s) -> falseMask(($Type$Species)s))); 507 } 508 509 /** 510 * Returns a shuffle of mapped indexes where each lane element is 511 * the result of applying a mapping function to the corresponding lane 512 * index. 513 * <p> 514 * Care should be taken to ensure Shuffle values produced from this 515 * method are consumed as constants to ensure optimal generation of 516 * code. For example, values held in static final fields or values 517 * held in loop constant local variables. 518 * <p> 519 * This method behaves as if a shuffle is created from an array of 520 * mapped indexes as follows: 521 * <pre>{@code 522 * int[] a = new int[species.length()]; 523 * for (int i = 0; i < a.length; i++) { 524 * a[i] = f.applyAsInt(i); 525 * } 526 * return this.shuffleFromValues(a); 527 * }</pre> 528 * 529 * @param species shuffle species 530 * @param f the lane index mapping function 531 * @return a shuffle of mapped indexes 532 */ 533 @ForceInline 534 public static Shuffle<$Boxtype$> shuffle($Type$Species species, IntUnaryOperator f) { 535 if (species.boxType() == $Type$MaxVector.class) 536 return new $Type$MaxVector.$Type$MaxShuffle(f); 537 switch (species.bitSize()) { 538 case 64: return new $Type$64Vector.$Type$64Shuffle(f); 539 case 128: return new $Type$128Vector.$Type$128Shuffle(f); 540 case 256: return new $Type$256Vector.$Type$256Shuffle(f); 541 case 512: return new $Type$512Vector.$Type$512Shuffle(f); 542 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 543 } 544 } 545 546 /** 547 * Returns a shuffle where each lane element is the value of its 548 * corresponding lane index. 549 * <p> 550 * This method behaves as if a shuffle is created from an identity 551 * index mapping function as follows: 552 * <pre>{@code 553 * return this.shuffle(i -> i); 554 * }</pre> 555 * 556 * @param species shuffle species 557 * @return a shuffle of lane indexes 558 */ 559 @ForceInline 560 public static Shuffle<$Boxtype$> shuffleIota($Type$Species species) { 561 if (species.boxType() == $Type$MaxVector.class) 562 return new $Type$MaxVector.$Type$MaxShuffle(AbstractShuffle.IDENTITY); 563 switch (species.bitSize()) { 564 case 64: return new $Type$64Vector.$Type$64Shuffle(AbstractShuffle.IDENTITY); 565 case 128: return new $Type$128Vector.$Type$128Shuffle(AbstractShuffle.IDENTITY); 566 case 256: return new $Type$256Vector.$Type$256Shuffle(AbstractShuffle.IDENTITY); 567 case 512: return new $Type$512Vector.$Type$512Shuffle(AbstractShuffle.IDENTITY); 568 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 569 } 570 } 571 572 /** 573 * Returns a shuffle where each lane element is set to a given 574 * {@code int} value logically AND'ed by the species length minus one. 575 * <p> 576 * For each shuffle lane, where {@code N} is the shuffle lane index, the 577 * the {@code int} value at index {@code N} logically AND'ed by 578 * {@code species.length() - 1} is placed into the resulting shuffle at 579 * lane index {@code N}. 580 * 581 * @param species shuffle species 582 * @param ixs the given {@code int} values 583 * @return a shuffle where each lane element is set to a given 584 * {@code int} value 585 * @throws IndexOutOfBoundsException if the number of int values is 586 * {@code < species.length()} 587 */ 588 @ForceInline 589 public static Shuffle<$Boxtype$> shuffleFromValues($Type$Species species, int... ixs) { 590 if (species.boxType() == $Type$MaxVector.class) 591 return new $Type$MaxVector.$Type$MaxShuffle(ixs); 592 switch (species.bitSize()) { 593 case 64: return new $Type$64Vector.$Type$64Shuffle(ixs); 594 case 128: return new $Type$128Vector.$Type$128Shuffle(ixs); 595 case 256: return new $Type$256Vector.$Type$256Shuffle(ixs); 596 case 512: return new $Type$512Vector.$Type$512Shuffle(ixs); 597 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 598 } 599 } 600 601 /** 602 * Loads a shuffle from an {@code int} array starting at an offset. 603 * <p> 604 * For each shuffle lane, where {@code N} is the shuffle lane index, the 605 * array element at index {@code i + N} logically AND'ed by 606 * {@code species.length() - 1} is placed into the resulting shuffle at lane 607 * index {@code N}. 608 * 609 * @param species shuffle species 610 * @param ixs the {@code int} array 611 * @param i the offset into the array 612 * @return a shuffle loaded from the {@code int} array 613 * @throws IndexOutOfBoundsException if {@code i < 0}, or 614 * {@code i > a.length - species.length()} 615 */ 616 @ForceInline 617 public static Shuffle<$Boxtype$> shuffleFromArray($Type$Species species, int[] ixs, int i) { 618 if (species.boxType() == $Type$MaxVector.class) 619 return new $Type$MaxVector.$Type$MaxShuffle(ixs, i); 620 switch (species.bitSize()) { 621 case 64: return new $Type$64Vector.$Type$64Shuffle(ixs, i); 622 case 128: return new $Type$128Vector.$Type$128Shuffle(ixs, i); 623 case 256: return new $Type$256Vector.$Type$256Shuffle(ixs, i); 624 case 512: return new $Type$512Vector.$Type$512Shuffle(ixs, i); 625 default: throw new IllegalArgumentException(Integer.toString(species.bitSize())); 626 } 627 } 628 629 630 // Ops 631 632 @Override 633 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v); 634 635 /** 636 * Adds this vector to the broadcast of an input scalar. 637 * <p> 638 * This is a vector binary operation where the primitive addition operation 639 * ({@code +}) is applied to lane elements. 640 * 641 * @param s the input scalar 642 * @return the result of adding this vector to the broadcast of an input 643 * scalar 644 */ 645 public abstract $abstractvectortype$ add($type$ s); 646 647 @Override 648 public abstract $abstractvectortype$ add(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 649 650 /** 651 * Adds this vector to broadcast of an input scalar, 652 * selecting lane elements controlled by a mask. 653 * <p> 654 * This is a vector binary operation where the primitive addition operation 655 * ({@code +}) is applied to lane elements. 656 * 657 * @param s the input scalar 658 * @param m the mask controlling lane selection 659 * @return the result of adding this vector to the broadcast of an input 660 * scalar 661 */ 662 public abstract $abstractvectortype$ add($type$ s, Mask<$Boxtype$> m); 663 664 @Override 665 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v); 666 667 /** 668 * Subtracts the broadcast of an input scalar from this vector. 669 * <p> 670 * This is a vector binary operation where the primitive subtraction 671 * operation ({@code -}) is applied to lane elements. 672 * 673 * @param s the input scalar 674 * @return the result of subtracting the broadcast of an input 675 * scalar from this vector 676 */ 677 public abstract $abstractvectortype$ sub($type$ s); 678 679 @Override 680 public abstract $abstractvectortype$ sub(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 681 682 /** 683 * Subtracts the broadcast of an input scalar from this vector, selecting 684 * lane elements controlled by a mask. 685 * <p> 686 * This is a vector binary operation where the primitive subtraction 687 * operation ({@code -}) is applied to lane elements. 688 * 689 * @param s the input scalar 690 * @param m the mask controlling lane selection 691 * @return the result of subtracting the broadcast of an input 692 * scalar from this vector 693 */ 694 public abstract $abstractvectortype$ sub($type$ s, Mask<$Boxtype$> m); 695 696 @Override 697 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v); 698 699 /** 700 * Multiplies this vector with the broadcast of an input scalar. 701 * <p> 702 * This is a vector binary operation where the primitive multiplication 703 * operation ({@code *}) is applied to lane elements. 704 * 705 * @param s the input scalar 706 * @return the result of multiplying this vector with the broadcast of an 707 * input scalar 708 */ 709 public abstract $abstractvectortype$ mul($type$ s); 710 711 @Override 712 public abstract $abstractvectortype$ mul(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 713 714 /** 715 * Multiplies this vector with the broadcast of an input scalar, selecting 716 * lane elements controlled by a mask. 717 * <p> 718 * This is a vector binary operation where the primitive multiplication 719 * operation ({@code *}) is applied to lane elements. 720 * 721 * @param s the input scalar 722 * @param m the mask controlling lane selection 723 * @return the result of multiplying this vector with the broadcast of an 724 * input scalar 725 */ 726 public abstract $abstractvectortype$ mul($type$ s, Mask<$Boxtype$> m); 727 728 @Override 729 public abstract $abstractvectortype$ neg(); 730 731 @Override 732 public abstract $abstractvectortype$ neg(Mask<$Boxtype$> m); 733 734 @Override 735 public abstract $abstractvectortype$ abs(); 736 737 @Override 738 public abstract $abstractvectortype$ abs(Mask<$Boxtype$> m); 739 740 @Override 741 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v); 742 743 @Override 744 public abstract $abstractvectortype$ min(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 745 746 /** 747 * Returns the minimum of this vector and the broadcast of an input scalar. 748 * <p> 749 * This is a vector binary operation where the operation 750 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements. 751 * 752 * @param s the input scalar 753 * @return the minimum of this vector and the broadcast of an input scalar 754 */ 755 public abstract $abstractvectortype$ min($type$ s); 756 757 @Override 758 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v); 759 760 @Override 761 public abstract $abstractvectortype$ max(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 762 763 /** 764 * Returns the maximum of this vector and the broadcast of an input scalar. 765 * <p> 766 * This is a vector binary operation where the operation 767 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements. 768 * 769 * @param s the input scalar 770 * @return the maximum of this vector and the broadcast of an input scalar 771 */ 772 public abstract $abstractvectortype$ max($type$ s); 773 774 @Override 775 public abstract Mask<$Boxtype$> equal(Vector<$Boxtype$> v); 776 777 /** 778 * Tests if this vector is equal to the broadcast of an input scalar. 779 * <p> 780 * This is a vector binary test operation where the primitive equals 781 * operation ({@code ==}) is applied to lane elements. 782 * 783 * @param s the input scalar 784 * @return the result mask of testing if this vector is equal to the 785 * broadcast of an input scalar 786 */ 787 public abstract Mask<$Boxtype$> equal($type$ s); 788 789 @Override 790 public abstract Mask<$Boxtype$> notEqual(Vector<$Boxtype$> v); 791 792 /** 793 * Tests if this vector is not equal to the broadcast of an input scalar. 794 * <p> 795 * This is a vector binary test operation where the primitive not equals 796 * operation ({@code !=}) is applied to lane elements. 797 * 798 * @param s the input scalar 799 * @return the result mask of testing if this vector is not equal to the 800 * broadcast of an input scalar 801 */ 802 public abstract Mask<$Boxtype$> notEqual($type$ s); 803 804 @Override 805 public abstract Mask<$Boxtype$> lessThan(Vector<$Boxtype$> v); 806 807 /** 808 * Tests if this vector is less than the broadcast of an input scalar. 809 * <p> 810 * This is a vector binary test operation where the primitive less than 811 * operation ({@code <}) is applied to lane elements. 812 * 813 * @param s the input scalar 814 * @return the mask result of testing if this vector is less than the 815 * broadcast of an input scalar 816 */ 817 public abstract Mask<$Boxtype$> lessThan($type$ s); 818 819 @Override 820 public abstract Mask<$Boxtype$> lessThanEq(Vector<$Boxtype$> v); 821 822 /** 823 * Tests if this vector is less or equal to the broadcast of an input scalar. 824 * <p> 825 * This is a vector binary test operation where the primitive less than 826 * or equal to operation ({@code <=}) is applied to lane elements. 827 * 828 * @param s the input scalar 829 * @return the mask result of testing if this vector is less than or equal 830 * to the broadcast of an input scalar 831 */ 832 public abstract Mask<$Boxtype$> lessThanEq($type$ s); 833 834 @Override 835 public abstract Mask<$Boxtype$> greaterThan(Vector<$Boxtype$> v); 836 837 /** 838 * Tests if this vector is greater than the broadcast of an input scalar. 839 * <p> 840 * This is a vector binary test operation where the primitive greater than 841 * operation ({@code >}) is applied to lane elements. 842 * 843 * @param s the input scalar 844 * @return the mask result of testing if this vector is greater than the 845 * broadcast of an input scalar 846 */ 847 public abstract Mask<$Boxtype$> greaterThan($type$ s); 848 849 @Override 850 public abstract Mask<$Boxtype$> greaterThanEq(Vector<$Boxtype$> v); 851 852 /** 853 * Tests if this vector is greater than or equal to the broadcast of an 854 * input scalar. 855 * <p> 856 * This is a vector binary test operation where the primitive greater than 857 * or equal to operation ({@code >=}) is applied to lane elements. 858 * 859 * @param s the input scalar 860 * @return the mask result of testing if this vector is greater than or 861 * equal to the broadcast of an input scalar 862 */ 863 public abstract Mask<$Boxtype$> greaterThanEq($type$ s); 864 865 @Override 866 public abstract $abstractvectortype$ blend(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 867 868 /** 869 * Blends the lane elements of this vector with those of the broadcast of an 870 * input scalar, selecting lanes controlled by a mask. 871 * <p> 872 * For each lane of the mask, at lane index {@code N}, if the mask lane 873 * is set then the lane element at {@code N} from the input vector is 874 * selected and placed into the resulting vector at {@code N}, 875 * otherwise the the lane element at {@code N} from this input vector is 876 * selected and placed into the resulting vector at {@code N}. 877 * 878 * @param s the input scalar 879 * @param m the mask controlling lane selection 880 * @return the result of blending the lane elements of this vector with 881 * those of the broadcast of an input scalar 882 */ 883 public abstract $abstractvectortype$ blend($type$ s, Mask<$Boxtype$> m); 884 885 @Override 886 public abstract $abstractvectortype$ rearrange(Vector<$Boxtype$> v, 887 Shuffle<$Boxtype$> s, Mask<$Boxtype$> m); 888 889 @Override 890 public abstract $abstractvectortype$ rearrange(Shuffle<$Boxtype$> m); 891 892 @Override 893 public abstract $abstractvectortype$ reshape(Species<$Boxtype$> s); 894 895 @Override 896 public abstract $abstractvectortype$ rotateEL(int i); 897 898 @Override 899 public abstract $abstractvectortype$ rotateER(int i); 900 901 @Override 902 public abstract $abstractvectortype$ shiftEL(int i); 903 904 @Override 905 public abstract $abstractvectortype$ shiftER(int i); 906 907 #if[FP] 908 /** 909 * Divides this vector by an input vector. 910 * <p> 911 * This is a vector binary operation where the primitive division 912 * operation ({@code /}) is applied to lane elements. 913 * 914 * @param v the input vector 915 * @return the result of dividing this vector by the input vector 916 */ 917 public abstract $abstractvectortype$ div(Vector<$Boxtype$> v); 918 919 /** 920 * Divides this vector by the broadcast of an input scalar. 921 * <p> 922 * This is a vector binary operation where the primitive division 923 * operation ({@code /}) is applied to lane elements. 924 * 925 * @param s the input scalar 926 * @return the result of dividing this vector by the broadcast of an input 927 * scalar 928 */ 929 public abstract $abstractvectortype$ div($type$ s); 930 931 /** 932 * Divides this vector by an input vector, selecting lane elements 933 * controlled by a mask. 934 * <p> 935 * This is a vector binary operation where the primitive division 936 * operation ({@code /}) is applied to lane elements. 937 * 938 * @param v the input vector 939 * @param m the mask controlling lane selection 940 * @return the result of dividing this vector by the input vector 941 */ 942 public abstract $abstractvectortype$ div(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 943 944 /** 945 * Divides this vector by the broadcast of an input scalar, selecting lane 946 * elements controlled by a mask. 947 * <p> 948 * This is a vector binary operation where the primitive division 949 * operation ({@code /}) is applied to lane elements. 950 * 951 * @param s the input scalar 952 * @param m the mask controlling lane selection 953 * @return the result of dividing this vector by the broadcast of an input 954 * scalar 955 */ 956 public abstract $abstractvectortype$ div($type$ s, Mask<$Boxtype$> m); 957 958 /** 959 * Calculates the square root of this vector. 960 * <p> 961 * This is a vector unary operation where the {@link Math#sqrt} operation 962 * is applied to lane elements. 963 * 964 * @return the square root of this vector 965 */ 966 public abstract $abstractvectortype$ sqrt(); 967 968 /** 969 * Calculates the square root of this vector, selecting lane elements 970 * controlled by a mask. 971 * <p> 972 * This is a vector unary operation where the {@link Math#sqrt} operation 973 * is applied to lane elements. 974 * 975 * @param m the mask controlling lane selection 976 * @return the square root of this vector 977 */ 978 public $abstractvectortype$ sqrt(Mask<$Boxtype$> m) { 979 return uOp(m, (i, a) -> ($type$) Math.sqrt((double) a)); 980 } 981 982 /** 983 * Calculates the trigonometric tangent of this vector. 984 * <p> 985 * This is a vector unary operation with same semantic definition as 986 * {@link Math#tan} operation applied to lane elements. 987 * The implementation is not required to return same 988 * results as {@link Math#tan}, but adheres to rounding, monotonicity, 989 * and special case semantics as defined in the {@link Math#tan} 990 * specifications. The computed result will be within 1 ulp of the 991 * exact result. 992 * 993 * @return the tangent of this vector 994 */ 995 public $abstractvectortype$ tan() { 996 return uOp((i, a) -> ($type$) Math.tan((double) a)); 997 } 998 999 /** 1000 * Calculates the trigonometric tangent of this vector, selecting lane 1001 * elements controlled by a mask. 1002 * <p> 1003 * Semantics for rounding, monotonicity, and special cases are 1004 * described in {@link $abstractvectortype$#tan} 1005 * 1006 * @param m the mask controlling lane selection 1007 * @return the tangent of this vector 1008 */ 1009 public $abstractvectortype$ tan(Mask<$Boxtype$> m) { 1010 return uOp(m, (i, a) -> ($type$) Math.tan((double) a)); 1011 } 1012 1013 /** 1014 * Calculates the hyperbolic tangent of this vector. 1015 * <p> 1016 * This is a vector unary operation with same semantic definition as 1017 * {@link Math#tanh} operation applied to lane elements. 1018 * The implementation is not required to return same 1019 * results as {@link Math#tanh}, but adheres to rounding, monotonicity, 1020 * and special case semantics as defined in the {@link Math#tanh} 1021 * specifications. The computed result will be within 2.5 ulps of the 1022 * exact result. 1023 * 1024 * @return the hyperbolic tangent of this vector 1025 */ 1026 public $abstractvectortype$ tanh() { 1027 return uOp((i, a) -> ($type$) Math.tanh((double) a)); 1028 } 1029 1030 /** 1031 * Calculates the hyperbolic tangent of this vector, selecting lane elements 1032 * controlled by a mask. 1033 * <p> 1034 * Semantics for rounding, monotonicity, and special cases are 1035 * described in {@link $abstractvectortype$#tanh} 1036 * 1037 * @param m the mask controlling lane selection 1038 * @return the hyperbolic tangent of this vector 1039 */ 1040 public $abstractvectortype$ tanh(Mask<$Boxtype$> m) { 1041 return uOp(m, (i, a) -> ($type$) Math.tanh((double) a)); 1042 } 1043 1044 /** 1045 * Calculates the trigonometric sine of this vector. 1046 * <p> 1047 * This is a vector unary operation with same semantic definition as 1048 * {@link Math#sin} operation applied to lane elements. 1049 * The implementation is not required to return same 1050 * results as {@link Math#sin}, but adheres to rounding, monotonicity, 1051 * and special case semantics as defined in the {@link Math#sin} 1052 * specifications. The computed result will be within 1 ulp of the 1053 * exact result. 1054 * 1055 * @return the sine of this vector 1056 */ 1057 public $abstractvectortype$ sin() { 1058 return uOp((i, a) -> ($type$) Math.sin((double) a)); 1059 } 1060 1061 /** 1062 * Calculates the trigonometric sine of this vector, selecting lane elements 1063 * controlled by a mask. 1064 * <p> 1065 * Semantics for rounding, monotonicity, and special cases are 1066 * described in {@link $abstractvectortype$#sin} 1067 * 1068 * @param m the mask controlling lane selection 1069 * @return the sine of this vector 1070 */ 1071 public $abstractvectortype$ sin(Mask<$Boxtype$> m) { 1072 return uOp(m, (i, a) -> ($type$) Math.sin((double) a)); 1073 } 1074 1075 /** 1076 * Calculates the hyperbolic sine of this vector. 1077 * <p> 1078 * This is a vector unary operation with same semantic definition as 1079 * {@link Math#sinh} operation applied to lane elements. 1080 * The implementation is not required to return same 1081 * results as {@link Math#sinh}, but adheres to rounding, monotonicity, 1082 * and special case semantics as defined in the {@link Math#sinh} 1083 * specifications. The computed result will be within 2.5 ulps of the 1084 * exact result. 1085 * 1086 * @return the hyperbolic sine of this vector 1087 */ 1088 public $abstractvectortype$ sinh() { 1089 return uOp((i, a) -> ($type$) Math.sinh((double) a)); 1090 } 1091 1092 /** 1093 * Calculates the hyperbolic sine of this vector, selecting lane elements 1094 * controlled by a mask. 1095 * <p> 1096 * Semantics for rounding, monotonicity, and special cases are 1097 * described in {@link $abstractvectortype$#sinh} 1098 * 1099 * @param m the mask controlling lane selection 1100 * @return the hyperbolic sine of this vector 1101 */ 1102 public $abstractvectortype$ sinh(Mask<$Boxtype$> m) { 1103 return uOp(m, (i, a) -> ($type$) Math.sinh((double) a)); 1104 } 1105 1106 /** 1107 * Calculates the trigonometric cosine of this vector. 1108 * <p> 1109 * This is a vector unary operation with same semantic definition as 1110 * {@link Math#cos} operation applied to lane elements. 1111 * The implementation is not required to return same 1112 * results as {@link Math#cos}, but adheres to rounding, monotonicity, 1113 * and special case semantics as defined in the {@link Math#cos} 1114 * specifications. The computed result will be within 1 ulp of the 1115 * exact result. 1116 * 1117 * @return the cosine of this vector 1118 */ 1119 public $abstractvectortype$ cos() { 1120 return uOp((i, a) -> ($type$) Math.cos((double) a)); 1121 } 1122 1123 /** 1124 * Calculates the trigonometric cosine of this vector, selecting lane 1125 * elements controlled by a mask. 1126 * <p> 1127 * Semantics for rounding, monotonicity, and special cases are 1128 * described in {@link $abstractvectortype$#cos} 1129 * 1130 * @param m the mask controlling lane selection 1131 * @return the cosine of this vector 1132 */ 1133 public $abstractvectortype$ cos(Mask<$Boxtype$> m) { 1134 return uOp(m, (i, a) -> ($type$) Math.cos((double) a)); 1135 } 1136 1137 /** 1138 * Calculates the hyperbolic cosine of this vector. 1139 * <p> 1140 * This is a vector unary operation with same semantic definition as 1141 * {@link Math#cosh} operation applied to lane elements. 1142 * The implementation is not required to return same 1143 * results as {@link Math#cosh}, but adheres to rounding, monotonicity, 1144 * and special case semantics as defined in the {@link Math#cosh} 1145 * specifications. The computed result will be within 2.5 ulps of the 1146 * exact result. 1147 * 1148 * @return the hyperbolic cosine of this vector 1149 */ 1150 public $abstractvectortype$ cosh() { 1151 return uOp((i, a) -> ($type$) Math.cosh((double) a)); 1152 } 1153 1154 /** 1155 * Calculates the hyperbolic cosine of this vector, selecting lane elements 1156 * controlled by a mask. 1157 * <p> 1158 * Semantics for rounding, monotonicity, and special cases are 1159 * described in {@link $abstractvectortype$#cosh} 1160 * 1161 * @param m the mask controlling lane selection 1162 * @return the hyperbolic cosine of this vector 1163 */ 1164 public $abstractvectortype$ cosh(Mask<$Boxtype$> m) { 1165 return uOp(m, (i, a) -> ($type$) Math.cosh((double) a)); 1166 } 1167 1168 /** 1169 * Calculates the arc sine of this vector. 1170 * <p> 1171 * This is a vector unary operation with same semantic definition as 1172 * {@link Math#asin} operation applied to lane elements. 1173 * The implementation is not required to return same 1174 * results as {@link Math#asin}, but adheres to rounding, monotonicity, 1175 * and special case semantics as defined in the {@link Math#asin} 1176 * specifications. The computed result will be within 1 ulp of the 1177 * exact result. 1178 * 1179 * @return the arc sine of this vector 1180 */ 1181 public $abstractvectortype$ asin() { 1182 return uOp((i, a) -> ($type$) Math.asin((double) a)); 1183 } 1184 1185 /** 1186 * Calculates the arc sine of this vector, selecting lane elements 1187 * controlled by a mask. 1188 * <p> 1189 * Semantics for rounding, monotonicity, and special cases are 1190 * described in {@link $abstractvectortype$#asin} 1191 * 1192 * @param m the mask controlling lane selection 1193 * @return the arc sine of this vector 1194 */ 1195 public $abstractvectortype$ asin(Mask<$Boxtype$> m) { 1196 return uOp(m, (i, a) -> ($type$) Math.asin((double) a)); 1197 } 1198 1199 /** 1200 * Calculates the arc cosine of this vector. 1201 * <p> 1202 * This is a vector unary operation with same semantic definition as 1203 * {@link Math#acos} operation applied to lane elements. 1204 * The implementation is not required to return same 1205 * results as {@link Math#acos}, but adheres to rounding, monotonicity, 1206 * and special case semantics as defined in the {@link Math#acos} 1207 * specifications. The computed result will be within 1 ulp of the 1208 * exact result. 1209 * 1210 * @return the arc cosine of this vector 1211 */ 1212 public $abstractvectortype$ acos() { 1213 return uOp((i, a) -> ($type$) Math.acos((double) a)); 1214 } 1215 1216 /** 1217 * Calculates the arc cosine of this vector, selecting lane elements 1218 * controlled by a mask. 1219 * <p> 1220 * Semantics for rounding, monotonicity, and special cases are 1221 * described in {@link $abstractvectortype$#acos} 1222 * 1223 * @param m the mask controlling lane selection 1224 * @return the arc cosine of this vector 1225 */ 1226 public $abstractvectortype$ acos(Mask<$Boxtype$> m) { 1227 return uOp(m, (i, a) -> ($type$) Math.acos((double) a)); 1228 } 1229 1230 /** 1231 * Calculates the arc tangent of this vector. 1232 * <p> 1233 * This is a vector unary operation with same semantic definition as 1234 * {@link Math#atan} operation applied to lane elements. 1235 * The implementation is not required to return same 1236 * results as {@link Math#atan}, but adheres to rounding, monotonicity, 1237 * and special case semantics as defined in the {@link Math#atan} 1238 * specifications. The computed result will be within 1 ulp of the 1239 * exact result. 1240 * 1241 * @return the arc tangent of this vector 1242 */ 1243 public $abstractvectortype$ atan() { 1244 return uOp((i, a) -> ($type$) Math.atan((double) a)); 1245 } 1246 1247 /** 1248 * Calculates the arc tangent of this vector, selecting lane elements 1249 * controlled by a mask. 1250 * <p> 1251 * Semantics for rounding, monotonicity, and special cases are 1252 * described in {@link $abstractvectortype$#atan} 1253 * 1254 * @param m the mask controlling lane selection 1255 * @return the arc tangent of this vector 1256 */ 1257 public $abstractvectortype$ atan(Mask<$Boxtype$> m) { 1258 return uOp(m, (i, a) -> ($type$) Math.atan((double) a)); 1259 } 1260 1261 /** 1262 * Calculates the arc tangent of this vector divided by an input vector. 1263 * <p> 1264 * This is a vector binary operation with same semantic definition as 1265 * {@link Math#atan2} operation applied to lane elements. 1266 * The implementation is not required to return same 1267 * results as {@link Math#atan2}, but adheres to rounding, monotonicity, 1268 * and special case semantics as defined in the {@link Math#atan2} 1269 * specifications. The computed result will be within 2 ulps of the 1270 * exact result. 1271 * 1272 * @param v the input vector 1273 * @return the arc tangent of this vector divided by the input vector 1274 */ 1275 public $abstractvectortype$ atan2(Vector<$Boxtype$> v) { 1276 return bOp(v, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b)); 1277 } 1278 1279 /** 1280 * Calculates the arc tangent of this vector divided by the broadcast of an 1281 * an input scalar. 1282 * <p> 1283 * This is a vector binary operation with same semantic definition as 1284 * {@link Math#atan2} operation applied to lane elements. 1285 * The implementation is not required to return same 1286 * results as {@link Math#atan2}, but adheres to rounding, monotonicity, 1287 * and special case semantics as defined in the {@link Math#atan2} 1288 * specifications. The computed result will be within 1 ulp of the 1289 * exact result. 1290 * 1291 * @param s the input scalar 1292 * @return the arc tangent of this vector over the input vector 1293 */ 1294 public abstract $abstractvectortype$ atan2($type$ s); 1295 1296 /** 1297 * Calculates the arc tangent of this vector divided by an input vector, 1298 * selecting lane elements controlled by a mask. 1299 * <p> 1300 * Semantics for rounding, monotonicity, and special cases are 1301 * described in {@link $abstractvectortype$#atan2} 1302 * 1303 * @param v the input vector 1304 * @param m the mask controlling lane selection 1305 * @return the arc tangent of this vector divided by the input vector 1306 */ 1307 public $abstractvectortype$ atan2(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 1308 return bOp(v, m, (i, a, b) -> ($type$) Math.atan2((double) a, (double) b)); 1309 } 1310 1311 /** 1312 * Calculates the arc tangent of this vector divided by the broadcast of an 1313 * an input scalar, selecting lane elements controlled by a mask. 1314 * <p> 1315 * Semantics for rounding, monotonicity, and special cases are 1316 * described in {@link $abstractvectortype$#atan2} 1317 * 1318 * @param s the input scalar 1319 * @param m the mask controlling lane selection 1320 * @return the arc tangent of this vector over the input vector 1321 */ 1322 public abstract $abstractvectortype$ atan2($type$ s, Mask<$Boxtype$> m); 1323 1324 /** 1325 * Calculates the cube root of this vector. 1326 * <p> 1327 * This is a vector unary operation with same semantic definition as 1328 * {@link Math#cbrt} operation applied to lane elements. 1329 * The implementation is not required to return same 1330 * results as {@link Math#cbrt}, but adheres to rounding, monotonicity, 1331 * and special case semantics as defined in the {@link Math#cbrt} 1332 * specifications. The computed result will be within 1 ulp of the 1333 * exact result. 1334 * 1335 * @return the cube root of this vector 1336 */ 1337 public $abstractvectortype$ cbrt() { 1338 return uOp((i, a) -> ($type$) Math.cbrt((double) a)); 1339 } 1340 1341 /** 1342 * Calculates the cube root of this vector, selecting lane elements 1343 * controlled by a mask. 1344 * <p> 1345 * Semantics for rounding, monotonicity, and special cases are 1346 * described in {@link $abstractvectortype$#cbrt} 1347 * 1348 * @param m the mask controlling lane selection 1349 * @return the cube root of this vector 1350 */ 1351 public $abstractvectortype$ cbrt(Mask<$Boxtype$> m) { 1352 return uOp(m, (i, a) -> ($type$) Math.cbrt((double) a)); 1353 } 1354 1355 /** 1356 * Calculates the natural logarithm of this vector. 1357 * <p> 1358 * This is a vector unary operation with same semantic definition as 1359 * {@link Math#log} operation applied to lane elements. 1360 * The implementation is not required to return same 1361 * results as {@link Math#log}, but adheres to rounding, monotonicity, 1362 * and special case semantics as defined in the {@link Math#log} 1363 * specifications. The computed result will be within 1 ulp of the 1364 * exact result. 1365 * 1366 * @return the natural logarithm of this vector 1367 */ 1368 public $abstractvectortype$ log() { 1369 return uOp((i, a) -> ($type$) Math.log((double) a)); 1370 } 1371 1372 /** 1373 * Calculates the natural logarithm of this vector, selecting lane elements 1374 * controlled by a mask. 1375 * <p> 1376 * Semantics for rounding, monotonicity, and special cases are 1377 * described in {@link $abstractvectortype$#log} 1378 * 1379 * @param m the mask controlling lane selection 1380 * @return the natural logarithm of this vector 1381 */ 1382 public $abstractvectortype$ log(Mask<$Boxtype$> m) { 1383 return uOp(m, (i, a) -> ($type$) Math.log((double) a)); 1384 } 1385 1386 /** 1387 * Calculates the base 10 logarithm of this vector. 1388 * <p> 1389 * This is a vector unary operation with same semantic definition as 1390 * {@link Math#log10} operation applied to lane elements. 1391 * The implementation is not required to return same 1392 * results as {@link Math#log10}, but adheres to rounding, monotonicity, 1393 * and special case semantics as defined in the {@link Math#log10} 1394 * specifications. The computed result will be within 1 ulp of the 1395 * exact result. 1396 * 1397 * @return the base 10 logarithm of this vector 1398 */ 1399 public $abstractvectortype$ log10() { 1400 return uOp((i, a) -> ($type$) Math.log10((double) a)); 1401 } 1402 1403 /** 1404 * Calculates the base 10 logarithm of this vector, selecting lane elements 1405 * controlled by a mask. 1406 * <p> 1407 * Semantics for rounding, monotonicity, and special cases are 1408 * described in {@link $abstractvectortype$#log10} 1409 * 1410 * @param m the mask controlling lane selection 1411 * @return the base 10 logarithm of this vector 1412 */ 1413 public $abstractvectortype$ log10(Mask<$Boxtype$> m) { 1414 return uOp(m, (i, a) -> ($type$) Math.log10((double) a)); 1415 } 1416 1417 /** 1418 * Calculates the natural logarithm of the sum of this vector and the 1419 * broadcast of {@code 1}. 1420 * <p> 1421 * This is a vector unary operation with same semantic definition as 1422 * {@link Math#log1p} operation applied to lane elements. 1423 * The implementation is not required to return same 1424 * results as {@link Math#log1p}, but adheres to rounding, monotonicity, 1425 * and special case semantics as defined in the {@link Math#log1p} 1426 * specifications. The computed result will be within 1 ulp of the 1427 * exact result. 1428 * 1429 * @return the natural logarithm of the sum of this vector and the broadcast 1430 * of {@code 1} 1431 */ 1432 public $abstractvectortype$ log1p() { 1433 return uOp((i, a) -> ($type$) Math.log1p((double) a)); 1434 } 1435 1436 /** 1437 * Calculates the natural logarithm of the sum of this vector and the 1438 * broadcast of {@code 1}, selecting lane elements controlled by a mask. 1439 * <p> 1440 * Semantics for rounding, monotonicity, and special cases are 1441 * described in {@link $abstractvectortype$#log1p} 1442 * 1443 * @param m the mask controlling lane selection 1444 * @return the natural logarithm of the sum of this vector and the broadcast 1445 * of {@code 1} 1446 */ 1447 public $abstractvectortype$ log1p(Mask<$Boxtype$> m) { 1448 return uOp(m, (i, a) -> ($type$) Math.log1p((double) a)); 1449 } 1450 1451 /** 1452 * Calculates this vector raised to the power of an input vector. 1453 * <p> 1454 * This is a vector binary operation with same semantic definition as 1455 * {@link Math#pow} operation applied to lane elements. 1456 * The implementation is not required to return same 1457 * results as {@link Math#pow}, but adheres to rounding, monotonicity, 1458 * and special case semantics as defined in the {@link Math#pow} 1459 * specifications. The computed result will be within 1 ulp of the 1460 * exact result. 1461 * 1462 * @param v the input vector 1463 * @return this vector raised to the power of an input vector 1464 */ 1465 public $abstractvectortype$ pow(Vector<$Boxtype$> v) { 1466 return bOp(v, (i, a, b) -> ($type$) Math.pow((double) a, (double) b)); 1467 } 1468 1469 /** 1470 * Calculates this vector raised to the power of the broadcast of an input 1471 * scalar. 1472 * <p> 1473 * This is a vector binary operation with same semantic definition as 1474 * {@link Math#pow} operation applied to lane elements. 1475 * The implementation is not required to return same 1476 * results as {@link Math#pow}, but adheres to rounding, monotonicity, 1477 * and special case semantics as defined in the {@link Math#pow} 1478 * specifications. The computed result will be within 1 ulp of the 1479 * exact result. 1480 * 1481 * @param s the input scalar 1482 * @return this vector raised to the power of the broadcast of an input 1483 * scalar. 1484 */ 1485 public abstract $abstractvectortype$ pow($type$ s); 1486 1487 /** 1488 * Calculates this vector raised to the power of an input vector, selecting 1489 * lane elements controlled by a mask. 1490 * <p> 1491 * Semantics for rounding, monotonicity, and special cases are 1492 * described in {@link $abstractvectortype$#pow} 1493 * 1494 * @param v the input vector 1495 * @param m the mask controlling lane selection 1496 * @return this vector raised to the power of an input vector 1497 */ 1498 public $abstractvectortype$ pow(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 1499 return bOp(v, m, (i, a, b) -> ($type$) Math.pow((double) a, (double) b)); 1500 } 1501 1502 /** 1503 * Calculates this vector raised to the power of the broadcast of an input 1504 * scalar, selecting lane elements controlled by a mask. 1505 * <p> 1506 * Semantics for rounding, monotonicity, and special cases are 1507 * described in {@link $abstractvectortype$#pow} 1508 * 1509 * @param s the input scalar 1510 * @param m the mask controlling lane selection 1511 * @return this vector raised to the power of the broadcast of an input 1512 * scalar. 1513 */ 1514 public abstract $abstractvectortype$ pow($type$ s, Mask<$Boxtype$> m); 1515 1516 /** 1517 * Calculates the broadcast of Euler's number {@code e} raised to the power 1518 * of this vector. 1519 * <p> 1520 * This is a vector unary operation with same semantic definition as 1521 * {@link Math#exp} operation applied to lane elements. 1522 * The implementation is not required to return same 1523 * results as {@link Math#exp}, but adheres to rounding, monotonicity, 1524 * and special case semantics as defined in the {@link Math#exp} 1525 * specifications. The computed result will be within 1 ulp of the 1526 * exact result. 1527 * 1528 * @return the broadcast of Euler's number {@code e} raised to the power of 1529 * this vector 1530 */ 1531 public $abstractvectortype$ exp() { 1532 return uOp((i, a) -> ($type$) Math.exp((double) a)); 1533 } 1534 1535 /** 1536 * Calculates the broadcast of Euler's number {@code e} raised to the power 1537 * of this vector, selecting lane elements controlled by a mask. 1538 * <p> 1539 * Semantics for rounding, monotonicity, and special cases are 1540 * described in {@link $abstractvectortype$#exp} 1541 * 1542 * @param m the mask controlling lane selection 1543 * @return the broadcast of Euler's number {@code e} raised to the power of 1544 * this vector 1545 */ 1546 public $abstractvectortype$ exp(Mask<$Boxtype$> m) { 1547 return uOp(m, (i, a) -> ($type$) Math.exp((double) a)); 1548 } 1549 1550 /** 1551 * Calculates the broadcast of Euler's number {@code e} raised to the power 1552 * of this vector minus the broadcast of {@code -1}. 1553 * More specifically as if the following (ignoring any differences in 1554 * numerical accuracy): 1555 * <pre>{@code 1556 * this.exp().sub(this.species().broadcast(1)) 1557 * }</pre> 1558 * <p> 1559 * This is a vector unary operation with same semantic definition as 1560 * {@link Math#expm1} operation applied to lane elements. 1561 * The implementation is not required to return same 1562 * results as {@link Math#expm1}, but adheres to rounding, monotonicity, 1563 * and special case semantics as defined in the {@link Math#expm1} 1564 * specifications. The computed result will be within 1 ulp of the 1565 * exact result. 1566 * 1567 * @return the broadcast of Euler's number {@code e} raised to the power of 1568 * this vector minus the broadcast of {@code -1} 1569 */ 1570 public $abstractvectortype$ expm1() { 1571 return uOp((i, a) -> ($type$) Math.expm1((double) a)); 1572 } 1573 1574 /** 1575 * Calculates the broadcast of Euler's number {@code e} raised to the power 1576 * of this vector minus the broadcast of {@code -1}, selecting lane elements 1577 * controlled by a mask 1578 * More specifically as if the following (ignoring any differences in 1579 * numerical accuracy): 1580 * <pre>{@code 1581 * this.exp(m).sub(this.species().broadcast(1), m) 1582 * }</pre> 1583 * <p> 1584 * Semantics for rounding, monotonicity, and special cases are 1585 * described in {@link $abstractvectortype$#expm1} 1586 * 1587 * @param m the mask controlling lane selection 1588 * @return the broadcast of Euler's number {@code e} raised to the power of 1589 * this vector minus the broadcast of {@code -1} 1590 */ 1591 public $abstractvectortype$ expm1(Mask<$Boxtype$> m) { 1592 return uOp(m, (i, a) -> ($type$) Math.expm1((double) a)); 1593 } 1594 1595 /** 1596 * Calculates the product of this vector and a first input vector summed 1597 * with a second input vector. 1598 * More specifically as if the following (ignoring any differences in 1599 * numerical accuracy): 1600 * <pre>{@code 1601 * this.mul(v1).add(v2) 1602 * }</pre> 1603 * <p> 1604 * This is a vector ternary operation where the {@link Math#fma} operation 1605 * is applied to lane elements. 1606 * 1607 * @param v1 the first input vector 1608 * @param v2 the second input vector 1609 * @return the product of this vector and the first input vector summed with 1610 * the second input vector 1611 */ 1612 public abstract $abstractvectortype$ fma(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2); 1613 1614 /** 1615 * Calculates the product of this vector and the broadcast of a first input 1616 * scalar summed with the broadcast of a second input scalar. 1617 * More specifically as if the following: 1618 * <pre>{@code 1619 * this.fma(this.species().broadcast(s1), this.species().broadcast(s2)) 1620 * }</pre> 1621 * <p> 1622 * This is a vector ternary operation where the {@link Math#fma} operation 1623 * is applied to lane elements. 1624 * 1625 * @param s1 the first input scalar 1626 * @param s2 the second input scalar 1627 * @return the product of this vector and the broadcast of a first input 1628 * scalar summed with the broadcast of a second input scalar 1629 */ 1630 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2); 1631 1632 /** 1633 * Calculates the product of this vector and a first input vector summed 1634 * with a second input vector, selecting lane elements controlled by a mask. 1635 * More specifically as if the following (ignoring any differences in 1636 * numerical accuracy): 1637 * <pre>{@code 1638 * this.mul(v1, m).add(v2, m) 1639 * }</pre> 1640 * <p> 1641 * This is a vector ternary operation where the {@link Math#fma} operation 1642 * is applied to lane elements. 1643 * 1644 * @param v1 the first input vector 1645 * @param v2 the second input vector 1646 * @param m the mask controlling lane selection 1647 * @return the product of this vector and the first input vector summed with 1648 * the second input vector 1649 */ 1650 public $abstractvectortype$ fma(Vector<$Boxtype$> v1, Vector<$Boxtype$> v2, Mask<$Boxtype$> m) { 1651 return tOp(v1, v2, m, (i, a, b, c) -> Math.fma(a, b, c)); 1652 } 1653 1654 /** 1655 * Calculates the product of this vector and the broadcast of a first input 1656 * scalar summed with the broadcast of a second input scalar, selecting lane 1657 * elements controlled by a mask 1658 * More specifically as if the following: 1659 * <pre>{@code 1660 * this.fma(this.species().broadcast(s1), this.species().broadcast(s2), m) 1661 * }</pre> 1662 * <p> 1663 * This is a vector ternary operation where the {@link Math#fma} operation 1664 * is applied to lane elements. 1665 * 1666 * @param s1 the first input scalar 1667 * @param s2 the second input scalar 1668 * @param m the mask controlling lane selection 1669 * @return the product of this vector and the broadcast of a first input 1670 * scalar summed with the broadcast of a second input scalar 1671 */ 1672 public abstract $abstractvectortype$ fma($type$ s1, $type$ s2, Mask<$Boxtype$> m); 1673 1674 /** 1675 * Calculates square root of the sum of the squares of this vector and an 1676 * input vector. 1677 * More specifically as if the following (ignoring any differences in 1678 * numerical accuracy): 1679 * <pre>{@code 1680 * this.mul(this).add(v.mul(v)).sqrt() 1681 * }</pre> 1682 * <p> 1683 * This is a vector binary operation with same semantic definition as 1684 * {@link Math#hypot} operation applied to lane elements. 1685 * The implementation is not required to return same 1686 * results as {@link Math#hypot}, but adheres to rounding, monotonicity, 1687 * and special case semantics as defined in the {@link Math#hypot} 1688 * specifications. The computed result will be within 1 ulp of the 1689 * exact result. 1690 * 1691 * @param v the input vector 1692 * @return square root of the sum of the squares of this vector and an input 1693 * vector 1694 */ 1695 public $abstractvectortype$ hypot(Vector<$Boxtype$> v) { 1696 return bOp(v, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b)); 1697 } 1698 1699 /** 1700 * Calculates square root of the sum of the squares of this vector and the 1701 * broadcast of an input scalar. 1702 * More specifically as if the following (ignoring any differences in 1703 * numerical accuracy): 1704 * <pre>{@code 1705 * this.mul(this).add(this.species().broadcast(v * v)).sqrt() 1706 * }</pre> 1707 * <p> 1708 * This is a vector binary operation with same semantic definition as 1709 * {@link Math#hypot} operation applied to lane elements. 1710 * The implementation is not required to return same 1711 * results as {@link Math#hypot}, but adheres to rounding, monotonicity, 1712 * and special case semantics as defined in the {@link Math#hypot} 1713 * specifications. The computed result will be within 1 ulp of the 1714 * exact result. 1715 * 1716 * @param s the input scalar 1717 * @return square root of the sum of the squares of this vector and the 1718 * broadcast of an input scalar 1719 */ 1720 public abstract $abstractvectortype$ hypot($type$ s); 1721 1722 /** 1723 * Calculates square root of the sum of the squares of this vector and an 1724 * input vector, selecting lane elements controlled by a mask. 1725 * More specifically as if the following (ignoring any differences in 1726 * numerical accuracy): 1727 * <pre>{@code 1728 * this.mul(this, m).add(v.mul(v), m).sqrt(m) 1729 * }</pre> 1730 * <p> 1731 * Semantics for rounding, monotonicity, and special cases are 1732 * described in {@link $abstractvectortype$#hypot} 1733 * 1734 * @param v the input vector 1735 * @param m the mask controlling lane selection 1736 * @return square root of the sum of the squares of this vector and an input 1737 * vector 1738 */ 1739 public $abstractvectortype$ hypot(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 1740 return bOp(v, m, (i, a, b) -> ($type$) Math.hypot((double) a, (double) b)); 1741 } 1742 1743 /** 1744 * Calculates square root of the sum of the squares of this vector and the 1745 * broadcast of an input scalar, selecting lane elements controlled by a 1746 * mask. 1747 * More specifically as if the following (ignoring any differences in 1748 * numerical accuracy): 1749 * <pre>{@code 1750 * this.mul(this, m).add(this.species().broadcast(v * v), m).sqrt(m) 1751 * }</pre> 1752 * <p> 1753 * Semantics for rounding, monotonicity, and special cases are 1754 * described in {@link $abstractvectortype$#hypot} 1755 * 1756 * @param s the input scalar 1757 * @param m the mask controlling lane selection 1758 * @return square root of the sum of the squares of this vector and the 1759 * broadcast of an input scalar 1760 */ 1761 public abstract $abstractvectortype$ hypot($type$ s, Mask<$Boxtype$> m); 1762 #end[FP] 1763 1764 #if[BITWISE] 1765 1766 /** 1767 * Bitwise ANDs this vector with an input vector. 1768 * <p> 1769 * This is a vector binary operation where the primitive bitwise AND 1770 * operation ({@code &}) is applied to lane elements. 1771 * 1772 * @param v the input vector 1773 * @return the bitwise AND of this vector with the input vector 1774 */ 1775 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v); 1776 1777 /** 1778 * Bitwise ANDs this vector with the broadcast of an input scalar. 1779 * <p> 1780 * This is a vector binary operation where the primitive bitwise AND 1781 * operation ({@code &}) is applied to lane elements. 1782 * 1783 * @param s the input scalar 1784 * @return the bitwise AND of this vector with the broadcast of an input 1785 * scalar 1786 */ 1787 public abstract $abstractvectortype$ and($type$ s); 1788 1789 /** 1790 * Bitwise ANDs this vector with an input vector, selecting lane elements 1791 * controlled by a mask. 1792 * <p> 1793 * This is a vector binary operation where the primitive bitwise AND 1794 * operation ({@code &}) is applied to lane elements. 1795 * 1796 * @param v the input vector 1797 * @param m the mask controlling lane selection 1798 * @return the bitwise AND of this vector with the input vector 1799 */ 1800 public abstract $abstractvectortype$ and(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 1801 1802 /** 1803 * Bitwise ANDs this vector with the broadcast of an input scalar, selecting 1804 * lane elements controlled by a mask. 1805 * <p> 1806 * This is a vector binary operation where the primitive bitwise AND 1807 * operation ({@code &}) is applied to lane elements. 1808 * 1809 * @param s the input scalar 1810 * @param m the mask controlling lane selection 1811 * @return the bitwise AND of this vector with the broadcast of an input 1812 * scalar 1813 */ 1814 public abstract $abstractvectortype$ and($type$ s, Mask<$Boxtype$> m); 1815 1816 /** 1817 * Bitwise ORs this vector with an input vector. 1818 * <p> 1819 * This is a vector binary operation where the primitive bitwise OR 1820 * operation ({@code |}) is applied to lane elements. 1821 * 1822 * @param v the input vector 1823 * @return the bitwise OR of this vector with the input vector 1824 */ 1825 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v); 1826 1827 /** 1828 * Bitwise ORs this vector with the broadcast of an input scalar. 1829 * <p> 1830 * This is a vector binary operation where the primitive bitwise OR 1831 * operation ({@code |}) is applied to lane elements. 1832 * 1833 * @param s the input scalar 1834 * @return the bitwise OR of this vector with the broadcast of an input 1835 * scalar 1836 */ 1837 public abstract $abstractvectortype$ or($type$ s); 1838 1839 /** 1840 * Bitwise ORs this vector with an input vector, selecting lane elements 1841 * controlled by a mask. 1842 * <p> 1843 * This is a vector binary operation where the primitive bitwise OR 1844 * operation ({@code |}) is applied to lane elements. 1845 * 1846 * @param v the input vector 1847 * @param m the mask controlling lane selection 1848 * @return the bitwise OR of this vector with the input vector 1849 */ 1850 public abstract $abstractvectortype$ or(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 1851 1852 /** 1853 * Bitwise ORs this vector with the broadcast of an input scalar, selecting 1854 * lane elements controlled by a mask. 1855 * <p> 1856 * This is a vector binary operation where the primitive bitwise OR 1857 * operation ({@code |}) is applied to lane elements. 1858 * 1859 * @param s the input scalar 1860 * @param m the mask controlling lane selection 1861 * @return the bitwise OR of this vector with the broadcast of an input 1862 * scalar 1863 */ 1864 public abstract $abstractvectortype$ or($type$ s, Mask<$Boxtype$> m); 1865 1866 /** 1867 * Bitwise XORs this vector with an input vector. 1868 * <p> 1869 * This is a vector binary operation where the primitive bitwise XOR 1870 * operation ({@code ^}) is applied to lane elements. 1871 * 1872 * @param v the input vector 1873 * @return the bitwise XOR of this vector with the input vector 1874 */ 1875 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v); 1876 1877 /** 1878 * Bitwise XORs this vector with the broadcast of an input scalar. 1879 * <p> 1880 * This is a vector binary operation where the primitive bitwise XOR 1881 * operation ({@code ^}) is applied to lane elements. 1882 * 1883 * @param s the input scalar 1884 * @return the bitwise XOR of this vector with the broadcast of an input 1885 * scalar 1886 */ 1887 public abstract $abstractvectortype$ xor($type$ s); 1888 1889 /** 1890 * Bitwise XORs this vector with an input vector, selecting lane elements 1891 * controlled by a mask. 1892 * <p> 1893 * This is a vector binary operation where the primitive bitwise XOR 1894 * operation ({@code ^}) is applied to lane elements. 1895 * 1896 * @param v the input vector 1897 * @param m the mask controlling lane selection 1898 * @return the bitwise XOR of this vector with the input vector 1899 */ 1900 public abstract $abstractvectortype$ xor(Vector<$Boxtype$> v, Mask<$Boxtype$> m); 1901 1902 /** 1903 * Bitwise XORs this vector with the broadcast of an input scalar, selecting 1904 * lane elements controlled by a mask. 1905 * <p> 1906 * This is a vector binary operation where the primitive bitwise XOR 1907 * operation ({@code ^}) is applied to lane elements. 1908 * 1909 * @param s the input scalar 1910 * @param m the mask controlling lane selection 1911 * @return the bitwise XOR of this vector with the broadcast of an input 1912 * scalar 1913 */ 1914 public abstract $abstractvectortype$ xor($type$ s, Mask<$Boxtype$> m); 1915 1916 /** 1917 * Bitwise NOTs this vector. 1918 * <p> 1919 * This is a vector unary operation where the primitive bitwise NOT 1920 * operation ({@code ~}) is applied to lane elements. 1921 * 1922 * @return the bitwise NOT of this vector 1923 */ 1924 public abstract $abstractvectortype$ not(); 1925 1926 /** 1927 * Bitwise NOTs this vector, selecting lane elements controlled by a mask. 1928 * <p> 1929 * This is a vector unary operation where the primitive bitwise NOT 1930 * operation ({@code ~}) is applied to lane elements. 1931 * 1932 * @param m the mask controlling lane selection 1933 * @return the bitwise NOT of this vector 1934 */ 1935 public abstract $abstractvectortype$ not(Mask<$Boxtype$> m); 1936 1937 #if[byte] 1938 /** 1939 * Logically left shifts this vector by the broadcast of an input scalar. 1940 * <p> 1941 * This is a vector binary operation where the primitive logical left shift 1942 * operation ({@code <<}) is applied to lane elements to left shift the 1943 * element by shift value as specified by the input scalar. Only the 3 1944 * lowest-order bits of shift value are used. It is as if the shift value 1945 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 1946 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 1947 * 1948 * @param s the input scalar; the number of the bits to left shift 1949 * @return the result of logically left shifting left this vector by the 1950 * broadcast of an input scalar 1951 */ 1952 #end[byte] 1953 #if[short] 1954 /** 1955 * Logically left shifts this vector by the broadcast of an input scalar. 1956 * <p> 1957 * This is a vector binary operation where the primitive logical left shift 1958 * operation ({@code <<}) is applied to lane elements to left shift the 1959 * element by shift value as specified by the input scalar. Only the 4 1960 * lowest-order bits of shift value are used. It is as if the shift value 1961 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 1962 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 1963 * 1964 * @param s the input scalar; the number of the bits to left shift 1965 * @return the result of logically left shifting left this vector by the 1966 * broadcast of an input scalar 1967 */ 1968 #end[short] 1969 #if[intOrLong] 1970 /** 1971 * Logically left shifts this vector by the broadcast of an input scalar. 1972 * <p> 1973 * This is a vector binary operation where the primitive logical left shift 1974 * operation ({@code <<}) is applied to lane elements. 1975 * 1976 * @param s the input scalar; the number of the bits to left shift 1977 * @return the result of logically left shifting left this vector by the 1978 * broadcast of an input scalar 1979 */ 1980 #end[intOrLong] 1981 public abstract $abstractvectortype$ shiftL(int s); 1982 1983 #if[byte] 1984 /** 1985 * Logically left shifts this vector by the broadcast of an input scalar, 1986 * selecting lane elements controlled by a mask. 1987 * <p> 1988 * This is a vector binary operation where the primitive logical left shift 1989 * operation ({@code <<}) is applied to lane elements to left shift the 1990 * element by shift value as specified by the input scalar. Only the 3 1991 * lowest-order bits of shift value are used. It is as if the shift value 1992 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 1993 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 1994 * 1995 * @param s the input scalar; the number of the bits to left shift 1996 * @param m the mask controlling lane selection 1997 * @return the result of logically left shifting left this vector by the 1998 * broadcast of an input scalar 1999 */ 2000 #end[byte] 2001 #if[short] 2002 /** 2003 * Logically left shifts this vector by the broadcast of an input scalar, 2004 * selecting lane elements controlled by a mask. 2005 * <p> 2006 * This is a vector binary operation where the primitive logical left shift 2007 * operation ({@code <<}) is applied to lane elements to left shift the 2008 * element by shift value as specified by the input scalar. Only the 4 2009 * lowest-order bits of shift value are used. It is as if the shift value 2010 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 2011 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 2012 * 2013 * @param s the input scalar; the number of the bits to left shift 2014 * @param m the mask controlling lane selection 2015 * @return the result of logically left shifting left this vector by the 2016 * broadcast of an input scalar 2017 */ 2018 #end[short] 2019 #if[intOrLong] 2020 /** 2021 * Logically left shifts this vector by the broadcast of an input scalar, 2022 * selecting lane elements controlled by a mask. 2023 * <p> 2024 * This is a vector binary operation where the primitive logical left shift 2025 * operation ({@code <<}) is applied to lane elements. 2026 * 2027 * @param s the input scalar; the number of the bits to left shift 2028 * @param m the mask controlling lane selection 2029 * @return the result of logically left shifting this vector by the 2030 * broadcast of an input scalar 2031 */ 2032 #end[intOrLong] 2033 public abstract $abstractvectortype$ shiftL(int s, Mask<$Boxtype$> m); 2034 2035 #if[intOrLong] 2036 /** 2037 * Logically left shifts this vector by an input vector. 2038 * <p> 2039 * This is a vector binary operation where the primitive logical left shift 2040 * operation ({@code <<}) is applied to lane elements. 2041 * 2042 * @param v the input vector 2043 * @return the result of logically left shifting this vector by the input 2044 * vector 2045 */ 2046 public abstract $abstractvectortype$ shiftL(Vector<$Boxtype$> v); 2047 2048 /** 2049 * Logically left shifts this vector by an input vector, selecting lane 2050 * elements controlled by a mask. 2051 * <p> 2052 * This is a vector binary operation where the primitive logical left shift 2053 * operation ({@code <<}) is applied to lane elements. 2054 * 2055 * @param v the input vector 2056 * @param m the mask controlling lane selection 2057 * @return the result of logically left shifting this vector by the input 2058 * vector 2059 */ 2060 public $abstractvectortype$ shiftL(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 2061 return bOp(v, m, (i, a, b) -> ($type$) (a << b)); 2062 } 2063 #end[intOrLong] 2064 2065 // logical, or unsigned, shift right 2066 2067 #if[byte] 2068 /** 2069 * Logically right shifts (or unsigned right shifts) this vector by the 2070 * broadcast of an input scalar. 2071 * <p> 2072 * This is a vector binary operation where the primitive logical right shift 2073 * operation ({@code >>>}) is applied to lane elements to logically right shift the 2074 * element by shift value as specified by the input scalar. Only the 3 2075 * lowest-order bits of shift value are used. It is as if the shift value 2076 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 2077 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 2078 * 2079 * @param s the input scalar; the number of the bits to right shift 2080 * @return the result of logically right shifting this vector by the 2081 * broadcast of an input scalar 2082 */ 2083 #end[byte] 2084 #if[short] 2085 /** 2086 * Logically right shifts (or unsigned right shifts) this vector by the 2087 * broadcast of an input scalar. 2088 * <p> 2089 * This is a vector binary operation where the primitive logical right shift 2090 * operation ({@code >>>}) is applied to lane elements to logically right shift the 2091 * element by shift value as specified by the input scalar. Only the 4 2092 * lowest-order bits of shift value are used. It is as if the shift value 2093 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 2094 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 2095 * 2096 * @param s the input scalar; the number of the bits to right shift 2097 * @return the result of logically right shifting this vector by the 2098 * broadcast of an input scalar 2099 */ 2100 #end[short] 2101 #if[intOrLong] 2102 /** 2103 * Logically right shifts (or unsigned right shifts) this vector by the 2104 * broadcast of an input scalar. 2105 * <p> 2106 * This is a vector binary operation where the primitive logical right shift 2107 * operation ({@code >>>}) is applied to lane elements. 2108 * 2109 * @param s the input scalar; the number of the bits to right shift 2110 * @return the result of logically right shifting this vector by the 2111 * broadcast of an input scalar 2112 */ 2113 #end[intOrLong] 2114 public abstract $abstractvectortype$ shiftR(int s); 2115 2116 #if[byte] 2117 /** 2118 * Logically right shifts (or unsigned right shifts) this vector by the 2119 * broadcast of an input scalar, selecting lane elements controlled by a 2120 * mask. 2121 * <p> 2122 * This is a vector binary operation where the primitive logical right shift 2123 * operation ({@code >>>}) is applied to lane elements to logically right shift the 2124 * element by shift value as specified by the input scalar. Only the 3 2125 * lowest-order bits of shift value are used. It is as if the shift value 2126 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 2127 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 2128 * 2129 * @param s the input scalar; the number of the bits to right shift 2130 * @param m the mask controlling lane selection 2131 * @return the result of logically right shifting this vector by the 2132 * broadcast of an input scalar 2133 */ 2134 #end[byte] 2135 #if[short] 2136 /** 2137 * Logically right shifts (or unsigned right shifts) this vector by the 2138 * broadcast of an input scalar, selecting lane elements controlled by a 2139 * mask. 2140 * <p> 2141 * This is a vector binary operation where the primitive logical right shift 2142 * operation ({@code >>>}) is applied to lane elements to logically right shift the 2143 * element by shift value as specified by the input scalar. Only the 4 2144 * lowest-order bits of shift value are used. It is as if the shift value 2145 * were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 2146 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 2147 * 2148 * @param s the input scalar; the number of the bits to right shift 2149 * @param m the mask controlling lane selection 2150 * @return the result of logically right shifting this vector by the 2151 * broadcast of an input scalar 2152 */ 2153 #end[short] 2154 #if[intOrLong] 2155 /** 2156 * Logically right shifts (or unsigned right shifts) this vector by the 2157 * broadcast of an input scalar, selecting lane elements controlled by a 2158 * mask. 2159 * <p> 2160 * This is a vector binary operation where the primitive logical right shift 2161 * operation ({@code >>>}) is applied to lane elements. 2162 * 2163 * @param s the input scalar; the number of the bits to right shift 2164 * @param m the mask controlling lane selection 2165 * @return the result of logically right shifting this vector by the 2166 * broadcast of an input scalar 2167 */ 2168 #end[intOrLong] 2169 public abstract $abstractvectortype$ shiftR(int s, Mask<$Boxtype$> m); 2170 2171 #if[intOrLong] 2172 /** 2173 * Logically right shifts (or unsigned right shifts) this vector by an 2174 * input vector. 2175 * <p> 2176 * This is a vector binary operation where the primitive logical right shift 2177 * operation ({@code >>>}) is applied to lane elements. 2178 * 2179 * @param v the input vector 2180 * @return the result of logically right shifting this vector by the 2181 * input vector 2182 */ 2183 public abstract $abstractvectortype$ shiftR(Vector<$Boxtype$> v); 2184 2185 /** 2186 * Logically right shifts (or unsigned right shifts) this vector by an 2187 * input vector, selecting lane elements controlled by a mask. 2188 * <p> 2189 * This is a vector binary operation where the primitive logical right shift 2190 * operation ({@code >>>}) is applied to lane elements. 2191 * 2192 * @param v the input vector 2193 * @param m the mask controlling lane selection 2194 * @return the result of logically right shifting this vector by the 2195 * input vector 2196 */ 2197 public $abstractvectortype$ shiftR(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 2198 return bOp(v, m, (i, a, b) -> ($type$) (a >>> b)); 2199 } 2200 #end[intOrLong] 2201 2202 #if[byte] 2203 /** 2204 * Arithmetically right shifts (or signed right shifts) this vector by the 2205 * broadcast of an input scalar. 2206 * <p> 2207 * This is a vector binary operation where the primitive arithmetic right 2208 * shift operation ({@code >>}) is applied to lane elements to arithmetically 2209 * right shift the element by shift value as specified by the input scalar. 2210 * Only the 3 lowest-order bits of shift value are used. It is as if the shift 2211 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 2212 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 2213 * 2214 * @param s the input scalar; the number of the bits to right shift 2215 * @return the result of arithmetically right shifting this vector by the 2216 * broadcast of an input scalar 2217 */ 2218 #end[byte] 2219 #if[short] 2220 /** 2221 * Arithmetically right shifts (or signed right shifts) this vector by the 2222 * broadcast of an input scalar. 2223 * <p> 2224 * This is a vector binary operation where the primitive arithmetic right 2225 * shift operation ({@code >>}) is applied to lane elements to arithmetically 2226 * right shift the element by shift value as specified by the input scalar. 2227 * Only the 4 lowest-order bits of shift value are used. It is as if the shift 2228 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 2229 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 2230 * 2231 * @param s the input scalar; the number of the bits to right shift 2232 * @return the result of arithmetically right shifting this vector by the 2233 * broadcast of an input scalar 2234 */ 2235 #end[short] 2236 #if[intOrLong] 2237 /** 2238 * Arithmetically right shifts (or signed right shifts) this vector by the 2239 * broadcast of an input scalar. 2240 * <p> 2241 * This is a vector binary operation where the primitive arithmetic right 2242 * shift operation ({@code >>}) is applied to lane elements. 2243 * 2244 * @param s the input scalar; the number of the bits to right shift 2245 * @return the result of arithmetically right shifting this vector by the 2246 * broadcast of an input scalar 2247 */ 2248 #end[intOrLong] 2249 public abstract $abstractvectortype$ aShiftR(int s); 2250 2251 #if[byte] 2252 /** 2253 * Arithmetically right shifts (or signed right shifts) this vector by the 2254 * broadcast of an input scalar, selecting lane elements controlled by a 2255 * mask. 2256 * <p> 2257 * This is a vector binary operation where the primitive arithmetic right 2258 * shift operation ({@code >>}) is applied to lane elements to arithmetically 2259 * right shift the element by shift value as specified by the input scalar. 2260 * Only the 3 lowest-order bits of shift value are used. It is as if the shift 2261 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0x7. 2262 * The shift distance actually used is therefore always in the range 0 to 7, inclusive. 2263 * 2264 * @param s the input scalar; the number of the bits to right shift 2265 * @param m the mask controlling lane selection 2266 * @return the result of arithmetically right shifting this vector by the 2267 * broadcast of an input scalar 2268 */ 2269 #end[byte] 2270 #if[short] 2271 /** 2272 * Arithmetically right shifts (or signed right shifts) this vector by the 2273 * broadcast of an input scalar, selecting lane elements controlled by a 2274 * mask. 2275 * <p> 2276 * This is a vector binary operation where the primitive arithmetic right 2277 * shift operation ({@code >>}) is applied to lane elements to arithmetically 2278 * right shift the element by shift value as specified by the input scalar. 2279 * Only the 4 lowest-order bits of shift value are used. It is as if the shift 2280 * value were subjected to a bitwise logical AND operator ({@code &}) with the mask value 0xF. 2281 * The shift distance actually used is therefore always in the range 0 to 15, inclusive. 2282 * 2283 * @param s the input scalar; the number of the bits to right shift 2284 * @param m the mask controlling lane selection 2285 * @return the result of arithmetically right shifting this vector by the 2286 * broadcast of an input scalar 2287 */ 2288 #end[short] 2289 #if[intOrLong] 2290 /** 2291 * Arithmetically right shifts (or signed right shifts) this vector by the 2292 * broadcast of an input scalar, selecting lane elements controlled by a 2293 * mask. 2294 * <p> 2295 * This is a vector binary operation where the primitive arithmetic right 2296 * shift operation ({@code >>}) is applied to lane elements. 2297 * 2298 * @param s the input scalar; the number of the bits to right shift 2299 * @param m the mask controlling lane selection 2300 * @return the result of arithmetically right shifting this vector by the 2301 * broadcast of an input scalar 2302 */ 2303 #end[intOrLong] 2304 public abstract $abstractvectortype$ aShiftR(int s, Mask<$Boxtype$> m); 2305 2306 #if[intOrLong] 2307 /** 2308 * Arithmetically right shifts (or signed right shifts) this vector by an 2309 * input vector. 2310 * <p> 2311 * This is a vector binary operation where the primitive arithmetic right 2312 * shift operation ({@code >>}) is applied to lane elements. 2313 * 2314 * @param v the input vector 2315 * @return the result of arithmetically right shifting this vector by the 2316 * input vector 2317 */ 2318 public abstract $abstractvectortype$ aShiftR(Vector<$Boxtype$> v); 2319 2320 /** 2321 * Arithmetically right shifts (or signed right shifts) this vector by an 2322 * input vector, selecting lane elements controlled by a mask. 2323 * <p> 2324 * This is a vector binary operation where the primitive arithmetic right 2325 * shift operation ({@code >>}) is applied to lane elements. 2326 * 2327 * @param v the input vector 2328 * @param m the mask controlling lane selection 2329 * @return the result of arithmetically right shifting this vector by the 2330 * input vector 2331 */ 2332 public $abstractvectortype$ aShiftR(Vector<$Boxtype$> v, Mask<$Boxtype$> m) { 2333 return bOp(v, m, (i, a, b) -> ($type$) (a >> b)); 2334 } 2335 2336 /** 2337 * Rotates left this vector by the broadcast of an input scalar. 2338 * <p> 2339 * This is a vector binary operation where the operation 2340 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where 2341 * lane elements of this vector apply to the first argument, and lane 2342 * elements of the broadcast vector apply to the second argument (the 2343 * rotation distance). 2344 * 2345 * @param s the input scalar; the number of the bits to rotate left 2346 * @return the result of rotating left this vector by the broadcast of an 2347 * input scalar 2348 */ 2349 @ForceInline 2350 public final $abstractvectortype$ rotateL(int s) { 2351 return shiftL(s).or(shiftR(-s)); 2352 } 2353 2354 /** 2355 * Rotates left this vector by the broadcast of an input scalar, selecting 2356 * lane elements controlled by a mask. 2357 * <p> 2358 * This is a vector binary operation where the operation 2359 * {@link $Wideboxtype$#rotateLeft} is applied to lane elements and where 2360 * lane elements of this vector apply to the first argument, and lane 2361 * elements of the broadcast vector apply to the second argument (the 2362 * rotation distance). 2363 * 2364 * @param s the input scalar; the number of the bits to rotate left 2365 * @param m the mask controlling lane selection 2366 * @return the result of rotating left this vector by the broadcast of an 2367 * input scalar 2368 */ 2369 @ForceInline 2370 public final $abstractvectortype$ rotateL(int s, Mask<$Boxtype$> m) { 2371 return shiftL(s, m).or(shiftR(-s, m), m); 2372 } 2373 2374 /** 2375 * Rotates right this vector by the broadcast of an input scalar. 2376 * <p> 2377 * This is a vector binary operation where the operation 2378 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where 2379 * lane elements of this vector apply to the first argument, and lane 2380 * elements of the broadcast vector apply to the second argument (the 2381 * rotation distance). 2382 * 2383 * @param s the input scalar; the number of the bits to rotate right 2384 * @return the result of rotating right this vector by the broadcast of an 2385 * input scalar 2386 */ 2387 @ForceInline 2388 public final $abstractvectortype$ rotateR(int s) { 2389 return shiftR(s).or(shiftL(-s)); 2390 } 2391 2392 /** 2393 * Rotates right this vector by the broadcast of an input scalar, selecting 2394 * lane elements controlled by a mask. 2395 * <p> 2396 * This is a vector binary operation where the operation 2397 * {@link $Wideboxtype$#rotateRight} is applied to lane elements and where 2398 * lane elements of this vector apply to the first argument, and lane 2399 * elements of the broadcast vector apply to the second argument (the 2400 * rotation distance). 2401 * 2402 * @param s the input scalar; the number of the bits to rotate right 2403 * @param m the mask controlling lane selection 2404 * @return the result of rotating right this vector by the broadcast of an 2405 * input scalar 2406 */ 2407 @ForceInline 2408 public final $abstractvectortype$ rotateR(int s, Mask<$Boxtype$> m) { 2409 return shiftR(s, m).or(shiftL(-s, m), m); 2410 } 2411 #end[intOrLong] 2412 #end[BITWISE] 2413 2414 @Override 2415 public abstract void intoByteArray(byte[] a, int ix); 2416 2417 @Override 2418 public abstract void intoByteArray(byte[] a, int ix, Mask<$Boxtype$> m); 2419 2420 @Override 2421 public abstract void intoByteBuffer(ByteBuffer bb, int ix); 2422 2423 @Override 2424 public abstract void intoByteBuffer(ByteBuffer bb, int ix, Mask<$Boxtype$> m); 2425 2426 2427 // Type specific horizontal reductions 2428 /** 2429 * Adds all lane elements of this vector. 2430 * <p> 2431 #if[FP] 2432 * This is a vector reduction operation where the addition 2433 * operation ({@code +}) is applied to lane elements, 2434 * and the identity value is {@code 0.0}. 2435 * 2436 * <p>The value of a floating-point sum is a function both of the input values as well 2437 * as the order of addition operations. The order of addition operations of this method 2438 * is intentionally not defined to allow for JVM to generate optimal machine 2439 * code for the underlying platform at runtime. If the platform supports a vector 2440 * instruction to add all values in the vector, or if there is some other efficient machine 2441 * code sequence, then the JVM has the option of generating this machine code. Otherwise, 2442 * the default implementation of adding vectors sequentially from left to right is used. 2443 * For this reason, the output of this method may vary for the same input values. 2444 #else[FP] 2445 * This is an associative vector reduction operation where the addition 2446 * operation ({@code +}) is applied to lane elements, 2447 * and the identity value is {@code 0}. 2448 #end[FP] 2449 * 2450 * @return the addition of all the lane elements of this vector 2451 */ 2452 public abstract $type$ addAll(); 2453 2454 /** 2455 * Adds all lane elements of this vector, selecting lane elements 2456 * controlled by a mask. 2457 * <p> 2458 #if[FP] 2459 * This is a vector reduction operation where the addition 2460 * operation ({@code +}) is applied to lane elements, 2461 * and the identity value is {@code 0.0}. 2462 * 2463 * <p>The value of a floating-point sum is a function both of the input values as well 2464 * as the order of addition operations. The order of addition operations of this method 2465 * is intentionally not defined to allow for JVM to generate optimal machine 2466 * code for the underlying platform at runtime. If the platform supports a vector 2467 * instruction to add all values in the vector, or if there is some other efficient machine 2468 * code sequence, then the JVM has the option of generating this machine code. Otherwise, 2469 * the default implementation of adding vectors sequentially from left to right is used. 2470 * For this reason, the output of this method may vary on the same input values. 2471 #else[FP] 2472 * This is an associative vector reduction operation where the addition 2473 * operation ({@code +}) is applied to lane elements, 2474 * and the identity value is {@code 0}. 2475 #end[FP] 2476 * 2477 * @param m the mask controlling lane selection 2478 * @return the addition of the selected lane elements of this vector 2479 */ 2480 public abstract $type$ addAll(Mask<$Boxtype$> m); 2481 2482 /** 2483 * Multiplies all lane elements of this vector. 2484 * <p> 2485 #if[FP] 2486 * This is a vector reduction operation where the 2487 * multiplication operation ({@code *}) is applied to lane elements, 2488 * and the identity value is {@code 1.0}. 2489 * 2490 * <p>The order of multiplication operations of this method 2491 * is intentionally not defined to allow for JVM to generate optimal machine 2492 * code for the underlying platform at runtime. If the platform supports a vector 2493 * instruction to multiply all values in the vector, or if there is some other efficient machine 2494 * code sequence, then the JVM has the option of generating this machine code. Otherwise, 2495 * the default implementation of multiplying vectors sequentially from left to right is used. 2496 * For this reason, the output of this method may vary on the same input values. 2497 #else[FP] 2498 * This is an associative vector reduction operation where the 2499 * multiplication operation ({@code *}) is applied to lane elements, 2500 * and the identity value is {@code 1}. 2501 #end[FP] 2502 * 2503 * @return the multiplication of all the lane elements of this vector 2504 */ 2505 public abstract $type$ mulAll(); 2506 2507 /** 2508 * Multiplies all lane elements of this vector, selecting lane elements 2509 * controlled by a mask. 2510 * <p> 2511 #if[FP] 2512 * This is a vector reduction operation where the 2513 * multiplication operation ({@code *}) is applied to lane elements, 2514 * and the identity value is {@code 1.0}. 2515 * 2516 * <p>The order of multiplication operations of this method 2517 * is intentionally not defined to allow for JVM to generate optimal machine 2518 * code for the underlying platform at runtime. If the platform supports a vector 2519 * instruction to multiply all values in the vector, or if there is some other efficient machine 2520 * code sequence, then the JVM has the option of generating this machine code. Otherwise, 2521 * the default implementation of multiplying vectors sequentially from left to right is used. 2522 * For this reason, the output of this method may vary on the same input values. 2523 #else[FP] 2524 * This is an associative vector reduction operation where the 2525 * multiplication operation ({@code *}) is applied to lane elements, 2526 * and the identity value is {@code 1}. 2527 #end[FP] 2528 * 2529 * @param m the mask controlling lane selection 2530 * @return the multiplication of all the lane elements of this vector 2531 */ 2532 public abstract $type$ mulAll(Mask<$Boxtype$> m); 2533 2534 /** 2535 * Returns the minimum lane element of this vector. 2536 * <p> 2537 * This is an associative vector reduction operation where the operation 2538 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements, 2539 * and the identity value is 2540 #if[FP] 2541 * {@link $Boxtype$#POSITIVE_INFINITY}. 2542 #else[FP] 2543 * {@link $Boxtype$#MAX_VALUE}. 2544 #end[FP] 2545 * 2546 * @return the minimum lane element of this vector 2547 */ 2548 public abstract $type$ minAll(); 2549 2550 /** 2551 * Returns the minimum lane element of this vector, selecting lane elements 2552 * controlled by a mask. 2553 * <p> 2554 * This is an associative vector reduction operation where the operation 2555 * {@code (a, b) -> Math.min(a, b)} is applied to lane elements, 2556 * and the identity value is 2557 #if[FP] 2558 * {@link $Boxtype$#POSITIVE_INFINITY}. 2559 #else[FP] 2560 * {@link $Boxtype$#MAX_VALUE}. 2561 #end[FP] 2562 * 2563 * @param m the mask controlling lane selection 2564 * @return the minimum lane element of this vector 2565 */ 2566 public abstract $type$ minAll(Mask<$Boxtype$> m); 2567 2568 /** 2569 * Returns the maximum lane element of this vector. 2570 * <p> 2571 * This is an associative vector reduction operation where the operation 2572 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements, 2573 * and the identity value is 2574 #if[FP] 2575 * {@link $Boxtype$#NEGATIVE_INFINITY}. 2576 #else[FP] 2577 * {@link $Boxtype$#MIN_VALUE}. 2578 #end[FP] 2579 * 2580 * @return the maximum lane element of this vector 2581 */ 2582 public abstract $type$ maxAll(); 2583 2584 /** 2585 * Returns the maximum lane element of this vector, selecting lane elements 2586 * controlled by a mask. 2587 * <p> 2588 * This is an associative vector reduction operation where the operation 2589 * {@code (a, b) -> Math.max(a, b)} is applied to lane elements, 2590 * and the identity value is 2591 #if[FP] 2592 * {@link $Boxtype$#NEGATIVE_INFINITY}. 2593 #else[FP] 2594 * {@link $Boxtype$#MIN_VALUE}. 2595 #end[FP] 2596 * 2597 * @param m the mask controlling lane selection 2598 * @return the maximum lane element of this vector 2599 */ 2600 public abstract $type$ maxAll(Mask<$Boxtype$> m); 2601 2602 #if[BITWISE] 2603 /** 2604 * Logically ORs all lane elements of this vector. 2605 * <p> 2606 * This is an associative vector reduction operation where the logical OR 2607 * operation ({@code |}) is applied to lane elements, 2608 * and the identity value is {@code 0}. 2609 * 2610 * @return the logical OR all the lane elements of this vector 2611 */ 2612 public abstract $type$ orAll(); 2613 2614 /** 2615 * Logically ORs all lane elements of this vector, selecting lane elements 2616 * controlled by a mask. 2617 * <p> 2618 * This is an associative vector reduction operation where the logical OR 2619 * operation ({@code |}) is applied to lane elements, 2620 * and the identity value is {@code 0}. 2621 * 2622 * @param m the mask controlling lane selection 2623 * @return the logical OR all the lane elements of this vector 2624 */ 2625 public abstract $type$ orAll(Mask<$Boxtype$> m); 2626 2627 /** 2628 * Logically ANDs all lane elements of this vector. 2629 * <p> 2630 * This is an associative vector reduction operation where the logical AND 2631 * operation ({@code |}) is applied to lane elements, 2632 * and the identity value is {@code -1}. 2633 * 2634 * @return the logical AND all the lane elements of this vector 2635 */ 2636 public abstract $type$ andAll(); 2637 2638 /** 2639 * Logically ANDs all lane elements of this vector, selecting lane elements 2640 * controlled by a mask. 2641 * <p> 2642 * This is an associative vector reduction operation where the logical AND 2643 * operation ({@code |}) is applied to lane elements, 2644 * and the identity value is {@code -1}. 2645 * 2646 * @param m the mask controlling lane selection 2647 * @return the logical AND all the lane elements of this vector 2648 */ 2649 public abstract $type$ andAll(Mask<$Boxtype$> m); 2650 2651 /** 2652 * Logically XORs all lane elements of this vector. 2653 * <p> 2654 * This is an associative vector reduction operation where the logical XOR 2655 * operation ({@code ^}) is applied to lane elements, 2656 * and the identity value is {@code 0}. 2657 * 2658 * @return the logical XOR all the lane elements of this vector 2659 */ 2660 public abstract $type$ xorAll(); 2661 2662 /** 2663 * Logically XORs all lane elements of this vector, selecting lane elements 2664 * controlled by a mask. 2665 * <p> 2666 * This is an associative vector reduction operation where the logical XOR 2667 * operation ({@code ^}) is applied to lane elements, 2668 * and the identity value is {@code 0}. 2669 * 2670 * @param m the mask controlling lane selection 2671 * @return the logical XOR all the lane elements of this vector 2672 */ 2673 public abstract $type$ xorAll(Mask<$Boxtype$> m); 2674 #end[BITWISE] 2675 2676 // Type specific accessors 2677 2678 /** 2679 * Gets the lane element at lane index {@code i} 2680 * 2681 * @param i the lane index 2682 * @return the lane element at lane index {@code i} 2683 * @throws IllegalArgumentException if the index is is out of range 2684 * ({@code < 0 || >= length()}) 2685 */ 2686 public abstract $type$ get(int i); 2687 2688 /** 2689 * Replaces the lane element of this vector at lane index {@code i} with 2690 * value {@code e}. 2691 * <p> 2692 * This is a cross-lane operation and behaves as if it returns the result 2693 * of blending this vector with an input vector that is the result of 2694 * broadcasting {@code e} and a mask that has only one lane set at lane 2695 * index {@code i}. 2696 * 2697 * @param i the lane index of the lane element to be replaced 2698 * @param e the value to be placed 2699 * @return the result of replacing the lane element of this vector at lane 2700 * index {@code i} with value {@code e}. 2701 * @throws IllegalArgumentException if the index is is out of range 2702 * ({@code < 0 || >= length()}) 2703 */ 2704 public abstract $abstractvectortype$ with(int i, $type$ e); 2705 2706 // Type specific extractors 2707 2708 /** 2709 * Returns an array containing the lane elements of this vector. 2710 * <p> 2711 * This method behaves as if it {@link #intoArray($type$[], int)} stores} 2712 * this vector into an allocated array and returns the array as follows: 2713 * <pre>{@code 2714 * $type$[] a = new $type$[this.length()]; 2715 * this.intoArray(a, 0); 2716 * return a; 2717 * }</pre> 2718 * 2719 * @return an array containing the the lane elements of this vector 2720 */ 2721 @ForceInline 2722 public final $type$[] toArray() { 2723 $type$[] a = new $type$[species().length()]; 2724 intoArray(a, 0); 2725 return a; 2726 } 2727 2728 /** 2729 * Stores this vector into an array starting at offset. 2730 * <p> 2731 * For each vector lane, where {@code N} is the vector lane index, 2732 * the lane element at index {@code N} is stored into the array at index 2733 * {@code i + N}. 2734 * 2735 * @param a the array 2736 * @param i the offset into the array 2737 * @throws IndexOutOfBoundsException if {@code i < 0}, or 2738 * {@code i > a.length - this.length()} 2739 */ 2740 public abstract void intoArray($type$[] a, int i); 2741 2742 /** 2743 * Stores this vector into an array starting at offset and using a mask. 2744 * <p> 2745 * For each vector lane, where {@code N} is the vector lane index, 2746 * if the mask lane at index {@code N} is set then the lane element at 2747 * index {@code N} is stored into the array index {@code i + N}. 2748 * 2749 * @param a the array 2750 * @param i the offset into the array 2751 * @param m the mask 2752 * @throws IndexOutOfBoundsException if {@code i < 0}, or 2753 * for any vector lane index {@code N} where the mask at lane {@code N} 2754 * is set {@code i >= a.length - N} 2755 */ 2756 public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m); 2757 2758 /** 2759 * Stores this vector into an array using indexes obtained from an index 2760 * map. 2761 * <p> 2762 * For each vector lane, where {@code N} is the vector lane index, the 2763 * lane element at index {@code N} is stored into the array at index 2764 * {@code i + indexMap[j + N]}. 2765 * 2766 * @param a the array 2767 * @param i the offset into the array, may be negative if relative 2768 * indexes in the index map compensate to produce a value within the 2769 * array bounds 2770 * @param indexMap the index map 2771 * @param j the offset into the index map 2772 * @throws IndexOutOfBoundsException if {@code j < 0}, or 2773 * {@code j > indexMap.length - this.length()}, 2774 * or for any vector lane index {@code N} the result of 2775 * {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length} 2776 */ 2777 #if[byteOrShort] 2778 public void intoArray($type$[] a, int i, int[] indexMap, int j) { 2779 forEach((n, e) -> a[i + indexMap[j + n]] = e); 2780 } 2781 #else[byteOrShort] 2782 public abstract void intoArray($type$[] a, int i, int[] indexMap, int j); 2783 #end[byteOrShort] 2784 2785 /** 2786 * Stores this vector into an array using indexes obtained from an index 2787 * map and using a mask. 2788 * <p> 2789 * For each vector lane, where {@code N} is the vector lane index, 2790 * if the mask lane at index {@code N} is set then the lane element at 2791 * index {@code N} is stored into the array at index 2792 * {@code i + indexMap[j + N]}. 2793 * 2794 * @param a the array 2795 * @param i the offset into the array, may be negative if relative 2796 * indexes in the index map compensate to produce a value within the 2797 * array bounds 2798 * @param m the mask 2799 * @param indexMap the index map 2800 * @param j the offset into the index map 2801 * @throws IndexOutOfBoundsException if {@code j < 0}, or 2802 * {@code j > indexMap.length - this.length()}, 2803 * or for any vector lane index {@code N} where the mask at lane 2804 * {@code N} is set the result of {@code i + indexMap[j + N]} is 2805 * {@code < 0} or {@code >= a.length} 2806 */ 2807 #if[byteOrShort] 2808 public void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j) { 2809 forEach(m, (n, e) -> a[i + indexMap[j + n]] = e); 2810 } 2811 #else[byteOrShort] 2812 public abstract void intoArray($type$[] a, int i, Mask<$Boxtype$> m, int[] indexMap, int j); 2813 #end[byteOrShort] 2814 // Species 2815 2816 @Override 2817 public abstract $Type$Species species(); 2818 2819 /** 2820 * Class representing {@link $abstractvectortype$}'s of the same {@link Vector.Shape Shape}. 2821 */ 2822 public static abstract class $Type$Species extends Vector.Species<$Boxtype$> { 2823 interface FOp { 2824 $type$ apply(int i); 2825 } 2826 2827 abstract $abstractvectortype$ op(FOp f); 2828 2829 abstract $abstractvectortype$ op(Mask<$Boxtype$> m, FOp f); 2830 2831 interface FOpm { 2832 boolean apply(int i); 2833 } 2834 2835 abstract Mask<$Boxtype$> opm(FOpm f); 2836 2837 #if[!byteOrShort] 2838 abstract IntVector.IntSpecies indexSpecies(); 2839 #end[!byteOrShort] 2840 2841 2842 // Factories 2843 2844 @Override 2845 public abstract $abstractvectortype$ zero(); 2846 2847 /** 2848 * Returns a vector where all lane elements are set to the primitive 2849 * value {@code e}. 2850 * 2851 * @param e the value 2852 * @return a vector of vector where all lane elements are set to 2853 * the primitive value {@code e} 2854 */ 2855 public abstract $abstractvectortype$ broadcast($type$ e); 2856 2857 /** 2858 * Returns a vector where the first lane element is set to the primtive 2859 * value {@code e}, all other lane elements are set to the default 2860 * value. 2861 * 2862 * @param e the value 2863 * @return a vector where the first lane element is set to the primitive 2864 * value {@code e} 2865 */ 2866 @ForceInline 2867 public final $abstractvectortype$ single($type$ e) { 2868 return zero().with(0, e); 2869 } 2870 2871 /** 2872 * Returns a vector where each lane element is set to a randomly 2873 * generated primitive value. 2874 * 2875 * The semantics are equivalent to calling 2876 #if[FP] 2877 * {@code ThreadLocalRandom#next$Type$}. 2878 #else[FP] 2879 * {@code ($type$)ThreadLocalRandom#nextInt()}. 2880 #end[FP] 2881 * 2882 * @return a vector where each lane elements is set to a randomly 2883 * generated primitive value 2884 */ 2885 #if[intOrLong] 2886 public $abstractvectortype$ random() { 2887 ThreadLocalRandom r = ThreadLocalRandom.current(); 2888 return op(i -> r.next$Type$()); 2889 } 2890 #else[intOrLong] 2891 #if[FP] 2892 public $abstractvectortype$ random() { 2893 ThreadLocalRandom r = ThreadLocalRandom.current(); 2894 return op(i -> r.next$Type$()); 2895 } 2896 #else[FP] 2897 public $abstractvectortype$ random() { 2898 ThreadLocalRandom r = ThreadLocalRandom.current(); 2899 return op(i -> ($type$) r.nextInt()); 2900 } 2901 #end[FP] 2902 #end[intOrLong] 2903 2904 /** 2905 * Returns a vector where each lane element is set to a given 2906 * primitive value. 2907 * <p> 2908 * For each vector lane, where {@code N} is the vector lane index, the 2909 * the primitive value at index {@code N} is placed into the resulting 2910 * vector at lane index {@code N}. 2911 * 2912 * @param es the given primitive values 2913 * @return a vector where each lane element is set to a given primitive 2914 * value 2915 * @throws IndexOutOfBoundsException if {@code es.length < this.length()} 2916 */ 2917 public abstract $abstractvectortype$ scalars($type$... es); 2918 } 2919 2920 /** 2921 * Finds the preferred species for an element type of {@code $type$}. 2922 * <p> 2923 * A preferred species is a species chosen by the platform that has a 2924 * shape of maximal bit size. A preferred species for different element 2925 * types will have the same shape, and therefore vectors, masks, and 2926 * shuffles created from such species will be shape compatible. 2927 * 2928 * @return the preferred species for an element type of {@code $type$} 2929 */ 2930 @SuppressWarnings("unchecked") 2931 public static $Type$Species preferredSpecies() { 2932 return ($Type$Species) Species.ofPreferred($type$.class); 2933 } 2934 2935 /** 2936 * Finds a species for an element type of {@code $type$} and shape. 2937 * 2938 * @param s the shape 2939 * @return a species for an element type of {@code $type$} and shape 2940 * @throws IllegalArgumentException if no such species exists for the shape 2941 */ 2942 @SuppressWarnings("unchecked") 2943 public static $Type$Species species(Vector.Shape s) { 2944 Objects.requireNonNull(s); 2945 switch (s) { 2946 case S_64_BIT: return $Type$64Vector.SPECIES; 2947 case S_128_BIT: return $Type$128Vector.SPECIES; 2948 case S_256_BIT: return $Type$256Vector.SPECIES; 2949 case S_512_BIT: return $Type$512Vector.SPECIES; 2950 case S_Max_BIT: return $Type$MaxVector.SPECIES; 2951 default: throw new IllegalArgumentException("Bad shape: " + s); 2952 } 2953 } 2954 }