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