src/cpuinfo/SDL_cpuinfo.c
author Ben Avison <bavison@riscosopen.org>
Thu, 31 Oct 2019 14:00:28 +0300
branchSDL-1.2
changeset 13212 3d6dc20a0974
parent 6908 8b9fcdd925d8
child 13219 4f88e197acad
permissions -rw-r--r--
ARM: Create configure option --enable-arm-simd to govern assembly optimizations
---
configure.in | 60 +++++++++++++++++++--------------------
include/SDL_config.h.in | 1 +
include/SDL_cpuinfo.h | 3 ++
src/cpuinfo/SDL_cpuinfo.c | 53 ++++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+), 30 deletions(-)
slouken@739
     1
/*
slouken@739
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 Sam Lantinga
slouken@739
     4
slouken@739
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@739
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@739
     9
slouken@739
    10
    This library is distributed in the hope that it will be useful,
slouken@739
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@739
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@739
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@739
    18
slouken@739
    19
    Sam Lantinga
slouken@739
    20
    slouken@libsdl.org
slouken@739
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@739
    23
slouken@739
    24
/* CPU feature detection for SDL */
slouken@739
    25
slouken@1361
    26
#include "SDL.h"
slouken@1361
    27
#include "SDL_cpuinfo.h"
slouken@1361
    28
slouken@4386
    29
#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
slouken@1487
    30
#include <sys/sysctl.h> /* For AltiVec check */
slouken@6364
    31
#elif defined(__OpenBSD__) && defined(__powerpc__)
slouken@6364
    32
#include <sys/param.h>
slouken@6364
    33
#include <sys/sysctl.h> /* For AltiVec check */
slouken@6364
    34
#include <machine/cpu.h>
slouken@1487
    35
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
    36
#include <signal.h>
slouken@793
    37
#include <setjmp.h>
slouken@793
    38
#endif
slouken@793
    39
slouken@745
    40
#define CPU_HAS_RDTSC	0x00000001
slouken@745
    41
#define CPU_HAS_MMX	0x00000002
slouken@785
    42
#define CPU_HAS_MMXEXT	0x00000004
slouken@785
    43
#define CPU_HAS_3DNOW	0x00000010
slouken@785
    44
#define CPU_HAS_3DNOWEXT 0x00000020
slouken@785
    45
#define CPU_HAS_SSE	0x00000040
slouken@785
    46
#define CPU_HAS_SSE2	0x00000080
slouken@785
    47
#define CPU_HAS_ALTIVEC	0x00000100
bavison@13212
    48
#define CPU_HAS_ARM_SIMD 0x00000200
slouken@739
    49
slouken@6364
    50
#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
slouken@793
    51
/* This is the brute force way of detecting instruction sets...
slouken@793
    52
   the idea is borrowed from the libmpeg2 library - thanks!
slouken@793
    53
 */
slouken@793
    54
static jmp_buf jmpbuf;
slouken@793
    55
static void illegal_instruction(int sig)
slouken@793
    56
{
slouken@793
    57
	longjmp(jmpbuf, 1);
slouken@793
    58
}
slouken@1361
    59
#endif /* HAVE_SETJMP */
slouken@793
    60
slouken@1426
    61
