Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/MacroLogicOpt.java
41161 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package org.openjdk.bench.vm.compiler;2324import org.openjdk.jmh.annotations.*;25import org.openjdk.jmh.infra.*;2627import java.util.concurrent.TimeUnit;28import java.util.Random;2930@BenchmarkMode(Mode.Throughput)31@OutputTimeUnit(TimeUnit.SECONDS)32@State(Scope.Thread)33public class MacroLogicOpt {34@Param({"64","128","256","512","1024","2048","4096"}) private int VECLEN;3536private int [] ai = new int[VECLEN];37private int [] bi = new int[VECLEN];38private int [] ci = new int[VECLEN];39private int [] ri = new int[VECLEN];4041private long [] al = new long[VECLEN];42private long [] bl = new long[VECLEN];43private long [] cl = new long[VECLEN];44private long [] dl = new long[VECLEN];45private long [] el = new long[VECLEN];46private long [] fl = new long[VECLEN];47private long [] rl = new long[VECLEN];4849private Random r = new Random();5051@Setup52public void init() {53ai = new int[VECLEN];54bi = new int[VECLEN];55ci = new int[VECLEN];56ri = new int[VECLEN];5758al = new long[VECLEN];59bl = new long[VECLEN];60cl = new long[VECLEN];61dl = new long[VECLEN];62el = new long[VECLEN];63fl = new long[VECLEN];64rl = new long[VECLEN];65for (int i=0; i<VECLEN; i++) {66ai[i] = r.nextInt();67bi[i] = r.nextInt();68ci[i] = r.nextInt();6970al[i] = r.nextLong();71bl[i] = r.nextLong();72cl[i] = r.nextLong();73dl[i] = r.nextLong();74el[i] = r.nextLong();75fl[i] = r.nextLong();76}77}7879@CompilerControl(CompilerControl.Mode.DONT_INLINE)80private int run_workload1(int count, int [] a , int [] b, int [] c, int [] r) {81for(int i = 0 ; i < r.length ; i++)82r[i] = (((a[i] & b[i]) ^ (a[i] & c[i]) ^ (b[i] & c[i])) & ((~a[i] & b[i]) | (~b[i] & c[i]) | ~c[i] & a[i]));83return r[count];84}8586@Benchmark87public void workload1_caller(Blackhole bh) {88int r = 0;89for(int i = 0 ; i < 10000; i++)90r += run_workload1(i&(ri.length-1), ai, bi, ci, ri);91bh.consume(r);92}9394@CompilerControl(CompilerControl.Mode.DONT_INLINE)95private long run_workload2(int count, long [] a , long [] b, long [] c, long [] r) {96for(int i = 0 ; i < r.length ; i++)97r[i] = (((a[i] & b[i]) ^ (a[i] & c[i]) ^ (b[i] & c[i])) & ((~a[i] & b[i]) | (~b[i] & c[i]) | ~c[i] & a[i]));98return r[count];99}100101@Benchmark102public void workload2_caller(Blackhole bh) {103long r = 0;104for(int i = 0 ; i < 100000; i++)105r += run_workload2(i&(rl.length-1), al, bl, cl, rl);106bh.consume(r);107}108109@CompilerControl(CompilerControl.Mode.DONT_INLINE)110private long run_workload3(int count, long [] a , long [] b, long [] c,111long [] d, long [] e, long [] f, long [] r) {112for(int i = 0 ; i < r.length ; i++)113r[i] = (((~a[i] | ~b[i]) & (~c[i])) | (~d[i] & (~e[i] & f[i])));114return r[count];115}116117@Benchmark118public void workload3_caller(Blackhole bh) {119long r = 0;120for(int i = 0 ; i < 10000; i++)121r += run_workload3(i&(ri.length-1), al, bl, cl, dl, el, fl, rl);122bh.consume(r);123}124}125126127