[vlc-commits] [Git][videolan/vlc][master] 2 commits: cpu: support cpuid with MSVC
Steve Lhomme (@robUx4)
gitlab at videolan.org
Thu Mar 2 09:58:36 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
f0a5c5c3 by Steve Lhomme at 2023-03-02T09:36:51+00:00
cpu: support cpuid with MSVC
- - - - -
e3f623c0 by Steve Lhomme at 2023-03-02T09:36:51+00:00
vlc_fixups: turn MSVC CPU defines into GCC CPU defines
For x64, x86, arm and arm64.
See https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
- - - - -
2 changed files:
- include/vlc_fixups.h
- src/misc/cpu.c
Changes:
=====================================
include/vlc_fixups.h
=====================================
@@ -57,6 +57,26 @@ typedef unsigned short mode_t;
#define _CRT_SUPPRESS_RESTRICT
#define DECLSPEC_RESTRICT
+// turn CPU MSVC-ism into more standard defines
+#if defined(_M_X64) && !defined(__x86_64__)
+# define __x86_64__
+#endif
+#if defined(_M_IX86) && !defined(__i386__)
+# define __i386__
+#endif
+#if defined(_M_ARM64) && !defined(__aarch64__)
+# define __aarch64__
+#endif
+#if defined(_M_ARM) && !defined(__arm__)
+# define __arm__
+#endif
+#if defined(_M_IX86_FP) && _M_IX86_FP == 1 && !defined(__SSE__)
+# define __SSE__
+#endif
+#if defined(_M_IX86_FP) && _M_IX86_FP == 2 && !defined(__SSE2__)
+# define __SSE2__
+#endif
+
#endif // _MSC_VER
#ifdef _WIN32
=====================================
src/misc/cpu.c
=====================================
@@ -46,6 +46,9 @@
#include <signal.h>
#else
#include <errno.h>
+#if defined(_MSC_VER) && !defined(__clang__)
+# include <intrin.h> // __cpuid
+#endif
#endif
#ifdef __APPLE__
@@ -109,11 +112,20 @@ VLC_WEAK unsigned vlc_CPU_raw(void)
unsigned int i_eax, i_ebx, i_ecx, i_edx;
/* Needed for x86 CPU capabilities detection */
+#if defined(_MSC_VER) && !defined(__clang__)
+# define cpuid(reg) \
+ do { \
+ int cpuInfo[4]; \
+ __cpuid(cpuInfo, reg); \
+ i_eax = cpuInfo[0]; i_ebx = cpuInfo[1]; i_ecx = cpuInfo[2]; i_edx = cpuInfo[3]; \
+ } while(0)
+#else // !_MSC_VER
# define cpuid(reg) \
asm ("cpuid" \
: "=a" (i_eax), "=b" (i_ebx), "=c" (i_ecx), "=d" (i_edx) \
: "a" (reg) \
: "cc");
+#endif // !_MSC_VER
/* Check if the OS really supports the requested instructions */
# if defined (__i386__) && !defined (__i586__) \
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/772080a5d84750d2a3ac9b576eba7a44a98d0e41...e3f623c019cf41977efcab2557eda8e1f305e6ad
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/772080a5d84750d2a3ac9b576eba7a44a98d0e41...e3f623c019cf41977efcab2557eda8e1f305e6ad
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list