1 /* 2 * Copyright (c) 2018, 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 21 * questions. 22 */ 23 24 package benchmark.jdk.incubator.vector; 25 26 import jdk.incubator.vector.Vector; 27 import jdk.incubator.vector.Vector.Shape; 28 import jdk.incubator.vector.Vector.Species; 29 import jdk.incubator.vector.$Type$Vector; 30 31 import java.util.concurrent.TimeUnit; 32 import java.util.function.BiFunction; 33 import java.util.function.IntFunction; 34 35 import org.openjdk.jmh.annotations.*; 36 import org.openjdk.jmh.infra.Blackhole; 37 38 @BenchmarkMode(Mode.Throughput) 39 @OutputTimeUnit(TimeUnit.MILLISECONDS) 40 @State(Scope.Benchmark) 41 @Warmup(iterations = 3, time = 1) 42 @Measurement(iterations = 5, time = 1) 43 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"}) 44 public class $vectorbenchtype$ extends AbstractVectorBenchmark { 45 #if[MaxBit] 46 static final Species<$Wideboxtype$> SPECIES = $Type$Vector.SPECIES_MAX; 47 #else[MaxBit] 48 static final Species<$Wideboxtype$> SPECIES = $Type$Vector.SPECIES_$bits$; 49 #end[MaxBit] 50 51 static final int INVOC_COUNT = 1; // get rid of outer loop 52 53 @Param("1024") 54 int size; 55 56 $type$[] fill(IntFunction<$Wideboxtype$> f) { 57 $type$[] array = new $type$[size]; 58 for (int i = 0; i < array.length; i++) { 59 array[i] = f.apply(i); 60 } 61 return array; 62 } 63 64 $type$[] a, b, c, r; 65 boolean[] m, rm; 66 int[] s; 67 68 @Setup 69 public void init() { 70 size += size % SPECIES.length(); // FIXME: add post-loops 71 72 a = fill(i -> ($type$)(2*i)); 73 b = fill(i -> ($type$)(i+1)); 74 c = fill(i -> ($type$)(i+5)); 75 r = fill(i -> ($type$)0); 76 77 m = fillMask(size, i -> (i % 2) == 0); 78 rm = fillMask(size, i -> false); 79 80 s = fillInt(size, i -> RANDOM.nextInt(SPECIES.length())); 81 } 82 83 final IntFunction<$type$[]> fa = vl -> a; 84 final IntFunction<$type$[]> fb = vl -> b; 85 final IntFunction<$type$[]> fc = vl -> c; 86 final IntFunction<$type$[]> fr = vl -> r; 87 final IntFunction<boolean[]> fm = vl -> m; 88 final IntFunction<boolean[]> fmr = vl -> rm; 89 final BiFunction<Integer,Integer,int[]> fs = (i,j) -> s; 90