Skip to content

Commit c98dffa

Browse files
author
Jatin Bhateja
committed
8357982: Fix several failing BMI tests with -XX:+UseAPX
Reviewed-by: epeter, sviswanathan
1 parent 7d7fc69 commit c98dffa

File tree

9 files changed

+122
-14
lines changed

9 files changed

+122
-14
lines changed

src/hotspot/cpu/x86/x86_64.ad

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10531,7 +10531,8 @@ instruct xorI_rReg_im1_ndd(rRegI dst, rRegI src, immI_M1 imm)
1053110531
// Xor Register with Immediate
1053210532
instruct xorI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
1053310533
%{
10534-
predicate(!UseAPX);
10534+
// Strict predicate check to make selection of xorI_rReg_im1 cost agnostic if immI src is -1.
10535+
predicate(!UseAPX && n->in(2)->bottom_type()->is_int()->get_con() != -1);
1053510536
match(Set dst (XorI dst src));
1053610537
effect(KILL cr);
1053710538
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
@@ -10545,7 +10546,8 @@ instruct xorI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
1054510546

1054610547
instruct xorI_rReg_rReg_imm_ndd(rRegI dst, rRegI src1, immI src2, rFlagsReg cr)
1054710548
%{
10548-
predicate(UseAPX);
10549+
// Strict predicate check to make selection of xorI_rReg_im1_ndd cost agnostic if immI src2 is -1.
10550+
predicate(UseAPX && n->in(2)->bottom_type()->is_int()->get_con() != -1);
1054910551
match(Set dst (XorI src1 src2));
1055010552
effect(KILL cr);
1055110553
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
@@ -10563,6 +10565,7 @@ instruct xorI_rReg_mem_imm_ndd(rRegI dst, memory src1, immI src2, rFlagsReg cr)
1056310565
predicate(UseAPX);
1056410566
match(Set dst (XorI (LoadI src1) src2));
1056510567
effect(KILL cr);
10568+
ins_cost(150);
1056610569
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
1056710570

1056810571
format %{ "exorl $dst, $src1, $src2\t# int ndd" %}
@@ -11205,7 +11208,8 @@ instruct xorL_rReg_im1_ndd(rRegL dst,rRegL src, immL_M1 imm)
1120511208
// Xor Register with Immediate
1120611209
instruct xorL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
1120711210
%{
11208-
predicate(!UseAPX);
11211+
// Strict predicate check to make selection of xorL_rReg_im1 cost agnostic if immL32 src is -1.
11212+
predicate(!UseAPX && n->in(2)->bottom_type()->is_long()->get_con() != -1L);
1120911213
match(Set dst (XorL dst src));
1121011214
effect(KILL cr);
1121111215
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
@@ -11219,7 +11223,8 @@ instruct xorL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
1121911223

1122011224
instruct xorL_rReg_rReg_imm(rRegL dst, rRegL src1, immL32 src2, rFlagsReg cr)
1122111225
%{
11222-
predicate(UseAPX);
11226+
// Strict predicate check to make selection of xorL_rReg_im1_ndd cost agnostic if immL32 src2 is -1.
11227+
predicate(UseAPX && n->in(2)->bottom_type()->is_long()->get_con() != -1L);
1122311228
match(Set dst (XorL src1 src2));
1122411229
effect(KILL cr);
1122511230
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
@@ -11238,6 +11243,7 @@ instruct xorL_rReg_mem_imm(rRegL dst, memory src1, immL32 src2, rFlagsReg cr)
1123811243
match(Set dst (XorL (LoadL src1) src2));
1123911244
effect(KILL cr);
1124011245
flag(PD::Flag_sets_sign_flag, PD::Flag_sets_zero_flag, PD::Flag_sets_parity_flag, PD::Flag_clears_overflow_flag, PD::Flag_clears_carry_flag);
11246+
ins_cost(150);
1124111247

1124211248
format %{ "exorq $dst, $src1, $src2\t# long ndd" %}
1124311249
ins_encode %{

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/AndnTestI.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,6 +57,19 @@ protected AndnTestI(Method method) {
5757
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
5858
(byte) 0x00,
5959
(byte) 0xF2};
60+
// from intel apx specifications EVEX.128.NP.0F38.W0 F2 /r
61+
instrMaskAPX = new byte[]{
62+
(byte) 0xFF,
63+
(byte) 0x07,
64+
(byte) 0x00,
65+
(byte) 0x00,
66+
(byte) 0xFF};
67+
instrPatternAPX = new byte[]{
68+
(byte) 0x62, // fixed prefix byte 0x62 for extended EVEX instruction
69+
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
70+
(byte) 0x00,
71+
(byte) 0x00,
72+
(byte) 0xF2};
6073
}
6174

6275
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/BlsiTestI.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ protected BlsiTestI(Method method) {
5959
(byte) 0x00,
6060
(byte) 0xF3,
6161
(byte) 0b0001_1000}; // bits 543 == 011 (3)
62+
63+
// from intel apx specifications EVEX.128.NP.0F38.W0 F3 /3(opcode extension)
64+
instrMaskAPX = new byte[]{
65+
(byte) 0xFF,
66+
(byte) 0x07,
67+
(byte) 0x00,
68+
(byte) 0x00,
69+
(byte) 0xFF,
70+
(byte) 0x38};
71+
72+
instrPatternAPX = new byte[]{
73+
(byte) 0x62, // fixed prefix byte 0x62 for extended EVEX instruction
74+
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
75+
(byte) 0x00,
76+
(byte) 0x00,
77+
(byte) 0xF3,
78+
(byte) 0b0001_1000}; // bits 543 == 011 (3)
6279
}
6380

6481
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/BlsmskTestI.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,24 @@ protected BlsmskTestI(Method method) {
5757
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
5858
(byte) 0x00,
5959
(byte) 0xF3,
60-
(byte) 0b0001_0000}; // bits 543 == 011 (3)
60+
(byte) 0b0001_0000}; // bits 543 == 010 (2)
61+
62+
// from intel apx specifications EVEX.128.NP.0F38.W1 F3 /2(opcode extension part of ModRM.REG)
63+
instrMaskAPX = new byte[]{
64+
(byte) 0xFF,
65+
(byte) 0x07,
66+
(byte) 0x00,
67+
(byte) 0x00,
68+
(byte) 0xFF,
69+
(byte) 0x38};
70+
71+
instrPatternAPX = new byte[]{
72+
(byte) 0x62, // fixed prefix byte 0x62 for extended EVEX instruction
73+
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
74+
(byte) 0x00,
75+
(byte) 0x00,
76+
(byte) 0xF3,
77+
(byte) 0b0001_0000}; // bits 543 == 010 (2)
6178
}
6279

6380
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/BlsrTestI.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,25 @@ protected BlsrTestI(Method method) {
5858
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
5959
(byte) 0x00,
6060
(byte) 0xF3,
61-
(byte) 0b0000_1000}; // bits 543 == 011 (3)
61+
(byte) 0b0000_1000}; // bits 543 == 001 (1)
62+
63+
// from intel apx specifications EVEX.128.NP.0F38.W1 F3 /1(opcode extension part of ModRM.REG)
64+
instrMaskAPX = new byte[]{
65+
(byte) 0xFF,
66+
(byte) 0x07,
67+
(byte) 0x00,
68+
(byte) 0x00,
69+
(byte) 0xFF,
70+
(byte) 0x38};
71+
72+
instrPatternAPX = new byte[]{
73+
(byte) 0x62, // fixed prefix byte 0x62 for extended EVEX instruction
74+
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
75+
(byte) 0x00,
76+
(byte) 0x00,
77+
(byte) 0xF3,
78+
(byte) 0b0000_1000}; // bits 543 == 001 (1)
79+
6280
}
6381