static __inline__ int CPU_haveCPUID(void)
slouken@745
    62
{
slouken@745
    63
	int has_CPUID = 0;
slouken@745
    64
#if defined(__GNUC__) && defined(i386)
slouken@745
    65
	__asm__ (
slouken@745
    66
"        pushfl                      # Get original EFLAGS             \n"
slouken@745
    67
"        popl    %%eax                                                 \n"
slouken@745
    68
"        movl    %%eax,%%ecx                                           \n"
slouken@745
    69
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
slouken@745
    70
"        pushl   %%eax               # Save new EFLAGS value on stack  \n"
slouken@745
    71
"        popfl                       # Replace current EFLAGS value    \n"
slouken@745
    72
"        pushfl                      # Get new EFLAGS                  \n"
slouken@745
    73
"        popl    %%eax               # Store new EFLAGS in EAX         \n"
slouken@745
    74
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
slouken@745
    75
"        jz      1f                  # Processor=80486                 \n"
slouken@745
    76
"        movl    $1,%0               # We have CPUID support           \n"
slouken@745
    77
"1:                                                                    \n"
slouken@784
    78
	: "=m" (has_CPUID)
slouken@745
    79
	:
slouken@745
    80
	: "%eax", "%ecx"
slouken@745
    81
	);
slouken@881
    82
#elif defined(__GNUC__) && defined(__x86_64__)
slouken@881
    83
/* Technically, if this is being compiled under __x86_64__ then it has 
slouken@881
    84
CPUid by definition.  But it's nice to be able to prove it.  :)      */
slouken@881
    85
	__asm__ (
slouken@881
    86
"        pushfq                      # Get original EFLAGS             \n"
slouken@881
    87
"        popq    %%rax                                                 \n"
slouken@881
    88
"        movq    %%rax,%%rcx                                           \n"
slouken@881
    89
"        xorl    $0x200000,%%eax     # Flip ID bit in EFLAGS           \n"
slouken@881
    90
"        pushq   %%rax               # Save new EFLAGS value on stack  \n"
slouken@881
    91
"        popfq                       # Replace current EFLAGS value    \n"
slouken@881
    92
"        pushfq                      # Get new EFLAGS                  \n"
slouken@881
    93
"        popq    %%rax               # Store new EFLAGS in EAX         \n"
slouken@881
    94
"        xorl    %%ecx,%%eax         # Can not toggle ID bit,          \n"
slouken@881
    95
"        jz      1f                  # Processor=80486                 \n"
slouken@881
    96
"        movl    $1,%0               # We have CPUID support           \n"
slouken@881
    97
"1:                                                                    \n"
slouken@881
    98
	: "=m" (has_CPUID)
slouken@881
    99
	:
slouken@881
   100
	: "%rax", "%rcx"
slouken@881
   101
	);
slouken@1442
   102
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@749
   103
	__asm {
slouken@745
   104
        pushfd                      ; Get original EFLAGS
slouken@745
   105
        pop     eax
slouken@745
   106
        mov     ecx, eax
slouken@745
   107
        xor     eax, 200000h        ; Flip ID bit in EFLAGS
slouken@745
   108
        push    eax                 ; Save new EFLAGS value on stack
slouken@745
   109
        popfd                       ; Replace current EFLAGS value
slouken@745
   110
        pushfd                      ; Get new EFLAGS
slouken@745
   111
        pop     eax                 ; Store new EFLAGS in EAX
slouken@745
   112
        xor     eax, ecx            ; Can not toggle ID bit,
slouken@745
   113
        jz      done                ; Processor=80486
slouken@745
   114
        mov     has_CPUID,1         ; We have CPUID support
slouken@745
   115
done:
slouken@745
   116
	}
slouken@1864
   117
#elif defined(__sun) && defined(__i386)
slouken@1361
   118
	__asm (
icculus@1229
   119
"       pushfl                 \n"
slouken@1361
   120
"	popl    %eax           \n"
slouken@1361
   121
"	movl    %eax,%ecx      \n"
slouken@1361
   122
"	xorl    $0x200000,%eax \n"
slouken@1361
   123
"	pushl   %eax           \n"
slouken@1361
   124
"	popfl                  \n"
slouken@1361
   125
"	pushfl                 \n"
slouken@1361
   126
"	popl    %eax           \n"
slouken@1361
   127
"	xorl    %ecx,%eax      \n"
slouken@1361
   128
"	jz      1f             \n"
slouken@1361
   129
"	movl    $1,-8(%ebp)    \n"
icculus@1229
   130
"1:                            \n"
icculus@1229
   131
	);
icculus@1229
   132
#elif defined(__sun) && defined(__amd64)
icculus@1229
   133
	__asm (
icculus@1229
   134
"       pushfq                 \n"
icculus@1229
   135
"       popq    %rax           \n"
icculus@1229
   136
"       movq    %rax,%rcx      \n"
icculus@1229
   137
"       xorl    $0x200000,%eax \n"
icculus@1229
   138
"       pushq   %rax           \n"
icculus@1229
   139
"       popfq                  \n"
icculus@1229
   140
"       pushfq                 \n"
icculus@1229
   141
"       popq    %rax           \n"
icculus@1229
   142
"       xorl    %ecx,%eax      \n"
icculus@1229
   143
"       jz      1f             \n"
icculus@1229
   144
"       movl    $1,-8(%rbp)    \n"
icculus@1229
   145
"1:                            \n"
icculus@1229
   146
	);
slouken@745
   147
#endif
slouken@745
   148
	return has_CPUID;
slouken@745
   149
}
slouken@745
   150
