SDL_cpuinfo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2013 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_config.h"
  19. /* CPU feature detection for SDL */
  20. #include "SDL_cpuinfo.h"
  21. #ifdef HAVE_SYSCONF
  22. #include <unistd.h>
  23. #endif
  24. #ifdef HAVE_SYSCTLBYNAME
  25. #include <sys/types.h>
  26. #include <sys/sysctl.h>
  27. #endif
  28. #if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
  29. #include <sys/sysctl.h> /* For AltiVec check */
  30. #elif defined(__OpenBSD__) && defined(__powerpc__)
  31. #include <sys/param.h>
  32. #include <sys/sysctl.h> /* For AltiVec check */
  33. #include <machine/cpu.h>
  34. #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
  35. #include <signal.h>
  36. #include <setjmp.h>
  37. #endif
  38. #ifdef __WIN32__
  39. #include "../core/windows/SDL_windows.h"
  40. #endif
  41. #define CPU_HAS_RDTSC 0x00000001
  42. #define CPU_HAS_ALTIVEC 0x00000002
  43. #define CPU_HAS_MMX 0x00000004
  44. #define CPU_HAS_3DNOW 0x00000008
  45. #define CPU_HAS_SSE 0x00000010
  46. #define CPU_HAS_SSE2 0x00000020
  47. #define CPU_HAS_SSE3 0x00000040
  48. #define CPU_HAS_SSE41 0x00000100
  49. #define CPU_HAS_SSE42 0x00000200
  50. #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
  51. /* This is the brute force way of detecting instruction sets...
  52. the idea is borrowed from the libmpeg2 library - thanks!
  53. */
  54. static jmp_buf jmpbuf;
  55. static void
  56. illegal_instruction(int sig)
  57. {
  58. longjmp(jmpbuf, 1);
  59. }
  60. #endif /* HAVE_SETJMP */
  61. static __inline__ int
  62. CPU_haveCPUID(void)
  63. {
  64. int has_CPUID = 0;
  65. /* *INDENT-OFF* */
  66. #if defined(__GNUC__) && defined(i386)
  67. __asm__ (
  68. " pushfl # Get original EFLAGS \n"
  69. " popl %%eax \n"
  70. " movl %%eax,%%ecx \n"
  71. " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
  72. " pushl %%eax # Save new EFLAGS value on stack \n"
  73. " popfl # Replace current EFLAGS value \n"
  74. " pushfl # Get new EFLAGS \n"
  75. " popl %%eax # Store new EFLAGS in EAX \n"
  76. " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
  77. " jz 1f # Processor=80486 \n"
  78. " movl $1,%0 # We have CPUID support \n"
  79. "1: \n"
  80. : "=m" (has_CPUID)
  81. :
  82. : "%eax", "%ecx"
  83. );
  84. #elif defined(__GNUC__) && defined(__x86_64__)
  85. /* Technically, if this is being compiled under __x86_64__ then it has
  86. CPUid by definition. But it's nice to be able to prove it. :) */
  87. __asm__ (
  88. " pushfq # Get original EFLAGS \n"
  89. " popq %%rax \n"
  90. " movq %%rax,%%rcx \n"
  91. " xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
  92. " pushq %%rax # Save new EFLAGS value on stack \n"
  93. " popfq # Replace current EFLAGS value \n"
  94. " pushfq # Get new EFLAGS \n"
  95. " popq %%rax # Store new EFLAGS in EAX \n"
  96. " xorl %%ecx,%%eax # Can not toggle ID bit, \n"
  97. " jz 1f # Processor=80486 \n"
  98. " movl $1,%0 # We have CPUID support \n"
  99. "1: \n"
  100. : "=m" (has_CPUID)
  101. :
  102. : "%rax", "%rcx"
  103. );
  104. #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  105. __asm {
  106. pushfd ; Get original EFLAGS
  107. pop eax
  108. mov ecx, eax
  109. xor eax, 200000h ; Flip ID bit in EFLAGS
  110. push eax ; Save new EFLAGS value on stack
  111. popfd ; Replace current EFLAGS value
  112. pushfd ; Get new EFLAGS
  113. pop eax ; Store new EFLAGS in EAX
  114. xor eax, ecx ; Can not toggle ID bit,
  115. jz done ; Processor=80486
  116. mov has_CPUID,1 ; We have CPUID support
  117. done:
  118. }
  119. #elif defined(__sun) && defined(__i386)
  120. __asm (
  121. " pushfl \n"
  122. " popl %eax \n"
  123. " movl %eax,%ecx \n"
  124. " xorl $0x200000,%eax \n"
  125. " pushl %eax \n"
  126. " popfl \n"
  127. " pushfl \n"
  128. " popl %eax \n"
  129. " xorl %ecx,%eax \n"
  130. " jz 1f \n"
  131. " movl $1,-8(%ebp) \n"
  132. "1: \n"
  133. );
  134. #elif defined(__sun) && defined(__amd64)
  135. __asm (
  136. " pushfq \n"
  137. " popq %rax \n"
  138. " movq %rax,%rcx \n"
  139. " xorl $0x200000,%eax \n"
  140. " pushq %rax \n"
  141. " popfq \n"
  142. " pushfq \n"
  143. " popq %rax \n"
  144. " xorl %ecx,%eax \n"
  145. " jz 1f \n"
  146. " movl $1,-8(%rbp) \n"
  147. "1: \n"
  148. );
  149. #endif
  150. /* *INDENT-ON* */
  151. return has_CPUID;
  152. }
  153. #if defined(__GNUC__) && defined(i386)
  154. #define cpuid(func, a, b, c, d) \
  155. __asm__ __volatile__ ( \
  156. " pushl %%ebx \n" \
  157. " cpuid \n" \
  158. " movl %%ebx, %%esi \n" \
  159. " popl %%ebx \n" : \
  160. "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
  161. #elif defined(__GNUC__) && defined(__x86_64__)
  162. #define cpuid(func, a, b, c, d) \
  163. __asm__ __volatile__ ( \
  164. " pushq %%rbx \n" \
  165. " cpuid \n" \
  166. " movq %%rbx, %%rsi \n" \
  167. " popq %%rbx \n" : \
  168. "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
  169. #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  170. #define cpuid(func, a, b, c, d) \
  171. __asm { \
  172. __asm mov eax, func \
  173. __asm cpuid \
  174. __asm mov a, eax \
  175. __asm mov b, ebx \
  176. __asm mov c, ecx \
  177. __asm mov d, edx \
  178. }
  179. #else
  180. #define cpuid(func, a, b, c, d) \
  181. a = b = c = d = 0
  182. #endif
  183. static __inline__ int
  184. CPU_getCPUIDFeatures(void)
  185. {
  186. int features = 0;
  187. int a, b, c, d;
  188. cpuid(0, a, b, c, d);
  189. if (a >= 1) {
  190. cpuid(1, a, b, c, d);
  191. features = d;
  192. }
  193. return features;
  194. }
  195. static __inline__ int
  196. CPU_haveRDTSC(void)
  197. {
  198. if (CPU_haveCPUID()) {
  199. return (CPU_getCPUIDFeatures() & 0x00000010);
  200. }
  201. return 0;
  202. }
  203. static __inline__ int
  204. CPU_haveAltiVec(void)
  205. {
  206. volatile int altivec = 0;
  207. #if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
  208. #ifdef __OpenBSD__
  209. int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
  210. #else
  211. int selectors[2] = { CTL_HW, HW_VECTORUNIT };
  212. #endif
  213. int hasVectorUnit = 0;
  214. size_t length = sizeof(hasVectorUnit);
  215. int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
  216. if (0 == error)
  217. altivec = (hasVectorUnit != 0);
  218. #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
  219. void (*handler) (int sig);
  220. handler = signal(SIGILL, illegal_instruction);
  221. if (setjmp(jmpbuf) == 0) {
  222. asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
  223. altivec = 1;
  224. }
  225. signal(SIGILL, handler);
  226. #endif
  227. return altivec;
  228. }
  229. static __inline__ int
  230. CPU_haveMMX(void)
  231. {
  232. if (CPU_haveCPUID()) {
  233. return (CPU_getCPUIDFeatures() & 0x00800000);
  234. }
  235. return 0;
  236. }
  237. static __inline__ int
  238. CPU_have3DNow(void)
  239. {
  240. if (CPU_haveCPUID()) {
  241. int a, b, c, d;
  242. cpuid(0x80000000, a, b, c, d);
  243. if (a >= 0x80000001) {
  244. cpuid(0x80000001, a, b, c, d);
  245. return (d & 0x80000000);
  246. }
  247. }
  248. return 0;
  249. }
  250. static __inline__ int
  251. CPU_haveSSE(void)
  252. {
  253. if (CPU_haveCPUID()) {
  254. return (CPU_getCPUIDFeatures() & 0x02000000);
  255. }
  256. return 0;
  257. }
  258. static __inline__ int
  259. CPU_haveSSE2(void)
  260. {
  261. if (CPU_haveCPUID()) {
  262. return (CPU_getCPUIDFeatures() & 0x04000000);
  263. }
  264. return 0;
  265. }
  266. static __inline__ int
  267. CPU_haveSSE3(void)
  268. {
  269. if (CPU_haveCPUID()) {
  270. int a, b, c, d;
  271. cpuid(0, a, b, c, d);
  272. if (a >= 1) {
  273. cpuid(1, a, b, c, d);
  274. return (c & 0x00000001);
  275. }
  276. }
  277. return 0;
  278. }
  279. static __inline__ int
  280. CPU_haveSSE41(void)
  281. {
  282. if (CPU_haveCPUID()) {
  283. int a, b, c, d;
  284. cpuid(1, a, b, c, d);
  285. if (a >= 1) {
  286. cpuid(1, a, b, c, d);
  287. return (c & 0x00080000);
  288. }
  289. }
  290. return 0;
  291. }
  292. static __inline__ int
  293. CPU_haveSSE42(void)
  294. {
  295. if (CPU_haveCPUID()) {
  296. int a, b, c, d;
  297. cpuid(1, a, b, c, d);
  298. if (a >= 1) {
  299. cpuid(1, a, b, c, d);
  300. return (c & 0x00100000);
  301. }
  302. }
  303. return 0;
  304. }
  305. static int SDL_CPUCount = 0;
  306. int
  307. SDL_GetCPUCount(void)
  308. {
  309. if (!SDL_CPUCount) {
  310. #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
  311. if (SDL_CPUCount <= 0) {
  312. SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
  313. }
  314. #endif
  315. #ifdef HAVE_SYSCTLBYNAME
  316. if (SDL_CPUCount <= 0) {
  317. size_t size = sizeof(SDL_CPUCount);
  318. sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
  319. }
  320. #endif
  321. #ifdef __WIN32__
  322. if (SDL_CPUCount <= 0) {
  323. SYSTEM_INFO info;
  324. GetSystemInfo(&info);
  325. SDL_CPUCount = info.dwNumberOfProcessors;
  326. }
  327. #endif
  328. /* There has to be at least 1, right? :) */
  329. if (SDL_CPUCount <= 0) {
  330. SDL_CPUCount = 1;
  331. }
  332. }
  333. return SDL_CPUCount;
  334. }
  335. /* Oh, such a sweet sweet trick, just not very useful. :) */
  336. static const char *
  337. SDL_GetCPUType(void)
  338. {
  339. static char SDL_CPUType[13];
  340. if (!SDL_CPUType[0]) {
  341. int i = 0;
  342. int a, b, c, d;
  343. if (CPU_haveCPUID()) {
  344. cpuid(0x00000000, a, b, c, d);
  345. SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
  346. SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
  347. SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
  348. SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
  349. SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
  350. SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
  351. SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
  352. SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
  353. SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
  354. SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
  355. SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
  356. SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
  357. }
  358. if (!SDL_CPUType[0]) {
  359. SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
  360. }
  361. }
  362. return SDL_CPUType;
  363. }
  364. #ifdef TEST_MAIN /* !!! FIXME: only used for test at the moment. */
  365. static const char *
  366. SDL_GetCPUName(void)
  367. {
  368. static char SDL_CPUName[48];
  369. if (!SDL_CPUName[0]) {
  370. int i = 0;
  371. int a, b, c, d;
  372. if (CPU_haveCPUID()) {
  373. cpuid(0x80000000, a, b, c, d);
  374. if (a >= 0x80000004) {
  375. cpuid(0x80000002, a, b, c, d);
  376. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  377. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  378. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  379. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  380. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  381. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  382. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  383. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  384. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  385. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  386. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  387. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  388. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  389. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  390. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  391. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  392. cpuid(0x80000003, a, b, c, d);
  393. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  394. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  395. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  396. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  397. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  398. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  399. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  400. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  401. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  402. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  403. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  404. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  405. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  406. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  407. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  408. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  409. cpuid(0x80000004, a, b, c, d);
  410. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  411. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  412. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  413. SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
  414. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  415. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  416. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  417. SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
  418. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  419. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  420. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  421. SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
  422. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  423. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  424. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  425. SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
  426. }
  427. }
  428. if (!SDL_CPUName[0]) {
  429. SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName));
  430. }
  431. }
  432. return SDL_CPUName;
  433. }
  434. #endif
  435. int
  436. SDL_GetCPUCacheLineSize(void)
  437. {
  438. const char *cpuType = SDL_GetCPUType();
  439. if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
  440. int a, b, c, d;
  441. cpuid(0x00000001, a, b, c, d);
  442. return (((b >> 8) & 0xff) * 8);
  443. } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
  444. int a, b, c, d;
  445. cpuid(0x80000005, a, b, c, d);
  446. return (c & 0xff);
  447. } else {
  448. /* Just make a guess here... */
  449. return SDL_CACHELINE_SIZE;
  450. }
  451. }
  452. static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
  453. static Uint32
  454. SDL_GetCPUFeatures(void)
  455. {
  456. if (SDL_CPUFeatures == 0xFFFFFFFF) {
  457. SDL_CPUFeatures = 0;
  458. if (CPU_haveRDTSC()) {
  459. SDL_CPUFeatures |= CPU_HAS_RDTSC;
  460. }
  461. if (CPU_haveAltiVec()) {
  462. SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
  463. }
  464. if (CPU_haveMMX()) {
  465. SDL_CPUFeatures |= CPU_HAS_MMX;
  466. }
  467. if (CPU_have3DNow()) {
  468. SDL_CPUFeatures |= CPU_HAS_3DNOW;
  469. }
  470. if (CPU_haveSSE()) {
  471. SDL_CPUFeatures |= CPU_HAS_SSE;
  472. }
  473. if (CPU_haveSSE2()) {
  474. SDL_CPUFeatures |= CPU_HAS_SSE2;
  475. }
  476. if (CPU_haveSSE3()) {
  477. SDL_CPUFeatures |= CPU_HAS_SSE3;
  478. }
  479. if (CPU_haveSSE41()) {
  480. SDL_CPUFeatures |= CPU_HAS_SSE41;
  481. }
  482. if (CPU_haveSSE42()) {
  483. SDL_CPUFeatures |= CPU_HAS_SSE42;
  484. }
  485. }
  486. return SDL_CPUFeatures;
  487. }
  488. SDL_bool
  489. SDL_HasRDTSC(void)
  490. {
  491. if (SDL_GetCPUFeatures() & CPU_HAS_RDTSC) {
  492. return SDL_TRUE;
  493. }
  494. return SDL_FALSE;
  495. }
  496. SDL_bool
  497. SDL_HasAltiVec(void)
  498. {
  499. if (SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC) {
  500. return SDL_TRUE;
  501. }
  502. return SDL_FALSE;
  503. }
  504. SDL_bool
  505. SDL_HasMMX(void)
  506. {
  507. if (SDL_GetCPUFeatures() & CPU_HAS_MMX) {
  508. return SDL_TRUE;
  509. }
  510. return SDL_FALSE;
  511. }
  512. SDL_bool
  513. SDL_Has3DNow(void)
  514. {
  515. if (SDL_GetCPUFeatures() & CPU_HAS_3DNOW) {
  516. return SDL_TRUE;
  517. }
  518. return SDL_FALSE;
  519. }
  520. SDL_bool
  521. SDL_HasSSE(void)
  522. {
  523. if (SDL_GetCPUFeatures() & CPU_HAS_SSE) {
  524. return SDL_TRUE;
  525. }
  526. return SDL_FALSE;
  527. }
  528. SDL_bool
  529. SDL_HasSSE2(void)
  530. {
  531. if (SDL_GetCPUFeatures() & CPU_HAS_SSE2) {
  532. return SDL_TRUE;
  533. }
  534. return SDL_FALSE;
  535. }
  536. SDL_bool
  537. SDL_HasSSE3(void)
  538. {
  539. if (SDL_GetCPUFeatures() & CPU_HAS_SSE3) {
  540. return SDL_TRUE;
  541. }
  542. return SDL_FALSE;
  543. }
  544. SDL_bool
  545. SDL_HasSSE41(void)
  546. {
  547. if (SDL_GetCPUFeatures() & CPU_HAS_SSE41) {
  548. return SDL_TRUE;
  549. }
  550. return SDL_FALSE;
  551. }
  552. SDL_bool
  553. SDL_HasSSE42(void)
  554. {
  555. if (SDL_GetCPUFeatures() & CPU_HAS_SSE42) {
  556. return SDL_TRUE;
  557. }
  558. return SDL_FALSE;
  559. }
  560. #ifdef TEST_MAIN
  561. #include <stdio.h>
  562. int
  563. main()
  564. {
  565. printf("CPU count: %d\n", SDL_GetCPUCount());
  566. printf("CPU type: %s\n", SDL_GetCPUType());
  567. printf("CPU name: %s\n", SDL_GetCPUName());
  568. printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
  569. printf("RDTSC: %d\n", SDL_HasRDTSC());
  570. printf("Altivec: %d\n", SDL_HasAltiVec());
  571. printf("MMX: %d\n", SDL_HasMMX());
  572. printf("3DNow: %d\n", SDL_Has3DNow());
  573. printf("SSE: %d\n", SDL_HasSSE());
  574. printf("SSE2: %d\n", SDL_HasSSE2());
  575. printf("SSE3: %d\n", SDL_HasSSE3());
  576. printf("SSE4.1: %d\n", SDL_HasSSE41());
  577. printf("SSE4.2: %d\n", SDL_HasSSE42());
  578. return 0;
  579. }
  580. #endif /* TEST_MAIN */
  581. /* vi: set ts=4 sw=4 expandtab: */