jdk

Форк
0
/
VectorizedMismatchTest.java 
288 строк · 11.5 Кб
1
/*
2
 * Copyright (c) 2021, 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

24
package compiler.intrinsics;
25

26
/*
27
 * @test
28
 * @requires vm.opt.final.UseVectorizedMismatchIntrinsic == true
29
 * @modules java.base/jdk.internal.misc
30
 *          java.base/jdk.internal.util
31
 *
32
 *  @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,*::test*
33
 *                    -Xbatch -XX:-TieredCompilation
34
 *                    -XX:UseAVX=3
35
 *                     compiler.intrinsics.VectorizedMismatchTest
36
 *
37
 *  @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,*::test*
38
 *                    -Xbatch -XX:-TieredCompilation
39
 *                    -XX:+UnlockDiagnosticVMOptions -XX:UseAVX=3 -XX:AVX3Threshold=0
40
 *                     compiler.intrinsics.VectorizedMismatchTest
41
 */
42

43
import jdk.internal.misc.Unsafe;
44
import jdk.internal.util.ArraysSupport;
45

46
public class VectorizedMismatchTest {
47
    private boolean[] boolean_a = new boolean[128];
48
    private boolean[] boolean_b = new boolean[128];
49

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);
56
    }
57

58
    int testBooleanConstantLength0()   { return testBooleanConstantLength(0);   }
59
    int testBooleanConstantLength1()   { return testBooleanConstantLength(1);   }
60
    int testBooleanConstantLength64()  { return testBooleanConstantLength(64);  }
61
    int testBooleanConstantLength128() { return testBooleanConstantLength(128); }
62

63
    /* ==================================================================================== */
64

65
    private byte[] byte_a = new byte[128];
66
    private byte[] byte_b = new byte[128];
67

68
    int testByteConstantLength(int length) {
69
        byte[] obja = byte_a;
70
        byte[] objb = byte_b;
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);
74
    }
75

76
    int testByteConstantLength0()   { return testByteConstantLength(0);   }
77
    int testByteConstantLength1()   { return testByteConstantLength(1);   }
78
    int testByteConstantLength64()  { return testByteConstantLength(64);  }
79
    int testByteConstantLength128() { return testByteConstantLength(128); }
80

81
    /* ==================================================================================== */
82

83
    private short[] short_a = new short[64];
84
    private short[] short_b = new short[64];
85

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);
92
    }
93

94
    int testShortConstantLength0()  { return testShortConstantLength(0);  }
95
    int testShortConstantLength1()  { return testShortConstantLength(1);  }
96
    int testShortConstantLength32() { return testShortConstantLength(32); }
97
    int testShortConstantLength64() { return testShortConstantLength(64); }
98

99
    /* ==================================================================================== */
100

101
    private char[] char_a = new char[64];
102
    private char[] char_b = new char[64];
103

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);
110
    }
111

112
    int testCharConstantLength0()  { return testCharConstantLength(0);  }
113
    int testCharConstantLength1()  { return testCharConstantLength(1);  }
114
    int testCharConstantLength32() { return testCharConstantLength(32); }
115
    int testCharConstantLength64() { return testCharConstantLength(64); }
116

117
    /* ==================================================================================== */
118

119
    private int[] int_a = new int[32];
120
    private int[] int_b = new int[32];
121

122
    int testIntConstantLength(int length) {
123
        int[] obja = int_a;
124
        int[] objb = int_b;
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);
128
    }
129

130
    int testIntConstantLength0()  { return testIntConstantLength(0);  }
131
    int testIntConstantLength1()  { return testIntConstantLength(1);  }
132
    int testIntConstantLength16() { return testIntConstantLength(16); }
133
    int testIntConstantLength32() { return testIntConstantLength(32); }
134

135
    /* ==================================================================================== */
136

137
    private float[] float_a = new float[32];
138
    private float[] float_b = new float[32];
139

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);
146
    }
147

148
    int testFloatConstantLength0()  { return testFloatConstantLength(0);  }
