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