Skip to content

Commit

Permalink
Return 0-values for XGETBV64 and CPUID64 when CRYPTOPP_DISABLE_ASM is…
Browse files Browse the repository at this point in the history
… in effect (GH #1240)

Some folks were defining CRYPTOPP_DISABLE_ASM and not building the *.asm files on WIndows. That happened to work until we refactored code for XGetBV and CpuId.

These alternate build systems are going to be the death of us...
  • Loading branch information
noloader committed Oct 2, 2023
1 parent 843d74c commit 121014b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,14 @@ extern bool CPU_ProbeSSE2();
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85684.
word64 XGetBV(word32 num)
{
// Explicitly handle CRYPTOPP_DISABLE_ASM case.
// https://github.com/weidai11/cryptopp/issues/1240
#if defined(CRYPTOPP_DISABLE_ASM)
return 0;

// Required by Visual Studio 2008 and below and Clang on Windows.
// Use it for all MSVC-compatible compilers.
#if defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
#elif defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)

return XGETBV64(num);

Expand Down Expand Up @@ -446,9 +451,15 @@ word64 XGetBV(word32 num)
// cpu.cpp (131): E2211 Inline assembly not allowed in inline and template functions
bool CpuId(word32 func, word32 subfunc, word32 output[4])
{
// Explicitly handle CRYPTOPP_DISABLE_ASM case.
// https://github.com/weidai11/cryptopp/issues/1240
#if defined(CRYPTOPP_DISABLE_ASM)
output[0] = output[1] = output[2] = output[3] = 0;
return false;

// Required by Visual Studio 2008 and below and Clang on Windows.
// Use it for all MSVC-compatible compilers.
#if defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
#elif defined(_M_X64) && defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)

CPUID64(func, subfunc, output);
return true;
Expand Down

0 comments on commit 121014b

Please sign in to comment.