slouken@1426
   151
static __inline__ int CPU_getCPUIDFeatures(void)
slouken@745
   152
{
slouken@745
   153
	int features = 0;
icculus@4180
   154
#if defined(__GNUC__) && defined(i386)
slouken@745
   155
	__asm__ (
slouken@745
   156
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
slouken@4386
   157
"        pushl   %%ebx                                                 \n"
slouken@745
   158
"        cpuid                       # Get and save vendor ID          \n"
slouken@4387
   159
"        popl    %%ebx                                                 \n"
slouken@745
   160
"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
slouken@745
   161
"        jl      1f                  # We dont have the CPUID instruction\n"
slouken@745
   162
"        xorl    %%eax,%%eax                                           \n"
slouken@745
   163
"        incl    %%eax                                                 \n"
slouken@4387
   164
"        pushl   %%ebx                                                 \n"
slouken@745
   165
"        cpuid                       # Get family/model/stepping/features\n"
slouken@4386
   166
"        popl    %%ebx                                                 \n"
slouken@745
   167
"        movl    %%edx,%0                                              \n"
slouken@745
   168
"1:                                                                    \n"
slouken@784
   169
	: "=m" (features)
slouken@745
   170
	:
icculus@4372
   171
	: "%eax", "%ecx", "%edx"
slouken@745
   172
	);
icculus@4180
   173
#elif defined(__GNUC__) && defined(__x86_64__)
icculus@4180
   174
	__asm__ (
slouken@4386
   175
"        xorl    %%eax,%%eax         # Set up for CPUID instruction    \n"
slouken@4387
   176
"        pushq   %%rbx                                                 \n"
icculus@4180
   177
"        cpuid                       # Get and save vendor ID          \n"
slouken@4387
   178
"        popq    %%rbx                                                 \n"
icculus@4180
   179
"        cmpl    $1,%%eax            # Make sure 1 is valid input for CPUID\n"
icculus@4180
   180
"        jl      1f                  # We dont have the CPUID instruction\n"
icculus@4180
   181
"        xorl    %%eax,%%eax                                           \n"
icculus@4180
   182
"        incl    %%eax                                                 \n"
slouken@4387
   183
"        pushq   %%rbx                                                 \n"
icculus@4180
   184
"        cpuid                       # Get family/model/stepping/features\n"
slouken@4387
   185
"        popq    %%rbx                                                 \n"
icculus@4180
   186
"        movl    %%edx,%0                                              \n"
icculus@4180
   187
"1:                                                                    \n"
icculus@4180
   188
	: "=m" (features)
icculus@4180
   189
	:
icculus@4372
   190
	: "%rax", "%rcx", "%rdx"
icculus@4180
   191
	);
slouken@1442
   192
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@749
   193
	__asm {
slouken@745
   194
        xor     eax, eax            ; Set up for CPUID instruction
slouken@4386
   195
        push    ebx
slouken@745
   196
        cpuid                       ; Get and save vendor ID
slouken@4387
   197
        pop     ebx
slouken@745
   198
        cmp     eax, 1              ; Make sure 1 is valid input for CPUID
slouken@745
   199
        jl      done                ; We dont have the CPUID instruction
slouken@745
   200
        xor     eax, eax
slouken@745
   201
        inc     eax
slouken@4387
   202
        push    ebx
slouken@745
   203
        cpuid                       ; Get family/model/stepping/features
slouken@4386
   204
        pop     ebx
slouken@745
   205
        mov     features, edx
slouken@745
   206
done:
slouken@745
   207
	}
slouken@1864
   208
#elif defined(__sun) && (defined(__i386) || defined(__amd64))
icculus@1229
   209
	    __asm(
icculus@1229
   210
"        xorl    %eax,%eax         \n"
slouken@4386
   211
"        pushl   %ebx              \n"
icculus@1229
   212
"        cpuid                     \n"
slouken@4387
   213
"        popl    %ebx              \n"
icculus@1229
   214
"        cmpl    $1,%eax           \n"
icculus@1229
   215
"        jl      1f                \n"
icculus@1229
   216
"        xorl    %eax,%eax         \n"
icculus@1229
   217
"        incl    %eax              \n"
slouken@4387
   218
"        pushl   %ebx              \n"
icculus@1229
   219
"        cpuid                     \n"
slouken@4386
   220
"        popl    %ebx              \n"
icculus@1229
   221
#ifdef __i386
icculus@1229
   222
"        movl    %edx,-8(%ebp)     \n"
icculus@1229
   223
#else
icculus@1229
   224
"        movl    %edx,-8(%rbp)     \n"
icculus@1229
   225
#endif
icculus@1229
   226
"1:                                \n"
eviltypeguy@6908
   227
	    );
slouken@745
   228
#endif
slouken@745
   229
	return features;
slouken@745
   230
}
slouken@745
   231
