jdk

Форк
0
/
TestPopulateIndex.java 
115 строк · 3.6 Кб
1
/*
2
 * Copyright (c) 2022, 2023, 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
/**
25
* @test
26
* @bug 8286972
27
* @summary Test vectorization of loop induction variable usage in the loop
28
* @requires vm.compiler2.enabled
29
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") |
30
*           (os.simpleArch == "aarch64" & vm.cpu.features ~= ".*sve.*")
31
* @library /test/lib /
32
* @run driver compiler.vectorization.TestPopulateIndex
33
*/
34

35
package compiler.vectorization;
36
import compiler.lib.ir_framework.*;
37
import java.util.Random;
38

39
public class TestPopulateIndex {
40
    private static final int count = 10000;
41

42
    private int[] idx;
43
    private int[] src;
44
    private int[] dst;
45
    private float[] f;
46

47
    public static void main(String args[]) {
48
        TestFramework.run(TestPopulateIndex.class);
49
    }
50

51
    public TestPopulateIndex() {
52
        idx = new int[count];
53
        src = new int[count];
54
        dst = new int[count];
55
        f = new float[count];
56
        Random ran = new Random(0);
57
        for (int i = 0; i < count; i++) {
58
            src[i] = ran.nextInt();
59
        }
60
    }
61

62
    @Test
63
    @IR(counts = {IRNode.POPULATE_INDEX, "> 0"})
64
    public void indexArrayFill() {
65
        for (int i = 0; i < count; i++) {
66
            idx[i] = i;
67
        }
68
        checkResultIndexArrayFill();
69
    }
70

71
    public void checkResultIndexArrayFill() {
72
        for (int i = 0; i < count; i++) {
73
            int expected = i;
74
            if (idx[i] != expected) {
75
                throw new RuntimeException("Invalid result: idx[" + i + "] = " + idx[i] + " != " + expected);
76
            }
77
        }
78
    }
79

80
    @Test
81
    @IR(counts = {IRNode.POPULATE_INDEX, "> 0"})
82
    public void exprWithIndex1() {
83
        for (int i = 0; i < count; i++) {
84
            dst[i] = src[i] * (i & 7);
85
        }
86
        checkResultExprWithIndex1();
87
    }
88

89
    public void checkResultExprWithIndex1() {
90
        for (int i = 0; i < count; i++) {
91
            int expected = src[i] * (i & 7);
92
            if (dst[i] != expected) {
93
                throw new RuntimeException("Invalid result: dst[" + i + "] = " + dst[i] + " != " + expected);
94
            }
95
        }
96
    }
97

98
    @Test
99
    @IR(counts = {IRNode.POPULATE_INDEX, "> 0"})
100
    public void exprWithIndex2() {
101
        for (int i = 0; i < count; i++) {
102
            f[i] = i * i + 100;
103
        }
104
        checkResultExprWithIndex2();
105
    }
106

107
    public void checkResultExprWithIndex2() {
108
        for (int i = 0; i < count; i++) {
109
            float expected = i * i  + 100;
110
            if (f[i] != expected) {
111
                throw new RuntimeException("Invalid result: f[" + i + "] = " + f[i] + " != " + expected);
112
            }
113
        }
114
    }
115
}
116

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

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

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

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