From 4e6aa28da45b4b618f0ede639d4e0477fb124c0a Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 2 Aug 2022 23:03:51 -0700 Subject: [PATCH 1/3] crypto/aes: silence warning on godforsaken android gcc --- Source/Core/Common/Crypto/AES.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/Crypto/AES.cpp b/Source/Core/Common/Crypto/AES.cpp index 7c67766ed4..fe8f4ec728 100644 --- a/Source/Core/Common/Crypto/AES.cpp +++ b/Source/Core/Common/Crypto/AES.cpp @@ -264,7 +264,7 @@ public: template inline constexpr void StoreRoundKey(const u32* rk) { - const uint8x16_t rk_block = vld1q_u32(rk); + const uint8x16_t rk_block = vreinterpretq_u8_u32(vld1q_u32(rk)); if constexpr (AesMode == Mode::Encrypt) round_keys[RoundIdx] = rk_block; else From 78142e30cccf5420d3f190ab595cce2e2ff5e489 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 2 Aug 2022 23:05:07 -0700 Subject: [PATCH 2/3] crypto/sha1: simplify enablement of sha insns on non-msvc --- Source/Core/Common/CMakeLists.txt | 1 + Source/Core/Common/Crypto/SHA1.cpp | 24 ++---------------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index f9e5109d17..8cf550a886 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -139,6 +139,7 @@ add_library(common if(NOT MSVC AND _M_ARM_64) set_source_files_properties( Crypto/AES.cpp + Crypto/SHA1.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto") endif() diff --git a/Source/Core/Common/Crypto/SHA1.cpp b/Source/Core/Common/Crypto/SHA1.cpp index 9789818f13..7dfbb1f0c0 100644 --- a/Source/Core/Common/Crypto/SHA1.cpp +++ b/Source/Core/Common/Crypto/SHA1.cpp @@ -19,14 +19,6 @@ #ifdef _M_X86_64 #include #elif defined(_M_ARM_64) -#if defined(__clang__) -// This is a bit of a hack to get clang to accept the sha1 intrinsics without modifying cmdline -// flags. Note __ARM_FEATURE_CRYPTO is deprecated and "SHA2" flag is the lowest one which includes -// SHA1. -#define __ARM_FEATURE_SHA2 -// ...needed for older clang before they made the switchover to more granular flags. -#define __ARM_FEATURE_CRYPTO -#endif #include #include #endif @@ -256,17 +248,6 @@ private: #ifdef _M_ARM_64 -// The armv8 flags are very annoying: -// clang inserts "+" prefixes itself, gcc does not. -// clang has deprecated "crypto" (removed in clang 13), gcc has not. -#ifdef _MSC_VER -#define TARGET_ARMV8_SHA1 -#elif defined(__clang__) -#define TARGET_ARMV8_SHA1 [[gnu::target("sha2")]] -#elif defined(__GNUC__) -#define TARGET_ARMV8_SHA1 [[gnu::target("+crypto")]] -#endif - class ContextNeon final : public BlockContext { public: @@ -287,7 +268,6 @@ private: u32 e{}; }; - TARGET_ARMV8_SHA1 static inline uint32x4_t MsgSchedule(WorkBlock* wblock, size_t i) { auto& w = *wblock; @@ -299,7 +279,7 @@ private: } template - TARGET_ARMV8_SHA1 static inline constexpr uint32x4_t f(State state, uint32x4_t w) + static inline constexpr uint32x4_t f(State state, uint32x4_t w) { const auto wk = vaddq_u32(w, vdupq_n_u32(K[Func])); if constexpr (Func == 0) @@ -311,7 +291,7 @@ private: } template - TARGET_ARMV8_SHA1 static inline constexpr State FourRounds(State state, uint32x4_t w) + static inline constexpr State FourRounds(State state, uint32x4_t w) { #ifdef _MSC_VER // FIXME it seems the msvc optimizer gets a little too happy From bf5076eb010a0c8928d7fb823b35105e9e9dc0c6 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Tue, 2 Aug 2022 23:05:45 -0700 Subject: [PATCH 3/3] crypto/sha1: add real workaround for msvc/arm64 bad codegen --- Source/Core/Common/CMakeLists.txt | 8 ++++++++ Source/Core/Common/Crypto/SHA1.cpp | 4 ---- Source/Core/DolphinLib.props | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 8cf550a886..134d38062c 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -136,6 +136,14 @@ add_library(common WorkQueueThread.h ) +if(MSVC AND _M_ARM_64) + # Workaround msvc arm64 optimizer bug + # TODO remove after updating to VS 17.4 + set_source_files_properties( + Crypto/SHA1.cpp + PROPERTIES COMPILE_FLAGS "/d2ssa-peeps-post-color-") +endif() + if(NOT MSVC AND _M_ARM_64) set_source_files_properties( Crypto/AES.cpp diff --git a/Source/Core/Common/Crypto/SHA1.cpp b/Source/Core/Common/Crypto/SHA1.cpp index 7dfbb1f0c0..8f22855b0e 100644 --- a/Source/Core/Common/Crypto/SHA1.cpp +++ b/Source/Core/Common/Crypto/SHA1.cpp @@ -293,10 +293,6 @@ private: template static inline constexpr State FourRounds(State state, uint32x4_t w) { -#ifdef _MSC_VER - // FIXME it seems the msvc optimizer gets a little too happy - _ReadBarrier(); -#endif return {f(state, w), vsha1h_u32(vgetq_lane_u32(state.abcd, 0))}; } diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index 0c73e3d980..b1da315c18 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -723,7 +723,12 @@ - + + + /d2ssa-peeps-post-color- %(AdditionalOptions) +