1 /*
   2  * Copyright (c) 2018, 2021, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package org.openjdk.bench.jdk.incubator.vector.operation;
  25 
  26 // -- This file was mechanically generated: Do not edit! -- //
  27 
  28 import java.util.concurrent.TimeUnit;
  29 import java.util.function.IntFunction;
  30 
  31 import org.openjdk.jmh.annotations.*;
  32 import org.openjdk.jmh.infra.Blackhole;
  33 
  34 @BenchmarkMode(Mode.Throughput)
  35 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  36 @State(Scope.Benchmark)
  37 @Warmup(iterations = 3, time = 1)
  38 @Measurement(iterations = 5, time = 1)
  39 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  40 public class FloatScalar extends AbstractVectorBenchmark {
  41     static final int INVOC_COUNT = 1; // To align with vector benchmarks.
  42 
  43     @Param("1024")
  44     int size;
  45 
  46     float[] fill(IntFunction<Float> f) {
  47         float[] array = new float[size];
  48         for (int i = 0; i < array.length; i++) {
  49             array[i] = f.apply(i);
  50         }
  51         return array;
  52     }
  53 
  54     static int bits(float e) {
  55         return Float.floatToIntBits(e);
  56     }
  57 
  58     float[] as, bs, cs, rs;
  59     boolean[] ms, mt, rms;
  60     int[] ss;
  61 
  62     @Setup
  63     public void init() {
  64         as = fill(i -> (float)(2*i));
  65         bs = fill(i -> (float)(i+1));
  66         cs = fill(i -> (float)(i+5));
  67         rs = fill(i -> (float)0);
  68         ms = fillMask(size, i -> (i % 2) == 0);
  69         mt = fillMask(size, i -> true);
  70         rms = fillMask(size, i -> false);
  71 
  72         ss = fillInt(size, i -> RANDOM.nextInt(Math.max(i,1)));
  73     }
  74 
  75     final IntFunction<float[]> fa = vl -> as;
  76     final IntFunction<float[]> fb = vl -> bs;
  77     final IntFunction<float[]> fc = vl -> cs;
  78     final IntFunction<float[]> fr = vl -> rs;
  79     final IntFunction<boolean[]> fm = vl -> ms;
  80     final IntFunction<boolean[]> fmt = vl -> mt;
  81     final IntFunction<boolean[]> fmr = vl -> rms;
  82     final IntFunction<int[]> fs = vl -> ss;
  83 
  84     static boolean eq(float a, float b) {
  85         return a == b;
  86     }
  87 
  88     static boolean neq(float a, float b) {
  89         return a != b;
  90     }
  91 
  92     static boolean lt(float a, float b) {
  93         return a < b;
  94     }
  95 
  96     static boolean le(float a, float b) {
  97         return a <= b;
  98     }
  99 
 100     static boolean gt(float a, float b) {
 101         return a > b;
 102     }
 103 
 104     static boolean ge(float a, float b) {
 105         return a >= b;
 106     }
 107 
 108 
 109     @Benchmark
 110     public void ADD(Blackhole bh) {
 111         float[] as = fa.apply(size);
 112         float[] bs = fb.apply(size);
 113         float[] rs = fr.apply(size);
 114 
 115         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 116             for (int i = 0; i < as.length; i++) {
 117                 float a = as[i];
 118                 float b = bs[i];
 119                 rs[i] = (float)(a + b);
 120             }
 121         }
 122 
 123         bh.consume(rs);
 124     }
 125 
 126     @Benchmark
 127     public void ADDMasked(Blackhole bh) {
 128         float[] as = fa.apply(size);
 129         float[] bs = fb.apply(size);
 130         float[] rs = fr.apply(size);
 131         boolean[] ms = fm.apply(size);
 132 
 133         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 134             for (int i = 0; i < as.length; i++) {
 135                 float a = as[i];
 136                 float b = bs[i];
 137                 if (ms[i % ms.length]) {
 138                     rs[i] = (float)(a + b);
 139                 } else {
 140                     rs[i] = a;
 141                 }
 142             }
 143         }
 144         bh.consume(rs);
 145     }
 146 
 147     @Benchmark
 148     public void SUB(Blackhole bh) {
 149         float[] as = fa.apply(size);
 150         float[] bs = fb.apply(size);
 151         float[] rs = fr.apply(size);
 152 
 153         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 154             for (int i = 0; i < as.length; i++) {
 155                 float a = as[i];
 156                 float b = bs[i];
 157                 rs[i] = (float)(a - b);
 158             }
 159         }
 160 
 161         bh.consume(rs);
 162     }
 163 
 164     @Benchmark
 165     public void SUBMasked(Blackhole bh) {
 166         float[] as = fa.apply(size);
 167         float[] bs = fb.apply(size);
 168         float[] rs = fr.apply(size);
 169         boolean[] ms = fm.apply(size);
 170 
 171         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 172             for (int i = 0; i < as.length; i++) {
 173                 float a = as[i];
 174                 float b = bs[i];
 175                 if (ms[i % ms.length]) {
 176                     rs[i] = (float)(a - b);
 177                 } else {
 178                     rs[i] = a;
 179                 }
 180             }
 181         }
 182         bh.consume(rs);
 183     }
 184 
 185     @Benchmark
 186     public void MUL(Blackhole bh) {
 187         float[] as = fa.apply(size);
 188         float[] bs = fb.apply(size);
 189         float[] rs = fr.apply(size);
 190 
 191         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 192             for (int i = 0; i < as.length; i++) {
 193                 float a = as[i];
 194                 float b = bs[i];
 195                 rs[i] = (float)(a * b);
 196             }
 197         }
 198 
 199         bh.consume(rs);
 200     }
 201 
 202     @Benchmark
 203     public void MULMasked(Blackhole bh) {
 204         float[] as = fa.apply(size);
 205         float[] bs = fb.apply(size);
 206         float[] rs = fr.apply(size);
 207         boolean[] ms = fm.apply(size);
 208 
 209         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 210             for (int i = 0; i < as.length; i++) {
 211                 float a = as[i];
 212                 float b = bs[i];
 213                 if (ms[i % ms.length]) {
 214                     rs[i] = (float)(a * b);
 215                 } else {
 216                     rs[i] = a;
 217                 }
 218             }
 219         }
 220         bh.consume(rs);
 221     }
 222 
 223 
 224     @Benchmark
 225     public void DIV(Blackhole bh) {
 226         float[] as = fa.apply(size);
 227         float[] bs = fb.apply(size);
 228         float[] rs = fr.apply(size);
 229 
 230         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 231             for (int i = 0; i < as.length; i++) {
 232                 float a = as[i];
 233                 float b = bs[i];
 234                 rs[i] = (float)(a / b);
 235             }
 236         }
 237 
 238         bh.consume(rs);
 239     }
 240 
 241 
 242 
 243     @Benchmark
 244     public void DIVMasked(Blackhole bh) {
 245         float[] as = fa.apply(size);
 246         float[] bs = fb.apply(size);
 247         float[] rs = fr.apply(size);
 248         boolean[] ms = fm.apply(size);
 249 
 250         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 251             for (int i = 0; i < as.length; i++) {
 252                 float a = as[i];
 253                 float b = bs[i];
 254                 if (ms[i % ms.length]) {
 255                     rs[i] = (float)(a / b);
 256                 } else {
 257                     rs[i] = a;
 258                 }
 259             }
 260         }
 261         bh.consume(rs);
 262     }
 263 
 264 
 265     @Benchmark
 266     public void FIRST_NONZERO(Blackhole bh) {
 267         float[] as = fa.apply(size);
 268         float[] bs = fb.apply(size);
 269         float[] rs = fr.apply(size);
 270 
 271         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 272             for (int i = 0; i < as.length; i++) {
 273                 float a = as[i];
 274                 float b = bs[i];
 275                 rs[i] = (float)(Double.doubleToLongBits(a)!=0?a:b);
 276             }
 277         }
 278 
 279         bh.consume(rs);
 280     }
 281 
 282     @Benchmark
 283     public void FIRST_NONZEROMasked(Blackhole bh) {
 284         float[] as = fa.apply(size);
 285         float[] bs = fb.apply(size);
 286         float[] rs = fr.apply(size);
 287         boolean[] ms = fm.apply(size);
 288 
 289         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 290             for (int i = 0; i < as.length; i++) {
 291                 float a = as[i];
 292                 float b = bs[i];
 293                 if (ms[i % ms.length]) {
 294                     rs[i] = (float)(Double.doubleToLongBits(a)!=0?a:b);
 295                 } else {
 296                     rs[i] = a;
 297                 }
 298             }
 299         }
 300         bh.consume(rs);
 301     }
 302 
 303 
 304 
 305 
 306 
 307 
 308 
 309 
 310 
 311 
 312 
 313 
 314 
 315 
 316 
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 
 326 
 327 
 328 
 329 
 330 
 331 
 332 
 333 
 334 
 335 
 336 
 337 
 338 
 339 
 340 
 341 
 342 
 343 
 344 
 345 
 346 
 347     @Benchmark
 348     public void MIN(Blackhole bh) {
 349         float[] as = fa.apply(size);
 350         float[] bs = fb.apply(size);
 351         float[] rs = fr.apply(size);
 352 
 353         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 354             for (int i = 0; i < as.length; i++) {
 355                 float a = as[i];
 356                 float b = bs[i];
 357                 rs[i] = (float)(Math.min(a, b));
 358             }
 359         }
 360 
 361         bh.consume(rs);
 362     }
 363 
 364     @Benchmark
 365     public void MAX(Blackhole bh) {
 366         float[] as = fa.apply(size);
 367         float[] bs = fb.apply(size);
 368         float[] rs = fr.apply(size);
 369 
 370         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 371             for (int i = 0; i < as.length; i++) {
 372                 float a = as[i];
 373                 float b = bs[i];
 374                 rs[i] = (float)(Math.max(a, b));
 375             }
 376         }
 377 
 378         bh.consume(rs);
 379     }
 380 
 381 
 382 
 383 
 384 
 385 
 386 
 387     @Benchmark
 388     public void ADDLanes(Blackhole bh) {
 389         float[] as = fa.apply(size);
 390         float r = 0;
 391         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 392             r = 0;
 393             for (int i = 0; i < as.length; i++) {
 394                 r += as[i];
 395             }
 396         }
 397         bh.consume(r);
 398     }
 399 
 400     @Benchmark
 401     public void ADDMaskedLanes(Blackhole bh) {
 402         float[] as = fa.apply(size);
 403         boolean[] ms = fm.apply(size);
 404         float r = 0;
 405         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 406             r = 0;
 407             for (int i = 0; i < as.length; i++) {
 408                 if (ms[i % ms.length])
 409                     r += as[i];
 410             }
 411         }
 412         bh.consume(r);
 413     }
 414 
 415     @Benchmark
 416     public void MULLanes(Blackhole bh) {
 417         float[] as = fa.apply(size);
 418         float r = 1;
 419         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 420             r = 1;
 421             for (int i = 0; i < as.length; i++) {
 422                 r *= as[i];
 423             }
 424         }
 425         bh.consume(r);
 426     }
 427 
 428     @Benchmark
 429     public void MULMaskedLanes(Blackhole bh) {
 430         float[] as = fa.apply(size);
 431         boolean[] ms = fm.apply(size);
 432         float r = 1;
 433         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 434             r = 1;
 435             for (int i = 0; i < as.length; i++) {
 436                 if (ms[i % ms.length])
 437                     r *= as[i];
 438             }
 439         }
 440         bh.consume(r);
 441     }
 442 
 443     @Benchmark
 444     public void MINLanes(Blackhole bh) {
 445         float[] as = fa.apply(size);
 446         float r = Float.POSITIVE_INFINITY;
 447         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 448             r = Float.POSITIVE_INFINITY;
 449             for (int i = 0; i < as.length; i++) {
 450                 r = (float)Math.min(r, as[i]);
 451             }
 452         }
 453         bh.consume(r);
 454     }
 455 
 456     @Benchmark
 457     public void MINMaskedLanes(Blackhole bh) {
 458         float[] as = fa.apply(size);
 459         boolean[] ms = fm.apply(size);
 460         float r = Float.POSITIVE_INFINITY;
 461         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 462             r = Float.POSITIVE_INFINITY;
 463             for (int i = 0; i < as.length; i++) {
 464                 if (ms[i % ms.length])
 465                     r = (float)Math.min(r, as[i]);
 466             }
 467         }
 468         bh.consume(r);
 469     }
 470 
 471     @Benchmark
 472     public void MAXLanes(Blackhole bh) {
 473         float[] as = fa.apply(size);
 474         float r = Float.NEGATIVE_INFINITY;
 475         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 476             r = Float.NEGATIVE_INFINITY;
 477             for (int i = 0; i < as.length; i++) {
 478                 r = (float)Math.max(r, as[i]);
 479             }
 480         }
 481         bh.consume(r);
 482     }
 483 
 484     @Benchmark
 485     public void MAXMaskedLanes(Blackhole bh) {
 486         float[] as = fa.apply(size);
 487         boolean[] ms = fm.apply(size);
 488         float r = Float.NEGATIVE_INFINITY;
 489         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 490             r = Float.NEGATIVE_INFINITY;
 491             for (int i = 0; i < as.length; i++) {
 492                 if (ms[i % ms.length])
 493                     r = (float)Math.max(r, as[i]);
 494             }
 495         }
 496         bh.consume(r);
 497     }
 498 
 499 
 500 
 501     @Benchmark
 502     public void IS_DEFAULT(Blackhole bh) {
 503         float[] as = fa.apply(size);
 504         boolean r = true;
 505 
 506         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 507             for (int i = 0; i < as.length; i++) {
 508                 float a = as[i];
 509                 r &= (bits(a)==0); // accumulate so JIT can't eliminate the computation
 510             }
 511         }
 512 
 513         bh.consume(r);
 514     }
 515 
 516     @Benchmark
 517     public void IS_NEGATIVE(Blackhole bh) {
 518         float[] as = fa.apply(size);
 519         boolean r = true;
 520 
 521         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 522             for (int i = 0; i < as.length; i++) {
 523                 float a = as[i];
 524                 r &= (bits(a)<0); // accumulate so JIT can't eliminate the computation
 525             }
 526         }
 527 
 528         bh.consume(r);
 529     }
 530 
 531 
 532     @Benchmark
 533     public void IS_FINITE(Blackhole bh) {
 534         float[] as = fa.apply(size);
 535         boolean r = true;
 536 
 537         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 538             for (int i = 0; i < as.length; i++) {
 539                 float a = as[i];
 540                 r &= (Float.isFinite(a)); // accumulate so JIT can't eliminate the computation
 541             }
 542         }
 543 
 544         bh.consume(r);
 545     }
 546 
 547 
 548 
 549     @Benchmark
 550     public void IS_NAN(Blackhole bh) {
 551         float[] as = fa.apply(size);
 552         boolean r = true;
 553 
 554         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 555             for (int i = 0; i < as.length; i++) {
 556                 float a = as[i];
 557                 r &= (Float.isNaN(a)); // accumulate so JIT can't eliminate the computation
 558             }
 559         }
 560 
 561         bh.consume(r);
 562     }
 563 
 564 
 565 
 566     @Benchmark
 567     public void IS_INFINITE(Blackhole bh) {
 568         float[] as = fa.apply(size);
 569         boolean r = true;
 570 
 571         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 572             for (int i = 0; i < as.length; i++) {
 573                 float a = as[i];
 574                 r &= (Float.isInfinite(a)); // accumulate so JIT can't eliminate the computation
 575             }
 576         }
 577 
 578         bh.consume(r);
 579     }
 580 
 581 
 582     @Benchmark
 583     public void LT(Blackhole bh) {
 584         float[] as = fa.apply(size);
 585         float[] bs = fb.apply(size);
 586         boolean r = true;
 587 
 588         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 589             for (int i = 0; i < as.length; i++) {
 590                 r &= lt(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 591             }
 592         }
 593 
 594         bh.consume(r);
 595     }
 596 
 597     @Benchmark
 598     public void GT(Blackhole bh) {
 599         float[] as = fa.apply(size);
 600         float[] bs = fb.apply(size);
 601         boolean r = true;
 602 
 603         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 604             for (int i = 0; i < as.length; i++) {
 605                 r &= gt(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 606             }
 607         }
 608 
 609         bh.consume(r);
 610     }
 611 
 612     @Benchmark
 613     public void EQ(Blackhole bh) {
 614         float[] as = fa.apply(size);
 615         float[] bs = fb.apply(size);
 616         boolean r = true;
 617 
 618         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 619             for (int i = 0; i < as.length; i++) {
 620                 r &= eq(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 621             }
 622         }
 623 
 624         bh.consume(r);
 625     }
 626 
 627     @Benchmark
 628     public void NE(Blackhole bh) {
 629         float[] as = fa.apply(size);
 630         float[] bs = fb.apply(size);
 631         boolean r = true;
 632 
 633         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 634             for (int i = 0; i < as.length; i++) {
 635                 r &= neq(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 636             }
 637         }
 638 
 639         bh.consume(r);
 640     }
 641 
 642     @Benchmark
 643     public void LE(Blackhole bh) {
 644         float[] as = fa.apply(size);
 645         float[] bs = fb.apply(size);
 646         boolean r = true;
 647 
 648         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 649             for (int i = 0; i < as.length; i++) {
 650                 r &= le(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 651             }
 652         }
 653 
 654         bh.consume(r);
 655     }
 656 
 657     @Benchmark
 658     public void GE(Blackhole bh) {
 659         float[] as = fa.apply(size);
 660         float[] bs = fb.apply(size);
 661         boolean r = true;
 662 
 663         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 664             for (int i = 0; i < as.length; i++) {
 665                 r &= ge(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 666             }
 667         }
 668 
 669         bh.consume(r);
 670     }
 671 
 672 
 673 
 674 
 675 
 676     @Benchmark
 677     public void blend(Blackhole bh) {
 678         float[] as = fa.apply(size);
 679         float[] bs = fb.apply(size);
 680         float[] rs = fr.apply(size);
 681         boolean[] ms = fm.apply(size);
 682 
 683         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 684             for (int i = 0; i < as.length; i++) {
 685                 float a = as[i];
 686                 float b = bs[i];
 687                 boolean m = ms[i % ms.length];
 688                 rs[i] = (m ? b : a);
 689             }
 690         }
 691 
 692         bh.consume(rs);
 693     }
 694     void rearrangeShared(int window, Blackhole bh) {
 695         float[] as = fa.apply(size);
 696         int[] order = fs.apply(size);
 697         float[] rs = fr.apply(size);
 698 
 699         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 700             for (int i = 0; i < as.length; i += window) {
 701                 for (int j = 0; j < window; j++) {
 702                     float a = as[i+j];
 703                     int pos = order[j];
 704                     rs[i + pos] = a;
 705                 }
 706             }
 707         }
 708 
 709         bh.consume(rs);
 710     }
 711 
 712     @Benchmark
 713     public void rearrange064(Blackhole bh) {
 714         int window = 64 / Float.SIZE;
 715         rearrangeShared(window, bh);
 716     }
 717 
 718     @Benchmark
 719     public void rearrange128(Blackhole bh) {
 720         int window = 128 / Float.SIZE;
 721         rearrangeShared(window, bh);
 722     }
 723 
 724     @Benchmark
 725     public void rearrange256(Blackhole bh) {
 726         int window = 256 / Float.SIZE;
 727         rearrangeShared(window, bh);
 728     }
 729 
 730     @Benchmark
 731     public void rearrange512(Blackhole bh) {
 732         int window = 512 / Float.SIZE;
 733         rearrangeShared(window, bh);
 734     }
 735     void broadcastShared(int window, Blackhole bh) {
 736         float[] as = fa.apply(size);
 737         float[] rs = fr.apply(size);
 738 
 739         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 740             for (int i = 0; i < as.length; i += window) {
 741                 int idx = i;
 742                 for (int j = 0; j < window; j++) {
 743                     rs[j] = as[idx];
 744                 }
 745             }
 746         }
 747 
 748         bh.consume(rs);
 749     }
 750 
 751     @Benchmark
 752     public void broadcast064(Blackhole bh) {
 753         int window = 64 / Float.SIZE;
 754         broadcastShared(window, bh);
 755     }
 756 
 757     @Benchmark
 758     public void broadcast128(Blackhole bh) {
 759         int window = 128 / Float.SIZE;
 760         broadcastShared(window, bh);
 761     }
 762 
 763     @Benchmark
 764     public void broadcast256(Blackhole bh) {
 765         int window = 256 / Float.SIZE;
 766         broadcastShared(window, bh);
 767     }
 768 
 769     @Benchmark
 770     public void broadcast512(Blackhole bh) {
 771         int window = 512 / Float.SIZE;
 772         broadcastShared(window, bh);
 773     }
 774 
 775     @Benchmark
 776     public void zero(Blackhole bh) {
 777         float[] as = fa.apply(size);
 778 
 779         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 780             for (int i = 0; i < as.length; i++) {
 781                 as[i] = (float)0;
 782             }
 783         }
 784 
 785         bh.consume(as);
 786     }
 787 
 788 
 789     @Benchmark
 790     public void SIN(Blackhole bh) {
 791         float[] as = fa.apply(size);
 792         float[] rs = fr.apply(size);
 793 
 794         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 795             for (int i = 0; i < as.length; i++) {
 796                 float a = as[i];
 797                 rs[i] = (float)(Math.sin((double)a));
 798             }
 799         }
 800 
 801         bh.consume(rs);
 802     }
 803 
 804 
 805 
 806     @Benchmark
 807     public void EXP(Blackhole bh) {
 808         float[] as = fa.apply(size);
 809         float[] rs = fr.apply(size);
 810 
 811         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 812             for (int i = 0; i < as.length; i++) {
 813                 float a = as[i];
 814                 rs[i] = (float)(Math.exp((double)a));
 815             }
 816         }
 817 
 818         bh.consume(rs);
 819     }
 820 
 821 
 822 
 823     @Benchmark
 824     public void LOG1P(Blackhole bh) {
 825         float[] as = fa.apply(size);
 826         float[] rs = fr.apply(size);
 827 
 828         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 829             for (int i = 0; i < as.length; i++) {
 830                 float a = as[i];
 831                 rs[i] = (float)(Math.log1p((double)a));
 832             }
 833         }
 834 
 835         bh.consume(rs);
 836     }
 837 
 838 
 839 
 840     @Benchmark
 841     public void LOG(Blackhole bh) {
 842         float[] as = fa.apply(size);
 843         float[] rs = fr.apply(size);
 844 
 845         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 846             for (int i = 0; i < as.length; i++) {
 847                 float a = as[i];
 848                 rs[i] = (float)(Math.log((double)a));
 849             }
 850         }
 851 
 852         bh.consume(rs);
 853     }
 854 
 855 
 856 
 857     @Benchmark
 858     public void LOG10(Blackhole bh) {
 859         float[] as = fa.apply(size);
 860         float[] rs = fr.apply(size);
 861 
 862         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 863             for (int i = 0; i < as.length; i++) {
 864                 float a = as[i];
 865                 rs[i] = (float)(Math.log10((double)a));
 866             }
 867         }
 868 
 869         bh.consume(rs);
 870     }
 871 
 872 
 873 
 874     @Benchmark
 875     public void EXPM1(Blackhole bh) {
 876         float[] as = fa.apply(size);
 877         float[] rs = fr.apply(size);
 878 
 879         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 880             for (int i = 0; i < as.length; i++) {
 881                 float a = as[i];
 882                 rs[i] = (float)(Math.expm1((double)a));
 883             }
 884         }
 885 
 886         bh.consume(rs);
 887     }
 888 
 889 
 890 
 891     @Benchmark
 892     public void COS(Blackhole bh) {
 893         float[] as = fa.apply(size);
 894         float[] rs = fr.apply(size);
 895 
 896         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 897             for (int i = 0; i < as.length; i++) {
 898                 float a = as[i];
 899                 rs[i] = (float)(Math.cos((double)a));
 900             }
 901         }
 902 
 903         bh.consume(rs);
 904     }
 905 
 906 
 907 
 908     @Benchmark
 909     public void TAN(Blackhole bh) {
 910         float[] as = fa.apply(size);
 911         float[] rs = fr.apply(size);
 912 
 913         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 914             for (int i = 0; i < as.length; i++) {
 915                 float a = as[i];
 916                 rs[i] = (float)(Math.tan((double)a));
 917             }
 918         }
 919 
 920         bh.consume(rs);
 921     }
 922 
 923 
 924 
 925     @Benchmark
 926     public void SINH(Blackhole bh) {
 927         float[] as = fa.apply(size);
 928         float[] rs = fr.apply(size);
 929 
 930         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 931             for (int i = 0; i < as.length; i++) {
 932                 float a = as[i];
 933                 rs[i] = (float)(Math.sinh((double)a));
 934             }
 935         }
 936 
 937         bh.consume(rs);
 938     }
 939 
 940 
 941 
 942     @Benchmark
 943     public void COSH(Blackhole bh) {
 944         float[] as = fa.apply(size);
 945         float[] rs = fr.apply(size);
 946 
 947         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 948             for (int i = 0; i < as.length; i++) {
 949                 float a = as[i];
 950                 rs[i] = (float)(Math.cosh((double)a));
 951             }
 952         }
 953 
 954         bh.consume(rs);
 955     }
 956 
 957 
 958 
 959     @Benchmark
 960     public void TANH(Blackhole bh) {
 961         float[] as = fa.apply(size);
 962         float[] rs = fr.apply(size);
 963 
 964         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 965             for (int i = 0; i < as.length; i++) {
 966                 float a = as[i];
 967                 rs[i] = (float)(Math.tanh((double)a));
 968             }
 969         }
 970 
 971         bh.consume(rs);
 972     }
 973 
 974 
 975 
 976     @Benchmark
 977     public void ASIN(Blackhole bh) {
 978         float[] as = fa.apply(size);
 979         float[] rs = fr.apply(size);
 980 
 981         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 982             for (int i = 0; i < as.length; i++) {
 983                 float a = as[i];
 984                 rs[i] = (float)(Math.asin((double)a));
 985             }
 986         }
 987 
 988         bh.consume(rs);
 989     }
 990 
 991 
 992 
 993     @Benchmark
 994     public void ACOS(Blackhole bh) {
 995         float[] as = fa.apply(size);
 996         float[] rs = fr.apply(size);
 997 
 998         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 999             for (int i = 0; i < as.length; i++) {
1000                 float a = as[i];
1001                 rs[i] = (float)(Math.acos((double)a));
1002             }
1003         }
1004 
1005         bh.consume(rs);
1006     }
1007 
1008 
1009 
1010     @Benchmark
1011     public void ATAN(Blackhole bh) {
1012         float[] as = fa.apply(size);
1013         float[] rs = fr.apply(size);
1014 
1015         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1016             for (int i = 0; i < as.length; i++) {
1017                 float a = as[i];
1018                 rs[i] = (float)(Math.atan((double)a));
1019             }
1020         }
1021 
1022         bh.consume(rs);
1023     }
1024 
1025 
1026 
1027     @Benchmark
1028     public void CBRT(Blackhole bh) {
1029         float[] as = fa.apply(size);
1030         float[] rs = fr.apply(size);
1031 
1032         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1033             for (int i = 0; i < as.length; i++) {
1034                 float a = as[i];
1035                 rs[i] = (float)(Math.cbrt((double)a));
1036             }
1037         }
1038 
1039         bh.consume(rs);
1040     }
1041 
1042 
1043 
1044     @Benchmark
1045     public void HYPOT(Blackhole bh) {
1046         float[] as = fa.apply(size);
1047         float[] bs = fb.apply(size);
1048         float[] rs = fr.apply(size);
1049 
1050         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1051             for (int i = 0; i < as.length; i++) {
1052                 float a = as[i];
1053                 float b = bs[i];
1054                 rs[i] = (float)(Math.hypot((double)a, (double)b));
1055             }
1056         }
1057 
1058         bh.consume(rs);
1059     }
1060 
1061 
1062 
1063     @Benchmark
1064     public void POW(Blackhole bh) {
1065         float[] as = fa.apply(size);
1066         float[] bs = fb.apply(size);
1067         float[] rs = fr.apply(size);
1068 
1069         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1070             for (int i = 0; i < as.length; i++) {
1071                 float a = as[i];
1072                 float b = bs[i];
1073                 rs[i] = (float)(Math.pow((double)a, (double)b));
1074             }
1075         }
1076 
1077         bh.consume(rs);
1078     }
1079 
1080 
1081 
1082     @Benchmark
1083     public void ATAN2(Blackhole bh) {
1084         float[] as = fa.apply(size);
1085         float[] bs = fb.apply(size);
1086         float[] rs = fr.apply(size);
1087 
1088         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1089             for (int i = 0; i < as.length; i++) {
1090                 float a = as[i];
1091                 float b = bs[i];
1092                 rs[i] = (float)(Math.atan2((double)a, (double)b));
1093             }
1094         }
1095 
1096         bh.consume(rs);
1097     }
1098 
1099 
1100 
1101     @Benchmark
1102     public void FMA(Blackhole bh) {
1103         float[] as = fa.apply(size);
1104         float[] bs = fb.apply(size);
1105         float[] cs = fc.apply(size);
1106         float[] rs = fr.apply(size);
1107 
1108         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1109             for (int i = 0; i < as.length; i++) {
1110                 float a = as[i];
1111                 float b = bs[i];
1112                 float c = cs[i];
1113                 rs[i] = (float)(Math.fma(a, b, c));
1114             }
1115         }
1116 
1117         bh.consume(rs);
1118     }
1119 
1120 
1121 
1122 
1123     @Benchmark
1124     public void FMAMasked(Blackhole bh) {
1125         float[] as = fa.apply(size);
1126         float[] bs = fb.apply(size);
1127         float[] cs = fc.apply(size);
1128         float[] rs = fr.apply(size);
1129         boolean[] ms = fm.apply(size);
1130 
1131         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1132             for (int i = 0; i < as.length; i++) {
1133                 float a = as[i];
1134                 float b = bs[i];
1135                 float c = cs[i];
1136                 if (ms[i % ms.length]) {
1137                     rs[i] = (float)(Math.fma(a, b, c));
1138                 } else {
1139                     rs[i] = a;
1140                 }
1141             }
1142         }
1143         bh.consume(rs);
1144     }
1145 
1146 
1147 
1148 
1149     @Benchmark
1150     public void NEG(Blackhole bh) {
1151         float[] as = fa.apply(size);
1152         float[] rs = fr.apply(size);
1153 
1154         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1155             for (int i = 0; i < as.length; i++) {
1156                 float a = as[i];
1157                 rs[i] = (float)(-((float)a));
1158             }
1159         }
1160 
1161         bh.consume(rs);
1162     }
1163 
1164     @Benchmark
1165     public void NEGMasked(Blackhole bh) {
1166         float[] as = fa.apply(size);
1167         float[] rs = fr.apply(size);
1168         boolean[] ms = fm.apply(size);
1169 
1170         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1171             for (int i = 0; i < as.length; i++) {
1172                 float a = as[i];
1173                 boolean m = ms[i % ms.length];
1174                 rs[i] = (m ? (float)(-((float)a)) : a);
1175             }
1176         }
1177 
1178         bh.consume(rs);
1179     }
1180 
1181     @Benchmark
1182     public void ABS(Blackhole bh) {
1183         float[] as = fa.apply(size);
1184         float[] rs = fr.apply(size);
1185 
1186         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1187             for (int i = 0; i < as.length; i++) {
1188                 float a = as[i];
1189                 rs[i] = (float)(Math.abs((float)a));
1190             }
1191         }
1192 
1193         bh.consume(rs);
1194     }
1195 
1196     @Benchmark
1197     public void ABSMasked(Blackhole bh) {
1198         float[] as = fa.apply(size);
1199         float[] rs = fr.apply(size);
1200         boolean[] ms = fm.apply(size);
1201 
1202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1203             for (int i = 0; i < as.length; i++) {
1204                 float a = as[i];
1205                 boolean m = ms[i % ms.length];
1206                 rs[i] = (m ? (float)(Math.abs((float)a)) : a);
1207             }
1208         }
1209 
1210         bh.consume(rs);
1211     }
1212 
1213 
1214 
1215 
1216 
1217 
1218     @Benchmark
1219     public void SQRT(Blackhole bh) {
1220         float[] as = fa.apply(size);
1221         float[] rs = fr.apply(size);
1222 
1223         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1224             for (int i = 0; i < as.length; i++) {
1225                 float a = as[i];
1226                 rs[i] = (float)(Math.sqrt((double)a));
1227             }
1228         }
1229 
1230         bh.consume(rs);
1231     }
1232 
1233 
1234 
1235     @Benchmark
1236     public void SQRTMasked(Blackhole bh) {
1237         float[] as = fa.apply(size);
1238         float[] rs = fr.apply(size);
1239         boolean[] ms = fm.apply(size);
1240 
1241         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1242             for (int i = 0; i < as.length; i++) {
1243                 float a = as[i];
1244                 boolean m = ms[i % ms.length];
1245                 rs[i] = (m ? (float)(Math.sqrt((double)a)) : a);
1246             }
1247         }
1248 
1249         bh.consume(rs);
1250     }
1251 
1252     @Benchmark
1253     public void gatherBase0(Blackhole bh) {
1254         float[] as = fa.apply(size);
1255         int[] is    = fs.apply(size);
1256         float[] rs = fr.apply(size);
1257 
1258         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1259             for (int i = 0; i < as.length; i++) {
1260                 int ix = 0 + is[i];
1261                 rs[i] = as[ix];
1262             }
1263         }
1264 
1265         bh.consume(rs);
1266     }
1267 
1268 
1269     void gather(int window, Blackhole bh) {
1270         float[] as = fa.apply(size);
1271         int[] is    = fs.apply(size);
1272         float[] rs = fr.apply(size);
1273 
1274         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1275             for (int i = 0; i < as.length; i += window) {
1276                 for (int j = 0; j < window; j++) {
1277                     int ix = is[i + j];
1278                     rs[i + j] = as[ix];
1279                 }
1280             }
1281         }
1282 
1283         bh.consume(rs);
1284     }
1285 
1286     @Benchmark
1287     public void gather064(Blackhole bh) {
1288         int window = 64 / Float.SIZE;
1289         gather(window, bh);
1290     }
1291 
1292     @Benchmark
1293     public void gather128(Blackhole bh) {
1294         int window = 128 / Float.SIZE;
1295         gather(window, bh);
1296     }
1297 
1298     @Benchmark
1299     public void gather256(Blackhole bh) {
1300         int window = 256 / Float.SIZE;
1301         gather(window, bh);
1302     }
1303 
1304     @Benchmark
1305     public void gather512(Blackhole bh) {
1306         int window = 512 / Float.SIZE;
1307         gather(window, bh);
1308     }
1309 
1310     @Benchmark
1311     public void scatterBase0(Blackhole bh) {
1312         float[] as = fa.apply(size);
1313         int[] is    = fs.apply(size);
1314         float[] rs = fr.apply(size);
1315 
1316         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1317             for (int i = 0; i < as.length; i++) {
1318                 int ix = 0 + is[i];
1319                 rs[ix] = as[i];
1320             }
1321         }
1322 
1323         bh.consume(rs);
1324     }
1325 
1326     void scatter(int window, Blackhole bh) {
1327         float[] as = fa.apply(size);
1328         int[] is    = fs.apply(size);
1329         float[] rs = fr.apply(size);
1330 
1331         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1332             for (int i = 0; i < as.length; i += window) {
1333                 for (int j = 0; j < window; j++) {
1334                     int ix = is[i + j];
1335                     rs[ix] = as[i + j];
1336                 }
1337             }
1338         }
1339 
1340         bh.consume(rs);
1341     }
1342 
1343     @Benchmark
1344     public void scatter064(Blackhole bh) {
1345         int window = 64 / Float.SIZE;
1346         scatter(window, bh);
1347     }
1348 
1349     @Benchmark
1350     public void scatter128(Blackhole bh) {
1351         int window = 128 / Float.SIZE;
1352         scatter(window, bh);
1353     }
1354 
1355     @Benchmark
1356     public void scatter256(Blackhole bh) {
1357         int window = 256 / Float.SIZE;
1358         scatter(window, bh);
1359     }
1360 
1361     @Benchmark
1362     public void scatter512(Blackhole bh) {
1363         int window = 512 / Float.SIZE;
1364         scatter(window, bh);
1365     }
1366 }
1367