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