~ubuntu-branches/ubuntu/vivid/libsdl2/vivid

« back to all changes in this revision

Viewing changes to src/cpuinfo/SDL_cpuinfo.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo, Felix Geyer
  • Date: 2013-12-28 12:31:19 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20131228123119-e0k27gckmnzskfgb
Tags: 2.0.1+dfsg1-1
* New upstream release (Closes: #728974)
  - Remove patch applied upstream:
    bug-723797-false_positives_in_mouse_wheel_code.patch
* Bump Standards-Version to 3.9.5, no changes needed.

[ Felix Geyer ]
* Import upstream gpg key for uscan to verify the orig tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
*/
21
21
#include "SDL_config.h"
22
22
 
 
23
#if defined(__WIN32__)
 
24
#include "../core/windows/SDL_windows.h"
 
25
#endif
 
26
 
23
27
/* CPU feature detection for SDL */
24
28
 
25
29
#include "SDL_cpuinfo.h"
41
45
#include <signal.h>
42
46
#include <setjmp.h>
43
47
#endif
44
 
#ifdef __WIN32__
45
 
#include "../core/windows/SDL_windows.h"
46
 
#endif
47
48
 
48
49
#define CPU_HAS_RDTSC   0x00000001
49
50
#define CPU_HAS_ALTIVEC 0x00000002
67
68
}
68
69
#endif /* HAVE_SETJMP */
69
70
 
70
 
static __inline__ int
 
71
static SDL_INLINE int
71
72
CPU_haveCPUID(void)
72
73
{
73
74
    int has_CPUID = 0;
191
192
    a = b = c = d = 0
192
193
#endif
193
194
 
194
 
static __inline__ int
 
195
static SDL_INLINE int
195
196
CPU_getCPUIDFeatures(void)
196
197
{
197
198
    int features = 0;
205
206
    return features;
206
207
}
207
208
 
208
 
static __inline__ int
 
209
static SDL_INLINE int
209
210
CPU_haveRDTSC(void)
210
211
{
211
212
    if (CPU_haveCPUID()) {
214
215
    return 0;
215
216
}
216
217
 
217
 
static __inline__ int
 
218
static SDL_INLINE int
218
219
CPU_haveAltiVec(void)
219
220
{
220
221
    volatile int altivec = 0;
241
242
    return altivec;
242
243
}
243
244
 
244
 
static __inline__ int
 
245
static SDL_INLINE int
245
246
CPU_haveMMX(void)
246
247
{
247
248
    if (CPU_haveCPUID()) {
250
251
    return 0;
251
252
}
252
253
 
253
 
static __inline__ int
 
254
static SDL_INLINE int
254
255
CPU_have3DNow(void)
255
256
{
256
257
    if (CPU_haveCPUID()) {
265
266
    return 0;
266
267
}
267
268
 
268
 
static __inline__ int
 
269
static SDL_INLINE int
269
270
CPU_haveSSE(void)
270
271
{
271
272
    if (CPU_haveCPUID()) {
274
275
    return 0;
275
276
}
276
277
 
277
 
static __inline__ int
 
278
static SDL_INLINE int
278
279
CPU_haveSSE2(void)
279
280
{
280
281
    if (CPU_haveCPUID()) {
283
284
    return 0;
284
285
}
285
286
 
286
 
static __inline__ int
 
287
static SDL_INLINE int
287
288
CPU_haveSSE3(void)
288
289
{
289
290
    if (CPU_haveCPUID()) {
298
299
    return 0;
299
300
}
300
301
 
301
 
static __inline__ int
 
302
static SDL_INLINE int
302
303
CPU_haveSSE41(void)
303
304
{
304
305
    if (CPU_haveCPUID()) {
313
314
    return 0;
314
315
}
315
316
 
316
 
static __inline__ int
 
317
static SDL_INLINE int
317
318
CPU_haveSSE42(void)
318
319
{
319
320
    if (CPU_haveCPUID()) {
607
608
    return SDL_FALSE;
608
609
}
609
610
 
 
611
static int SDL_SystemRAM = 0;
 
612
 
 
613
int
 
614
SDL_GetSystemRAM(void)
 
615
{
 
616
    if (!SDL_SystemRAM) {
 
617
#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
 
618
        if (SDL_SystemRAM <= 0) {
 
619
            SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
 
620
        }
 
621
#endif
 
622
#ifdef HAVE_SYSCTLBYNAME
 
623
        if (SDL_SystemRAM <= 0) {
 
624
#ifdef __FreeBSD__
 
625
#ifdef HW_REALMEM
 
626
            int mib[2] = {CTL_HW, HW_REALMEM};
 
627
#else
 
628
            /* might only report up to 2 GiB */
 
629
            int mib[2] = {CTL_HW, HW_PHYSMEM};
 
630
#endif /* HW_REALMEM */
 
631
#else
 
632
            int mib[2] = {CTL_HW, HW_MEMSIZE};
 
633
#endif /* __FreeBSD__ */
 
634
            Uint64 memsize = 0;
 
635
            size_t len = sizeof(memsize);
 
636
            
 
637
            if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
 
638
                SDL_SystemRAM = (int)(memsize / (1024*1024));
 
639
            }
 
640
        }
 
641
#endif
 
642
#ifdef __WIN32__
 
643
        if (SDL_SystemRAM <= 0) {
 
644
            MEMORYSTATUSEX stat;
 
645
            stat.dwLength = sizeof(stat);
 
646
            if (GlobalMemoryStatusEx(&stat)) {
 
647
                SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
 
648
            }
 
649
        }
 
650
#endif
 
651
    }
 
652
    return SDL_SystemRAM;
 
653
}
 
654
 
 
655
 
610
656
#ifdef TEST_MAIN
611
657
 
612
658
#include <stdio.h>
627
673
    printf("SSE3: %d\n", SDL_HasSSE3());
628
674
    printf("SSE4.1: %d\n", SDL_HasSSE41());
629
675
    printf("SSE4.2: %d\n", SDL_HasSSE42());
 
676
    printf("RAM: %d MB\n", SDL_GetSystemRAM());
630
677
    return 0;
631
678
}
632
679