1 /*
  2  * Copyright (c) 2020, 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 package org.openjdk.bench.valhalla.acmp.array;
 24 
 25 import org.openjdk.bench.valhalla.types.Int64;
 26 import org.openjdk.bench.valhalla.types.Q64byte;
 27 import org.openjdk.jmh.annotations.Benchmark;
 28 import org.openjdk.jmh.annotations.BenchmarkMode;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 import org.openjdk.jmh.annotations.Fork;
 31 import org.openjdk.jmh.annotations.Measurement;
 32 import org.openjdk.jmh.annotations.Mode;
 33 import org.openjdk.jmh.annotations.OperationsPerInvocation;
 34 import org.openjdk.jmh.annotations.OutputTimeUnit;
 35 import org.openjdk.jmh.annotations.Scope;
 36 import org.openjdk.jmh.annotations.State;
 37 import org.openjdk.jmh.annotations.Warmup;
 38 
 39 import java.util.concurrent.TimeUnit;
 40 
 41 @Fork(3)
 42 @Warmup(iterations = 3, time = 1)
 43 @Measurement(iterations = 5, time = 1)
 44 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 45 @BenchmarkMode(Mode.AverageTime)
 46 @State(Scope.Thread)
 47 public class InlineIsCmpBranch64byte extends StatesQ64byte {
 48 
 49     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 50     private static int cmp_Obj(Object[] objects1, Object[] objects2) {
 51         int s = 0;
 52         for (int i = 0; i < SIZE; i++) {
 53             if (objects1[i] == objects2[i]) {
 54                 s += 1;
 55             } else {
 56                 s -= 1;
 57             }
 58         }
 59         return s;
 60     }
 61 
 62     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 63     private static int cmp_Int(Int64[] objects1, Int64[] objects2) {
 64         int s = 0;
 65         for (int i = 0; i < SIZE; i++) {
 66             if (objects1[i] == objects2[i]) {
 67                 s += 1;
 68             } else {
 69                 s -= 1;
 70             }
 71         }
 72         return s;
 73     }
 74 
 75     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 76     private static int cmp_Ref(Q64byte.ref[] objects1, Q64byte.ref[] objects2) {
 77         int s = 0;
 78         for (int i = 0; i < SIZE; i++) {
 79             if (objects1[i] == objects2[i]) {
 80                 s += 1;
 81             } else {
 82                 s -= 1;
 83             }
 84         }
 85         return s;
 86     }
 87 
 88     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 89     private static int cmp_Val(Q64byte[] objects1, Q64byte[] objects2) {
 90         int s = 0;
 91         for (int i = 0; i < SIZE; i++) {
 92             if (objects1[i] == objects2[i]) {
 93                 s += 1;
 94             } else {
 95                 s -= 1;
 96             }
 97         }
 98         return s;
 99     }
100 
101 
102     @Benchmark
103     @OperationsPerInvocation(SIZE)
104     @CompilerControl(CompilerControl.Mode.INLINE)
105     public int Obj_equals000(ObjState00 st) {
106         return cmp_Obj(st.arr1, st.arr2);
107     }
108 
109     @Benchmark
110     @OperationsPerInvocation(SIZE)
111     @CompilerControl(CompilerControl.Mode.INLINE)
112     public int Obj_equals025(ObjState25 st) {
113         return cmp_Obj(st.arr1, st.arr2);
114     }
115 
116     @Benchmark
117     @OperationsPerInvocation(SIZE)
118     @CompilerControl(CompilerControl.Mode.INLINE)
119     public int Obj_equals050(ObjState50 st) {
120         return cmp_Obj(st.arr1, st.arr2);
121     }
122 
123     @Benchmark
124     @OperationsPerInvocation(SIZE)
125     @CompilerControl(CompilerControl.Mode.INLINE)
126     public int Obj_equals075(ObjState75 st) {
127         return cmp_Obj(st.arr1, st.arr2);
128     }
129 
130     @Benchmark
131     @OperationsPerInvocation(SIZE)
132     @CompilerControl(CompilerControl.Mode.INLINE)
133     public int Obj_equals100(ObjState100 st) {
134         return cmp_Obj(st.arr1, st.arr2);
135     }
136 
137     @Benchmark
138     @OperationsPerInvocation(SIZE)
139     @CompilerControl(CompilerControl.Mode.INLINE)
140     public int Int_equals000(IntState00 st) {
141         return cmp_Int(st.arr1, st.arr2);
142     }
143 
144     @Benchmark
145     @OperationsPerInvocation(SIZE)
146     @CompilerControl(CompilerControl.Mode.INLINE)
147     public int Int_equals025(IntState25 st) {
148         return cmp_Int(st.arr1, st.arr2);
149     }
150 
151     @Benchmark
152     @OperationsPerInvocation(SIZE)
153     @CompilerControl(CompilerControl.Mode.INLINE)
154     public int Int_equals050(IntState50 st) {
155         return cmp_Int(st.arr1, st.arr2);
156     }
157 
158     @Benchmark
159     @OperationsPerInvocation(SIZE)
160     @CompilerControl(CompilerControl.Mode.INLINE)
161     public int Int_equals075(IntState75 st) {
162         return cmp_Int(st.arr1, st.arr2);
163     }
164 
165     @Benchmark
166     @OperationsPerInvocation(SIZE)
167     @CompilerControl(CompilerControl.Mode.INLINE)
168     public int Int_equals100(IntState100 st) {
169         return cmp_Int(st.arr1, st.arr2);
170     }
171 
172     @Benchmark
173     @OperationsPerInvocation(SIZE)
174     @CompilerControl(CompilerControl.Mode.INLINE)
175     public int Ref_equals000(RefState00 st) {
176         return cmp_Ref(st.arr1, st.arr2);
177     }
178 
179     @Benchmark
180     @OperationsPerInvocation(SIZE)
181     @CompilerControl(CompilerControl.Mode.INLINE)
182     public int Ref_equals025(RefState25 st) {
183         return cmp_Ref(st.arr1, st.arr2);
184     }
185 
186     @Benchmark
187     @OperationsPerInvocation(SIZE)
188     @CompilerControl(CompilerControl.Mode.INLINE)
189     public int Ref_equals050(RefState50 st) {
190         return cmp_Ref(st.arr1, st.arr2);
191     }
192 
193     @Benchmark
194     @OperationsPerInvocation(SIZE)
195     @CompilerControl(CompilerControl.Mode.INLINE)
196     public int Ref_equals075(RefState75 st) {
197         return cmp_Ref(st.arr1, st.arr2);
198     }
199 
200     @Benchmark
201     @OperationsPerInvocation(SIZE)
202     @CompilerControl(CompilerControl.Mode.INLINE)
203     public int Ref_equals100(RefState100 st) {
204         return cmp_Ref(st.arr1, st.arr2);
205     }
206 
207     @Benchmark
208     @OperationsPerInvocation(SIZE)
209     @CompilerControl(CompilerControl.Mode.INLINE)
210     public int Val_equals000(ValState00 st) {
211         return cmp_Val(st.arr1, st.arr2);
212     }
213 
214     @Benchmark
215     @OperationsPerInvocation(SIZE)
216     @CompilerControl(CompilerControl.Mode.INLINE)
217     public int Val_equals025(ValState25 st) {
218         return cmp_Val(st.arr1, st.arr2);
219     }
220 
221     @Benchmark
222     @OperationsPerInvocation(SIZE)
223     @CompilerControl(CompilerControl.Mode.INLINE)
224     public int Val_equals050(ValState50 st) {
225         return cmp_Val(st.arr1, st.arr2);
226     }
227 
228     @Benchmark
229     @OperationsPerInvocation(SIZE)
230     @CompilerControl(CompilerControl.Mode.INLINE)
231     public int Val_equals075(ValState75 st) {
232         return cmp_Val(st.arr1, st.arr2);
233     }
234 
235     @Benchmark
236     @OperationsPerInvocation(SIZE)
237     @CompilerControl(CompilerControl.Mode.INLINE)
238     public int Val_equals100(ValState100 st) {
239         return cmp_Val(st.arr1, st.arr2);
240     }
241 
242 }