1
1
/*
2
- * Copyright (c) 2022, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2022, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -37,19 +37,9 @@ public class MaskedLogicOpts {
37
37
@ Param ({"256" ,"512" ,"1024" })
38
38
private int ARRAYLEN ;
39
39
40
- boolean [] mask_arr = {
41
- false , false , false , true , false , false , false , false ,
42
- false , false , false , true , false , false , false , false ,
43
- false , false , false , true , false , false , false , false ,
44
- true , true , true , true , true , true , true , true ,
45
- true , true , true , true , true , true , true , true ,
46
- false , false , false , true , false , false , false , false ,
47
- false , false , false , true , false , false , false , false ,
48
- false , false , false , true , false , false , false , false
49
- };
50
-
51
40
int INVOC_COUNTER = 4096 ;
52
41
42
+ boolean [] mask_arr = new boolean [ARRAYLEN ];
53
43
int [] i1 = new int [ARRAYLEN ];
54
44
int [] i2 = new int [ARRAYLEN ];
55
45
int [] i3 = new int [ARRAYLEN ];
@@ -62,39 +52,23 @@ public class MaskedLogicOpts {
62
52
long [] l4 = new long [ARRAYLEN ];
63
53
long [] l5 = new long [ARRAYLEN ];
64
54
65
- Vector <Integer > iv1 ;
66
- Vector <Integer > iv2 ;
67
- Vector <Integer > iv3 ;
68
- Vector <Integer > iv4 ;
69
- Vector <Integer > iv5 ;
70
-
71
- Vector <Long > lv1 ;
72
- Vector <Long > lv2 ;
73
- Vector <Long > lv3 ;
74
- Vector <Long > lv4 ;
75
- Vector <Long > lv5 ;
76
-
77
- VectorMask <Integer > imask ;
78
- VectorMask <Long > lmask ;
79
-
80
- VectorSpecies <Integer > ispecies ;
81
- VectorSpecies <Long > lspecies ;
82
-
83
55
int int512_arr_idx ;
84
56
int int256_arr_idx ;
85
57
int int128_arr_idx ;
86
58
int long256_arr_idx ;
87
59
int long512_arr_idx ;
88
60
89
- private Random r = new Random ();
61
+ private Random r = new Random (1024 );
90
62
91
63
@ Setup (Level .Trial )
92
64
public void init () {
93
- int512_arr_idx = 0 ;
94
- int256_arr_idx = 0 ;
95
- int128_arr_idx = 0 ;
96
- long256_arr_idx = 0 ;
97
- long512_arr_idx = 0 ;
65
+ int512_arr_idx = -16 ;
66
+ int256_arr_idx = -8 ;
67
+ int128_arr_idx = -4 ;
68
+ long256_arr_idx = -4 ;
69
+ long512_arr_idx = -8 ;
70
+
71
+ mask_arr = new boolean [ARRAYLEN ];
98
72
i1 = new int [ARRAYLEN ];
99
73
i2 = new int [ARRAYLEN ];
100
74
i3 = new int [ARRAYLEN ];
@@ -108,6 +82,8 @@ public void init() {
108
82
l5 = new long [ARRAYLEN ];
109
83
110
84
for (int i =0 ; i <ARRAYLEN ; i ++) {
85
+ mask_arr [i ] = r .nextBoolean ();
86
+
111
87
i1 [i ] = r .nextInt ();
112
88
i2 [i ] = r .nextInt ();
113
89
i3 [i ] = r .nextInt ();
@@ -125,22 +101,22 @@ public void init() {
125
101
126
102
@ Setup (Level .Invocation )
127
103
public void init_per_invoc () {
128
- int512_arr_idx = (int512_arr_idx + 16 ) & ( ARRAYLEN - 1 ) ;
129
- int256_arr_idx = (int256_arr_idx + 8 ) & ( ARRAYLEN - 1 ) ;
130
- int128_arr_idx = (int128_arr_idx + 4 ) & ( ARRAYLEN - 1 ) ;
131
- long512_arr_idx = (long512_arr_idx + 8 ) & ( ARRAYLEN - 1 ) ;
132
- long256_arr_idx = (long256_arr_idx + 4 ) & ( ARRAYLEN - 1 ) ;
104
+ int512_arr_idx = ((( ARRAYLEN & ~ 15 ) - int512_arr_idx ) <= 16 ) ? 0 : int512_arr_idx + 16 ;
105
+ int256_arr_idx = ((( ARRAYLEN & ~ 7 ) - int256_arr_idx ) <= 8 ) ? 0 : int256_arr_idx + 8 ;
106
+ int128_arr_idx = ((( ARRAYLEN & ~ 3 ) - int128_arr_idx ) <= 4 ) ? 0 : int128_arr_idx + 4 ;
107
+ long512_arr_idx = ((( ARRAYLEN & ~ 7 ) - long512_arr_idx ) <= 8 ) ? 0 : long512_arr_idx + 8 ;
108
+ long256_arr_idx = ((( ARRAYLEN & ~ 3 ) - long256_arr_idx ) <= 4 ) ? 0 : long256_arr_idx + 4 ;
133
109
}
134
110
135
111
@ CompilerControl (CompilerControl .Mode .INLINE )
136
- public void maskedLogicKernel (VectorSpecies <Integer > SPECIES ) {
137
- imask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
138
- iv2 = IntVector .fromArray (SPECIES , i2 , int512_arr_idx );
139
- iv3 = IntVector .fromArray (SPECIES , i3 , int512_arr_idx );
140
- iv4 = IntVector .fromArray (SPECIES , i4 , int512_arr_idx );
141
- iv5 = IntVector .fromArray (SPECIES , i5 , int512_arr_idx );
112
+ public void maskedLogicKernel (VectorSpecies <Integer > SPECIES , int index ) {
113
+ VectorMask < Integer > imask = VectorMask .fromArray (SPECIES , mask_arr , index );
114
+ IntVector iv2 = IntVector .fromArray (SPECIES , i2 , index );
115
+ IntVector iv3 = IntVector .fromArray (SPECIES , i3 , index );
116
+ IntVector iv4 = IntVector .fromArray (SPECIES , i4 , index );
117
+ IntVector iv5 = IntVector .fromArray (SPECIES , i5 , index );
142
118
for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
143
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
119
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
144
120
IntVector .fromArray (SPECIES , i1 , j )
145
121
.lanewise (VectorOperators .AND , iv2 , imask )
146
122
.lanewise (VectorOperators .OR , iv2 , imask )
@@ -157,65 +133,65 @@ public void maskedLogicKernel(VectorSpecies<Integer> SPECIES) {
157
133
158
134
@ Benchmark
159
135
public void maskedLogicOperationsInt512 () {
160
- maskedLogicKernel (IntVector .SPECIES_512 );
136
+ maskedLogicKernel (IntVector .SPECIES_512 , int512_arr_idx );
161
137
}
162
138
163
139
@ Benchmark
164
140
public void maskedLogicOperationsInt256 () {
165
- maskedLogicKernel (IntVector .SPECIES_256 );
141
+ maskedLogicKernel (IntVector .SPECIES_256 , int256_arr_idx );
166
142
}
167
143
168
144
@ Benchmark
169
145
public void maskedLogicOperationsInt128 () {
170
- maskedLogicKernel (IntVector .SPECIES_128 );
146
+ maskedLogicKernel (IntVector .SPECIES_128 , int128_arr_idx );
171
147
}
172
148
173
149
@ CompilerControl (CompilerControl .Mode .INLINE )
174
- public void partiallyMaskedLogicOperationsIntKernel (VectorSpecies <Integer > SPECIES ) {
175
- imask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
176
- iv2 = IntVector .fromArray (SPECIES , i2 , int512_arr_idx );
177
- iv3 = IntVector .fromArray (SPECIES , i3 , int512_arr_idx );
178
- iv4 = IntVector .fromArray (SPECIES , i4 , int512_arr_idx );
179
- iv5 = IntVector .fromArray (SPECIES , i5 , int512_arr_idx );
180
- for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
181
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
182
- IntVector .fromArray (SPECIES , i1 , j )
183
- .lanewise (VectorOperators .AND , iv2 , imask )
184
- .lanewise (VectorOperators .OR , iv2 , imask )
185
- .lanewise (VectorOperators .AND , iv3 )
186
- .lanewise (VectorOperators .OR , iv3 )
187
- .lanewise (VectorOperators .OR , iv4 , imask )
188
- .lanewise (VectorOperators .AND , iv4 , imask )
189
- .lanewise (VectorOperators .XOR , iv5 , imask )
190
- .intoArray (i1 , j );
191
- }
192
- }
150
+ public void partiallyMaskedLogicOperationsIntKernel (VectorSpecies <Integer > SPECIES , int index ) {
151
+ VectorMask < Integer > imask = VectorMask .fromArray (SPECIES , mask_arr , index );
152
+ IntVector iv2 = IntVector .fromArray (SPECIES , i2 , index );
153
+ IntVector iv3 = IntVector .fromArray (SPECIES , i3 , index );
154
+ IntVector iv4 = IntVector .fromArray (SPECIES , i4 , index );
155
+ IntVector iv5 = IntVector .fromArray (SPECIES , i5 , index );
156
+ for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
157
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
158
+ IntVector .fromArray (SPECIES , i1 , j )
159
+ .lanewise (VectorOperators .AND , iv2 , imask )
160
+ .lanewise (VectorOperators .OR , iv2 , imask )
161
+ .lanewise (VectorOperators .AND , iv3 )
162
+ .lanewise (VectorOperators .OR , iv3 )
163
+ .lanewise (VectorOperators .OR , iv4 , imask )
164
+ .lanewise (VectorOperators .AND , iv4 , imask )
165
+ .lanewise (VectorOperators .XOR , iv5 , imask )
166
+ .intoArray (i1 , j );
167
+ }
168
+ }
193
169
}
194
170
195
171
@ Benchmark
196
172
public void partiallyMaskedLogicOperationsInt512 () {
197
- partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_512 );
173
+ partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_512 , int512_arr_idx );
198
174
}
199
175
200
176
@ Benchmark
201
177
public void partiallyMaskedLogicOperationsInt256 () {
202
- partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_256 );
178
+ partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_256 , int256_arr_idx );
203
179
}
204
180
205
181
@ Benchmark
206
182
public void partiallyMaskedLogicOperationsInt128 () {
207
- partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_128 );
183
+ partiallyMaskedLogicOperationsIntKernel (IntVector .SPECIES_128 , int128_arr_idx );
208
184
}
209
185
210
186
@ CompilerControl (CompilerControl .Mode .INLINE )
211
- public void bitwiseBlendOperationIntKernel (VectorSpecies <Integer > SPECIES ) {
212
- imask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
213
- iv2 = IntVector .fromArray (SPECIES , i2 , int512_arr_idx );
214
- iv3 = IntVector .fromArray (SPECIES , i3 , int512_arr_idx );
215
- iv4 = IntVector .fromArray (SPECIES , i4 , int512_arr_idx );
216
- iv5 = IntVector .fromArray (SPECIES , i5 , int512_arr_idx );
217
- for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
218
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
187
+ public void bitwiseBlendOperationIntKernel (VectorSpecies <Integer > SPECIES , int index ) {
188
+ VectorMask < Integer > imask = VectorMask .fromArray (SPECIES , mask_arr , index );
189
+ IntVector iv2 = IntVector .fromArray (SPECIES , i2 , index );
190
+ IntVector iv3 = IntVector .fromArray (SPECIES , i3 , index );
191
+ IntVector iv4 = IntVector .fromArray (SPECIES , i4 , index );
192
+ IntVector iv5 = IntVector .fromArray (SPECIES , i5 , index );
193
+ for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
194
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
219
195
IntVector .fromArray (SPECIES , i1 , j )
220
196
.lanewise (VectorOperators .BITWISE_BLEND , iv2 , iv3 , imask )
221
197
.lanewise (VectorOperators .BITWISE_BLEND , iv3 , iv4 , imask )
@@ -227,106 +203,106 @@ public void bitwiseBlendOperationIntKernel(VectorSpecies<Integer> SPECIES) {
227
203
228
204
@ Benchmark
229
205
public void bitwiseBlendOperationInt512 () {
230
- bitwiseBlendOperationIntKernel (IntVector .SPECIES_512 );
206
+ bitwiseBlendOperationIntKernel (IntVector .SPECIES_512 , int512_arr_idx );
231
207
}
232
208
233
209
@ Benchmark
234
210
public void bitwiseBlendOperationInt256 () {
235
- bitwiseBlendOperationIntKernel (IntVector .SPECIES_256 );
211
+ bitwiseBlendOperationIntKernel (IntVector .SPECIES_256 , int256_arr_idx );
236
212
}
237
213
238
214
@ Benchmark
239
215
public void bitwiseBlendOperationInt128 () {
240
- bitwiseBlendOperationIntKernel (IntVector .SPECIES_128 );
216
+ bitwiseBlendOperationIntKernel (IntVector .SPECIES_128 , int128_arr_idx );
241
217
}
242
218
243
219
@ CompilerControl (CompilerControl .Mode .INLINE )
244
- public void maskedLogicOperationsLongKernel (VectorSpecies <Long > SPECIES ) {
245
- lmask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
246
- lv2 = LongVector .fromArray (SPECIES , l2 , long256_arr_idx );
247
- lv3 = LongVector .fromArray (SPECIES , l3 , long256_arr_idx );
248
- lv4 = LongVector .fromArray (SPECIES , l4 , long256_arr_idx );
249
- lv5 = LongVector .fromArray (SPECIES , l5 , long256_arr_idx );
250
- for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
251
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
252
- LongVector .fromArray (SPECIES , l1 , j )
253
- .lanewise (VectorOperators .AND , lv2 , lmask )
254
- .lanewise (VectorOperators .OR , lv3 , lmask )
255
- .lanewise (VectorOperators .AND , lv3 , lmask )
256
- .lanewise (VectorOperators .OR , lv4 , lmask )
257
- .lanewise (VectorOperators .AND , lv4 , lmask )
258
- .lanewise (VectorOperators .XOR , lv5 , lmask )
259
- .intoArray (l1 , j );
260
- }
261
- }
220
+ public void maskedLogicOperationsLongKernel (VectorSpecies <Long > SPECIES , int index ) {
221
+ VectorMask < Long > lmask = VectorMask .fromArray (SPECIES , mask_arr , index );
222
+ LongVector lv2 = LongVector .fromArray (SPECIES , l2 , index );
223
+ LongVector lv3 = LongVector .fromArray (SPECIES , l3 , index );
224
+ LongVector lv4 = LongVector .fromArray (SPECIES , l4 , index );
225
+ LongVector lv5 = LongVector .fromArray (SPECIES , l5 , index );
226
+ for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
227
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
228
+ LongVector .fromArray (SPECIES , l1 , j )
229
+ .lanewise (VectorOperators .AND , lv2 , lmask )
230
+ .lanewise (VectorOperators .OR , lv3 , lmask )
231
+ .lanewise (VectorOperators .AND , lv3 , lmask )
232
+ .lanewise (VectorOperators .OR , lv4 , lmask )
233
+ .lanewise (VectorOperators .AND , lv4 , lmask )
234
+ .lanewise (VectorOperators .XOR , lv5 , lmask )
235
+ .intoArray (l1 , j );
236
+ }
237
+ }
262
238
}
263
239
264
240
@ Benchmark
265
241
public void maskedLogicOperationsLong512 () {
266
- maskedLogicOperationsLongKernel (LongVector .SPECIES_512 );
242
+ maskedLogicOperationsLongKernel (LongVector .SPECIES_512 , long512_arr_idx );
267
243
}
268
244
@ Benchmark
269
245
public void maskedLogicOperationsLong256 () {
270
- maskedLogicOperationsLongKernel (LongVector .SPECIES_256 );
246
+ maskedLogicOperationsLongKernel (LongVector .SPECIES_256 , long256_arr_idx );
271
247
}
272
248
273
249
@ CompilerControl (CompilerControl .Mode .INLINE )
274
- public void partiallyMaskedLogicOperationsLongKernel (VectorSpecies <Long > SPECIES ) {
275
- lmask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
276
- lv2 = LongVector .fromArray (SPECIES , l2 , long512_arr_idx );
277
- lv3 = LongVector .fromArray (SPECIES , l3 , long512_arr_idx );
278
- lv4 = LongVector .fromArray (SPECIES , l4 , long512_arr_idx );
279
- lv5 = LongVector .fromArray (SPECIES , l5 , long512_arr_idx );
280
- for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
281
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
282
- LongVector .fromArray (SPECIES , l1 , j )
283
- .lanewise (VectorOperators .AND , lv2 , lmask )
284
- .lanewise (VectorOperators .OR , lv2 , lmask )
285
- .lanewise (VectorOperators .AND , lv3 )
286
- .lanewise (VectorOperators .OR , lv3 )
287
- .lanewise (VectorOperators .AND , lv4 )
288
- .lanewise (VectorOperators .OR , lv4 , lmask )
289
- .lanewise (VectorOperators .XOR , lv5 , lmask )
290
- .intoArray (l1 , j );
291
- }
292
- }
250
+ public void partiallyMaskedLogicOperationsLongKernel (VectorSpecies <Long > SPECIES , int index ) {
251
+ VectorMask < Long > lmask = VectorMask .fromArray (SPECIES , mask_arr , index );
252
+ LongVector lv2 = LongVector .fromArray (SPECIES , l2 , index );
253
+ LongVector lv3 = LongVector .fromArray (SPECIES , l3 , index );
254
+ LongVector lv4 = LongVector .fromArray (SPECIES , l4 , index );
255
+ LongVector lv5 = LongVector .fromArray (SPECIES , l5 , index );
256
+ for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
257
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
258
+ LongVector .fromArray (SPECIES , l1 , j )
259
+ .lanewise (VectorOperators .AND , lv2 , lmask )
260
+ .lanewise (VectorOperators .OR , lv2 , lmask )
261
+ .lanewise (VectorOperators .AND , lv3 )
262
+ .lanewise (VectorOperators .OR , lv3 )
263
+ .lanewise (VectorOperators .AND , lv4 )
264
+ .lanewise (VectorOperators .OR , lv4 , lmask )
265
+ .lanewise (VectorOperators .XOR , lv5 , lmask )
266
+ .intoArray (l1 , j );
267
+ }
268
+ }
293
269
}
294
270
295
271
@ Benchmark
296
272
public void partiallyMaskedLogicOperationsLong512 () {
297
- partiallyMaskedLogicOperationsLongKernel (LongVector .SPECIES_512 );
273
+ partiallyMaskedLogicOperationsLongKernel (LongVector .SPECIES_512 , long512_arr_idx );
298
274
}
299
275
300
276
@ Benchmark
301
277
public void partiallyMaskedLogicOperationsLong256 () {
302
- partiallyMaskedLogicOperationsLongKernel (LongVector .SPECIES_256 );
278
+ partiallyMaskedLogicOperationsLongKernel (LongVector .SPECIES_256 , long256_arr_idx );
303
279
}
304
280
305
281
@ CompilerControl (CompilerControl .Mode .INLINE )
306
- public void bitwiseBlendOperationLongKernel (VectorSpecies <Long > SPECIES ) {
307
- lmask = VectorMask .fromArray (SPECIES , mask_arr , 0 );
308
- lv2 = LongVector .fromArray (SPECIES , l2 , long512_arr_idx );
309
- lv3 = LongVector .fromArray (SPECIES , l3 , long512_arr_idx );
310
- lv4 = LongVector .fromArray (SPECIES , l4 , long512_arr_idx );
311
- lv5 = LongVector .fromArray (SPECIES , l5 , long512_arr_idx );
312
- for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
313
- for (int j = 0 ; j < ARRAYLEN ; j += SPECIES .length ()) {
314
- LongVector .fromArray (SPECIES , l1 , j )
315
- .lanewise (VectorOperators .BITWISE_BLEND , lv2 , lv3 , lmask )
316
- .lanewise (VectorOperators .BITWISE_BLEND , lv3 , lv4 , lmask )
317
- .lanewise (VectorOperators .BITWISE_BLEND , lv4 , lv5 , lmask )
318
- .intoArray (l1 , j );
282
+ public void bitwiseBlendOperationLongKernel (VectorSpecies <Long > SPECIES , int index ) {
283
+ VectorMask < Long > lmask = VectorMask .fromArray (SPECIES , mask_arr , index );
284
+ LongVector lv2 = LongVector .fromArray (SPECIES , l2 , index );
285
+ LongVector lv3 = LongVector .fromArray (SPECIES , l3 , index );
286
+ LongVector lv4 = LongVector .fromArray (SPECIES , l4 , index );
287
+ LongVector lv5 = LongVector .fromArray (SPECIES , l5 , index );
288
+ for (int i = 0 ; i < INVOC_COUNTER ; i ++) {
289
+ for (int j = 0 ; j < SPECIES . loopBound ( ARRAYLEN ) ; j += SPECIES .length ()) {
290
+ LongVector .fromArray (SPECIES , l1 , j )
291
+ .lanewise (VectorOperators .BITWISE_BLEND , lv2 , lv3 , lmask )
292
+ .lanewise (VectorOperators .BITWISE_BLEND , lv3 , lv4 , lmask )
293
+ .lanewise (VectorOperators .BITWISE_BLEND , lv4 , lv5 , lmask )
294
+ .intoArray (l1 , j );
319
295
}
320
296
}
321
297
}
322
298
323
299
@ Benchmark
324
300
public void bitwiseBlendOperationLong512 () {
325
- bitwiseBlendOperationLongKernel (LongVector .SPECIES_512 );
301
+ bitwiseBlendOperationLongKernel (LongVector .SPECIES_512 , long512_arr_idx );
326
302
}
327
303
328
304
@ Benchmark
329
305
public void bitwiseBlendOperationLong256 () {
330
- bitwiseBlendOperationLongKernel (LongVector .SPECIES_256 );
306
+ bitwiseBlendOperationLongKernel (LongVector .SPECIES_256 , long256_arr_idx );
331
307
}
332
308
}
0 commit comments