Skip to content

Commit

Permalink
Add vendor identity check for Hygon Dhyana processor in Scudo
Browse files Browse the repository at this point in the history
Summary:
The Hygon Dhyana processor supports hardware CRC32.

Related link:
https://reviews.llvm.org/D78874

Result of "make check":
Testing Time: 1364.04s
  Unsupported Tests:   317
  Expected Passes  : 36802
  Expected Failures:   161
[100%] Built target check-llvm
[100%] Built target check

Reviewers: cryptoad

Reviewed By: cryptoad

Subscribers: craig.topper, cryptoad, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D62368
  • Loading branch information
Kostya Kortchinsky committed May 11, 2020
1 parent b02473d commit 9959eb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 12 additions & 1 deletion compiler-rt/lib/scudo/scudo_utils.cpp
Expand Up @@ -62,6 +62,14 @@ FORMAT(1, 2) void NORETURN dieWithMessage(const char *Format, ...) {
# ifndef bit_SSE4_2
# define bit_SSE4_2 bit_SSE42 // clang and gcc have different defines.
# endif

#ifndef signature_HYGON_ebx // They are not defined in gcc.
// HYGON: "HygonGenuine".
#define signature_HYGON_ebx 0x6f677948
#define signature_HYGON_edx 0x6e65476e
#define signature_HYGON_ecx 0x656e6975
#endif

bool hasHardwareCRC32() {
u32 Eax, Ebx, Ecx, Edx;
__get_cpuid(0, &Eax, &Ebx, &Ecx, &Edx);
Expand All @@ -71,7 +79,10 @@ bool hasHardwareCRC32() {
const bool IsAMD = (Ebx == signature_AMD_ebx) &&
(Edx == signature_AMD_edx) &&
(Ecx == signature_AMD_ecx);
if (!IsIntel && !IsAMD)
const bool IsHygon = (Ebx == signature_HYGON_ebx) &&
(Edx == signature_HYGON_edx) &&
(Ecx == signature_HYGON_ecx);
if (!IsIntel && !IsAMD && !IsHygon)
return false;
__get_cpuid(1, &Eax, &Ebx, &Ecx, &Edx);
return !!(Ecx & bit_SSE4_2);
Expand Down
12 changes: 11 additions & 1 deletion compiler-rt/lib/scudo/standalone/checksum.cpp
Expand Up @@ -31,6 +31,13 @@ Checksum HashAlgorithm = {Checksum::BSD};
#define bit_SSE4_2 bit_SSE42 // clang and gcc have different defines.
#endif

#ifndef signature_HYGON_ebx // They are not defined in gcc.
// HYGON: "HygonGenuine".
#define signature_HYGON_ebx 0x6f677948
#define signature_HYGON_edx 0x6e65476e
#define signature_HYGON_ecx 0x656e6975
#endif

bool hasHardwareCRC32() {
u32 Eax, Ebx = 0, Ecx = 0, Edx = 0;
__get_cpuid(0, &Eax, &Ebx, &Ecx, &Edx);
Expand All @@ -39,7 +46,10 @@ bool hasHardwareCRC32() {
(Ecx == signature_INTEL_ecx);
const bool IsAMD = (Ebx == signature_AMD_ebx) && (Edx == signature_AMD_edx) &&
(Ecx == signature_AMD_ecx);
if (!IsIntel && !IsAMD)
const bool IsHygon = (Ebx == signature_HYGON_ebx) &&
(Edx == signature_HYGON_edx) &&
(Ecx == signature_HYGON_ecx);
if (!IsIntel && !IsAMD && !IsHygon)
return false;
__get_cpuid(1, &Eax, &Ebx, &Ecx, &Edx);
return !!(Ecx & bit_SSE4_2);
Expand Down

0 comments on commit 9959eb9

Please sign in to comment.