Commit 30bc41d9 authored by jan.koester's avatar jan.koester
Browse files

musl cpu fix

parent d38c7bec
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -125,8 +125,19 @@ static std::vector<uint8_t> sha256_hash_shani(const std::vector<uint8_t>& input)
}

static bool cpu_has_shani() {
#if defined(__GNUC__) || defined(__clang__)
#if defined(__SHA__)
    // Compiled with -msha, assume CPU supports it
    return true;
#elif defined(__GNUC__) || defined(__clang__)
  #if defined(__linux__) && !defined(__GLIBC__)
    // musl: use cpuid directly
    unsigned int eax, ebx, ecx, edx;
    __asm__ __volatile__("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                         : "a"(7), "c"(0));
    return (ebx >> 29) & 1; // SHA bit is bit 29 of EBX for CPUID leaf 7
  #else
    return __builtin_cpu_supports("sha");
  #endif
#else
    return false;
#endif