1 /*
  2  * Copyright (c) 2020, 2024, 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.arraytotal.sum;
 24 
 25 import org.openjdk.bench.valhalla.arraytotal.util.StatesQ64long;
 26 import org.openjdk.bench.valhalla.types.ByLong;
 27 import org.openjdk.bench.valhalla.types.Q64long;
 28 import org.openjdk.jmh.annotations.Benchmark;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 
 31 public class Inline64long extends StatesQ64long {
 32 
 33     @Benchmark
 34     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 35     public long Val_as_Val_fields0(Val_as_Val st) {
 36         long s = 0;
 37         Q64long[] arr = st.arr;
 38         for(int i=0; i < arr.length; i++) {
 39             s += arr[i].v0;
 40         }
 41         return s;
 42     }
 43 
 44     @Benchmark
 45     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 46     public long Val_as_Val_fields1(Val_as_Val st) {
 47         long s = 0;
 48         int len = st.arr.length;
 49         for(int i=0; i < len; i++) {
 50             s += st.arr[i].v0;
 51         }
 52         return s;
 53     }
 54 
 55     @Benchmark
 56     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 57     public long Val_as_Ref_fields0(Val_as_Ref st) {
 58         long s = 0;
 59         Q64long[] arr = st.arr;
 60         for(int i=0; i < arr.length; i++) {
 61             s += arr[i].v0;
 62         }
 63         return s;
 64     }
 65 
 66     @Benchmark
 67     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 68     public long Val_as_Ref_fields1(Val_as_Ref st) {
 69         long s = 0;
 70         int len = st.arr.length;
 71         for(int i=0; i < len; i++) {
 72             s += st.arr[i].v0;
 73         }
 74         return s;
 75     }
 76 
 77     @Benchmark
 78     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 79     public long Ref_as_Ref_fields0(Ref_as_Ref st) {
 80         long s = 0;
 81         Q64long[] arr = st.arr;
 82         for(int i=0; i < arr.length; i++) {
 83             s += arr[i].v0;
 84         }
 85         return s;
 86     }
 87 
 88     @Benchmark
 89     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 90     public long Ref_as_Ref_fields1(Ref_as_Ref st) {
 91         long s = 0;
 92         int len = st.arr.length;
 93         for(int i=0; i < len; i++) {
 94             s += st.arr[i].v0;
 95         }
 96         return s;
 97     }
 98 
 99     @Benchmark
100     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
101     public long Val_as_Val_sum0(Val_as_Val st) {
102         long s = 0;
103         Q64long[] arr = st.arr;
104         for(int i=0; i < arr.length; i++) {
105             s += arr[i].longSum();
106         }
107         return s;
108     }
109 
110     @Benchmark
111     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
112     public long Val_as_Val_sum1(Val_as_Val st) {
113         long s = 0;
114         int len = st.arr.length;
115         for(int i=0; i < len; i++) {
116             s += st.arr[i].longSum();
117         }
118         return s;
119     }
120 
121     @Benchmark
122     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
123     public long Val_as_Ref_sum0(Val_as_Ref st) {
124         long s = 0;
125         Q64long[] arr = st.arr;
126         for(int i=0; i < arr.length; i++) {
127             s += arr[i].longSum();
128         }
129         return s;
130     }
131 
132     @Benchmark
133     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
134     public long Val_as_Ref_sum1(Val_as_Ref st) {
135         long s = 0;
136         int len = st.arr.length;
137         for(int i=0; i < len; i++) {
138             s += st.arr[i].longSum();
139         }
140         return s;
141     }
142 
143     @Benchmark
144     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
145     public long Val_as_Int_sum0(Val_as_By st) {
146         long s = 0;
147         ByLong[] arr = st.arr;
148         for(int i=0; i < arr.length; i++) {
149             s += arr[i].longSum();
150         }
151         return s;
152     }
153 
154     @Benchmark
155     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
156     public long Val_as_Int_sum1(Val_as_By st) {
157         long s = 0;
158         int len = st.arr.length;
159         for(int i=0; i < len; i++) {
160             s += st.arr[i].longSum();
161         }
162         return s;
163     }
164 
165     @Benchmark
166     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
167     public long Ref_as_Ref_sum0(Ref_as_Ref st) {
168         long s = 0;
169         Q64long[] arr = st.arr;
170         for(int i=0; i < arr.length; i++) {
171             s += arr[i].longSum();
172         }
173         return s;
174     }
175 
176     @Benchmark
177     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
178     public long Ref_as_Ref_sum1(Ref_as_Ref st) {
179         long s = 0;
180         int len = st.arr.length;
181         for(int i=0; i < len; i++) {
182             s += st.arr[i].longSum();
183         }
184         return s;
185     }
186 
187     @Benchmark
188     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
189     public long Ref_as_Int_sum0(Ref_as_By st) {
190         long s = 0;
191         ByLong[] arr = st.arr;
192         for(int i=0; i < arr.length; i++) {
193             s += arr[i].longSum();
194         }
195         return s;
196     }
197 
198     @Benchmark
199     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
200     public long Ref_as_Int_sum1(Ref_as_By st) {
201         long s = 0;
202         int len = st.arr.length;
203         for(int i=0; i < len; i++) {
204             s += st.arr[i].longSum();
205         }
206         return s;
207     }
208 
209     @Benchmark
210     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
211     public long Int_as_Int_sum0(By_as_By st) {
212         long s = 0;
213         ByLong[] arr = st.arr;
214         for(int i=0; i < arr.length; i++) {
215             s += arr[i].longSum();
216         }
217         return s;
218     }
219 
220     @Benchmark
221     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
222     public long Int_as_Int_sum1(By_as_By st) {
223         long s = 0;
224         int len = st.arr.length;
225         for(int i=0; i < len; i++) {
226             s += st.arr[i].longSum();
227         }
228         return s;
229     }
230 
231 }