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