Skip to content

Commit

Permalink
jpgd: Fix detection of SSE2 support with MSVC
Browse files Browse the repository at this point in the history
The previous code would always use SSE2 intrinsics, which is not valid
on UWP ARM platforms (and likely not on some x86 platforms either).

The patch has been submitted upstream too:
richgel999/jpeg-compressor#13

(cherry picked from commit 3806efb)
  • Loading branch information
akien-mga committed May 7, 2020
1 parent bab5953 commit d090369
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
16 changes: 7 additions & 9 deletions thirdparty/jpeg-compressor/jpgd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@

#ifndef JPGD_USE_SSE2

#if defined(__GNUC__)

#if (defined(__x86_64__) || defined(_M_X64))
#if defined(__SSE2__)
#define JPGD_USE_SSE2 (1)
#endif
#if defined(__GNUC__)
#if defined(__SSE2__)
#define JPGD_USE_SSE2 (1)
#endif
#elif defined(_MSC_VER)
#if defined(_M_X64)
#define JPGD_USE_SSE2 (1)
#endif

#else
#define JPGD_USE_SSE2 (1)
#endif

#endif
Expand Down
44 changes: 44 additions & 0 deletions thirdparty/jpeg-compressor/patches/fix-msvc-sse2-detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From ae74fa2fcdef8ec44b925a649f66e8cbefce8315 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= <rverschelde@gmail.com>
Date: Thu, 7 May 2020 12:14:09 +0200
Subject: [PATCH] Fix detection of SSE2 with Visual Studio

The previous code assumed that SSE2 is available when building with
Visual Studio, but that's not accurate on ARM with UWP.

SSE2 could also be enabled on x86 if `_M_IX86_FP == 2`, but it requires
checking first that it's not actually set to 2 for AVX, AVX2 or AVX512
(see https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019),
so I left it out for this quick fix.
---
jpgd.cpp | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/jpgd.cpp b/jpgd.cpp
index 91e66ad..db1f3b4 100644
--- a/jpgd.cpp
+++ b/jpgd.cpp
@@ -37,16 +37,14 @@

#ifndef JPGD_USE_SSE2

- #if defined(__GNUC__)
-
- #if (defined(__x86_64__) || defined(_M_X64))
- #if defined(__SSE2__)
- #define JPGD_USE_SSE2 (1)
- #endif
+ #if defined(__GNUC__)
+ #if defined(__SSE2__)
+ #define JPGD_USE_SSE2 (1)
+ #endif
+ #elif defined(_MSC_VER)
+ #if defined(_M_X64)
+ #define JPGD_USE_SSE2 (1)
#endif
-
- #else
- #define JPGD_USE_SSE2 (1)
#endif

#endif

0 comments on commit d090369

Please sign in to comment.