slouken@1426
   232
static __inline__ int CPU_getCPUIDFeaturesExt(void)
slouken@785
   233
{
slouken@785
   234
	int features = 0;
icculus@4180
   235
#if defined(__GNUC__) && defined(i386)
slouken@785
   236
	__asm__ (
slouken@785
   237
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   238
"        pushl   %%ebx                                                 \n"
slouken@785
   239
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   240
"        popl    %%ebx                                                 \n"
slouken@785
   241
"        cmpl    $0x80000001,%%eax                                     \n"
slouken@787
   242
"        jl      1f                  # Nope, we dont have function 800000001h\n"
slouken@785
   243
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   244
"        pushl   %%ebx                                                 \n"
slouken@785
   245
"        cpuid                       # and get the information         \n"
slouken@4386
   246
"        popl    %%ebx                                                 \n"
slouken@785
   247
"        movl    %%edx,%0                                              \n"
slouken@785
   248
"1:                                                                    \n"
slouken@785
   249
	: "=m" (features)
slouken@785
   250
	:
icculus@4372
   251
	: "%eax", "%ecx", "%edx"
slouken@785
   252
	);
icculus@4180
   253
#elif defined(__GNUC__) && defined (__x86_64__)
icculus@4180
   254
	__asm__ (
icculus@4180
   255
"        movl    $0x80000000,%%eax   # Query for extended functions    \n"
slouken@4386
   256
"        pushq   %%rbx                                                 \n"
icculus@4180
   257
"        cpuid                       # Get extended function limit     \n"
slouken@4387
   258
"        popq    %%rbx                                                 \n"
icculus@4180
   259
"        cmpl    $0x80000001,%%eax                                     \n"
icculus@4180
   260
"        jl      1f                  # Nope, we dont have function 800000001h\n"
icculus@4180
   261
"        movl    $0x80000001,%%eax   # Setup extended function 800000001h\n"
slouken@4387
   262
"        pushq   %%rbx                                                 \n"
icculus@4180
   263
"        cpuid                       # and get the information         \n"
slouken@4386
   264
"        popq    %%rbx                                                 \n"
icculus@4180
   265
"        movl    %%edx,%0                                              \n"
icculus@4180
   266
"1:                                                                    \n"
icculus@4180
   267
	: "=m" (features)
icculus@4180
   268
	:
icculus@4372
   269
	: "%rax", "%rcx", "%rdx"
icculus@4180
   270
	);
slouken@1442
   271
#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
slouken@785
   272
	__asm {
slouken@785
   273
        mov     eax,80000000h       ; Query for extended functions
slouken@4386
   274
        push    ebx
slouken@785
   275
        cpuid                       ; Get extended function limit
slouken@4387
   276
        pop     ebx
slouken@785
   277
        cmp     eax,80000001h
slouken@787
   278
        jl      done                ; Nope, we dont have function 800000001h
slouken@785
   279
        mov     eax,80000001h       ; Setup extended function 800000001h
slouken@4387
   280
        push    ebx
slouken@785
   281
        cpuid                       ; and get the information
slouken@4386
   282
        pop     ebx
slouken@785
   283
        mov     features,edx
slouken@785
   284
done:
slouken@785
   285
	}
icculus@1229
   286
#elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
icculus@1229
   287
	    __asm (
icculus@1229
   288
"        movl    $0x80000000,%eax \n"
slouken@4386
   289
"        pushl   %ebx             \n"
icculus@1229
   290
"        cpuid                    \n"
slouken@4387
   291
"        popl    %ebx             \n"
icculus@1229
   292
"        cmpl    $0x80000001,%eax \n"
icculus@1229
   293
"        jl      1f               \n"
icculus@1229
   294
"        movl    $0x80000001,%eax \n"
slouken@4387
   295
"        pushl   %ebx             \n"
icculus@1229
   296
"        cpuid                    \n"
slouken@4386
   297
"        popl    %ebx             \n"
icculus@1229
   298
#ifdef __i386
icculus@1229
   299
"        movl    %edx,-8(%ebp)   \n"
icculus@1229
   300
#else
icculus@1229
   301
"        movl    %edx,-8(%rbp)   \n"
icculus@1229
   302
#endif
icculus@1229
   303
"1:                               \n"
icculus@1229
   304
	    );
slouken@785
   305
#endif
slouken@785
   306
	return features;
slouken@785
   307
}
slouken@785
   308