149
    int testFloatConstantLength1()  { return testFloatConstantLength(1);  }
150
    int testFloatConstantLength16() { return testFloatConstantLength(16); }
151
    int testFloatConstantLength32() { return testFloatConstantLength(32); }
152

153
    /* ==================================================================================== */
154

155
    private long[] long_a = new long[16];
156
    private long[] long_b = new long[16];
157

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);
164
    }
165

166
    int testLongConstantLength0()  { return testLongConstantLength(0);  }
167
    int testLongConstantLength1()  { return testLongConstantLength(1);  }
168
    int testLongConstantLength8()  { return testLongConstantLength(8);  }
169
    int testLongConstantLength16() { return testLongConstantLength(16); }
170

171
    /* ==================================================================================== */
172

173
    private double[] double_a = new double[16];
174
    private double[] double_b = new double[16];
175

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);
182
    }
183

184
    int testDoubleConstantLength0()  { return testDoubleConstantLength(0);  }
185
    int testDoubleConstantLength1()  { return testDoubleConstantLength(1);  }
186
    int testDoubleConstantLength8()  { return testDoubleConstantLength(8);  }
187
    int testDoubleConstantLength16() { return testDoubleConstantLength(16); }
188

189
    /* ==================================================================================== */
190

191
    static class ClassInitTest {
192
        static final int LENGTH = 64;
193
        static final int RESULT;
194
        static {
195
            byte[] arr1 = new byte[LENGTH];
196
            byte[] arr2 = new byte[LENGTH];
197
            for (int i = 0; i < 20_000; i++) {
198
                test(arr1, arr2);
199
            }
200
            RESULT = test(arr1, arr2);
201
        }
202

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); // LENGTH is not considered a constant
207
        }
208
    }
209

210
    int testConstantBeingInitialized() {
211
        return ClassInitTest.RESULT; // trigger class initialization
212
    }
213

214
    /* ==================================================================================== */
215

216
    int testLoopUnswitch(int length) {
217
        long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
218
        int  scale  = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
219

220
        int acc = 0;
221
        for (int i = 0; i < 32; i++) {
222
            acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);
223
        }
224
        return acc;
225
    }
226

227
    int testLoopHoist(int length, int stride) {
228
        long offset = Unsafe.ARRAY_BYTE_BASE_OFFSET;
229
        int  scale  = ArraysSupport.LOG2_ARRAY_BYTE_INDEX_SCALE;
230

231
        int acc = 0;
232

233
        for (int i = 0; i < 32; i += stride) {
234
            acc += ArraysSupport.vectorizedMismatch(byte_a, offset, byte_b, offset, length, scale);
235
        }
236
        return acc;
237
    }
238

239
    /* ==================================================================================== */
240

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();
248

249
            t.testByteConstantLength0();
250
            t.testByteConstantLength1();
251
            t.testByteConstantLength64();
252
            t.testByteConstantLength128();
253

254
            t.testShortConstantLength0();
255
            t.testShortConstantLength1();
256
            t.testShortConstantLength32();
257
            t.testShortConstantLength64();
258

259
            t.testCharConstantLength0();
260
            t.testCharConstantLength1();
261
            t.testCharConstantLength32();
262
            t.testCharConstantLength64();
263

264
            t.testIntConstantLength0();
265
            t.testIntConstantLength1();
266
            t.testIntConstantLength16();
267
            t.testIntConstantLength32();
268

269
            t.testFloatConstantLength0();
270
            t.testFloatConstantLength1();
271
            t.testFloatConstantLength16();
272
            t.testFloatConstantLength32();
273

274
            t.testLongConstantLength0();
275
            t.testLongConstantLength1();
276
            t.testLongConstantLength8();
277
            t.testLongConstantLength16();
278

279
            t.testDoubleConstantLength0();
280
            t.testDoubleConstantLength1();
281
            t.testDoubleConstantLength8();
282
            t.testDoubleConstantLength16();
283

284
            t.testLoopUnswitch(32);
285
            t.testLoopHoist(128, 2);
286
        }
287
    }
288
}
289

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.