From 224ddac07c49db1bd2f1185de133c8cfc9704406 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 20 Nov 2024 02:29:27 +0200 Subject: [PATCH] Fix SIMD on MSVC (#639) --- CMakeLists.txt | 5 +++++ include/helpers.hpp | 14 -------------- src/core/crypto/aes_engine.cpp | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 280abf0c..9e910b4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,11 @@ endif() if(NOT MSVC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT DISABLE_SSE4 AND HOST_X64) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") +elseif(MSVC AND NOT DISABLE_SSE4) + # Tell our SIMD code to use SSE4.1 by defining the relevant macros. + # Clang defines these macros, MSVC does not. + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D__SSE3__ /D__SSE4_1__") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__SSE3__ /D__SSE4_1__") endif() if(ENABLE_RENDERDOC_API) diff --git a/include/helpers.hpp b/include/helpers.hpp index 037c8976..a95931d4 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -162,19 +161,6 @@ namespace Helpers { return std::bit_cast(from); } #endif - - static std::vector split(const std::string& s, const char c) { - std::istringstream tmp(s); - std::vector result(1); - - while (std::getline(tmp, *result.rbegin(), c)) { - result.emplace_back(); - } - - // Remove temporary slot - result.pop_back(); - return result; - } }; // namespace Helpers // UDLs for memory size values diff --git a/src/core/crypto/aes_engine.cpp b/src/core/crypto/aes_engine.cpp index dc3ae060..1d7baad9 100644 --- a/src/core/crypto/aes_engine.cpp +++ b/src/core/crypto/aes_engine.cpp @@ -2,7 +2,10 @@ #include #include +#include +#include #include +#include #include "helpers.hpp" @@ -15,6 +18,19 @@ namespace Crypto { return; } + auto splitString = [](const std::string& s, const char c) -> std::vector { + std::istringstream tmp(s); + std::vector result(1); + + while (std::getline(tmp, *result.rbegin(), c)) { + result.emplace_back(); + } + + // Remove temporary slot + result.pop_back(); + return result; + }; + while (!file.eof()) { std::string line; std::getline(file, line); @@ -24,7 +40,7 @@ namespace Crypto { continue; } - const auto parts = Helpers::split(line, '='); + const auto parts = splitString(line, '='); if (parts.size() != 2) { Helpers::warn("Keys: Failed to parse %s", line.c_str()); continue;