slouken@1426
   309
static __inline__ int CPU_haveRDTSC(void)
slouken@745
   310
{
slouken@745
   311
	if ( CPU_haveCPUID() ) {
slouken@745
   312
		return (CPU_getCPUIDFeatures() & 0x00000010);
slouken@745
   313
	}
slouken@745
   314
	return 0;
slouken@745
   315
}
slouken@745
   316
slouken@1426
   317
static __inline__ int CPU_haveMMX(void)
slouken@745
   318
{
slouken@745
   319
	if ( CPU_haveCPUID() ) {
slouken@745
   320
		return (CPU_getCPUIDFeatures() & 0x00800000);
slouken@745
   321
	}
slouken@745
   322
	return 0;
slouken@745
   323
}
slouken@745
   324
slouken@1426
   325
static __inline__ int CPU_haveMMXExt(void)
slouken@785
   326
{
slouken@785
   327
	if ( CPU_haveCPUID() ) {
slouken@785
   328
		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
slouken@785
   329
	}
slouken@785
   330
	return 0;
slouken@785
   331
}
slouken@785
   332
slouken@1426
   333
static __inline__ int CPU_have3DNow(void)
slouken@745
   334
{
slouken@785
   335
	if ( CPU_haveCPUID() ) {
slouken@785
   336
		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
slouken@747
   337
	}
slouken@785
   338
	return 0;
slouken@785
   339
}
slouken@785
   340
slouken@1426
   341
static __inline__ int CPU_have3DNowExt(void)
slouken@785
   342
{
slouken@785
   343
	if ( CPU_haveCPUID() ) {
slouken@785
   344
		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
slouken@745
   345
	}
slouken@785
   346
	return 0;
slouken@745
   347
}
slouken@745
   348
slouken@1426
   349
static __inline__ int CPU_haveSSE(void)
slouken@745
   350
{
slouken@745
   351
	if ( CPU_haveCPUID() ) {
slouken@745
   352
		return (CPU_getCPUIDFeatures() & 0x02000000);
slouken@745
   353
	}
slouken@745
   354
	return 0;
slouken@745
   355
}
slouken@739
   356
slouken@1426
   357
static __inline__ int CPU_haveSSE2(void)
slouken@785
   358
{
slouken@785
   359
	if ( CPU_haveCPUID() ) {
slouken@785
   360
		return (CPU_getCPUIDFeatures() & 0x04000000);
slouken@785
   361
	}
slouken@785
   362
	return 0;
slouken@785
   363
}
slouken@785
   364
slouken@1426
   365
static __inline__ int CPU_haveAltiVec(void)
slouken@778
   366
{
slouken@796
   367
	volatile int altivec = 0;
slouken@6364
   368
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
slouken@6364
   369
# ifdef __OpenBSD__
slouken@6364
   370
	int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
slouken@6364
   371
# else
slouken@6364
   372
	int selectors[2] = { CTL_HW, HW_VECTORUNIT };
slouken@6364
   373
# endif
slouken@778
   374
	int hasVectorUnit = 0; 
slouken@778
   375
	size_t length = sizeof(hasVectorUnit); 
slouken@778
   376
	int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); 
slouken@778
   377
	if( 0 == error )
slouken@793
   378
		altivec = (hasVectorUnit != 0); 
slouken@1361
   379
#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
slouken@793
   380
	void (*handler)(int sig);
