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 * @summary Test vectorization of popcount for Long
27 * @requires vm.compiler2.enabled
28 * @requires vm.cpu.features ~= ".*avx512bw.*"
29 * @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64"
30 * @library /test/lib /
31 * @run driver compiler.vectorization.TestPopCountVectorLong
32 */
33
34 package compiler.vectorization;
35 import compiler.lib.ir_framework.*;
36 import java.util.Random;
37
38
39 public class TestPopCountVectorLong {
40 private long[] input;
41 private int[] output;
42 private static final int LEN = 1024;
43 private Random rng;
44
45 public static void main(String args[]) {
46 TestFramework.run(TestPopCountVectorLong.class);
47 }
48
49 public TestPopCountVectorLong() {
50 input = new long[LEN];
51 output = new int[LEN];
52 rng = new Random(42);
53 for (int i = 0; i < LEN; ++i) {
54 input[i] = rng.nextLong();
55 }
56 }
57
58 @Test // needs to be run in (fast) debug mode
59 @Warmup(10000)
60 @IR(counts = {"PopCountVL", ">= 1"}) // Atleast one PopCountVL node is generated if vectorization is successful
61 public void vectorizeBitCount() {
62 for (int i = 0; i < LEN; ++i) {
63 output[i] = Long.bitCount(input[i]);
64 }
65 checkResult();
66 }
67
68 public void checkResult() {
69 for (int i = 0; i < LEN; ++i) {
70 int expected = Long.bitCount(input[i]);
71 if (output[i] != expected) {
72 throw new RuntimeException("Invalid result: output[" + i + "] = " + output[i] + " != " + expected);
73 }
74 }
75 }
76 }
77
|
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 * @summary Test vectorization of popcount for Long
27 * @requires vm.compiler2.enabled
28 * @requires vm.cpu.features ~= ".*avx512bw.*" | vm.cpu.features ~= ".*sve.*"
29 * @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64"
30 * @library /test/lib /
31 * @run driver compiler.vectorization.TestPopCountVectorLong
32 */
33
34 package compiler.vectorization;
35 import compiler.lib.ir_framework.*;
36 import java.util.Random;
37
38
39 public class TestPopCountVectorLong {
40 private long[] input;
41 private int[] output;
42 private static final int LEN = 1024;
43 private Random rng;
44
45 public static void main(String args[]) {
46 TestFramework.run(TestPopCountVectorLong.class);
47 }
48
49 public TestPopCountVectorLong() {
50 input = new long[LEN];
51 output = new int[LEN];
52 rng = new Random(42);
53 for (int i = 0; i < LEN; ++i) {
54 input[i] = rng.nextLong();
55 }
56 }
57
58 @Test // needs to be run in (fast) debug mode
59 @Warmup(10000)
60 @IR(counts = {"PopCountVL", ">= 1"}) // At least one PopCountVL node is generated if vectorization is successful
61 public void vectorizeBitCount() {
62 for (int i = 0; i < LEN; ++i) {
63 output[i] = Long.bitCount(input[i]);
64 }
65 checkResult();
66 }
67
68 public void checkResult() {
69 for (int i = 0; i < LEN; ++i) {
70 int expected = Long.bitCount(input[i]);
71 if (output[i] != expected) {
72 throw new RuntimeException("Invalid result: output[" + i + "] = " + output[i] + " != " + expected);
73 }
74 }
75 }
76 }
77
|