6482
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/BmiIntrinsicBase.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -111,7 +111,8 @@ protected void checkCompilation(Executable executable, int level) {
111111
protected void checkEmittedCode(Executable executable) {
112112
final byte[] nativeCode = NMethod.get(executable, false).insts;
113113
final byte[] matchInstrPattern = (((BmiTestCase) testCase).getTestCaseX64() && Platform.isX64()) ? ((BmiTestCase_x64) testCase).getInstrPattern_x64() : ((BmiTestCase) testCase).getInstrPattern();
114-
if (!((BmiTestCase) testCase).verifyPositive(nativeCode)) {
114+
boolean use_apx = CPUInfo.hasFeature("apx_f");
115+
if (!((BmiTestCase) testCase).verifyPositive(nativeCode, use_apx)) {
115116
throw new AssertionError(testCase.name() + " " + "CPU instructions expected not found in nativeCode: " + Utils.toHexString(nativeCode) + " ---- Expected instrPattern: " +
116117
Utils.toHexString(matchInstrPattern));
117118
} else {
@@ -124,6 +125,8 @@ abstract static class BmiTestCase implements CompilerWhiteBoxTest.TestCase {
124125
private final Method method;
125126
protected byte[] instrMask;
126127
protected byte[] instrPattern;
128+
protected byte[] instrMaskAPX;
129+
protected byte[] instrPatternAPX;
127130
protected boolean isLongOperation;
128131
protected String cpuFlag = "bmi1";
129132
protected String vmFlag = "UseBMI1Instructions";
@@ -160,6 +163,13 @@ protected int countCpuInstructions(byte[] nativeCode) {
160163
return countCpuInstructions(nativeCode, instrMask, instrPattern);
161164
}
162165

166+
protected int countCpuInstructionsAPX(byte[] nativeCode) {
167+
if (instrMaskAPX == null || instrPatternAPX == null) {
168+
return 0;
169+
}
170+
return countCpuInstructions(nativeCode, instrMaskAPX, instrPatternAPX);
171+
}
172+
163173
public static int countCpuInstructions(byte[] nativeCode, byte[] instrMask, byte[] instrPattern) {
164174
int count = 0;
165175
int patternSize = Math.min(instrMask.length, instrPattern.length);
@@ -181,8 +191,12 @@ public static int countCpuInstructions(byte[] nativeCode, byte[] instrMask, byte
181191
return count;
182192
}
183193

184-
public boolean verifyPositive(byte[] nativeCode) {
185-
final int cnt = countCpuInstructions(nativeCode);
194+
public boolean verifyPositive(byte[] nativeCode, boolean use_apx) {
195+
int cnt = countCpuInstructions(nativeCode);
196+
if (use_apx) {
197+
System.out.println("CHECKING APX INST PATTERNS");
198+
cnt += countCpuInstructionsAPX(nativeCode);
199+
}
186200
if (Platform.isX86()) {
187201
return cnt >= (isLongOperation ? 2 : 1);
188202
} else {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/BzhiTestI2L.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,6 +73,21 @@ protected BzhiTestI2L(Method method) {
7373
(byte) 0x62, // 00010 implied 0F 38 leading opcode bytes
7474
(byte) 0xA8,
7575
(byte) 0xF5};
76+
77+
// from intel apx specifications EVEX.128.NP.0F38.W0 F5 /r
78+
instrMaskAPX = new byte[]{
79+
(byte) 0xFF,
80+
(byte) 0x07,
81+
(byte) 0x00,
82+
(byte) 0x00,
83+
(byte) 0xFF};
84+
85+
instrPatternAPX = new byte[]{
86+
(byte) 0x62, // fixed prefix byte 0x62 for extended EVEX instruction
87+
(byte) 0x02, // 00010 implied 0F 38 leading opcode bytes
88+
(byte) 0x00,
89+
(byte) 0x00,
90+
(byte) 0xF5};
7691
}
7792

7893
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/LZcntTestI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,6 +51,10 @@ protected LZcntTestI(Method method) {
5151

5252
instrMask_x64 = new byte[]{(byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF};
5353
instrPattern_x64 = new byte[]{(byte) 0xF3, (byte) 0x00, (byte) 0x0F, (byte) 0xBD};
54+
55+
// REX2 variant
56+
instrMaskAPX = new byte[]{(byte) 0xFF, (byte) 0xFF, (byte)0x80, (byte) 0xFF};
57+
instrPatternAPX = new byte[]{(byte) 0xF3, (byte) 0xD5, (byte) 0x80, (byte) 0xBD};
5458
}
5559

5660
public static void main(String[] args) throws Exception {

test/hotspot/jtreg/compiler/intrinsics/bmi/verifycode/TZcntTestI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,6 +50,10 @@ protected TZcntTestI(Method method) {
5050

5151
instrMask_x64 = new byte[]{(byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xFF};
5252
instrPattern_x64 = new byte[]{(byte) 0xF3, (byte) 0x00, (byte) 0x0F, (byte) 0xBC};
53+
54+
// REX2 variant
55+
instrMaskAPX = new byte[]{(byte) 0xFF, (byte) 0xFF, (byte)0x80, (byte) 0xFF};
56+
instrPatternAPX = new byte[]{(byte) 0xF3, (byte) 0xD5, (byte) 0x80, (byte) 0xBC};
5357
}
5458

5559
public static void main(String[] args) throws Exception {

0 commit comments

Comments
 (0)