slouken@793
   381
	handler = signal(SIGILL, illegal_instruction);
slouken@793
   382
	if ( setjmp(jmpbuf) == 0 ) {
slouken@793
   383
		asm volatile ("mtspr 256, %0\n\t"
slouken@793
   384
			      "vand %%v0, %%v0, %%v0"
slouken@793
   385
			      :
slouken@793
   386
			      : "r" (-1));
slouken@793
   387
		altivec = 1;
slouken@793
   388
	}
slouken@793
   389
	signal(SIGILL, handler);
slouken@778
   390
#endif
slouken@793
   391
	return altivec; 
slouken@778
   392
}
slouken@778
   393
bavison@13212
   394
#ifdef __linux__
bavison@13212
   395
bavison@13212
   396
#include <unistd.h>
bavison@13212
   397
#include <sys/types.h>
bavison@13212
   398
#include <sys/stat.h>
bavison@13212
   399
#include <fcntl.h>
bavison@13212
   400
#include <elf.h>
bavison@13212
   401
bavison@13212
   402
static __inline__ int CPU_haveARMSIMD(void)
bavison@13212
   403
{
bavison@13212
   404
	int arm_simd = 0;
bavison@13212
   405
	int fd;
bavison@13212
   406
bavison@13212
   407
	fd = open("/proc/self/auxv", O_RDONLY);
bavison@13212
   408
	if (fd >= 0)
bavison@13212
   409
	{
bavison@13212
   410
		Elf32_auxv_t aux;
bavison@13212
   411
		while (read(fd, &aux, sizeof aux) == sizeof aux)
bavison@13212
   412
		{
bavison@13212
   413
			if (aux.a_type == AT_PLATFORM)
bavison@13212
   414
			{
bavison@13212
   415
				const char *plat = (const char *) aux.a_un.a_val;
bavison@13212
   416
				arm_simd = strncmp(plat, "v6l", 3) == 0 ||
bavison@13212
   417
				           strncmp(plat, "v7l", 3) == 0;
bavison@13212
   418
			}
bavison@13212
   419
		}
bavison@13212
   420
		close(fd);
bavison@13212
   421
	}
bavison@13212
   422
	return arm_simd;
bavison@13212
   423
}
bavison@13212
   424
bavison@13212
   425
#else
bavison@13212
   426
bavison@13212
   427
static __inline__ int CPU_haveARMSIMD(void)
bavison@13212
   428
{
bavison@13212
   429
	return 0;
bavison@13212
   430
}
bavison@13212
   431
bavison@13212
   432
#endif
bavison@13212
   433
slouken@739
   434
static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
slouken@739
   435
slouken@1426
   436
static Uint32 SDL_GetCPUFeatures(void)
slouken@739
   437
{
slouken@739
   438
	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
slouken@739
   439
		SDL_CPUFeatures = 0;
slouken@745
   440
		if ( CPU_haveRDTSC() ) {
slouken@745
   441
			SDL_CPUFeatures |= CPU_HAS_RDTSC;
slouken@745
   442
		}
slouken@739
   443
		if ( CPU_haveMMX() ) {
slouken@739
   444
			SDL_CPUFeatures |= CPU_HAS_MMX;
slouken@739
   445
		}
slouken@786
   446
		if ( CPU_haveMMXExt() ) {
slouken@786
   447
			SDL_CPUFeatures |= CPU_HAS_MMXEXT;
slouken@786
   448
		}
slouken@739
   449
		if ( CPU_have3DNow() ) {
slouken@739
   450
			SDL_CPUFeatures |= CPU_HAS_3DNOW;
slouken@739
   451
		}
slouken@786
   452
		if ( CPU_have3DNowExt() ) {
slouken@786
   453
			SDL_CPUFeatures |= CPU_HAS_3DNOWEXT;
slouken@786
   454
		}
slouken@739
   455
		if ( CPU_haveSSE() ) {
slouken@739
   456
			SDL_CPUFeatures |= CPU_HAS_SSE;
slouken@739
   457
		}
slouken@786
   458
		if ( CPU_haveSSE2() ) {
slouken@786
   459
			SDL_CPUFeatures |= CPU_HAS_SSE2;
slouken@786
   460
		}
slouken@778
   461
		if ( CPU_haveAltiVec() ) {
slouken@778
   462
			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
slouken@778
   463
		}
bavison@13212
   464
		if ( CPU_haveARMSIMD() ) {
bavison@13212
   465
			SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
bavison@13212
   466
		}
slouken@739
   467
	}
