From 6e1b11368d72aef6c412764a8b3d50bb22e936de Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 16 Jan 2024 21:43:54 -0800
Subject: [PATCH] Removed SDL_CPUINFO_DISABLED
CPU info is a core part of the SDL API, and shouldn't be disabled
---
CMakeLists.txt | 2 --
include/build_config/SDL_build_config.h.cmake | 1 -
include/build_config/SDL_build_config_emscripten.h | 1 -
src/audio/SDL_audiotypecvt.c | 6 +++---
src/cpuinfo/SDL_cpuinfo.c | 14 +++++---------
5 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 521d52b5aa89..d9ee77a87519 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,7 +211,6 @@ if(EMSCRIPTEN)
set(SDL_ASSEMBLY_DEFAULT OFF)
set(SDL_SHARED_AVAILABLE OFF)
set(SDL_ATOMIC_DEFAULT OFF)
- set(SDL_CPUINFO_DEFAULT OFF)
endif()
if(VITA OR PSP OR PS2 OR N3DS OR RISCOS)
@@ -250,7 +249,6 @@ set(SDL_SUBSYSTEMS
Threads
Timers
File
- CPUinfo
Filesystem
Sensor
Locale
diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake
index b3cd2d602905..340c6cd293ce 100644
--- a/include/build_config/SDL_build_config.h.cmake
+++ b/include/build_config/SDL_build_config.h.cmake
@@ -258,7 +258,6 @@
/* Allow disabling of core subsystems */
#cmakedefine SDL_ATOMIC_DISABLED @SDL_ATOMIC_DISABLED@
#cmakedefine SDL_AUDIO_DISABLED @SDL_AUDIO_DISABLED@
-#cmakedefine SDL_CPUINFO_DISABLED @SDL_CPUINFO_DISABLED@
#cmakedefine SDL_FILE_DISABLED @SDL_FILE_DISABLED@
#cmakedefine SDL_JOYSTICK_DISABLED @SDL_JOYSTICK_DISABLED@
#cmakedefine SDL_HAPTIC_DISABLED @SDL_HAPTIC_DISABLED@
diff --git a/include/build_config/SDL_build_config_emscripten.h b/include/build_config/SDL_build_config_emscripten.h
index fcaa277c0d5d..7fb5294ded8d 100644
--- a/include/build_config/SDL_build_config_emscripten.h
+++ b/include/build_config/SDL_build_config_emscripten.h
@@ -156,7 +156,6 @@
/* SDL internal assertion support */
/* #undef SDL_DEFAULT_ASSERT_LEVEL */
-#define SDL_CPUINFO_DISABLED 1
#define SDL_HAPTIC_DISABLED 1
#define SDL_HIDAPI_DISABLED 1
#ifndef __EMSCRIPTEN_PTHREADS__
diff --git a/src/audio/SDL_audiotypecvt.c b/src/audio/SDL_audiotypecvt.c
index 770922bbaa8f..73dd7965997f 100644
--- a/src/audio/SDL_audiotypecvt.c
+++ b/src/audio/SDL_audiotypecvt.c
@@ -25,7 +25,7 @@
// TODO: NEON is disabled until https://github.com/libsdl-org/SDL/issues/8352 can be fixed
#undef SDL_NEON_INTRINSICS
-#ifndef SDL_CPUINFO_DISABLED
+#ifndef __EMSCRIPTEN__
#if defined(__x86_64__) && defined(SDL_SSE2_INTRINSICS)
#define NEED_SCALAR_CONVERTER_FALLBACKS 0 // x86_64 guarantees SSE2.
#elif defined(__MACOS__) && defined(SDL_SSE2_INTRINSICS)
@@ -35,10 +35,10 @@
#elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7) && defined(SDL_NEON_INTRINSICS)
#define NEED_SCALAR_CONVERTER_FALLBACKS 0 // All Apple ARMv7 chips promise NEON support.
#endif
-#endif
+#endif /* __EMSCRIPTEN__ */
// Set to zero if platform is guaranteed to use a SIMD codepath here.
-#if !defined(NEED_SCALAR_CONVERTER_FALLBACKS) || defined(SDL_CPUINFO_DISABLED)
+#if !defined(NEED_SCALAR_CONVERTER_FALLBACKS)
#define NEED_SCALAR_CONVERTER_FALLBACKS 1
#endif
diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index 2f0dc1e575cd..8469b4e7949b 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -122,7 +122,7 @@ static int CPU_haveCPUID(void)
int has_CPUID = 0;
/* *INDENT-OFF* */ /* clang-format off */
-#ifndef SDL_CPUINFO_DISABLED
+#ifndef __EMSCRIPTEN__
#if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
__asm__ (
" pushfl # Get original EFLAGS \n"
@@ -209,7 +209,7 @@ static int CPU_haveCPUID(void)
"1: \n"
);
#endif
-#endif
+#endif /* !__EMSCRIPTEN__ */
/* *INDENT-ON* */ /* clang-format on */
return has_CPUID;
}
@@ -439,9 +439,7 @@ static int CPU_haveNEON(void)
{
/* The way you detect NEON is a privileged instruction on ARM, so you have
query the OS kernel in a platform-specific way. :/ */
-#ifdef SDL_CPUINFO_DISABLED
- return 0; /* disabled */
-#elif (defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)) && (defined(_M_ARM) || defined(_M_ARM64))
+#if (defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)) && (defined(_M_ARM) || defined(_M_ARM64))
/* Visual Studio, for ARM, doesn't define __ARM_ARCH. Handle this first. */
/* Seems to have been removed */
#ifndef PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
@@ -498,6 +496,8 @@ static int CPU_haveNEON(void)
}
return 0;
}
+#elif defined(__EMSCRIPTEN__)
+ return 0;
#else
#warning SDL_HasNEON is not implemented for this ARM platform. Write me.
return 0;
@@ -618,7 +618,6 @@ static int SDL_CPUCount = 0;
int SDL_GetCPUCount(void)
{
if (!SDL_CPUCount) {
-#ifndef SDL_CPUINFO_DISABLED
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
if (SDL_CPUCount <= 0) {
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
@@ -636,7 +635,6 @@ int SDL_GetCPUCount(void)
GetSystemInfo(&info);
SDL_CPUCount = info.dwNumberOfProcessors;
}
-#endif
#endif
/* There has to be at least 1, right? :) */
if (SDL_CPUCount <= 0) {
@@ -1003,7 +1001,6 @@ static int SDL_SystemRAM = 0;
int SDL_GetSystemRAM(void)
{
if (!SDL_SystemRAM) {
-#ifndef SDL_CPUINFO_DISABLED
#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
if (SDL_SystemRAM <= 0) {
SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024 * 1024));
@@ -1072,7 +1069,6 @@ int SDL_GetSystemRAM(void)
SDL_SystemRAM = (int)SDL_round((info.max_pages + info.ignored_pages > 0 ? info.ignored_pages : 0) * B_PAGE_SIZE / 1048576.0);
}
}
-#endif
#endif
}
return SDL_SystemRAM;