8
8
#include < assert.h>
9
9
#include < string.h>
10
10
11
+ #include < compat/cpuid.h>
12
+
11
13
#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
12
14
#if defined(USE_ASM)
13
- #include < cpuid.h>
14
15
namespace sha256_sse4
15
16
{
16
17
void Transform (uint32_t * s, const unsigned char * chunk, size_t blocks);
@@ -546,18 +547,7 @@ bool SelfTest() {
546
547
return true ;
547
548
}
548
549
549
-
550
550
#if defined(USE_ASM) && (defined(__x86_64__) || defined(__amd64__) || defined(__i386__))
551
- // We can't use cpuid.h's __get_cpuid as it does not support subleafs.
552
- void inline cpuid (uint32_t leaf, uint32_t subleaf, uint32_t & a, uint32_t & b, uint32_t & c, uint32_t & d)
553
- {
554
- #ifdef __GNUC__
555
- __cpuid_count (leaf, subleaf, a, b, c, d);
556
- #else
557
- __asm__ (" cpuid" : " =a" (a), " =b" (b), " =c" (c), " =d" (d) : " 0" (leaf), " 2" (subleaf));
558
- #endif
559
- }
560
-
561
551
/* * Check whether the OS has enabled AVX registers. */
562
552
bool AVXEnabled ()
563
553
{
@@ -572,7 +562,7 @@ bool AVXEnabled()
572
562
std::string SHA256AutoDetect ()
573
563
{
574
564
std::string ret = " standard" ;
575
- #if defined(USE_ASM) && ( defined(__x86_64__) || defined(__amd64__) || defined(__i386__) )
565
+ #if defined(USE_ASM) && defined(HAVE_GETCPUID )
576
566
bool have_sse4 = false ;
577
567
bool have_xsave = false ;
578
568
bool have_avx = false ;
@@ -589,15 +579,15 @@ std::string SHA256AutoDetect()
589
579
(void )enabled_avx;
590
580
591
581
uint32_t eax, ebx, ecx, edx;
592
- cpuid (1 , 0 , eax, ebx, ecx, edx);
582
+ GetCPUID (1 , 0 , eax, ebx, ecx, edx);
593
583
have_sse4 = (ecx >> 19 ) & 1 ;
594
584
have_xsave = (ecx >> 27 ) & 1 ;
595
585
have_avx = (ecx >> 28 ) & 1 ;
596
586
if (have_xsave && have_avx) {
597
587
enabled_avx = AVXEnabled ();
598
588
}
599
589
if (have_sse4) {
600
- cpuid (7 , 0 , eax, ebx, ecx, edx);
590
+ GetCPUID (7 , 0 , eax, ebx, ecx, edx);
601
591
have_avx2 = (ebx >> 5 ) & 1 ;
602
592
have_shani = (ebx >> 29 ) & 1 ;
603
593
}
0 commit comments