slouken@739
   468
	return SDL_CPUFeatures;
slouken@739
   469
}
slouken@739
   470
slouken@1426
   471
SDL_bool SDL_HasRDTSC(void)
slouken@745
   472
{
slouken@745
   473
	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
slouken@745
   474
		return SDL_TRUE;
slouken@745
   475
	}
slouken@745
   476
	return SDL_FALSE;
slouken@745
   477
}
slouken@745
   478
slouken@1426
   479
SDL_bool SDL_HasMMX(void)
slouken@739
   480
{
slouken@739
   481
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
slouken@739
   482
		return SDL_TRUE;
slouken@739
   483
	}
slouken@739
   484
	return SDL_FALSE;
slouken@739
   485
}
slouken@739
   486
slouken@1426
   487
SDL_bool SDL_HasMMXExt(void)
slouken@804
   488
{
slouken@804
   489
	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
slouken@804
   490
		return SDL_TRUE;
slouken@804
   491
	}
slouken@804
   492
	return SDL_FALSE;
slouken@804
   493
}
slouken@804
   494
slouken@1426
   495
SDL_bool SDL_Has3DNow(void)
slouken@739
   496
{
slouken@739
   497
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
slouken@739
   498
		return SDL_TRUE;
slouken@739
   499
	}
slouken@739
   500
	return SDL_FALSE;
slouken@739
   501
}
slouken@739
   502
slouken@1426
   503
SDL_bool SDL_Has3DNowExt(void)
slouken@804
   504
{
slouken@804
   505
	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
slouken@804
   506
		return SDL_TRUE;
slouken@804
   507
	}
slouken@804
   508
	return SDL_FALSE;
slouken@804
   509
}
slouken@804
   510
slouken@1426
   511
SDL_bool SDL_HasSSE(void)
slouken@739
   512
{
slouken@739
   513
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
slouken@739
   514
		return SDL_TRUE;
slouken@739
   515
	}
slouken@739
   516
	return SDL_FALSE;
slouken@739
   517
}
slouken@739
   518
slouken@1426
   519
SDL_bool SDL_HasSSE2(void)
slouken@804
   520
{
slouken@804
   521
	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
slouken@804
   522
		return SDL_TRUE;
slouken@804
   523
	}
slouken@804
   524
	return SDL_FALSE;
slouken@804
   525
}
slouken@804
   526
slouken@1426
   527
SDL_bool SDL_HasAltiVec(void)
slouken@778
   528
{
slouken@778
   529
	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
slouken@778
   530
		return SDL_TRUE;
slouken@778
   531
	}
slouken@778
   532
	return SDL_FALSE;
slouken@778
   533
}
slouken@778
   534
bavison@13212
   535
SDL_bool SDL_HasARMSIMD(void)
bavison@13212
   536
{
bavison@13212
   537
	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_SIMD ) {
bavison@13212
   538
		return SDL_TRUE;
bavison@13212
   539
	}
bavison@13212
   540
	return SDL_FALSE;
bavison@13212
   541
}
bavison@13212
   542
slouken@739
   543
#ifdef TEST_MAIN
slouken@739
   544
slouken@739
   545
#include <stdio.h>
slouken@739
   546
slouken@739
   547
int main()
slouken@739
   548
{
slouken@778
   549
	printf("RDTSC: %d\n", SDL_HasRDTSC());
slouken@739
   550
	printf("MMX: %d\n", SDL_HasMMX());
slouken@785
   551
	printf("MMXExt: %d\n", SDL_HasMMXExt());
slouken@739
   552
	printf("3DNow: %d\n", SDL_Has3DNow());
slouken@785
   553
	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
slouken@739
   554
	printf("SSE: %d\n", SDL_HasSSE());
slouken@785
   555
	printf("SSE2: %d\n", SDL_HasSSE2());
slouken@778
   556
	printf("AltiVec: %d\n", SDL_HasAltiVec());
bavison@13212
   557
	printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
slouken@745
   558
	return 0;
slouken@739
   559
}
slouken@739
   560
slouken@739
   561
#endif /* TEST_MAIN */