Skip to content

Commit 35d80b9

Browse files
committed
Adapt JDK-8353572: x86: AMD platforms miss the check for CLWB feature flag
1 parent 130dfe0 commit 35d80b9

File tree

1 file changed

+16
-26
lines changed
  • substratevm/src/com.oracle.svm.native.libchelper/src

1 file changed

+16
-26
lines changed

substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ NO_INLINE static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_i
494494
features->fTSCINV_BIT = 1;
495495
if (_cpuid_info->std_cpuid1_ecx.bits.aes != 0)
496496
features->fAES = 1;
497+
if (_cpuid_info->ext_cpuid1_ecx.bits.lzcnt != 0)
498+
features->fLZCNT = 1;
499+
if (_cpuid_info->ext_cpuid1_ecx.bits.prefetchw != 0)
500+
features->fAMD_3DNOW_PREFETCH = 1;
497501
if (_cpuid_info->sef_cpuid7_ebx.bits.erms != 0)
498502
features->fERMS = 1;
499503
if (_cpuid_info->sef_cpuid7_edx.bits.fast_short_rep_mov != 0)
@@ -512,6 +516,8 @@ NO_INLINE static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_i
512516
features->fFMA = 1;
513517
if (_cpuid_info->sef_cpuid7_ebx.bits.clflushopt != 0)
514518
features->fFLUSHOPT = 1;
519+
if (_cpuid_info->sef_cpuid7_ebx.bits.clwb != 0)
520+
features->fCLWB = 1;
515521
if (_cpuid_info->ext_cpuid1_edx.bits.rdtscp != 0)
516522
features->fRDTSCP = 1;
517523
if (_cpuid_info->sef_cpuid7_ecx.bits.rdpid != 0)
@@ -520,47 +526,31 @@ NO_INLINE static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_i
520526
_cpuid_info->xem_xcr0_eax.bits.apx_f != 0)
521527
features->fAPX_F = 1;
522528

523-
// AMD|Hygon features.
529+
// AMD|Hygon additional features.
524530
if (is_amd_family(_cpuid_info))
525531
{
526-
if ((_cpuid_info->ext_cpuid1_edx.bits.tdnow != 0) ||
527-
(_cpuid_info->ext_cpuid1_ecx.bits.prefetchw != 0))
532+
// PREFETCHW was checked above, check TDNOW here.
533+
if (_cpuid_info->ext_cpuid1_edx.bits.tdnow != 0)
528534
features->fAMD_3DNOW_PREFETCH = 1;
529-
if (_cpuid_info->ext_cpuid1_ecx.bits.lzcnt != 0)
530-
features->fLZCNT = 1;
531535
if (_cpuid_info->ext_cpuid1_ecx.bits.sse4a != 0)
532536
features->fSSE4A = 1;
533537
}
534538

535-
// Intel features.
539+
// Intel additional features.
536540
if (is_intel(_cpuid_info))
537541
{
538-
if (_cpuid_info->ext_cpuid1_ecx.bits.lzcnt != 0) {
539-
features->fLZCNT = 1;
540-
}
541-
if (_cpuid_info->ext_cpuid1_ecx.bits.prefetchw != 0) {
542-
features->fAMD_3DNOW_PREFETCH = 1;
543-
}
544-
if (_cpuid_info->sef_cpuid7_ebx.bits.clwb != 0) {
545-
features->fCLWB = 1;
546-
}
547-
if (_cpuid_info->sef_cpuid7_edx.bits.serialize != 0) {
542+
if (_cpuid_info->sef_cpuid7_edx.bits.serialize != 0)
548543
features->fSERIALIZE = 1;
549-
}
550-
if (_cpuid_info->sef_cpuid7_edx.bits.avx512_fp16 != 0) {
544+
if (_cpuid_info->sef_cpuid7_edx.bits.avx512_fp16 != 0)
551545
features->fAVX512_FP16 = 1;
552-
}
553546
}
554547

555-
// ZX features.
548+
// ZX additional features.
556549
if (is_zx(_cpuid_info))
557550
{
558-
if (_cpuid_info->ext_cpuid1_ecx.bits.lzcnt != 0) {
559-
features->fLZCNT = 1;
560-
}
561-
if (_cpuid_info->ext_cpuid1_ecx.bits.prefetchw != 0) {
562-
features->fAMD_3DNOW_PREFETCH = 1;
563-
}
551+
// We do not know if these are supported by ZX, so we cannot trust
552+
// common CPUID bit for them.
553+
features->fCLWB = 0;
564554
}
565555

566556
// Protection key features.

0 commit comments

Comments
 (0)