SDL_cpuinfo.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #if defined(__WIN32__) || defined(__WINRT__) || defined(__GDK__)
  20. #include "../core/windows/SDL_windows.h"
  21. #endif
  22. /* CPU feature detection for SDL */
  23. #ifdef HAVE_SYSCONF
  24. #include <unistd.h>
  25. #endif
  26. #ifdef HAVE_SYSCTLBYNAME
  27. #include <sys/types.h>
  28. #include <sys/sysctl.h>
  29. #endif
  30. #if defined(__MACOS__) && (defined(__ppc__) || defined(__ppc64__))
  31. #include <sys/sysctl.h> /* For AltiVec check */
  32. #elif defined(__OpenBSD__) && defined(__powerpc__)
  33. #include <sys/types.h>
  34. #include <sys/sysctl.h> /* For AltiVec check */
  35. #include <machine/cpu.h>
  36. #elif defined(__FreeBSD__) && defined(__powerpc__)
  37. #include <machine/cpu.h>
  38. #include <sys/auxv.h>
  39. #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
  40. #include <signal.h>
  41. #include <setjmp.h>
  42. #endif
  43. #if (defined(__LINUX__) || defined(__ANDROID__)) && defined(__arm__)
  44. #include <unistd.h>
  45. #include <sys/types.h>
  46. #include <sys/stat.h>
  47. #include <fcntl.h>
  48. #include <elf.h>
  49. /*#include <asm/hwcap.h>*/
  50. #ifndef AT_HWCAP
  51. #define AT_HWCAP 16
  52. #endif
  53. #ifndef AT_PLATFORM
  54. #define AT_PLATFORM 15
  55. #endif
  56. #ifndef HWCAP_NEON
  57. #define HWCAP_NEON (1 << 12)
  58. #endif
  59. #endif
  60. #if defined(__ANDROID__) && defined(__arm__) && !defined(HAVE_GETAUXVAL)
  61. #include <cpu-features.h>
  62. #endif
  63. #if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
  64. #include <sys/auxv.h>
  65. #endif
  66. #ifdef __RISCOS__
  67. #include <kernel.h>
  68. #include <swis.h>
  69. #endif
  70. #ifdef __PS2__
  71. #include <kernel.h>
  72. #endif
  73. #define CPU_HAS_RDTSC (1 << 0)
  74. #define CPU_HAS_ALTIVEC (1 << 1)
  75. #define CPU_HAS_MMX (1 << 2)
  76. #define CPU_HAS_SSE (1 << 3)
  77. #define CPU_HAS_SSE2 (1 << 4)
  78. #define CPU_HAS_SSE3 (1 << 5)
  79. #define CPU_HAS_SSE41 (1 << 6)
  80. #define CPU_HAS_SSE42 (1 << 7)
  81. #define CPU_HAS_AVX (1 << 8)
  82. #define CPU_HAS_AVX2 (1 << 9)
  83. #define CPU_HAS_NEON (1 << 10)
  84. #define CPU_HAS_AVX512F (1 << 11)
  85. #define CPU_HAS_ARM_SIMD (1 << 12)
  86. #define CPU_HAS_LSX (1 << 13)
  87. #define CPU_HAS_LASX (1 << 14)
  88. #define CPU_CFG2 0x2
  89. #define CPU_CFG2_LSX (1 << 6)
  90. #define CPU_CFG2_LASX (1 << 7)
  91. #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOS__ && !__OpenBSD__ && !__FreeBSD__
  92. /* This is the brute force way of detecting instruction sets...
  93. the idea is borrowed from the libmpeg2 library - thanks!
  94. */
  95. static jmp_buf jmpbuf;
  96. static void illegal_instruction(int sig)
  97. {
  98. longjmp(jmpbuf, 1);
  99. }
  100. #endif /* HAVE_SETJMP */
  101. static int CPU_haveCPUID(void)
  102. {
  103. int has_CPUID = 0;
  104. /* *INDENT-OFF* */ /* clang-format off */
  105. #ifndef SDL_CPUINFO_DISABLED
  106. #if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
  107. __asm__ (
  108. " pushfl # Get original EFLAGS \n"
  109. " popl %%eax \n"
  110. " movl %%eax,%%ecx \n"
  111. " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
  112. " pushl %%eax # Save new EFLAGS value on stack \n"
  113. " popfl # Replace current EFLAGS value \n"
  114. " pushfl # Get new EFLAGS \n"
  115. " popl %%eax # Store new EFLAGS in EAX \n"
  116. " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
  117. " jz 1f # Processor=80486 \n"
  118. " movl $1,%0 # We have CPUID support \n"
  119. "1: \n"
  120. : "=m" (has_CPUID)
  121. :
  122. : "%eax", "%ecx"
  123. );
  124. #elif (defined(__GNUC__) || defined(__llvm__)) && defined(__x86_64__)
  125. /* Technically, if this is being compiled under __x86_64__ then it has
  126. CPUid by definition. But it's nice to be able to prove it. :) */
  127. __asm__ (
  128. " pushfq # Get original EFLAGS \n"
  129. " popq %%rax \n"
  130. " movq %%rax,%%rcx \n"
  131. " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
  132. " pushq %%rax # Save new EFLAGS value on stack \n"
  133. " popfq # Replace current EFLAGS value \n"
  134. " pushfq # Get new EFLAGS \n"
  135. " popq %%rax # Store new EFLAGS in EAX \n"
  136. " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
  137. " jz 1f # Processor=80486 \n"
  138. " movl $1,%0 # We have CPUID support \n"
  139. "1: \n"
  140. : "=m" (has_CPUID)
  141. :
  142. : "%rax", "%rcx"
  143. );
  144. #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  145. __asm {
  146. pushfd ; Get original EFLAGS
  147. pop eax
  148. mov ecx, eax
  149. xor eax, 200000h ; Flip ID bit in EFLAGS
  150. push eax ; Save new EFLAGS value on stack
  151. popfd ; Replace current EFLAGS value
  152. pushfd ; Get new EFLAGS
  153. pop eax ; Store new EFLAGS in EAX
  154. xor eax, ecx ; Can not toggle ID bit,
  155. jz done ; Processor=80486
  156. mov has_CPUID,1 ; We have CPUID support
  157. done:
  158. }
  159. #elif defined(_MSC_VER) && defined(_M_X64)
  160. has_CPUID = 1;
  161. #elif defined(__sun) && defined(__i386)
  162. __asm (
  163. " pushfl \n"
  164. " popl %eax \n"
  165. " movl %eax,%ecx \n"
  166. " xorl $0x200000,%eax \n"
  167. " pushl %eax \n"
  168. " popfl \n"
  169. " pushfl \n"
  170. " popl %eax \n"
  171. " xorl %ecx,%eax \n"
  172. " jz 1f \n"
  173. " movl $1,-8(%ebp) \n"
  174. "1: \n"
  175. );
  176. #elif defined(__sun) && defined(__amd64)
  177. __asm (
  178. " pushfq \n"
  179. " popq %rax \n"
  180. " movq %rax,%rcx \n"
  181. " xorl $0x200000,%eax \n"
  182. " pushq %rax \n"
  183. " popfq \n"
  184. " pushfq \n"
  185. " popq %rax \n"
  186. " xorl %ecx,%eax \n"
  187. " jz 1f \n"
  188. " movl $1,-8(%rbp) \n"
  189. "1: \n"
  190. );
  191. #endif
  192. #endif
  193. /* *INDENT-ON* */ /* clang-format on */
  194. return has_CPUID;
  195. }
  196. #if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
  197. #define cpuid(func, a, b, c, d) \
  198. __asm__ __volatile__( \
  199. " pushl %%ebx \n" \
  200. " xorl %%ecx,%%ecx \n" \
  201. " cpuid \n" \
  202. " movl %%ebx, %%esi \n" \
  203. " popl %%ebx \n" \
  204. : "=a"(a), "=S"(b), "=c"(c), "=d"(d) \
  205. : "a"(func))
  206. #elif (defined(__GNUC__) || defined(__llvm__)) && defined(__x86_64__)
  207. #define cpuid(func, a, b, c, d) \
  208. __asm__ __volatile__( \
  209. " pushq %%rbx \n" \
  210. " xorq %%rcx,%%rcx \n" \
  211. " cpuid \n" \
  212. " movq %%rbx, %%rsi \n" \
  213. " popq %%rbx \n" \
  214. : "=a"(a), "=S"(b), "=c"(c), "=d"(d) \
  215. : "a"(func))
  216. #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  217. #define cpuid(func, a, b, c, d) \
  218. __asm { \
  219. __asm mov eax, func \
  220. __asm xor ecx, ecx \
  221. __asm cpuid \
  222. __asm mov a, eax \
  223. __asm mov b, ebx \
  224. __asm mov c, ecx \
  225. __asm mov d, edx \
  226. }
  227. #elif defined(_MSC_VER) && defined(_M_X64)
  228. #define cpuid(func, a, b, c, d) \
  229. { \
  230. int CPUInfo[4]; \
  231. __cpuid(CPUInfo, func); \
  232. a = CPUInfo[0]; \
  233. b = CPUInfo[1]; \
  234. c = CPUInfo[2]; \
  235. d = CPUInfo[3]; \
  236. }
  237. #else
  238. #define cpuid(func, a, b, c, d) \
  239. do { \
  240. a = b = c = d = 0; \
  241. (void)a; \
  242. (void)b; \
  243. (void)c; \
  244. (void)d; \
  245. } while (0)
  246. #endif
  247. static int CPU_CPUIDFeatures[4];
  248. static int CPU_CPUIDMaxFunction = 0;
  249. static SDL_bool CPU_OSSavesYMM = SDL_FALSE;
  250. static SDL_bool CPU_OSSavesZMM = SDL_FALSE;
  251. static void CPU_calcCPUIDFeatures(void)
  252. {
  253. static SDL_bool checked = SDL_FALSE;
  254. if (!checked) {
  255. checked = SDL_TRUE;
  256. if (CPU_haveCPUID()) {
  257. int a, b, c, d;
  258. cpuid(0, a, b, c, d);
  259. CPU_CPUIDMaxFunction = a;
  260. if (CPU_CPUIDMaxFunction >= 1) {
  261. cpuid(1, a, b, c, d);
  262. CPU_CPUIDFeatures[0] = a;
  263. CPU_CPUIDFeatures[1] = b;
  264. CPU_CPUIDFeatures[2] = c;
  265. CPU_CPUIDFeatures[3] = d;
  266. /* Check to make sure we can call xgetbv */
  267. if (c & 0x08000000) {
  268. /* Call xgetbv to see if YMM (etc) register state is saved */
  269. #if (defined(__GNUC__) || defined(__llvm__)) && (defined(__i386__) || defined(__x86_64__))
  270. __asm__(".byte 0x0f, 0x01, 0xd0"
  271. : "=a"(a)
  272. : "c"(0)
  273. : "%edx");
  274. #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
  275. a = (int)_xgetbv(0);
  276. #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  277. __asm
  278. {
  279. xor ecx, ecx
  280. _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
  281. mov a, eax
  282. }
  283. #endif
  284. CPU_OSSavesYMM = ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
  285. CPU_OSSavesZMM = (CPU_OSSavesYMM && ((a & 0xe0) == 0xe0)) ? SDL_TRUE : SDL_FALSE;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. static int CPU_haveAltiVec(void)
  292. {
  293. volatile int altivec = 0;
  294. #ifndef SDL_CPUINFO_DISABLED
  295. #if (defined(__MACOS__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
  296. #ifdef __OpenBSD__
  297. int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
  298. #else
  299. int selectors[2] = { CTL_HW, HW_VECTORUNIT };
  300. #endif
  301. int hasVectorUnit = 0;
  302. size_t length = sizeof(hasVectorUnit);
  303. int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
  304. if (0 == error) {
  305. altivec = (hasVectorUnit != 0);
  306. }
  307. #elif defined(__FreeBSD__) && defined(__powerpc__)
  308. unsigned long cpufeatures = 0;
  309. elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
  310. altivec = cpufeatures & PPC_FEATURE_HAS_ALTIVEC;
  311. return altivec;
  312. #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
  313. void (*handler)(int sig);
  314. handler = signal(SIGILL, illegal_instruction);
  315. if (setjmp(jmpbuf) == 0) {
  316. asm volatile("mtspr 256, %0\n\t"
  317. "vand %%v0, %%v0, %%v0" ::"r"(-1));
  318. altivec = 1;
  319. }
  320. signal(SIGILL, handler);
  321. #endif
  322. #endif
  323. return altivec;
  324. }
  325. #if (defined(__ARM_ARCH) && (__ARM_ARCH >= 6)) || defined(__aarch64__)
  326. static int CPU_haveARMSIMD(void)
  327. {
  328. return 1;
  329. }
  330. #elif !defined(__arm__)
  331. static int CPU_haveARMSIMD(void)
  332. {
  333. return 0;
  334. }
  335. #elif defined(__LINUX__)
  336. static int CPU_haveARMSIMD(void)
  337. {
  338. int arm_simd = 0;
  339. int fd;
  340. fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
  341. if (fd >= 0) {
  342. Elf32_auxv_t aux;
  343. while (read(fd, &aux, sizeof aux) == sizeof aux) {
  344. if (aux.a_type == AT_PLATFORM) {
  345. const char *plat = (const char *)aux.a_un.a_val;
  346. if (plat) {
  347. arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
  348. SDL_strncmp(plat, "v7l", 3) == 0;
  349. }
  350. }
  351. }
  352. close(fd);
  353. }
  354. return arm_simd;
  355. }
  356. #elif defined(__RISCOS__)
  357. static int CPU_haveARMSIMD(void)
  358. {
  359. _kernel_swi_regs regs;
  360. regs.r[0] = 0;
  361. if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
  362. return 0;
  363. }
  364. if (!(regs.r[0] & (1 << 31))) {
  365. return 0;
  366. }
  367. regs.r[0] = 34;
  368. regs.r[1] = 29;
  369. if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL) {
  370. return 0;
  371. }
  372. return regs.r[0];
  373. }
  374. #else
  375. static int CPU_haveARMSIMD(void)
  376. {
  377. #warning SDL_HasARMSIMD is not implemented for this ARM platform. Write me.
  378. return 0;
  379. }
  380. #endif
  381. #if defined(__LINUX__) && defined(__arm__) && !defined(HAVE_GETAUXVAL)
  382. static int readProcAuxvForNeon(void)
  383. {
  384. int neon = 0;
  385. int fd;
  386. fd = open("/proc/self/auxv", O_RDONLY | O_CLOEXEC);
  387. if (fd >= 0) {
  388. Elf32_auxv_t aux;
  389. while (read(fd, &aux, sizeof(aux)) == sizeof(aux)) {
  390. if (aux.a_type == AT_HWCAP) {
  391. neon = (aux.a_un.a_val & HWCAP_NEON) == HWCAP_NEON;
  392. break;
  393. }
  394. }
  395. close(fd);
  396. }
  397. return neon;
  398. }
  399. #endif
  400. static int CPU_haveNEON(void)
  401. {
  402. /* The way you detect NEON is a privileged instruction on ARM, so you have
  403. query the OS kernel in a platform-specific way. :/ */
  404. #if defined(SDL_CPUINFO_DISABLED)
  405. return 0; /* disabled */
  406. #elif (defined(__WINDOWS__) || defined(__WINRT__) || defined(__GDK__)) && (defined(_M_ARM) || defined(_M_ARM64))
  407. /* Visual Studio, for ARM, doesn't define __ARM_ARCH. Handle this first. */
  408. /* Seems to have been removed */
  409. #if !defined(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)
  410. #define PF_ARM_NEON_INSTRUCTIONS_AVAILABLE 19
  411. #endif
  412. /* All WinRT ARM devices are required to support NEON, but just in case. */
  413. return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
  414. #elif (defined(__ARM_ARCH) && (__ARM_ARCH >= 8)) || defined(__aarch64__)
  415. return 1; /* ARMv8 always has non-optional NEON support. */
  416. #elif __VITA__
  417. return 1;
  418. #elif __3DS__
  419. return 0;
  420. #elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7)
  421. /* (note that sysctlbyname("hw.optional.neon") doesn't work!) */
  422. return 1; /* all Apple ARMv7 chips and later have NEON. */
  423. #elif defined(__APPLE__)
  424. return 0; /* assume anything else from Apple doesn't have NEON. */
  425. #elif !defined(__arm__)
  426. return 0; /* not an ARM CPU at all. */
  427. #elif defined(__OpenBSD__)
  428. return 1; /* OpenBSD only supports ARMv7 CPUs that have NEON. */
  429. #elif defined(HAVE_ELF_AUX_INFO)
  430. unsigned long hasneon = 0;
  431. if (elf_aux_info(AT_HWCAP, (void *)&hasneon, (int)sizeof(hasneon)) != 0) {
  432. return 0;
  433. }
  434. return (hasneon & HWCAP_NEON) == HWCAP_NEON;
  435. #elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
  436. return (getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON;
  437. #elif defined(__LINUX__)
  438. return readProcAuxvForNeon();
  439. #elif defined(__ANDROID__)
  440. /* Use NDK cpufeatures to read either /proc/self/auxv or /proc/cpuinfo */
  441. {
  442. AndroidCpuFamily cpu_family = android_getCpuFamily();
  443. if (cpu_family == ANDROID_CPU_FAMILY_ARM) {
  444. uint64_t cpu_features = android_getCpuFeatures();
  445. if ((cpu_features & ANDROID_CPU_ARM_FEATURE_NEON) != 0) {
  446. return 1;
  447. }
  448. }
  449. return 0;
  450. }
  451. #elif defined(__RISCOS__)
  452. /* Use the VFPSupport_Features SWI to access the MVFR registers */
  453. {
  454. _kernel_swi_regs regs;
  455. regs.r[0] = 0;
  456. if (_kernel_swi(VFPSupport_Features, &regs, &regs) == NULL) {
  457. if ((regs.r[2] & 0xFFF000) == 0x111000) {
  458. return 1;
  459. }
  460. }
  461. return 0;
  462. }
  463. #else
  464. #warning SDL_HasNEON is not implemented for this ARM platform. Write me.
  465. return 0;
  466. #endif
  467. }
  468. static int CPU_readCPUCFG(void)
  469. {
  470. uint32_t cfg2 = 0;
  471. #if defined __loongarch__
  472. __asm__ volatile(
  473. "cpucfg %0, %1 \n\t"
  474. : "+&r"(cfg2)
  475. : "r"(CPU_CFG2));
  476. #endif
  477. return cfg2;
  478. }
  479. #define CPU_haveLSX() (CPU_readCPUCFG() & CPU_CFG2_LSX)
  480. #define CPU_haveLASX() (CPU_readCPUCFG() & CPU_CFG2_LASX)
  481. #if defined(__e2k__)
  482. #define CPU_haveRDTSC() (0)
  483. #if defined(__MMX__)
  484. #define CPU_haveMMX() (1)
  485. #else
  486. #define CPU_haveMMX() (0)
  487. #endif
  488. #if defined(__SSE__)
  489. #define CPU_haveSSE() (1)
  490. #else
  491. #define CPU_haveSSE() (0)
  492. #endif
  493. #if defined(__SSE2__)
  494. #define CPU_haveSSE2() (1)
  495. #else
  496. #define CPU_haveSSE2() (0)
  497. #endif
  498. #if defined(__SSE3__)
  499. #define CPU_haveSSE3() (1)
  500. #else
  501. #define CPU_haveSSE3() (0)
  502. #endif
  503. #if defined(__SSE4_1__)
  504. #define CPU_haveSSE41() (1)
  505. #else
  506. #define CPU_haveSSE41() (0)
  507. #endif
  508. #if defined(__SSE4_2__)
  509. #define CPU_haveSSE42() (1)
  510. #else
  511. #define CPU_haveSSE42() (0)
  512. #endif
  513. #if defined(__AVX__)
  514. #define CPU_haveAVX() (1)
  515. #else
  516. #define CPU_haveAVX() (0)
  517. #endif
  518. #else
  519. #define CPU_haveRDTSC() (CPU_CPUIDFeatures[3] & 0x00000010)
  520. #define CPU_haveMMX() (CPU_CPUIDFeatures[3] & 0x00800000)
  521. #define CPU_haveSSE() (CPU_CPUIDFeatures[3] & 0x02000000)
  522. #define CPU_haveSSE2() (CPU_CPUIDFeatures[3] & 0x04000000)
  523. #define CPU_haveSSE3() (CPU_CPUIDFeatures[2] & 0x00000001)
  524. #define CPU_haveSSE41() (CPU_CPUIDFeatures[2] & 0x00080000)
  525. #define CPU_haveSSE42() (CPU_CPUIDFeatures[2] & 0x00100000)
  526. #define CPU_haveAVX() (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000))
  527. #endif
  528. #if defined(__e2k__)
  529. inline int
  530. CPU_haveAVX2(void)
  531. {
  532. #if defined(__AVX2__)
  533. return 1;
  534. #else
  535. return 0;
  536. #endif
  537. }
  538. #else
  539. static int CPU_haveAVX2(void)
  540. {
  541. if (CPU_OSSavesYMM && (CPU_CPUIDMaxFunction >= 7)) {
  542. int a, b, c, d;
  543. (void)a;
  544. (void)b;
  545. (void)c;
  546. (void)d; /* compiler warnings... */
  547. cpuid(7, a, b, c, d);
  548. return b & 0x00000020;
  549. }
  550. return 0;
  551. }
  552. #endif
  553. #if defined(__e2k__)
  554. inline int
  555. CPU_haveAVX512F(void)
  556. {
  557. return 0;
  558. }
  559. #else
  560. static int CPU_haveAVX512F(void)
  561. {
  562. if (CPU_OSSavesZMM && (CPU_CPUIDMaxFunction >= 7)) {
  563. int a, b, c, d;
  564. (void)a;
  565. (void)b;
  566. (void)c;
  567. (void)d; /* compiler warnings... */
  568. cpuid(7, a, b, c, d);
  569. return b & 0x00010000;
  570. }
  571. return 0;
  572. }
  573. #endif
  574. static int SDL_CPUCount = 0;
  575. int SDL_GetCPUCount(void)
  576. {
  577. if (!SDL_CPUCount) {
  578. #ifndef SDL_CPUINFO_DISABLED
  579. #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
  580. if (SDL_CPUCount <= 0) {
  581. SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
  582. }
  583. #endif
  584. #ifdef HAVE_SYSCTLBYNAME
  585. if (SDL_CPUCount <= 0) {
  586. size_t size = sizeof(SDL_CPUCount);
  587. sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
  588. }
  589. #endif
  590. #if defined(__WIN32__) || defined(__GDK__)
  591. if (SDL_CPUCount <= 0) {
  592. SYSTEM_INFO info;
  593. GetSystemInfo(&info);
  594. SDL_CPUCount = info.dwNumberOfProcessors;
  595. }
  596. #endif
  597. #endif
  598. /* There has to be at least 1, right? :) */
  599. if (SDL_CPUCount <= 0) {
  600. SDL_CPUCount = 1;
  601. }
  602. }
  603. return SDL_CPUCount;
  604. }
  605. #if defined(__e2k__)
  606. inline const char *
  607. SDL_GetCPUType(void)
  608. {
  609. static char SDL_CPUType[13];
  610. SDL_strlcpy(SDL_CPUType, "E2K MACHINE", sizeof(SDL_CPUType));
  611. return SDL_CPUType;
  612. }
  613. #else
  614. /* Oh, such a sweet sweet trick, just not very useful. :) */
  615. static const char *SDL_GetCPUType(void)
  616. {
  617. static char SDL_CPUType[13];
  618. if (!SDL_CPUType[0]) {
  619. int i = 0;
  620. CPU_calcCPUIDFeatures();
  621. if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
  622. int a, b, c, d;
  623. cpuid(0x00000000, a, b, c, d);
  624. (void)a;
  625. SDL_CPUType[i++] = (char)(b & 0xff);
  626. b >>= 8;
  627. SDL_CPUType[i++] = (char)(b & 0xff);
  628. b >>= 8;
  629. SDL_CPUType[i++] = (char)(b & 0xff);
  630. b >>= 8;
  631. SDL_CPUType[i++] = (char)(b & 0xff);
  632. SDL_CPUType[i++] = (char)(d & 0xff);
  633. d >>= 8;
  634. SDL_CPUType[i++] = (char)(d & 0xff);
  635. d >>= 8;
  636. SDL_CPUType[i++] = (char)(d & 0xff);
  637. d >>= 8;
  638. SDL_CPUType[i++] = (char)(d & 0xff);
  639. SDL_CPUType[i++] = (char)(c & 0xff);
  640. c >>= 8;
  641. SDL_CPUType[i++] = (char)(c & 0xff);
  642. c >>= 8;
  643. SDL_CPUType[i++] = (char)(c & 0xff);
  644. c >>= 8;
  645. SDL_CPUType[i++] = (char)(c & 0xff);
  646. }
  647. if (!SDL_CPUType[0]) {
  648. SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
  649. }
  650. }
  651. return SDL_CPUType;
  652. }
  653. #endif
  654. #ifdef TEST_MAIN /* !!! FIXME: only used for test at the moment. */
  655. #if defined(__e2k__)
  656. inline const char *
  657. SDL_GetCPUName(void)
  658. {
  659. static char SDL_CPUName[48];
  660. SDL_strlcpy(SDL_CPUName, __builtin_cpu_name(), sizeof(SDL_CPUName));
  661. return SDL_CPUName;
  662. }
  663. #else
  664. static const char *SDL_GetCPUName(void)
  665. {
  666. static char SDL_CPUName[48];
  667. if (!SDL_CPUName[0]) {
  668. int i = 0;
  669. int a, b, c, d;
  670. CPU_calcCPUIDFeatures();
  671. if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
  672. cpuid(0x80000000, a, b, c, d);
  673. if (a >= 0x80000004) {
  674. cpuid(0x80000002, a, b, c, d);
  675. SDL_CPUName[i++] = (char)(a & 0xff);
  676. a >>= 8;
  677. SDL_CPUName[i++] = (char)(a & 0xff);
  678. a >>= 8;
  679. SDL_CPUName[i++] = (char)(a & 0xff);
  680. a >>= 8;
  681. SDL_CPUName[i++] = (char)(a & 0xff);
  682. a >>= 8;
  683. SDL_CPUName[i++] = (char)(b & 0xff);
  684. b >>= 8;
  685. SDL_CPUName[i++] = (char)(b & 0xff);
  686. b >>= 8;
  687. SDL_CPUName[i++] = (char)(b & 0xff);
  688. b >>= 8;
  689. SDL_CPUName[i++] = (char)(b & 0xff);
  690. b >>= 8;
  691. SDL_CPUName[i++] = (char)(c & 0xff);
  692. c >>= 8;
  693. SDL_CPUName[i++] = (char)(c & 0xff);
  694. c >>= 8;
  695. SDL_CPUName[i++] = (char)(c & 0xff);
  696. c >>= 8;
  697. SDL_CPUName[i++] = (char)(c & 0xff);
  698. c >>= 8;
  699. SDL_CPUName[i++] = (char)(d & 0xff);
  700. d >>= 8;
  701. SDL_CPUName[i++] = (char)(d & 0xff);
  702. d >>= 8;
  703. SDL_CPUName[i++] = (char)(d & 0xff);
  704. d >>= 8;
  705. SDL_CPUName[i++] = (char)(d & 0xff);
  706. d >>= 8;
  707. cpuid(0x80000003, a, b, c, d);
  708. SDL_CPUName[i++] = (char)(a & 0xff);
  709. a >>= 8;
  710. SDL_CPUName[i++] = (char)(a & 0xff);
  711. a >>= 8;
  712. SDL_CPUName[i++] = (char)(a & 0xff);
  713. a >>= 8;
  714. SDL_CPUName[i++] = (char)(a & 0xff);
  715. a >>= 8;
  716. SDL_CPUName[i++] = (char)(b & 0xff);
  717. b >>= 8;
  718. SDL_CPUName[i++] = (char)(b & 0xff);
  719. b >>= 8;
  720. SDL_CPUName[i++] = (char)(b & 0xff);
  721. b >>= 8;
  722. SDL_CPUName[i++] = (char)(b & 0xff);
  723. b >>= 8;
  724. SDL_CPUName[i++] = (char)(c & 0xff);
  725. c >>= 8;
  726. SDL_CPUName[i++] = (char)(c & 0xff);
  727. c >>= 8;
  728. SDL_CPUName[i++] = (char)(c & 0xff);
  729. c >>= 8;
  730. SDL_CPUName[i++] = (char)(c & 0xff);
  731. c >>= 8;
  732. SDL_CPUName[i++] = (char)(d & 0xff);
  733. d >>= 8;
  734. SDL_CPUName[i++] = (char)(d & 0xff);
  735. d >>= 8;
  736. SDL_CPUName[i++] = (char)(d & 0xff);
  737. d >>= 8;
  738. SDL_CPUName[i++] = (char)(d & 0xff);
  739. d >>= 8;
  740. cpuid(0x80000004, a, b, c, d);
  741. SDL_CPUName[i++] = (char)(a & 0xff);
  742. a >>= 8;
  743. SDL_CPUName[i++] = (char)(a & 0xff);
  744. a >>= 8;
  745. SDL_CPUName[i++] = (char)(a & 0xff);
  746. a >>= 8;
  747. SDL_CPUName[i++] = (char)(a & 0xff);
  748. a >>= 8;
  749. SDL_CPUName[i++] = (char)(b & 0xff);
  750. b >>= 8;
  751. SDL_CPUName[i++] = (char)(b & 0xff);
  752. b >>= 8;
  753. SDL_CPUName[i++] = (char)(b & 0xff);
  754. b >>= 8;
  755. SDL_CPUName[i++] = (char)(b & 0xff);
  756. b >>= 8;
  757. SDL_CPUName[i++] = (char)(c & 0xff);
  758. c >>= 8;
  759. SDL_CPUName[i++] = (char)(c & 0xff);
  760. c >>= 8;
  761. SDL_CPUName[i++] = (char)(c & 0xff);
  762. c >>= 8;
  763. SDL_CPUName[i++] = (char)(c & 0xff);
  764. c >>= 8;
  765. SDL_CPUName[i++] = (char)(d & 0xff);
  766. d >>= 8;
  767. SDL_CPUName[i++] = (char)(d & 0xff);
  768. d >>= 8;
  769. SDL_CPUName[i++] = (char)(d & 0xff);
  770. d >>= 8;
  771. SDL_CPUName[i++] = (char)(d & 0xff);
  772. d >>= 8;
  773. }
  774. }
  775. if (!SDL_CPUName[0]) {
  776. SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName));
  777. }
  778. }
  779. return SDL_CPUName;
  780. }
  781. #endif
  782. #endif
  783. int SDL_GetCPUCacheLineSize(void)
  784. {
  785. const char *cpuType = SDL_GetCPUType();
  786. int a, b, c, d;
  787. (void)a;
  788. (void)b;
  789. (void)c;
  790. (void)d;
  791. if (SDL_strcmp(cpuType, "GenuineIntel") == 0 || SDL_strcmp(cpuType, "CentaurHauls") == 0 || SDL_strcmp(cpuType, " Shanghai ") == 0) {
  792. cpuid(0x00000001, a, b, c, d);
  793. return ((b >> 8) & 0xff) * 8;
  794. } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0 || SDL_strcmp(cpuType, "HygonGenuine") == 0) {
  795. cpuid(0x80000005, a, b, c, d);
  796. return c & 0xff;
  797. } else {
  798. /* Just make a guess here... */
  799. return SDL_CACHELINE_SIZE;
  800. }
  801. }
  802. static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
  803. static Uint32 SDL_SIMDAlignment = 0xFFFFFFFF;
  804. static Uint32 SDL_GetCPUFeatures(void)
  805. {
  806. if (SDL_CPUFeatures == 0xFFFFFFFF) {
  807. CPU_calcCPUIDFeatures();
  808. SDL_CPUFeatures = 0;
  809. SDL_SIMDAlignment = sizeof(void *); /* a good safe base value */
  810. if (CPU_haveRDTSC()) {
  811. SDL_CPUFeatures |= CPU_HAS_RDTSC;
  812. }
  813. if (CPU_haveAltiVec()) {
  814. SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
  815. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  816. }
  817. if (CPU_haveMMX()) {
  818. SDL_CPUFeatures |= CPU_HAS_MMX;
  819. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 8);
  820. }
  821. if (CPU_haveSSE()) {
  822. SDL_CPUFeatures |= CPU_HAS_SSE;
  823. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  824. }
  825. if (CPU_haveSSE2()) {
  826. SDL_CPUFeatures |= CPU_HAS_SSE2;
  827. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  828. }
  829. if (CPU_haveSSE3()) {
  830. SDL_CPUFeatures |= CPU_HAS_SSE3;
  831. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  832. }
  833. if (CPU_haveSSE41()) {
  834. SDL_CPUFeatures |= CPU_HAS_SSE41;
  835. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  836. }
  837. if (CPU_haveSSE42()) {
  838. SDL_CPUFeatures |= CPU_HAS_SSE42;
  839. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  840. }
  841. if (CPU_haveAVX()) {
  842. SDL_CPUFeatures |= CPU_HAS_AVX;
  843. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 32);
  844. }
  845. if (CPU_haveAVX2()) {
  846. SDL_CPUFeatures |= CPU_HAS_AVX2;
  847. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 32);
  848. }
  849. if (CPU_haveAVX512F()) {
  850. SDL_CPUFeatures |= CPU_HAS_AVX512F;
  851. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 64);
  852. }
  853. if (CPU_haveARMSIMD()) {
  854. SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
  855. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  856. }
  857. if (CPU_haveNEON()) {
  858. SDL_CPUFeatures |= CPU_HAS_NEON;
  859. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  860. }
  861. if (CPU_haveLSX()) {
  862. SDL_CPUFeatures |= CPU_HAS_LSX;
  863. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 16);
  864. }
  865. if (CPU_haveLASX()) {
  866. SDL_CPUFeatures |= CPU_HAS_LASX;
  867. SDL_SIMDAlignment = SDL_max(SDL_SIMDAlignment, 32);
  868. }
  869. }
  870. return SDL_CPUFeatures;
  871. }
  872. #define CPU_FEATURE_AVAILABLE(f) ((SDL_GetCPUFeatures() & (f)) ? SDL_TRUE : SDL_FALSE)
  873. SDL_bool SDL_HasRDTSC(void)
  874. {
  875. return CPU_FEATURE_AVAILABLE(CPU_HAS_RDTSC);
  876. }
  877. SDL_bool
  878. SDL_HasAltiVec(void)
  879. {
  880. return CPU_FEATURE_AVAILABLE(CPU_HAS_ALTIVEC);
  881. }
  882. SDL_bool
  883. SDL_HasMMX(void)
  884. {
  885. return CPU_FEATURE_AVAILABLE(CPU_HAS_MMX);
  886. }
  887. SDL_bool
  888. SDL_HasSSE(void)
  889. {
  890. return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE);
  891. }
  892. SDL_bool
  893. SDL_HasSSE2(void)
  894. {
  895. return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE2);
  896. }
  897. SDL_bool
  898. SDL_HasSSE3(void)
  899. {
  900. return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE3);
  901. }
  902. SDL_bool
  903. SDL_HasSSE41(void)
  904. {
  905. return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE41);
  906. }
  907. SDL_bool
  908. SDL_HasSSE42(void)
  909. {
  910. return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE42);
  911. }
  912. SDL_bool
  913. SDL_HasAVX(void)
  914. {
  915. return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX);
  916. }
  917. SDL_bool
  918. SDL_HasAVX2(void)
  919. {
  920. return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX2);
  921. }
  922. SDL_bool
  923. SDL_HasAVX512F(void)
  924. {
  925. return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX512F);
  926. }
  927. SDL_bool
  928. SDL_HasARMSIMD(void)
  929. {
  930. return CPU_FEATURE_AVAILABLE(CPU_HAS_ARM_SIMD);
  931. }
  932. SDL_bool
  933. SDL_HasNEON(void)
  934. {
  935. return CPU_FEATURE_AVAILABLE(CPU_HAS_NEON);
  936. }
  937. SDL_bool
  938. SDL_HasLSX(void)
  939. {
  940. return CPU_FEATURE_AVAILABLE(CPU_HAS_LSX);
  941. }
  942. SDL_bool
  943. SDL_HasLASX(void)
  944. {
  945. return CPU_FEATURE_AVAILABLE(CPU_HAS_LASX);
  946. }
  947. static int SDL_SystemRAM = 0;
  948. int SDL_GetSystemRAM(void)
  949. {
  950. if (!SDL_SystemRAM) {
  951. #ifndef SDL_CPUINFO_DISABLED
  952. #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
  953. if (SDL_SystemRAM <= 0) {
  954. SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024 * 1024));
  955. }
  956. #endif
  957. #ifdef HAVE_SYSCTLBYNAME
  958. if (SDL_SystemRAM <= 0) {
  959. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
  960. #ifdef HW_REALMEM
  961. int mib[2] = { CTL_HW, HW_REALMEM };
  962. #else
  963. /* might only report up to 2 GiB */
  964. int mib[2] = { CTL_HW, HW_PHYSMEM };
  965. #endif /* HW_REALMEM */
  966. #else
  967. int mib[2] = { CTL_HW, HW_MEMSIZE };
  968. #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
  969. Uint64 memsize = 0;
  970. size_t len = sizeof(memsize);
  971. if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
  972. SDL_SystemRAM = (int)(memsize / (1024 * 1024));
  973. }
  974. }
  975. #endif
  976. #if defined(__WIN32__) || defined(__GDK__)
  977. if (SDL_SystemRAM <= 0) {
  978. MEMORYSTATUSEX stat;
  979. stat.dwLength = sizeof(stat);
  980. if (GlobalMemoryStatusEx(&stat)) {
  981. SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
  982. }
  983. }
  984. #endif
  985. #ifdef __RISCOS__
  986. if (SDL_SystemRAM <= 0) {
  987. _kernel_swi_regs regs;
  988. regs.r[0] = 0x108;
  989. if (_kernel_swi(OS_Memory, &regs, &regs) == NULL) {
  990. SDL_SystemRAM = (int)(regs.r[1] * regs.r[2] / (1024 * 1024));
  991. }
  992. }
  993. #endif
  994. #ifdef __VITA__
  995. if (SDL_SystemRAM <= 0) {
  996. /* Vita has 512MiB on SoC, that's split into 256MiB(+109MiB in extended memory mode) for app
  997. +26MiB of physically continuous memory, +112MiB of CDRAM(VRAM) + system reserved memory. */
  998. SDL_SystemRAM = 536870912;
  999. }
  1000. #endif
  1001. #ifdef __PS2__
  1002. if (SDL_SystemRAM <= 0) {
  1003. /* PlayStation 2 has 32MiB however there are some special models with 64 and 128 */
  1004. SDL_SystemRAM = GetMemorySize();
  1005. }
  1006. #endif
  1007. #endif
  1008. }
  1009. return SDL_SystemRAM;
  1010. }
  1011. size_t
  1012. SDL_SIMDGetAlignment(void)
  1013. {
  1014. if (SDL_SIMDAlignment == 0xFFFFFFFF) {
  1015. SDL_GetCPUFeatures(); /* make sure this has been calculated */
  1016. }
  1017. SDL_assert(SDL_SIMDAlignment != 0);
  1018. return SDL_SIMDAlignment;
  1019. }
  1020. #ifdef TEST_MAIN
  1021. #include <stdio.h>
  1022. int main()
  1023. {
  1024. printf("CPU count: %d\n", SDL_GetCPUCount());
  1025. printf("CPU type: %s\n", SDL_GetCPUType());
  1026. printf("CPU name: %s\n", SDL_GetCPUName());
  1027. printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
  1028. printf("RDTSC: %d\n", SDL_HasRDTSC());
  1029. printf("Altivec: %d\n", SDL_HasAltiVec());
  1030. printf("MMX: %d\n", SDL_HasMMX());
  1031. printf("SSE: %d\n", SDL_HasSSE());
  1032. printf("SSE2: %d\n", SDL_HasSSE2());
  1033. printf("SSE3: %d\n", SDL_HasSSE3());
  1034. printf("SSE4.1: %d\n", SDL_HasSSE41());
  1035. printf("SSE4.2: %d\n", SDL_HasSSE42());
  1036. printf("AVX: %d\n", SDL_HasAVX());
  1037. printf("AVX2: %d\n", SDL_HasAVX2());
  1038. printf("AVX-512F: %d\n", SDL_HasAVX512F());
  1039. printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
  1040. printf("NEON: %d\n", SDL_HasNEON());
  1041. printf("LSX: %d\n", SDL_HasLSX());
  1042. printf("LASX: %d\n", SDL_HasLASX());
  1043. printf("RAM: %d MB\n", SDL_GetSystemRAM());
  1044. return 0;
  1045. }
  1046. #endif /* TEST_MAIN */