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 FloatScalar extends AbstractVectorBenchmark { 41 static final int INVOC_COUNT = 1; // To align with vector benchmarks. 42 43 44 @Param("1024") 45 int size; 46 47 float[] fill(IntFunction<Float> f) { 48 float[] array = new float[size]; 49 for (int i = 0; i < array.length; i++) { 50 array[i] = f.apply(i); 51 } 52 return array; 53 } 54 55 static int bits(float e) { 56 return Float.floatToIntBits(e); 57 } 58 59 float[] as, bs, cs, rs; 60 boolean[] ms, mt, rms; 61 int[] ss; 62 63 @Setup 64 public void init() { 65 as = fill(i -> (float)(2*i)); 66 bs = fill(i -> (float)(i+1)); 67 cs = fill(i -> (float)(i+5)); 68 rs = fill(i -> (float)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<float[]> fa = vl -> as; 77 final IntFunction<float[]> fb = vl -> bs; 78 final IntFunction<float[]> fc = vl -> cs; 79 final IntFunction<float[]> 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(float a, float b) { 86 return a == b; 87 } 88 89 static boolean neq(float a, float b) { 90 return a != b; 91 } 92 93 static boolean lt(float a, float b) { 94 return a < b; 95 } 96 97 static boolean le(float a, float b) { 98 return a <= b; 99 } 100 101 static boolean gt(float a, float b) { 102 return a > b; 103 } 104 105 static boolean ge(float a, float b) { 106 return a >= b; 107 } 108 109 110 111 @Benchmark 112 public void ADD(Blackhole bh) { 113 float[] as = fa.apply(size); 114 float[] bs = fb.apply(size); 115 float[] rs = fr.apply(size); 116 117 for (int ic = 0; ic < INVOC_COUNT; ic++) { 118 for (int i = 0; i < as.length; i++) { 119 float a = as[i]; 120 float b = bs[i]; 121 rs[i] = (float)(a + b); 122 } 123 } 124 125 bh.consume(rs); 126 } 127 128 @Benchmark 129 public void ADDMasked(Blackhole bh) { 130 float[] as = fa.apply(size); 131 float[] bs = fb.apply(size); 132 float[] 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 float a = as[i]; 138 float b = bs[i]; 139 if (ms[i % ms.length]) { 140 rs[i] = (float)(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 float[] as = fa.apply(size); 152 float[] bs = fb.apply(size); 153 float[] rs = fr.apply(size); 154 155 for (int ic = 0; ic < INVOC_COUNT; ic++) { 156 for (int i = 0; i < as.length; i++) { 157 float a = as[i]; 158 float b = bs[i]; 159 rs[i] = (float)(a - b); 160 } 161 } 162 163 bh.consume(rs); 164 } 165 166 @Benchmark 167 public void SUBMasked(Blackhole bh) { 168 float[] as = fa.apply(size); 169 float[] bs = fb.apply(size); 170 float[] 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 float a = as[i]; 176 float b = bs[i]; 177 if (ms[i % ms.length]) { 178 rs[i] = (float)(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 float[] as = fa.apply(size); 190 float[] bs = fb.apply(size); 191 float[] rs = fr.apply(size); 192 193 for (int ic = 0; ic < INVOC_COUNT; ic++) { 194 for (int i = 0; i < as.length; i++) { 195 float a = as[i]; 196 float b = bs[i]; 197 rs[i] = (float)(a * b); 198 } 199 } 200 201 bh.consume(rs); 202 } 203 204 @Benchmark 205 public void MULMasked(Blackhole bh) { 206 float[] as = fa.apply(size); 207 float[] bs = fb.apply(size); 208 float[] 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 float a = as[i]; 214 float b = bs[i]; 215 if (ms[i % ms.length]) { 216 rs[i] = (float)(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 float[] as = fa.apply(size); 228 float[] bs = fb.apply(size); 229 float[] rs = fr.apply(size); 230 231 for (int ic = 0; ic < INVOC_COUNT; ic++) { 232 for (int i = 0; i < as.length; i++) { 233 float a = as[i]; 234 float b = bs[i]; 235 rs[i] = (float)(a / b); 236 } 237 } 238 239 bh.consume(rs); 240 } 241 242 @Benchmark 243 public void DIVMasked(Blackhole bh) { 244 float[] as = fa.apply(size); 245 float[] bs = fb.apply(size); 246 float[] 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 float a = as[i]; 252 float b = bs[i]; 253 if (ms[i % ms.length]) { 254 rs[i] = (float)(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 float[] as = fa.apply(size); 266 float[] bs = fb.apply(size); 267 float[] rs = fr.apply(size); 268 269 for (int ic = 0; ic < INVOC_COUNT; ic++) { 270 for (int i = 0; i < as.length; i++) { 271 float a = as[i]; 272 float b = bs[i]; 273 rs[i] = (float)(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 float[] as = fa.apply(size); 283 float[] bs = fb.apply(size); 284 float[] 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 float a = as[i]; 290 float b = bs[i]; 291 if (ms[i % ms.length]) { 292 rs[i] = (float)(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 float[] as = fa.apply(size); 304 float[] bs = fb.apply(size); 305 float[] rs = fr.apply(size); 306 307 for (int ic = 0; ic < INVOC_COUNT; ic++) { 308 for (int i = 0; i < as.length; i++) { 309 float a = as[i]; 310 float b = bs[i]; 311 rs[i] = (float)(Math.min(a, b)); 312 } 313 } 314 315 bh.consume(rs); 316 } 317 318 @Benchmark 319 public void MAX(Blackhole bh) { 320 float[] as = fa.apply(size); 321 float[] bs = fb.apply(size); 322 float[] rs = fr.apply(size); 323 324 for (int ic = 0; ic < INVOC_COUNT; ic++) { 325 for (int i = 0; i < as.length; i++) { 326 float a = as[i]; 327 float b = bs[i]; 328 rs[i] = (float)(Math.max(a, b)); 329 } 330 } 331 332 bh.consume(rs); 333 } 334 335 @Benchmark 336 public void ADDLanes(Blackhole bh) { 337 float[] as = fa.apply(size); 338 float 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 float[] as = fa.apply(size); 351 boolean[] ms = fm.apply(size); 352 float 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 float[] as = fa.apply(size); 366 float 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 float[] as = fa.apply(size); 379 boolean[] ms = fm.apply(size); 380 float 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 float[] 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 float 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 float[] 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 float 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 float[] 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 float a = as[i]; 429 r &= (Float.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 float[] 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 float a = as[i]; 444 r &= (Float.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 float[] 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 float a = as[i]; 459 r &= (Float.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 float[] as = fa.apply(size); 469 float[] 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 float[] as = fa.apply(size); 484 float[] 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 float[] as = fa.apply(size); 499 float[] 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 float[] as = fa.apply(size); 514 float[] 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 float[] as = fa.apply(size); 529 float[] 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 float[] as = fa.apply(size); 544 float[] 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 float[] as = fa.apply(size); 559 float[] bs = fb.apply(size); 560 float[] 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 float a = as[i]; 566 float 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 float[] as = fa.apply(size); 577 int[] order = fs.apply(size); 578 float[] 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 float 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 / Float.SIZE; 596 rearrangeShared(window, bh); 597 } 598 599 @Benchmark 600 public void rearrange128(Blackhole bh) { 601 int window = 128 / Float.SIZE; 602 rearrangeShared(window, bh); 603 } 604 605 @Benchmark 606 public void rearrange256(Blackhole bh) { 607 int window = 256 / Float.SIZE; 608 rearrangeShared(window, bh); 609 } 610 611 @Benchmark 612 public void rearrange512(Blackhole bh) { 613 int window = 512 / Float.SIZE; 614 rearrangeShared(window, bh); 615 } 616 617 @Benchmark 618 public void compressScalar(Blackhole bh) { 619 float[] as = fa.apply(size); 620 float[] rs = new float[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 float[] as = fa.apply(size); 637 float[] rs = new float[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 float[] as = fa.apply(size); 669 float[] 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 / Float.SIZE; 686 broadcastShared(window, bh); 687 } 688 689 @Benchmark 690 public void broadcast128(Blackhole bh) { 691 int window = 128 / Float.SIZE; 692 broadcastShared(window, bh); 693 } 694 695 @Benchmark 696 public void broadcast256(Blackhole bh) { 697 int window = 256 / Float.SIZE; 698 broadcastShared(window, bh); 699 } 700 701 @Benchmark 702 public void broadcast512(Blackhole bh) { 703 int window = 512 / Float.SIZE; 704 broadcastShared(window, bh); 705 } 706 707 @Benchmark 708 public void zero(Blackhole bh) { 709 float[] 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] = (float)0; 714 } 715 } 716 717 bh.consume(as); 718 } 719 720 @Benchmark 721 public void SIN(Blackhole bh) { 722 float[] as = fa.apply(size); 723 float[] rs = fr.apply(size); 724 725 for (int ic = 0; ic < INVOC_COUNT; ic++) { 726 for (int i = 0; i < as.length; i++) { 727 float a = as[i]; 728 rs[i] = (float)(Math.sin((double)a)); 729 } 730 } 731 732 bh.consume(rs); 733 } 734 735 @Benchmark 736 public void EXP(Blackhole bh) { 737 float[] as = fa.apply(size); 738 float[] rs = fr.apply(size); 739 740 for (int ic = 0; ic < INVOC_COUNT; ic++) { 741 for (int i = 0; i < as.length; i++) { 742 float a = as[i]; 743 rs[i] = (float)(Math.exp((double)a)); 744 } 745 } 746 747 bh.consume(rs); 748 } 749 750 @Benchmark 751 public void LOG1P(Blackhole bh) { 752 float[] as = fa.apply(size); 753 float[] rs = fr.apply(size); 754 755 for (int ic = 0; ic < INVOC_COUNT; ic++) { 756 for (int i = 0; i < as.length; i++) { 757 float a = as[i]; 758 rs[i] = (float)(Math.log1p((double)a)); 759 } 760 } 761 762 bh.consume(rs); 763 } 764 765 @Benchmark 766 public void LOG(Blackhole bh) { 767 float[] as = fa.apply(size); 768 float[] rs = fr.apply(size); 769 770 for (int ic = 0; ic < INVOC_COUNT; ic++) { 771 for (int i = 0; i < as.length; i++) { 772 float a = as[i]; 773 rs[i] = (float)(Math.log((double)a)); 774 } 775 } 776 777 bh.consume(rs); 778 } 779 780 @Benchmark 781 public void LOG10(Blackhole bh) { 782 float[] as = fa.apply(size); 783 float[] rs = fr.apply(size); 784 785 for (int ic = 0; ic < INVOC_COUNT; ic++) { 786 for (int i = 0; i < as.length; i++) { 787 float a = as[i]; 788 rs[i] = (float)(Math.log10((double)a)); 789 } 790 } 791 792 bh.consume(rs); 793 } 794 795 @Benchmark 796 public void EXPM1(Blackhole bh) { 797 float[] as = fa.apply(size); 798 float[] rs = fr.apply(size); 799 800 for (int ic = 0; ic < INVOC_COUNT; ic++) { 801 for (int i = 0; i < as.length; i++) { 802 float a = as[i]; 803 rs[i] = (float)(Math.expm1((double)a)); 804 } 805 } 806 807 bh.consume(rs); 808 } 809 810 @Benchmark 811 public void COS(Blackhole bh) { 812 float[] as = fa.apply(size); 813 float[] rs = fr.apply(size); 814 815 for (int ic = 0; ic < INVOC_COUNT; ic++) { 816 for (int i = 0; i < as.length; i++) { 817 float a = as[i]; 818 rs[i] = (float)(Math.cos((double)a)); 819 } 820 } 821 822 bh.consume(rs); 823 } 824 825 @Benchmark 826 public void TAN(Blackhole bh) { 827 float[] as = fa.apply(size); 828 float[] rs = fr.apply(size); 829 830 for (int ic = 0; ic < INVOC_COUNT; ic++) { 831 for (int i = 0; i < as.length; i++) { 832 float a = as[i]; 833 rs[i] = (float)(Math.tan((double)a)); 834 } 835 } 836 837 bh.consume(rs); 838 } 839 840 @Benchmark 841 public void SINH(Blackhole bh) { 842 float[] as = fa.apply(size); 843 float[] rs = fr.apply(size); 844 845 for (int ic = 0; ic < INVOC_COUNT; ic++) { 846 for (int i = 0; i < as.length; i++) { 847 float a = as[i]; 848 rs[i] = (float)(Math.sinh((double)a)); 849 } 850 } 851 852 bh.consume(rs); 853 } 854 855 @Benchmark 856 public void COSH(Blackhole bh) { 857 float[] as = fa.apply(size); 858 float[] rs = fr.apply(size); 859 860 for (int ic = 0; ic < INVOC_COUNT; ic++) { 861 for (int i = 0; i < as.length; i++) { 862 float a = as[i]; 863 rs[i] = (float)(Math.cosh((double)a)); 864 } 865 } 866 867 bh.consume(rs); 868 } 869 870 @Benchmark 871 public void TANH(Blackhole bh) { 872 float[] as = fa.apply(size); 873 float[] rs = fr.apply(size); 874 875 for (int ic = 0; ic < INVOC_COUNT; ic++) { 876 for (int i = 0; i < as.length; i++) { 877 float a = as[i]; 878 rs[i] = (float)(Math.tanh((double)a)); 879 } 880 } 881 882 bh.consume(rs); 883 } 884 885 @Benchmark 886 public void ASIN(Blackhole bh) { 887 float[] as = fa.apply(size); 888 float[] rs = fr.apply(size); 889 890 for (int ic = 0; ic < INVOC_COUNT; ic++) { 891 for (int i = 0; i < as.length; i++) { 892 float a = as[i]; 893 rs[i] = (float)(Math.asin((double)a)); 894 } 895 } 896 897 bh.consume(rs); 898 } 899 900 @Benchmark 901 public void ACOS(Blackhole bh) { 902 float[] as = fa.apply(size); 903 float[] rs = fr.apply(size); 904 905 for (int ic = 0; ic < INVOC_COUNT; ic++) { 906 for (int i = 0; i < as.length; i++) { 907 float a = as[i]; 908 rs[i] = (float)(Math.acos((double)a)); 909 } 910 } 911 912 bh.consume(rs); 913 } 914 915 @Benchmark 916 public void ATAN(Blackhole bh) { 917 float[] as = fa.apply(size); 918 float[] rs = fr.apply(size); 919 920 for (int ic = 0; ic < INVOC_COUNT; ic++) { 921 for (int i = 0; i < as.length; i++) { 922 float a = as[i]; 923 rs[i] = (float)(Math.atan((double)a)); 924 } 925 } 926 927 bh.consume(rs); 928 } 929 930 @Benchmark 931 public void CBRT(Blackhole bh) { 932 float[] as = fa.apply(size); 933 float[] rs = fr.apply(size); 934 935 for (int ic = 0; ic < INVOC_COUNT; ic++) { 936 for (int i = 0; i < as.length; i++) { 937 float a = as[i]; 938 rs[i] = (float)(Math.cbrt((double)a)); 939 } 940 } 941 942 bh.consume(rs); 943 } 944 945 @Benchmark 946 public void HYPOT(Blackhole bh) { 947 float[] as = fa.apply(size); 948 float[] bs = fb.apply(size); 949 float[] rs = fr.apply(size); 950 951 for (int ic = 0; ic < INVOC_COUNT; ic++) { 952 for (int i = 0; i < as.length; i++) { 953 float a = as[i]; 954 float b = bs[i]; 955 rs[i] = (float)(Math.hypot((double)a, (double)b)); 956 } 957 } 958 959 bh.consume(rs); 960 } 961 962 @Benchmark 963 public void POW(Blackhole bh) { 964 float[] as = fa.apply(size); 965 float[] bs = fb.apply(size); 966 float[] rs = fr.apply(size); 967 968 for (int ic = 0; ic < INVOC_COUNT; ic++) { 969 for (int i = 0; i < as.length; i++) { 970 float a = as[i]; 971 float b = bs[i]; 972 rs[i] = (float)(Math.pow((double)a, (double)b)); 973 } 974 } 975 976 bh.consume(rs); 977 } 978 979 @Benchmark 980 public void ATAN2(Blackhole bh) { 981 float[] as = fa.apply(size); 982 float[] bs = fb.apply(size); 983 float[] rs = fr.apply(size); 984 985 for (int ic = 0; ic < INVOC_COUNT; ic++) { 986 for (int i = 0; i < as.length; i++) { 987 float a = as[i]; 988 float b = bs[i]; 989 rs[i] = (float)(Math.atan2((double)a, (double)b)); 990 } 991 } 992 993 bh.consume(rs); 994 } 995 996 @Benchmark 997 public void FMA(Blackhole bh) { 998 float[] as = fa.apply(size); 999 float[] bs = fb.apply(size); 1000 float[] cs = fc.apply(size); 1001 float[] rs = fr.apply(size); 1002 1003 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1004 for (int i = 0; i < as.length; i++) { 1005 float a = as[i]; 1006 float b = bs[i]; 1007 float c = cs[i]; 1008 rs[i] = (float)(Math.fma(a, b, c)); 1009 } 1010 } 1011 1012 bh.consume(rs); 1013 } 1014 1015 @Benchmark 1016 public void FMAMasked(Blackhole bh) { 1017 float[] as = fa.apply(size); 1018 float[] bs = fb.apply(size); 1019 float[] cs = fc.apply(size); 1020 float[] 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 float a = as[i]; 1026 float b = bs[i]; 1027 float c = cs[i]; 1028 if (ms[i % ms.length]) { 1029 rs[i] = (float)(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 float[] as = fa.apply(size); 1040 float[] rs = fr.apply(size); 1041 1042 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1043 for (int i = 0; i < as.length; i++) { 1044 float a = as[i]; 1045 rs[i] = (float)(-((float)a)); 1046 } 1047 } 1048 1049 bh.consume(rs); 1050 } 1051 1052 @Benchmark 1053 public void NEGMasked(Blackhole bh) { 1054 float[] as = fa.apply(size); 1055 float[] 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 float a = as[i]; 1061 boolean m = ms[i % ms.length]; 1062 rs[i] = (m ? (float)(-((float)a)) : a); 1063 } 1064 } 1065 1066 bh.consume(rs); 1067 } 1068 @Benchmark 1069 public void ABS(Blackhole bh) { 1070 float[] as = fa.apply(size); 1071 float[] rs = fr.apply(size); 1072 1073 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1074 for (int i = 0; i < as.length; i++) { 1075 float a = as[i]; 1076 rs[i] = (float)(Math.abs((float)a)); 1077 } 1078 } 1079 1080 bh.consume(rs); 1081 } 1082 1083 @Benchmark 1084 public void ABSMasked(Blackhole bh) { 1085 float[] as = fa.apply(size); 1086 float[] 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 float a = as[i]; 1092 boolean m = ms[i % ms.length]; 1093 rs[i] = (m ? (float)(Math.abs((float)a)) : a); 1094 } 1095 } 1096 1097 bh.consume(rs); 1098 } 1099 @Benchmark 1100 public void SQRT(Blackhole bh) { 1101 float[] as = fa.apply(size); 1102 float[] rs = fr.apply(size); 1103 1104 for (int ic = 0; ic < INVOC_COUNT; ic++) { 1105 for (int i = 0; i < as.length; i++) { 1106 float a = as[i]; 1107 rs[i] = (float)(Math.sqrt((double)a)); 1108 } 1109 } 1110 1111 bh.consume(rs); 1112 } 1113 1114 @Benchmark 1115 public void SQRTMasked(Blackhole bh) { 1116 float[] as = fa.apply(size); 1117 float[] 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 float a = as[i]; 1123 boolean m = ms[i % ms.length]; 1124 rs[i] = (m ? (float)(Math.sqrt((double)a)) : a); 1125 } 1126 } 1127 1128 bh.consume(rs); 1129 } 1130 }