1 /*
   2  * Copyright (c) 2018, 2024, 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 import jdk.incubator.vector.VectorMath;
  31 
  32 import org.openjdk.jmh.annotations.*;
  33 import org.openjdk.jmh.infra.Blackhole;
  34 
  35 @BenchmarkMode(Mode.Throughput)
  36 @OutputTimeUnit(TimeUnit.MILLISECONDS)
  37 @State(Scope.Benchmark)
  38 @Warmup(iterations = 3, time = 1)
  39 @Measurement(iterations = 5, time = 1)
  40 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
  41 public class DoubleScalar extends AbstractVectorBenchmark {
  42     static final int INVOC_COUNT = 1; // To align with vector benchmarks.
  43 
  44 
  45     @Param("1024")
  46     int size;
  47 
  48     double[] fill(IntFunction<Double> f) {
  49         double[] array = new double[size];
  50         for (int i = 0; i < array.length; i++) {
  51             array[i] = f.apply(i);
  52         }
  53         return array;
  54     }
  55 
  56     static long bits(double e) {
  57         return Double.doubleToLongBits(e);
  58     }
  59 
  60     double[] as, bs, cs, rs;
  61     boolean[] ms, mt, rms;
  62     int[] ss;
  63 
  64     @Setup
  65     public void init() {
  66         as = fill(i -> (double)(2*i));
  67         bs = fill(i -> (double)(i+1));
  68         cs = fill(i -> (double)(i+5));
  69         rs = fill(i -> (double)0);
  70         ms = fillMask(size, i -> (i % 2) == 0);
  71         mt = fillMask(size, i -> true);
  72         rms = fillMask(size, i -> false);
  73 
  74         ss = fillInt(size, i -> RAND.nextInt(Math.max(i,1)));
  75     }
  76 
  77     final IntFunction<double[]> fa = vl -> as;
  78     final IntFunction<double[]> fb = vl -> bs;
  79     final IntFunction<double[]> fc = vl -> cs;
  80     final IntFunction<double[]> fr = vl -> rs;
  81     final IntFunction<boolean[]> fm = vl -> ms;
  82     final IntFunction<boolean[]> fmt = vl -> mt;
  83     final IntFunction<boolean[]> fmr = vl -> rms;
  84     final IntFunction<int[]> fs = vl -> ss;
  85 
  86     static boolean eq(double a, double b) {
  87         return a == b;
  88     }
  89 
  90     static boolean neq(double a, double b) {
  91         return a != b;
  92     }
  93 
  94     static boolean lt(double a, double b) {
  95         return a < b;
  96     }
  97 
  98     static boolean le(double a, double b) {
  99         return a <= b;
 100     }
 101 
 102     static boolean gt(double a, double b) {
 103         return a > b;
 104     }
 105 
 106     static boolean ge(double a, double b) {
 107         return a >= b;
 108     }
 109 
 110 
 111 
 112     @Benchmark
 113     public void ADD(Blackhole bh) {
 114         double[] as = fa.apply(size);
 115         double[] bs = fb.apply(size);
 116         double[] rs = fr.apply(size);
 117 
 118         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 119             for (int i = 0; i < as.length; i++) {
 120                 double a = as[i];
 121                 double b = bs[i];
 122                 rs[i] = (double)(a + b);
 123             }
 124         }
 125 
 126         bh.consume(rs);
 127     }
 128 
 129     @Benchmark
 130     public void ADDMasked(Blackhole bh) {
 131         double[] as = fa.apply(size);
 132         double[] bs = fb.apply(size);
 133         double[] rs = fr.apply(size);
 134         boolean[] ms = fm.apply(size);
 135 
 136         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 137             for (int i = 0; i < as.length; i++) {
 138                 double a = as[i];
 139                 double b = bs[i];
 140                 if (ms[i % ms.length]) {
 141                     rs[i] = (double)(a + b);
 142                 } else {
 143                     rs[i] = a;
 144                 }
 145             }
 146         }
 147         bh.consume(rs);
 148     }
 149 
 150     @Benchmark
 151     public void SUB(Blackhole bh) {
 152         double[] as = fa.apply(size);
 153         double[] bs = fb.apply(size);
 154         double[] rs = fr.apply(size);
 155 
 156         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 157             for (int i = 0; i < as.length; i++) {
 158                 double a = as[i];
 159                 double b = bs[i];
 160                 rs[i] = (double)(a - b);
 161             }
 162         }
 163 
 164         bh.consume(rs);
 165     }
 166 
 167     @Benchmark
 168     public void SUBMasked(Blackhole bh) {
 169         double[] as = fa.apply(size);
 170         double[] bs = fb.apply(size);
 171         double[] rs = fr.apply(size);
 172         boolean[] ms = fm.apply(size);
 173 
 174         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 175             for (int i = 0; i < as.length; i++) {
 176                 double a = as[i];
 177                 double b = bs[i];
 178                 if (ms[i % ms.length]) {
 179                     rs[i] = (double)(a - b);
 180                 } else {
 181                     rs[i] = a;
 182                 }
 183             }
 184         }
 185         bh.consume(rs);
 186     }
 187 
 188     @Benchmark
 189     public void MUL(Blackhole bh) {
 190         double[] as = fa.apply(size);
 191         double[] bs = fb.apply(size);
 192         double[] rs = fr.apply(size);
 193 
 194         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 195             for (int i = 0; i < as.length; i++) {
 196                 double a = as[i];
 197                 double b = bs[i];
 198                 rs[i] = (double)(a * b);
 199             }
 200         }
 201 
 202         bh.consume(rs);
 203     }
 204 
 205     @Benchmark
 206     public void MULMasked(Blackhole bh) {
 207         double[] as = fa.apply(size);
 208         double[] bs = fb.apply(size);
 209         double[] rs = fr.apply(size);
 210         boolean[] ms = fm.apply(size);
 211 
 212         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 213             for (int i = 0; i < as.length; i++) {
 214                 double a = as[i];
 215                 double b = bs[i];
 216                 if (ms[i % ms.length]) {
 217                     rs[i] = (double)(a * b);
 218                 } else {
 219                     rs[i] = a;
 220                 }
 221             }
 222         }
 223         bh.consume(rs);
 224     }
 225 
 226     @Benchmark
 227     public void DIV(Blackhole bh) {
 228         double[] as = fa.apply(size);
 229         double[] bs = fb.apply(size);
 230         double[] rs = fr.apply(size);
 231 
 232         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 233             for (int i = 0; i < as.length; i++) {
 234                 double a = as[i];
 235                 double b = bs[i];
 236                 rs[i] = (double)(a / b);
 237             }
 238         }
 239 
 240         bh.consume(rs);
 241     }
 242 
 243     @Benchmark
 244     public void DIVMasked(Blackhole bh) {
 245         double[] as = fa.apply(size);
 246         double[] bs = fb.apply(size);
 247         double[] 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                 double a = as[i];
 253                 double b = bs[i];
 254                 if (ms[i % ms.length]) {
 255                     rs[i] = (double)(a / b);
 256                 } else {
 257                     rs[i] = a;
 258                 }
 259             }
 260         }
 261         bh.consume(rs);
 262     }
 263 
 264     @Benchmark
 265     public void FIRST_NONZERO(Blackhole bh) {
 266         double[] as = fa.apply(size);
 267         double[] bs = fb.apply(size);
 268         double[] rs = fr.apply(size);
 269 
 270         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 271             for (int i = 0; i < as.length; i++) {
 272                 double a = as[i];
 273                 double b = bs[i];
 274                 rs[i] = (double)(Double.doubleToLongBits(a)!=0?a:b);
 275             }
 276         }
 277 
 278         bh.consume(rs);
 279     }
 280 
 281     @Benchmark
 282     public void FIRST_NONZEROMasked(Blackhole bh) {
 283         double[] as = fa.apply(size);
 284         double[] bs = fb.apply(size);
 285         double[] rs = fr.apply(size);
 286         boolean[] ms = fm.apply(size);
 287 
 288         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 289             for (int i = 0; i < as.length; i++) {
 290                 double a = as[i];
 291                 double b = bs[i];
 292                 if (ms[i % ms.length]) {
 293                     rs[i] = (double)(Double.doubleToLongBits(a)!=0?a:b);
 294                 } else {
 295                     rs[i] = a;
 296                 }
 297             }
 298         }
 299         bh.consume(rs);
 300     }
 301 
 302     @Benchmark
 303     public void MIN(Blackhole bh) {
 304         double[] as = fa.apply(size);
 305         double[] bs = fb.apply(size);
 306         double[] rs = fr.apply(size);
 307 
 308         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 309             for (int i = 0; i < as.length; i++) {
 310                 double a = as[i];
 311                 double b = bs[i];
 312                 rs[i] = (double)(Math.min(a, b));
 313             }
 314         }
 315 
 316         bh.consume(rs);
 317     }
 318 
 319     @Benchmark
 320     public void MAX(Blackhole bh) {
 321         double[] as = fa.apply(size);
 322         double[] bs = fb.apply(size);
 323         double[] rs = fr.apply(size);
 324 
 325         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 326             for (int i = 0; i < as.length; i++) {
 327                 double a = as[i];
 328                 double b = bs[i];
 329                 rs[i] = (double)(Math.max(a, b));
 330             }
 331         }
 332 
 333         bh.consume(rs);
 334     }
 335 
 336     @Benchmark
 337     public void ADDLanes(Blackhole bh) {
 338         double[] as = fa.apply(size);
 339         double r = 0;
 340         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 341             r = 0;
 342             for (int i = 0; i < as.length; i++) {
 343                 r += as[i];
 344             }
 345         }
 346         bh.consume(r);
 347     }
 348 
 349     @Benchmark
 350     public void ADDMaskedLanes(Blackhole bh) {
 351         double[] as = fa.apply(size);
 352         boolean[] ms = fm.apply(size);
 353         double r = 0;
 354         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 355             r = 0;
 356             for (int i = 0; i < as.length; i++) {
 357                 if (ms[i % ms.length])
 358                     r += as[i];
 359             }
 360         }
 361         bh.consume(r);
 362     }
 363 
 364     @Benchmark
 365     public void MULLanes(Blackhole bh) {
 366         double[] as = fa.apply(size);
 367         double r = 1;
 368         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 369             r = 1;
 370             for (int i = 0; i < as.length; i++) {
 371                 r *= as[i];
 372             }
 373         }
 374         bh.consume(r);
 375     }
 376 
 377     @Benchmark
 378     public void MULMaskedLanes(Blackhole bh) {
 379         double[] as = fa.apply(size);
 380         boolean[] ms = fm.apply(size);
 381         double r = 1;
 382         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 383             r = 1;
 384             for (int i = 0; i < as.length; i++) {
 385                 if (ms[i % ms.length])
 386                     r *= as[i];
 387             }
 388         }
 389         bh.consume(r);
 390     }
 391 
 392     @Benchmark
 393     public void IS_DEFAULT(Blackhole bh) {
 394         double[] as = fa.apply(size);
 395         boolean r = true;
 396 
 397         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 398             for (int i = 0; i < as.length; i++) {
 399                 double a = as[i];
 400                 r &= (bits(a)==0); // accumulate so JIT can't eliminate the computation
 401             }
 402         }
 403 
 404         bh.consume(r);
 405     }
 406 
 407     @Benchmark
 408     public void IS_NEGATIVE(Blackhole bh) {
 409         double[] as = fa.apply(size);
 410         boolean r = true;
 411 
 412         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 413             for (int i = 0; i < as.length; i++) {
 414                 double a = as[i];
 415                 r &= (bits(a)<0); // accumulate so JIT can't eliminate the computation
 416             }
 417         }
 418 
 419         bh.consume(r);
 420     }
 421 
 422     @Benchmark
 423     public void IS_FINITE(Blackhole bh) {
 424         double[] as = fa.apply(size);
 425         boolean r = true;
 426 
 427         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 428             for (int i = 0; i < as.length; i++) {
 429                 double a = as[i];
 430                 r &= (Double.isFinite(a)); // accumulate so JIT can't eliminate the computation
 431             }
 432         }
 433 
 434         bh.consume(r);
 435     }
 436 
 437     @Benchmark
 438     public void IS_NAN(Blackhole bh) {
 439         double[] as = fa.apply(size);
 440         boolean r = true;
 441 
 442         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 443             for (int i = 0; i < as.length; i++) {
 444                 double a = as[i];
 445                 r &= (Double.isNaN(a)); // accumulate so JIT can't eliminate the computation
 446             }
 447         }
 448 
 449         bh.consume(r);
 450     }
 451 
 452     @Benchmark
 453     public void IS_INFINITE(Blackhole bh) {
 454         double[] as = fa.apply(size);
 455         boolean r = true;
 456 
 457         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 458             for (int i = 0; i < as.length; i++) {
 459                 double a = as[i];
 460                 r &= (Double.isInfinite(a)); // accumulate so JIT can't eliminate the computation
 461             }
 462         }
 463 
 464         bh.consume(r);
 465     }
 466 
 467     @Benchmark
 468     public void LT(Blackhole bh) {
 469         double[] as = fa.apply(size);
 470         double[] bs = fb.apply(size);
 471         boolean r = true;
 472 
 473         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 474             for (int i = 0; i < as.length; i++) {
 475                 r &= lt(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 476             }
 477         }
 478 
 479         bh.consume(r);
 480     }
 481 
 482     @Benchmark
 483     public void GT(Blackhole bh) {
 484         double[] as = fa.apply(size);
 485         double[] bs = fb.apply(size);
 486         boolean r = true;
 487 
 488         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 489             for (int i = 0; i < as.length; i++) {
 490                 r &= gt(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 491             }
 492         }
 493 
 494         bh.consume(r);
 495     }
 496 
 497     @Benchmark
 498     public void EQ(Blackhole bh) {
 499         double[] as = fa.apply(size);
 500         double[] bs = fb.apply(size);
 501         boolean r = true;
 502 
 503         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 504             for (int i = 0; i < as.length; i++) {
 505                 r &= eq(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 506             }
 507         }
 508 
 509         bh.consume(r);
 510     }
 511 
 512     @Benchmark
 513     public void NE(Blackhole bh) {
 514         double[] as = fa.apply(size);
 515         double[] bs = fb.apply(size);
 516         boolean r = true;
 517 
 518         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 519             for (int i = 0; i < as.length; i++) {
 520                 r &= neq(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 521             }
 522         }
 523 
 524         bh.consume(r);
 525     }
 526 
 527     @Benchmark
 528     public void LE(Blackhole bh) {
 529         double[] as = fa.apply(size);
 530         double[] bs = fb.apply(size);
 531         boolean r = true;
 532 
 533         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 534             for (int i = 0; i < as.length; i++) {
 535                 r &= le(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 536             }
 537         }
 538 
 539         bh.consume(r);
 540     }
 541 
 542     @Benchmark
 543     public void GE(Blackhole bh) {
 544         double[] as = fa.apply(size);
 545         double[] bs = fb.apply(size);
 546         boolean r = true;
 547 
 548         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 549             for (int i = 0; i < as.length; i++) {
 550                 r &= ge(as[i], bs[i]); // accumulate so JIT can't eliminate the computation
 551             }
 552         }
 553 
 554         bh.consume(r);
 555     }
 556 
 557     @Benchmark
 558     public void blend(Blackhole bh) {
 559         double[] as = fa.apply(size);
 560         double[] bs = fb.apply(size);
 561         double[] rs = fr.apply(size);
 562         boolean[] ms = fm.apply(size);
 563 
 564         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 565             for (int i = 0; i < as.length; i++) {
 566                 double a = as[i];
 567                 double b = bs[i];
 568                 boolean m = ms[i % ms.length];
 569                 rs[i] = (m ? b : a);
 570             }
 571         }
 572 
 573         bh.consume(rs);
 574     }
 575 
 576     void rearrangeShared(int window, Blackhole bh) {
 577         double[] as = fa.apply(size);
 578         int[] order = fs.apply(size);
 579         double[] rs = fr.apply(size);
 580 
 581         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 582             for (int i = 0; i < as.length; i += window) {
 583                 for (int j = 0; j < window; j++) {
 584                     double a = as[i+j];
 585                     int pos = order[j];
 586                     rs[i + pos] = a;
 587                 }
 588             }
 589         }
 590 
 591         bh.consume(rs);
 592     }
 593 
 594     @Benchmark
 595     public void rearrange064(Blackhole bh) {
 596         int window = 64 / Double.SIZE;
 597         rearrangeShared(window, bh);
 598     }
 599 
 600     @Benchmark
 601     public void rearrange128(Blackhole bh) {
 602         int window = 128 / Double.SIZE;
 603         rearrangeShared(window, bh);
 604     }
 605 
 606     @Benchmark
 607     public void rearrange256(Blackhole bh) {
 608         int window = 256 / Double.SIZE;
 609         rearrangeShared(window, bh);
 610     }
 611 
 612     @Benchmark
 613     public void rearrange512(Blackhole bh) {
 614         int window = 512 / Double.SIZE;
 615         rearrangeShared(window, bh);
 616     }
 617 
 618     @Benchmark
 619     public void compressScalar(Blackhole bh) {
 620         double[] as = fa.apply(size);
 621         double[] rs = new double[size];
 622         boolean[] im = fmt.apply(size);
 623 
 624         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 625             for (int i = 0, j = 0; i < as.length; i++) {
 626                 if (im[i]) {
 627                     rs[j++] = as[i];
 628                 }
 629             }
 630         }
 631 
 632         bh.consume(rs);
 633     }
 634 
 635     @Benchmark
 636     public void expandScalar(Blackhole bh) {
 637         double[] as = fa.apply(size);
 638         double[] rs = new double[size];
 639         boolean[] im = fmt.apply(size);
 640 
 641         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 642             for (int i = 0, j = 0; i < as.length; i++) {
 643                 if (im[i]) {
 644                     rs[i++] = as[j++];
 645                 }
 646             }
 647         }
 648 
 649         bh.consume(rs);
 650     }
 651 
 652     @Benchmark
 653     public void maskCompressScalar(Blackhole bh) {
 654         boolean[] im = fmt.apply(size);
 655         boolean[] rm = new boolean[size];
 656 
 657         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 658             for (int i = 0, j = 0; i < im.length; i++) {
 659                 if (im[i]) {
 660                     rm[j++] = im[i];
 661                 }
 662             }
 663         }
 664 
 665         bh.consume(rm);
 666     }
 667 
 668     void broadcastShared(int window, Blackhole bh) {
 669         double[] as = fa.apply(size);
 670         double[] rs = fr.apply(size);
 671 
 672         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 673             for (int i = 0; i < as.length; i += window) {
 674                 int idx = i;
 675                 for (int j = 0; j < window; j++) {
 676                     rs[j] = as[idx];
 677                 }
 678             }
 679         }
 680 
 681         bh.consume(rs);
 682     }
 683 
 684     @Benchmark
 685     public void broadcast064(Blackhole bh) {
 686         int window = 64 / Double.SIZE;
 687         broadcastShared(window, bh);
 688     }
 689 
 690     @Benchmark
 691     public void broadcast128(Blackhole bh) {
 692         int window = 128 / Double.SIZE;
 693         broadcastShared(window, bh);
 694     }
 695 
 696     @Benchmark
 697     public void broadcast256(Blackhole bh) {
 698         int window = 256 / Double.SIZE;
 699         broadcastShared(window, bh);
 700     }
 701 
 702     @Benchmark
 703     public void broadcast512(Blackhole bh) {
 704         int window = 512 / Double.SIZE;
 705         broadcastShared(window, bh);
 706     }
 707 
 708     @Benchmark
 709     public void zero(Blackhole bh) {
 710         double[] as = fa.apply(size);
 711 
 712         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 713             for (int i = 0; i < as.length; i++) {
 714                 as[i] = (double)0;
 715             }
 716         }
 717 
 718         bh.consume(as);
 719     }
 720 
 721     @Benchmark
 722     public void SIN(Blackhole bh) {
 723         double[] as = fa.apply(size);
 724         double[] rs = fr.apply(size);
 725 
 726         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 727             for (int i = 0; i < as.length; i++) {
 728                 double a = as[i];
 729                 rs[i] = (double)(Math.sin((double)a));
 730             }
 731         }
 732 
 733         bh.consume(rs);
 734     }
 735 
 736     @Benchmark
 737     public void EXP(Blackhole bh) {
 738         double[] as = fa.apply(size);
 739         double[] rs = fr.apply(size);
 740 
 741         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 742             for (int i = 0; i < as.length; i++) {
 743                 double a = as[i];
 744                 rs[i] = (double)(Math.exp((double)a));
 745             }
 746         }
 747 
 748         bh.consume(rs);
 749     }
 750 
 751     @Benchmark
 752     public void LOG1P(Blackhole bh) {
 753         double[] as = fa.apply(size);
 754         double[] rs = fr.apply(size);
 755 
 756         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 757             for (int i = 0; i < as.length; i++) {
 758                 double a = as[i];
 759                 rs[i] = (double)(Math.log1p((double)a));
 760             }
 761         }
 762 
 763         bh.consume(rs);
 764     }
 765 
 766     @Benchmark
 767     public void LOG(Blackhole bh) {
 768         double[] as = fa.apply(size);
 769         double[] rs = fr.apply(size);
 770 
 771         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 772             for (int i = 0; i < as.length; i++) {
 773                 double a = as[i];
 774                 rs[i] = (double)(Math.log((double)a));
 775             }
 776         }
 777 
 778         bh.consume(rs);
 779     }
 780 
 781     @Benchmark
 782     public void LOG10(Blackhole bh) {
 783         double[] as = fa.apply(size);
 784         double[] rs = fr.apply(size);
 785 
 786         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 787             for (int i = 0; i < as.length; i++) {
 788                 double a = as[i];
 789                 rs[i] = (double)(Math.log10((double)a));
 790             }
 791         }
 792 
 793         bh.consume(rs);
 794     }
 795 
 796     @Benchmark
 797     public void EXPM1(Blackhole bh) {
 798         double[] as = fa.apply(size);
 799         double[] rs = fr.apply(size);
 800 
 801         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 802             for (int i = 0; i < as.length; i++) {
 803                 double a = as[i];
 804                 rs[i] = (double)(Math.expm1((double)a));
 805             }
 806         }
 807 
 808         bh.consume(rs);
 809     }
 810 
 811     @Benchmark
 812     public void COS(Blackhole bh) {
 813         double[] as = fa.apply(size);
 814         double[] rs = fr.apply(size);
 815 
 816         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 817             for (int i = 0; i < as.length; i++) {
 818                 double a = as[i];
 819                 rs[i] = (double)(Math.cos((double)a));
 820             }
 821         }
 822 
 823         bh.consume(rs);
 824     }
 825 
 826     @Benchmark
 827     public void TAN(Blackhole bh) {
 828         double[] as = fa.apply(size);
 829         double[] rs = fr.apply(size);
 830 
 831         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 832             for (int i = 0; i < as.length; i++) {
 833                 double a = as[i];
 834                 rs[i] = (double)(Math.tan((double)a));
 835             }
 836         }
 837 
 838         bh.consume(rs);
 839     }
 840 
 841     @Benchmark
 842     public void SINH(Blackhole bh) {
 843         double[] as = fa.apply(size);
 844         double[] rs = fr.apply(size);
 845 
 846         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 847             for (int i = 0; i < as.length; i++) {
 848                 double a = as[i];
 849                 rs[i] = (double)(Math.sinh((double)a));
 850             }
 851         }
 852 
 853         bh.consume(rs);
 854     }
 855 
 856     @Benchmark
 857     public void COSH(Blackhole bh) {
 858         double[] as = fa.apply(size);
 859         double[] rs = fr.apply(size);
 860 
 861         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 862             for (int i = 0; i < as.length; i++) {
 863                 double a = as[i];
 864                 rs[i] = (double)(Math.cosh((double)a));
 865             }
 866         }
 867 
 868         bh.consume(rs);
 869     }
 870 
 871     @Benchmark
 872     public void TANH(Blackhole bh) {
 873         double[] as = fa.apply(size);
 874         double[] rs = fr.apply(size);
 875 
 876         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 877             for (int i = 0; i < as.length; i++) {
 878                 double a = as[i];
 879                 rs[i] = (double)(Math.tanh((double)a));
 880             }
 881         }
 882 
 883         bh.consume(rs);
 884     }
 885 
 886     @Benchmark
 887     public void ASIN(Blackhole bh) {
 888         double[] as = fa.apply(size);
 889         double[] rs = fr.apply(size);
 890 
 891         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 892             for (int i = 0; i < as.length; i++) {
 893                 double a = as[i];
 894                 rs[i] = (double)(Math.asin((double)a));
 895             }
 896         }
 897 
 898         bh.consume(rs);
 899     }
 900 
 901     @Benchmark
 902     public void ACOS(Blackhole bh) {
 903         double[] as = fa.apply(size);
 904         double[] rs = fr.apply(size);
 905 
 906         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 907             for (int i = 0; i < as.length; i++) {
 908                 double a = as[i];
 909                 rs[i] = (double)(Math.acos((double)a));
 910             }
 911         }
 912 
 913         bh.consume(rs);
 914     }
 915 
 916     @Benchmark
 917     public void ATAN(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.atan((double)a));
 925             }
 926         }
 927 
 928         bh.consume(rs);
 929     }
 930 
 931     @Benchmark
 932     public void CBRT(Blackhole bh) {
 933         double[] as = fa.apply(size);
 934         double[] rs = fr.apply(size);
 935 
 936         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 937             for (int i = 0; i < as.length; i++) {
 938                 double a = as[i];
 939                 rs[i] = (double)(Math.cbrt((double)a));
 940             }
 941         }
 942 
 943         bh.consume(rs);
 944     }
 945 
 946     @Benchmark
 947     public void HYPOT(Blackhole bh) {
 948         double[] as = fa.apply(size);
 949         double[] bs = fb.apply(size);
 950         double[] rs = fr.apply(size);
 951 
 952         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 953             for (int i = 0; i < as.length; i++) {
 954                 double a = as[i];
 955                 double b = bs[i];
 956                 rs[i] = (double)(Math.hypot((double)a, (double)b));
 957             }
 958         }
 959 
 960         bh.consume(rs);
 961     }
 962 
 963     @Benchmark
 964     public void POW(Blackhole bh) {
 965         double[] as = fa.apply(size);
 966         double[] bs = fb.apply(size);
 967         double[] rs = fr.apply(size);
 968 
 969         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 970             for (int i = 0; i < as.length; i++) {
 971                 double a = as[i];
 972                 double b = bs[i];
 973                 rs[i] = (double)(Math.pow((double)a, (double)b));
 974             }
 975         }
 976 
 977         bh.consume(rs);
 978     }
 979 
 980     @Benchmark
 981     public void ATAN2(Blackhole bh) {
 982         double[] as = fa.apply(size);
 983         double[] bs = fb.apply(size);
 984         double[] rs = fr.apply(size);
 985 
 986         for (int ic = 0; ic < INVOC_COUNT; ic++) {
 987             for (int i = 0; i < as.length; i++) {
 988                 double a = as[i];
 989                 double b = bs[i];
 990                 rs[i] = (double)(Math.atan2((double)a, (double)b));
 991             }
 992         }
 993 
 994         bh.consume(rs);
 995     }
 996 
 997     @Benchmark
 998     public void FMA(Blackhole bh) {
 999         double[] as = fa.apply(size);
1000         double[] bs = fb.apply(size);
1001         double[] cs = fc.apply(size);
1002         double[] rs = fr.apply(size);
1003 
1004         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1005             for (int i = 0; i < as.length; i++) {
1006                 double a = as[i];
1007                 double b = bs[i];
1008                 double c = cs[i];
1009                 rs[i] = (double)(Math.fma(a, b, c));
1010             }
1011         }
1012 
1013         bh.consume(rs);
1014     }
1015 
1016     @Benchmark
1017     public void FMAMasked(Blackhole bh) {
1018         double[] as = fa.apply(size);
1019         double[] bs = fb.apply(size);
1020         double[] cs = fc.apply(size);
1021         double[] rs = fr.apply(size);
1022         boolean[] ms = fm.apply(size);
1023 
1024         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1025             for (int i = 0; i < as.length; i++) {
1026                 double a = as[i];
1027                 double b = bs[i];
1028                 double c = cs[i];
1029                 if (ms[i % ms.length]) {
1030                     rs[i] = (double)(Math.fma(a, b, c));
1031                 } else {
1032                     rs[i] = a;
1033                 }
1034             }
1035         }
1036         bh.consume(rs);
1037     }
1038     @Benchmark
1039     public void NEG(Blackhole bh) {
1040         double[] as = fa.apply(size);
1041         double[] rs = fr.apply(size);
1042 
1043         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1044             for (int i = 0; i < as.length; i++) {
1045                 double a = as[i];
1046                 rs[i] = (double)(-((double)a));
1047             }
1048         }
1049 
1050         bh.consume(rs);
1051     }
1052 
1053     @Benchmark
1054     public void NEGMasked(Blackhole bh) {
1055         double[] as = fa.apply(size);
1056         double[] rs = fr.apply(size);
1057         boolean[] ms = fm.apply(size);
1058 
1059         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1060             for (int i = 0; i < as.length; i++) {
1061                 double a = as[i];
1062                 boolean m = ms[i % ms.length];
1063                 rs[i] = (m ? (double)(-((double)a)) : a);
1064             }
1065         }
1066 
1067         bh.consume(rs);
1068     }
1069     @Benchmark
1070     public void ABS(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.abs((double)a));
1078             }
1079         }
1080 
1081         bh.consume(rs);
1082     }
1083 
1084     @Benchmark
1085     public void ABSMasked(Blackhole bh) {
1086         double[] as = fa.apply(size);
1087         double[] rs = fr.apply(size);
1088         boolean[] ms = fm.apply(size);
1089 
1090         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1091             for (int i = 0; i < as.length; i++) {
1092                 double a = as[i];
1093                 boolean m = ms[i % ms.length];
1094                 rs[i] = (m ? (double)(Math.abs((double)a)) : a);
1095             }
1096         }
1097 
1098         bh.consume(rs);
1099     }
1100     @Benchmark
1101     public void SQRT(Blackhole bh) {
1102         double[] as = fa.apply(size);
1103         double[] rs = fr.apply(size);
1104 
1105         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1106             for (int i = 0; i < as.length; i++) {
1107                 double a = as[i];
1108                 rs[i] = (double)(Math.sqrt((double)a));
1109             }
1110         }
1111 
1112         bh.consume(rs);
1113     }
1114 
1115     @Benchmark
1116     public void SQRTMasked(Blackhole bh) {
1117         double[] as = fa.apply(size);
1118         double[] rs = fr.apply(size);
1119         boolean[] ms = fm.apply(size);
1120 
1121         for (int ic = 0; ic < INVOC_COUNT; ic++) {
1122             for (int i = 0; i < as.length; i++) {
1123                 double a = as[i];
1124                 boolean m = ms[i % ms.length];
1125                 rs[i] = (m ? (double)(Math.sqrt((double)a)) : a);
1126             }
1127         }
1128 
1129         bh.consume(rs);
1130     }
1131 }