MCPcopy Create free account
hub / github.com/ElementsProject/elements / SHA256AutoDetect

Function SHA256AutoDetect

src/crypto/sha256.cpp:582–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580
581
582std::string SHA256AutoDetect()
583{
584 std::string ret = "standard";
585#if defined(USE_ASM) && defined(HAVE_GETCPUID)
586 bool have_sse4 = false;
587 bool have_xsave = false;
588 bool have_avx = false;
589 bool have_avx2 = false;
590 bool have_x86_shani = false;
591 bool enabled_avx = false;
592
593 (void)AVXEnabled;
594 (void)have_sse4;
595 (void)have_avx;
596 (void)have_xsave;
597 (void)have_avx2;
598 (void)have_x86_shani;
599 (void)enabled_avx;
600
601 uint32_t eax, ebx, ecx, edx;
602 GetCPUID(1, 0, eax, ebx, ecx, edx);
603 have_sse4 = (ecx >> 19) & 1;
604 have_xsave = (ecx >> 27) & 1;
605 have_avx = (ecx >> 28) & 1;
606 if (have_xsave && have_avx) {
607 enabled_avx = AVXEnabled();
608 }
609 if (have_sse4) {
610 GetCPUID(7, 0, eax, ebx, ecx, edx);
611 have_avx2 = (ebx >> 5) & 1;
612 have_x86_shani = (ebx >> 29) & 1;
613 }
614
615#if defined(ENABLE_X86_SHANI) && !defined(BUILD_BITCOIN_INTERNAL)
616 if (have_x86_shani) {
617 Transform = sha256_x86_shani::Transform;
618 TransformD64 = TransformD64Wrapper<sha256_x86_shani::Transform>;
619 TransformD64_2way = sha256d64_x86_shani::Transform_2way;
620 ret = "x86_shani(1way,2way)";
621 have_sse4 = false; // Disable SSE4/AVX2;
622 have_avx2 = false;
623 }
624#endif
625
626 if (have_sse4) {
627#if defined(__x86_64__) || defined(__amd64__)
628 Transform = sha256_sse4::Transform;
629 TransformD64 = TransformD64Wrapper<sha256_sse4::Transform>;
630 ret = "sse4(1way)";
631#endif
632#if defined(ENABLE_SSE41) && !defined(BUILD_BITCOIN_INTERNAL)
633 TransformD64_4way = sha256d64_sse41::Transform_4way;
634 ret += ",sse41(4way)";
635#endif
636 }
637
638#if defined(ENABLE_AVX2) && !defined(BUILD_BITCOIN_INTERNAL)
639 if (have_avx2 && have_avx && enabled_avx) {

Callers 3

SetGlobalsFunction · 0.85
BasicTestingSetupMethod · 0.85
mainFunction · 0.85

Calls 3

GetCPUIDFunction · 0.85
AVXEnabledFunction · 0.85
SelfTestFunction · 0.85

Tested by 1

BasicTestingSetupMethod · 0.68