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.array.sum;
 24 
 25 import org.openjdk.bench.valhalla.array.util.StatesQ32int;
 26 import org.openjdk.bench.valhalla.types.ByInt;
 27 import org.openjdk.bench.valhalla.types.Q32int;
 28 import org.openjdk.jmh.annotations.Benchmark;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 
 31 public class Inline32int extends StatesQ32int {
 32 
 33     @Benchmark
 34     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 35     public int Val_as_Val_fields(Val_as_Val st) {
 36         int s = 0;
 37         Q32int[] 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 int Val_as_Ref_fields(Val_as_Ref st) {
 47         int s = 0;
 48         Q32int.ref[] arr = st.arr;
 49         for(int i=0; i < arr.length; i++) {
 50             s += arr[i].v0;
 51         }
 52         return s;
 53     }
 54 
 55     @Benchmark
 56     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 57     public int Ref_as_Ref_fields(Ref_as_Ref st) {
 58         int s = 0;
 59         Q32int.ref[] 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 int Val_as_Val_sum(Val_as_Val st) {
 69         int s = 0;
 70         Q32int[] arr = st.arr;
 71         for(int i=0; i < arr.length; i++) {
 72             s += arr[i].intSum();
 73         }
 74         return s;
 75     }
 76 
 77     @Benchmark
 78     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 79     public int Val_as_Ref_sum(Val_as_Ref st) {
 80         int s = 0;
 81         Q32int.ref[] arr = st.arr;
 82         for(int i=0; i < arr.length; i++) {
 83             s += arr[i].intSum();
 84         }
 85         return s;
 86     }
 87 
 88     @Benchmark
 89     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 90     public int Ref_as_Ref_sum(Ref_as_Ref st) {
 91         int s = 0;
 92         Q32int.ref[] arr = st.arr;
 93         for(int i=0; i < arr.length; i++) {
 94             s += arr[i].intSum();
 95         }
 96         return s;
 97     }
 98 
 99     @Benchmark
100     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
101     public int Val_as_Int_sum(Val_as_By st) {
102         int s = 0;
103         ByInt[] arr = st.arr;
104         for(int i=0; i < arr.length; i++) {
105             s += arr[i].intSum();
106         }
107         return s;
108     }
109 
110     @Benchmark
111     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
112     public int Int_as_Int_sum(By_as_By st) {
113         int s = 0;
114         ByInt[] arr = st.arr;
115         for(int i=0; i < arr.length; i++) {
116             s += arr[i].intSum();
117         }
118         return s;
119     }
120 
121 }