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.array.sum;
 24 
 25 import org.openjdk.bench.valhalla.array.util.StatesQ64int;
 26 import org.openjdk.bench.valhalla.types.ByInt;
 27 import org.openjdk.bench.valhalla.types.Q64int;
 28 import org.openjdk.jmh.annotations.Benchmark;
 29 import org.openjdk.jmh.annotations.CompilerControl;
 30 
 31 public class Inline64int extends StatesQ64int {
 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         Q64int[] arr = st.arr;
 38         for(int i=0; i < arr.length; i++) {
 39             s += arr[i].v0.v0;
 40             s += arr[i].v1.v0;
 41         }
 42         return s;
 43     }
 44 
 45     @Benchmark
 46     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 47     public int Val_as_Ref_fields(Val_as_Ref st) {
 48         int s = 0;
 49         Q64int[] arr = st.arr;
 50         for(int i=0; i < arr.length; i++) {
 51             s += arr[i].v0.v0;
 52             s += arr[i].v1.v0;
 53         }
 54         return s;
 55     }
 56 
 57     @Benchmark
 58     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 59     public int Ref_as_Ref_fields(Ref_as_Ref st) {
 60         int s = 0;
 61         Q64int[] arr = st.arr;
 62         for(int i=0; i < arr.length; i++) {
 63             s += arr[i].v0.v0;
 64             s += arr[i].v1.v0;
 65         }
 66         return s;
 67     }
 68 
 69     @Benchmark
 70     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 71     public int Val_as_Val_sum(Val_as_Val st) {
 72         int s = 0;
 73         Q64int[] arr = st.arr;
 74         for(int i=0; i < arr.length; i++) {
 75             s += arr[i].intSum();
 76         }
 77         return s;
 78     }
 79 
 80     @Benchmark
 81     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 82     public int Val_as_Ref_sum(Val_as_Ref st) {
 83         int s = 0;
 84         Q64int[] arr = st.arr;
 85         for(int i=0; i < arr.length; i++) {
 86             s += arr[i].intSum();
 87         }
 88         return s;
 89     }
 90 
 91     @Benchmark
 92     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 93     public int Ref_as_Ref_sum(Ref_as_Ref st) {
 94         int s = 0;
 95         Q64int[] arr = st.arr;
 96         for(int i=0; i < arr.length; i++) {
 97             s += arr[i].intSum();
 98         }
 99         return s;
100     }
101 
102     @Benchmark
103     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
104     public int Val_as_Int_sum(Val_as_By st) {
105         int s = 0;
106         ByInt[] arr = st.arr;
107         for(int i=0; i < arr.length; i++) {
108             s += arr[i].intSum();
109         }
110         return s;
111     }
112 
113     @Benchmark
114     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
115     public int Ref_as_Int_sum(Ref_as_By st) {
116         int s = 0;
117         ByInt[] arr = st.arr;
118         for(int i=0; i < arr.length; i++) {
119             s += arr[i].intSum();
120         }
121         return s;
122     }
123 
124     @Benchmark
125     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
126     public int Int_as_Int_sum(By_as_By st) {
127         int s = 0;
128         ByInt[] arr = st.arr;
129         for(int i=0; i < arr.length; i++) {
130             s += arr[i].intSum();
131         }
132         return s;
133     }
134 
135 }