24
package compiler.intrinsics;
43
import jdk.internal.misc.Unsafe;
44
import jdk.internal.util.ArraysSupport;
46
public class VectorizedMismatchTest {
47
private boolean[] boolean_a = new boolean[128];
48
private boolean[] boolean_b = new boolean[128];
50
int testBooleanConstantLength(int length) {
51
boolean[] obja = boolean_a;
52
boolean[] objb = boolean_b;
53
long offset = Unsafe.ARRAY_BOOLEAN_BASE_OFFSET;
54
int scale = ArraysSupport.LOG2_ARRAY_BOOLEAN_INDEX_SCALE;
55
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
58
int testBooleanConstantLength0() { return testBooleanConstantLength(0); }
59
int testBooleanConstantLength1() { return testBooleanConstantLength(1); }
60
int testBooleanConstantLength64() { return testBooleanConstantLength(64); }
61
int testBooleanConstantLength128() { return testBooleanConstantLength(128); }
65
private byte[] byte_a = new byte[128];
66
private byte[] byte_b = new byte[128];
68
int testByteConstantLength(int length) {
71
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
72
int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
73
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
76
int testByteConstantLength0() { return testByteConstantLength(0); }
77
int testByteConstantLength1() { return testByteConstantLength(1); }
78
int testByteConstantLength64() { return testByteConstantLength(64); }
79
int testByteConstantLength128() { return testByteConstantLength(128); }
83
private short[] short_a = new short[64];
84
private short[] short_b = new short[64];
86
int testShortConstantLength(int length) {
87
short[] obja = short_a;
88
short[] objb = short_b;
89
long offset = Unsafe.ARRAY_SHORT_BASE_OFFSET;
90
int scale = ArraysSupport.LOG2_ARRAY_SHORT_INDEX_SCALE;
91
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
94
int testShortConstantLength0() { return testShortConstantLength(0); }
95
int testShortConstantLength1() { return testShortConstantLength(1); }
96
int testShortConstantLength32() { return testShortConstantLength(32); }
97
int testShortConstantLength64() { return testShortConstantLength(64); }
101
private char[] char_a = new char[64];
102
private char[] char_b = new char[64];
104
int testCharConstantLength(int length) {
105
char[] obja = char_a;
106
char[] objb = char_b;
107
long offset = Unsafe.ARRAY_CHAR_BASE_OFFSET;
108
int scale = ArraysSupport.LOG2_ARRAY_CHAR_INDEX_SCALE;
109
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
112
int testCharConstantLength0() { return testCharConstantLength(0); }
113
int testCharConstantLength1() { return testCharConstantLength(1); }
114
int testCharConstantLength32() { return testCharConstantLength(32); }
115
int testCharConstantLength64() { return testCharConstantLength(64); }
119
private int[] int_a = new int[32];
120
private int[] int_b = new int[32];
122
int testIntConstantLength(int length) {
125
long offset = Unsafe.ARRAY_INT_BASE_OFFSET;
126
int scale = ArraysSupport.LOG2_ARRAY_INT_INDEX_SCALE;
127
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
130
int testIntConstantLength0() { return testIntConstantLength(0); }
131
int testIntConstantLength1() { return testIntConstantLength(1); }
132
int testIntConstantLength16() { return testIntConstantLength(16); }
133
int testIntConstantLength32() { return testIntConstantLength(32); }
137
private float[] float_a = new float[32];
138
private float[] float_b = new float[32];
140
int testFloatConstantLength(int length) {
141
float[] obja = float_a;
142
float[] objb = float_b;
143
long offset = Unsafe.ARRAY_FLOAT_BASE_OFFSET;
144
int scale = ArraysSupport.LOG2_ARRAY_FLOAT_INDEX_SCALE;
145
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
148
int testFloatConstantLength0() { return testFloatConstantLength(0); }
149
int testFloatConstantLength1() { return testFloatConstantLength(1); }
150
int testFloatConstantLength16() { return testFloatConstantLength(16); }
151
int testFloatConstantLength32() { return testFloatConstantLength(32); }
155
private long[] long_a = new long[16];
156
private long[] long_b = new long[16];
158
int testLongConstantLength(int length) {
159
long[] obja = long_a;
160
long[] objb = long_b;
161
long offset = Unsafe.ARRAY_LONG_BASE_OFFSET;
162
int scale = ArraysSupport.LOG2_ARRAY_LONG_INDEX_SCALE;
163
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
166
int testLongConstantLength0() { return testLongConstantLength(0); }
167
int testLongConstantLength1() { return testLongConstantLength(1); }
168
int testLongConstantLength8() { return testLongConstantLength(8); }
169
int testLongConstantLength16() { return testLongConstantLength(16); }
173
private double[] double_a = new double[16];
174
private double[] double_b = new double[16];
176
int testDoubleConstantLength(int length) {
177
double[] obja = double_a;
178
double[] objb = double_b;
179
long offset = Unsafe.ARRAY_DOUBLE_BASE_OFFSET;
180
int scale = ArraysSupport.LOG2_ARRAY_DOUBLE_INDEX_SCALE;
181
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, length, scale);
184
int testDoubleConstantLength0() { return testDoubleConstantLength(0); }
185
int testDoubleConstantLength1() { return testDoubleConstantLength(1); }
186
int testDoubleConstantLength8() { return testDoubleConstantLength(8); }
187
int testDoubleConstantLength16() { return testDoubleConstantLength(16); }
191
static class ClassInitTest {
192
static final int LENGTH = 64;
193
static final int RESULT;
195
byte[] arr1 = new byte[LENGTH];
196
byte[] arr2 = new byte[LENGTH];
197
for (int i = 0; i < 20_000; i++) {
200
RESULT = test(arr1, arr2);
203
static int test(byte[] obja, byte[] objb) {
204
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
205
int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
206
return ArraysSupport.vectorizedMismatch(obja, offset, objb, offset, LENGTH, scale);
210
int testConstantBeingInitialized() {
211
return ClassInitTest.RESULT;
216
int testLoopUnswitch(int length) {
217
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
218
int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
221
for (int i = 0; i < 32; i++) {
222
acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);
227
int testLoopHoist(int length, int stride) {
228
long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
229
int scale = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
233
for (int i = 0; i < 32; i += stride) {
234
acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);
241
public static void main(String[] args) {
242
VectorizedMismatchTest t = new VectorizedMismatchTest();
243
for (int i = 0; i < 20_000; i++) {
244
t.testBooleanConstantLength0();
245
t.testBooleanConstantLength1();
246
t.testBooleanConstantLength64();
247
t.testBooleanConstantLength128();
249
t.testByteConstantLength0();
250
t.testByteConstantLength1();
251
t.testByteConstantLength64();
252
t.testByteConstantLength128();
254
t.testShortConstantLength0();
255
t.testShortConstantLength1();
256
t.testShortConstantLength32();
257
t.testShortConstantLength64();
259
t.testCharConstantLength0();
260
t.testCharConstantLength1();
261
t.testCharConstantLength32();
262
t.testCharConstantLength64();
264
t.testIntConstantLength0();
265
t.testIntConstantLength1();
266
t.testIntConstantLength16();
267
t.testIntConstantLength32();
269
t.testFloatConstantLength0();
270
t.testFloatConstantLength1();
271
t.testFloatConstantLength16();
272
t.testFloatConstantLength32();
274
t.testLongConstantLength0();
275
t.testLongConstantLength1();
276
t.testLongConstantLength8();
277
t.testLongConstantLength16();
279
t.testDoubleConstantLength0();
280
t.testDoubleConstantLength1();
281
t.testDoubleConstantLength8();
282
t.testDoubleConstantLength16();
284
t.testLoopUnswitch(32);
285
t.testLoopHoist(128, 2);