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