@@ -579,9 +579,15 @@ bool AVXEnabled()
579
579
} // namespace
580
580
581
581
582
- std::string SHA256AutoDetect ()
582
+ std::string SHA256AutoDetect (sha256_implementation::UseImplementation use_implementation )
583
583
{
584
584
std::string ret = " standard" ;
585
+ Transform = sha256::Transform;
586
+ TransformD64 = sha256::TransformD64;
587
+ TransformD64_2way = nullptr ;
588
+ TransformD64_4way = nullptr ;
589
+ TransformD64_8way = nullptr ;
590
+
585
591
#if defined(USE_ASM) && defined(HAVE_GETCPUID)
586
592
bool have_sse4 = false ;
587
593
bool have_xsave = false ;
@@ -592,16 +598,22 @@ std::string SHA256AutoDetect()
592
598
593
599
uint32_t eax, ebx, ecx, edx;
594
600
GetCPUID (1 , 0 , eax, ebx, ecx, edx);
595
- have_sse4 = (ecx >> 19 ) & 1 ;
601
+ if (use_implementation & sha256_implementation::USE_SSE4) {
602
+ have_sse4 = (ecx >> 19 ) & 1 ;
603
+ }
596
604
have_xsave = (ecx >> 27 ) & 1 ;
597
605
have_avx = (ecx >> 28 ) & 1 ;
598
606
if (have_xsave && have_avx) {
599
607
enabled_avx = AVXEnabled ();
600
608
}
601
609
if (have_sse4) {
602
610
GetCPUID (7 , 0 , eax, ebx, ecx, edx);
603
- have_avx2 = (ebx >> 5 ) & 1 ;
604
- have_x86_shani = (ebx >> 29 ) & 1 ;
611
+ if (use_implementation & sha256_implementation::USE_AVX2) {
612
+ have_avx2 = (ebx >> 5 ) & 1 ;
613
+ }
614
+ if (use_implementation & sha256_implementation::USE_SHANI) {
615
+ have_x86_shani = (ebx >> 29 ) & 1 ;
616
+ }
605
617
}
606
618
607
619
#if defined(ENABLE_X86_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
@@ -637,27 +649,28 @@ std::string SHA256AutoDetect()
637
649
638
650
#if defined(ENABLE_ARM_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
639
651
bool have_arm_shani = false ;
640
-
652
+ if (use_implementation & sha256_implementation::USE_SHANI) {
641
653
#if defined(__linux__)
642
654
#if defined(__arm__) // 32-bit
643
- if (getauxval (AT_HWCAP2) & HWCAP2_SHA2) {
644
- have_arm_shani = true ;
645
- }
655
+ if (getauxval (AT_HWCAP2) & HWCAP2_SHA2) {
656
+ have_arm_shani = true ;
657
+ }
646
658
#endif
647
659
#if defined(__aarch64__) // 64-bit
648
- if (getauxval (AT_HWCAP) & HWCAP_SHA2) {
649
- have_arm_shani = true ;
650
- }
660
+ if (getauxval (AT_HWCAP) & HWCAP_SHA2) {
661
+ have_arm_shani = true ;
662
+ }
651
663
#endif
652
664
#endif
653
665
654
666
#if defined(MAC_OSX)
655
- int val = 0 ;
656
- size_t len = sizeof (val);
657
- if (sysctlbyname (" hw.optional.arm.FEAT_SHA256" , &val, &len, nullptr , 0 ) == 0 ) {
658
- have_arm_shani = val != 0 ;
659
- }
667
+ int val = 0 ;
668
+ size_t len = sizeof (val);
669
+ if (sysctlbyname (" hw.optional.arm.FEAT_SHA256" , &val, &len, nullptr , 0 ) == 0 ) {
670
+ have_arm_shani = val != 0 ;
671
+ }
660
672
#endif
673
+ }
661
674
662
675
if (have_arm_shani) {
663
676
Transform = sha256_arm_shani::Transform;
0 commit comments