MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SHA256AutoDetect

Function SHA256AutoDetect

src/crypto/sha256.cpp:573–639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

571
572
573std::string SHA256AutoDetect()
574{
575 std::string ret = "standard";
576#if defined(USE_ASM) && (defined(__x86_64__) || defined(__amd64__) || defined(__i386__))
577 bool have_sse4 = false;
578 bool have_xsave = false;
579 bool have_avx = false;
580 bool have_avx2 = false;
581 bool have_shani = false;
582 bool enabled_avx = false;
583
584 (void)AVXEnabled;
585 (void)have_sse4;
586 (void)have_avx;
587 (void)have_xsave;
588 (void)have_avx2;
589 (void)have_shani;
590 (void)enabled_avx;
591
592 uint32_t eax, ebx, ecx, edx;
593 cpuid(1, 0, eax, ebx, ecx, edx);
594 have_sse4 = (ecx >> 19) & 1;
595 have_xsave = (ecx >> 27) & 1;
596 have_avx = (ecx >> 28) & 1;
597 if (have_xsave && have_avx) {
598 enabled_avx = AVXEnabled();
599 }
600 if (have_sse4) {
601 cpuid(7, 0, eax, ebx, ecx, edx);
602 have_avx2 = (ebx >> 5) & 1;
603 have_shani = (ebx >> 29) & 1;
604 }
605
606#if defined(ENABLE_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
607 if (have_shani) {
608 Transform = sha256_shani::Transform;
609 TransformD64 = TransformD64Wrapper<sha256_shani::Transform>;
610 TransformD64_2way = sha256d64_shani::Transform_2way;
611 ret = "shani(1way,2way)";
612 have_sse4 = false; // Disable SSE4/AVX2;
613 have_avx2 = false;
614 }
615#endif
616
617 if (have_sse4) {
618#if defined(__x86_64__) || defined(__amd64__)
619 Transform = sha256_sse4::Transform;
620 TransformD64 = TransformD64Wrapper<sha256_sse4::Transform>;
621 ret = "sse4(1way)";
622#endif
623#if defined(ENABLE_SSE41) && !defined(BUILD_BITCOIN_INTERNAL)
624 TransformD64_4way = sha256d64_sse41::Transform_4way;
625 ret += ",sse41(4way)";
626#endif
627 }
628
629#if defined(ENABLE_AVX2) && !defined(BUILD_BITCOIN_INTERNAL)
630 if (have_avx2 && have_avx && enabled_avx) {

Callers 3

AppInitSanityChecksFunction · 0.85
BasicTestingSetupMethod · 0.85
mainFunction · 0.85

Calls 3

cpuidFunction · 0.85
AVXEnabledFunction · 0.85
SelfTestFunction · 0.85

Tested by 1

BasicTestingSetupMethod · 0.68