test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 11627 97bc026b46de
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
slouken@5535
     1
/*
slouken@10737
     2
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@1421
    12
slouken@1421
    13
#include <stdio.h>
slouken@1421
    14
slouken@1421
    15
#include "SDL.h"
slouken@1421
    16
slouken@1421
    17
/*
slouken@1421
    18
 * Watcom C flags these as Warning 201: "Unreachable code" if you just
slouken@1421
    19
 *  compare them directly, so we push it through a function to keep the
slouken@1421
    20
 *  compiler quiet.  --ryan.
slouken@1421
    21
 */
slouken@1895
    22
static int
slouken@1895
    23
badsize(size_t sizeoftype, size_t hardcodetype)
slouken@1421
    24
{
slouken@1421
    25
    return sizeoftype != hardcodetype;
slouken@1421
    26
}
slouken@1421
    27
slouken@1895
    28
int
slouken@1895
    29
TestTypes(SDL_bool verbose)
slouken@1421
    30
{
slouken@1895
    31
    int error = 0;
slouken@1421
    32
slouken@11627
    33
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
slouken@11627
    34
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
slouken@11627
    35
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
slouken@11627
    36
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
slouken@11627
    37
slouken@11627
    38
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
slouken@11627
    39
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
slouken@11627
    40
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
slouken@11627
    41
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
slouken@11627
    42
slouken@11627
    43
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
slouken@11627
    44
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
slouken@11627
    45
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
slouken@11627
    46
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
slouken@11627
    47
slouken@11627
    48
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
slouken@11627
    49
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
slouken@11627
    50
	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
slouken@11627
    51
	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
slouken@11627
    52
slouken@1895
    53
    if (badsize(sizeof(Uint8), 1)) {
slouken@1895
    54
        if (verbose)
aschiffler@7639
    55
            SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
slouken@3687
    56
                   (unsigned int)sizeof(Uint8));
slouken@1895
    57
        ++error;
slouken@1895
    58
    }
slouken@1895
    59
    if (badsize(sizeof(Uint16), 2)) {
slouken@1895
    60
        if (verbose)
aschiffler@7639
    61
            SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
slouken@3687
    62
                   (unsigned int)sizeof(Uint16));
slouken@1895
    63
        ++error;
slouken@1895
    64
    }
slouken@1895
    65
    if (badsize(sizeof(Uint32), 4)) {
slouken@1895
    66
        if (verbose)
aschiffler@7639
    67
            SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
slouken@3687
    68
                   (unsigned int)sizeof(Uint32));
slouken@1895
    69
        ++error;
slouken@1895
    70
    }
slouken@1895
    71
    if (badsize(sizeof(Uint64), 8)) {
slouken@1895
    72
        if (verbose)
aschiffler@7639
    73
            SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
slouken@3687
    74
                   (unsigned int)sizeof(Uint64));
slouken@1895
    75
        ++error;
slouken@1895
    76
    }
slouken@1895
    77
    if (verbose && !error)
aschiffler@7639
    78
        SDL_Log("All data types are the expected size.\n");
slouken@1421
    79
slouken@1895
    80
    return (error ? 1 : 0);
slouken@1421
    81
}
slouken@1421
    82
slouken@1895
    83
int
slouken@1895
    84
TestEndian(SDL_bool verbose)
slouken@1421
    85
{
slouken@1895
    86
    int error = 0;
slouken@1895
    87
    Uint16 value = 0x1234;
slouken@1895
    88
    int real_byteorder;
slouken@1895
    89
    Uint16 value16 = 0xCDAB;
slouken@1895
    90
    Uint16 swapped16 = 0xABCD;
slouken@1895
    91
    Uint32 value32 = 0xEFBEADDE;
slouken@1895
    92
    Uint32 swapped32 = 0xDEADBEEF;
slouken@1895
    93
    Uint64 value64, swapped64;
slouken@5512
    94
slouken@1895
    95
    value64 = 0xEFBEADDE;
slouken@1895
    96
    value64 <<= 32;
slouken@1895
    97
    value64 |= 0xCDAB3412;
slouken@1895
    98
    swapped64 = 0x1234ABCD;
slouken@1895
    99
    swapped64 <<= 32;
slouken@1895
   100
    swapped64 |= 0xDEADBEEF;
slouken@1421
   101
slouken@1895
   102
    if (verbose) {
aschiffler@7639
   103
        SDL_Log("Detected a %s endian machine.\n",
slouken@1895
   104
               (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
   105
    }
slouken@1895
   106
    if ((*((char *) &value) >> 4) == 0x1) {
slouken@1895
   107
        real_byteorder = SDL_BIG_ENDIAN;
slouken@1895
   108
    } else {
slouken@1895
   109
        real_byteorder = SDL_LIL_ENDIAN;
slouken@1895
   110
    }
slouken@1895
   111
    if (real_byteorder != SDL_BYTEORDER) {
slouken@1895
   112
        if (verbose) {
aschiffler@7639
   113
            SDL_Log("Actually a %s endian machine!\n",
slouken@1895
   114
                   (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
   115
        }
slouken@1895
   116
        ++error;
slouken@1895
   117
    }
slouken@1895
   118
    if (verbose) {
aschiffler@7639
   119
        SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
slouken@1895
   120
               SDL_Swap16(value16));
slouken@1895
   121
    }
slouken@1895
   122
    if (SDL_Swap16(value16) != swapped16) {
slouken@1895
   123
        if (verbose) {
aschiffler@7639
   124
            SDL_Log("16 bit value swapped incorrectly!\n");
slouken@1895
   125
        }
slouken@1895
   126
        ++error;
slouken@1895
   127
    }
slouken@1895
   128
    if (verbose) {
aschiffler@7639
   129
        SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
slouken@1895
   130
               SDL_Swap32(value32));
slouken@1895
   131
    }
slouken@1895
   132
    if (SDL_Swap32(value32) != swapped32) {
slouken@1895
   133
        if (verbose) {
aschiffler@7639
   134
            SDL_Log("32 bit value swapped incorrectly!\n");
slouken@1895
   135
        }
slouken@1895
   136
        ++error;
slouken@1895
   137
    }
slouken@1895
   138
    if (verbose) {
urkle@9260
   139
        SDL_Log("Value 64 = 0x%"SDL_PRIX64", swapped = 0x%"SDL_PRIX64"\n", value64,
slouken@1895
   140
               SDL_Swap64(value64));
slouken@1895
   141
    }
slouken@1895
   142
    if (SDL_Swap64(value64) != swapped64) {
slouken@1895
   143
        if (verbose) {
aschiffler@7639
   144
            SDL_Log("64 bit value swapped incorrectly!\n");
slouken@1895
   145
        }
slouken@1895
   146
        ++error;
slouken@1895
   147
    }
slouken@1895
   148
    return (error ? 1 : 0);
slouken@1421
   149
}
slouken@1421
   150
slouken@10587
   151
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   152
{
slouken@10587
   153
    (*(long long *)result) = ((*(long long *)a) * (*(long long *)b));
slouken@10587
   154
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   155
}
slouken@10587
   156
slouken@10587
   157
static int TST_alldiv (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   158
{
slouken@10587
   159
    (*(long long *)result) = ((*(long long *)a) / (*(long long *)b));
slouken@10587
   160
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   161
}
slouken@10587
   162
slouken@10587
   163
static int TST_allrem (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   164
{
slouken@10587
   165
    (*(long long *)result) = ((*(long long *)a) % (*(long long *)b));
slouken@10587
   166
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   167
}
slouken@10587
   168
slouken@10587
   169
static int TST_ualldiv (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   170
{
slouken@10587
   171
    (*(unsigned long long *)result) = ((*(unsigned long long *)a) / (*(unsigned long long *)b));
slouken@10587
   172
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   173
}
slouken@10587
   174
slouken@10587
   175
static int TST_uallrem (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   176
{
slouken@10587
   177
    (*(unsigned long long *)result) = ((*(unsigned long long *)a) % (*(unsigned long long *)b));
slouken@10587
   178
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   179
}
slouken@10587
   180
slouken@10587
   181
static int TST_allshl (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   182
{
slouken@10587
   183
    (*(long long *)result) = (*(long long *)a) << arg;
slouken@10587
   184
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   185
}
slouken@10587
   186
slouken@10587
   187
static int TST_aullshl (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   188
{
slouken@10587
   189
    (*(unsigned long long *)result) = (*(unsigned long long *)a) << arg;
slouken@10587
   190
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   191
}
slouken@10587
   192
slouken@10587
   193
static int TST_allshr (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   194
{
slouken@10587
   195
    (*(long long *)result) = (*(long long *)a) >> arg;
slouken@10587
   196
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   197
}
slouken@10587
   198
slouken@10587
   199
static int TST_aullshr (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   200
{
slouken@10587
   201
    (*(unsigned long long *)result) = (*(unsigned long long *)a) >> arg;
slouken@10587
   202
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   203
}
slouken@10587
   204
slouken@10587
   205
slouken@10587
   206
typedef int (*LL_Intrinsic)(void *a, void *b, int arg, void *result, void *expected);
slouken@10587
   207
slouken@10587
   208
typedef struct {
slouken@10587
   209
    const char *operation;
slouken@10587
   210
    LL_Intrinsic routine;
slouken@10587
   211
    unsigned long long a, b;
slouken@10587
   212
    int arg;
slouken@10587
   213
    unsigned long long expected_result;
slouken@10587
   214
} LL_Test;
slouken@10587
   215
slouken@10587
   216
static LL_Test LL_Tests[] = 
slouken@10587
   217
{
slouken@10588
   218
    /* UNDEFINED {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   219
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   220
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFF00000000ll},
slouken@10587
   221
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFE00000000ll},
slouken@10587
   222
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   223
slouken@10587
   224
    {"_allshr",   &TST_allshr,   0xAAAAAAAA55555555ll,                  0ll, 63, 0xFFFFFFFFFFFFFFFFll},
slouken@10588
   225
    /* UNDEFINED {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0xFFFFFFFFFFFFFFFFll}, */
slouken@10587
   226
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   227
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   228
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   229
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10588
   230
    /* UNDEFINED {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   231
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll,  1, 0x2FAFAFAFAFAFAFAFll},
slouken@10587
   232
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 32, 0x000000005F5F5F5Fll},
slouken@10587
   233
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 33, 0x000000002FAFAFAFll},
slouken@10587
   234
slouken@10588
   235
    /* UNDEFINED {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   236
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   237
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFF00000000ll},
slouken@10587
   238
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFE00000000ll},
slouken@10587
   239
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   240
slouken@10588
   241
    /* UNDEFINED {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   242
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0x7FFFFFFFFFFFFFFFll},
slouken@10587
   243
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0x00000000FFFFFFFFll},
slouken@10587
   244
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0x000000007FFFFFFFll},
slouken@10587
   245
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   246
slouken@10587
   247
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll,  0, 0x0000000000000000ll},
slouken@10587
   248
    {"_allmul",   &TST_allmul,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   249
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   250
    {"_allmul",   &TST_allmul,   0x0000000000000001ll, 0x000000000FFFFFFFll,  0, 0x000000000FFFFFFFll},
slouken@10587
   251
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFF0ll},
slouken@10587
   252
    {"_allmul",   &TST_allmul,   0x0000000000000010ll, 0x000000000FFFFFFFll,  0, 0x00000000FFFFFFF0ll},
slouken@10587
   253
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000100ll,  0, 0x0000000FFFFFFF00ll},
slouken@10587
   254
    {"_allmul",   &TST_allmul,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000FFFFFFF00ll},
slouken@10587
   255
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000010000000ll,  0, 0x00FFFFFFF0000000ll},
slouken@10587
   256
    {"_allmul",   &TST_allmul,   0x0000000010000000ll, 0x000000000FFFFFFFll,  0, 0x00FFFFFFF0000000ll},
slouken@10587
   257
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000080000000ll,  0, 0x07FFFFFF80000000ll},
slouken@10587
   258
    {"_allmul",   &TST_allmul,   0x0000000080000000ll, 0x000000000FFFFFFFll,  0, 0x07FFFFFF80000000ll},
slouken@10587
   259
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0xFFFFFFFF00000000ll},
slouken@10587
   260
    {"_allmul",   &TST_allmul,   0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFF00000000ll},
slouken@10587
   261
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   262
    {"_allmul",   &TST_allmul,   0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   263
    {"_allmul",   &TST_allmul,   0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll,  0, 0xFFFFFFFE00000001ll},
slouken@10587
   264
slouken@10587
   265
    {"_alldiv",   &TST_alldiv,   0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   266
    {"_alldiv",   &TST_alldiv,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   267
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   268
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   269
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   270
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000001ll},
slouken@10587
   271
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   272
    {"_alldiv",   &TST_alldiv,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   273
    {"_alldiv",   &TST_alldiv,   0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFFFll},
slouken@10587
   274
    {"_alldiv",   &TST_alldiv,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   275
    {"_alldiv",   &TST_alldiv,   0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   276
    {"_alldiv",   &TST_alldiv,   0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   277
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   278
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000080000008ll},
slouken@10587
   279
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xC000000080000008ll},
slouken@10587
   280
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000000000007FFFll},
slouken@10587
   281
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000001ll},
slouken@10587
   282
slouken@10587
   283
    {"_allrem",   &TST_allrem,   0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   284
    {"_allrem",   &TST_allrem,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   285
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   286
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   287
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   288
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   289
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   290
    {"_allrem",   &TST_allrem,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   291
    {"_allrem",   &TST_allrem,   0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x000000000000000Fll},
slouken@10587
   292
    {"_allrem",   &TST_allrem,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000100ll},
slouken@10587
   293
    {"_allrem",   &TST_allrem,   0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x0000000000000000ll},
slouken@10587
   294
    {"_allrem",   &TST_allrem,   0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   295
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   296
    {"_allrem",   &TST_allrem,   0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   297
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   298
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000FFFF0000FFEEll},
slouken@10587
   299
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000000ll},
slouken@10587
   300
slouken@10587
   301
slouken@10587
   302
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   303
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   304
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   305
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   306
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   307
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000001ll},
slouken@10587
   308
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   309
    {"_ualldiv",  &TST_ualldiv,  0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   310
    {"_ualldiv",  &TST_ualldiv,  0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFFFll},
slouken@10587
   311
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   312
    {"_ualldiv",  &TST_ualldiv,  0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   313
    {"_ualldiv",  &TST_ualldiv,  0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   314
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x00000001FFFFFFFFll},
slouken@10587
   315
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   316
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   317
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000000000007FFFll},
slouken@10587
   318
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000001ll},
slouken@10587
   319
slouken@10587
   320
    {"_uallrem",  &TST_uallrem,  0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   321
    {"_uallrem",  &TST_uallrem,  0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   322
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   323
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   324
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   325
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   326
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   327
    {"_uallrem",  &TST_uallrem,  0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   328
    {"_uallrem",  &TST_uallrem,  0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x000000000000000Fll},
slouken@10587
   329
    {"_uallrem",  &TST_uallrem,  0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000100ll},
slouken@10587
   330
    {"_uallrem",  &TST_uallrem,  0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x0000000000000000ll},
slouken@10587
   331
    {"_uallrem",  &TST_uallrem,  0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   332
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x000000007FFFFFFEll},
slouken@10587
   333
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   334
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x7FFFFFFEFFFFFFF0ll},
slouken@10587
   335
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000FFFF0000FFEEll},
slouken@10587
   336
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000000ll},
slouken@10587
   337
slouken@10587
   338
    {NULL}
slouken@10587
   339
};
slouken@10587
   340
slouken@10587
   341
int
slouken@10587
   342
Test64Bit (SDL_bool verbose)
slouken@10587
   343
{
slouken@10587
   344
    LL_Test *t;
slouken@10587
   345
    int failed = 0;
slouken@10587
   346
slouken@10587
   347
    for (t = LL_Tests; t->routine != NULL; t++) {
slouken@10587
   348
        unsigned long long result = 0;
slouken@10587
   349
        unsigned int *al = (unsigned int *)&t->a;
slouken@10587
   350
        unsigned int *bl = (unsigned int *)&t->b;
slouken@10587
   351
        unsigned int *el = (unsigned int *)&t->expected_result;
slouken@10587
   352
        unsigned int *rl = (unsigned int *)&result;
slouken@10587
   353
slouken@10587
   354
        if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) {
slouken@10587
   355
            if (verbose)
slouken@10587
   356
                SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n",
slouken@10587
   357
                        t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]);
slouken@10587
   358
            ++failed;
slouken@10587
   359
        }
slouken@10587
   360
    }
slouken@10587
   361
    if (verbose && (failed == 0))
slouken@10587
   362
        SDL_Log("All 64bit instrinsic tests passed\n");
slouken@10587
   363
    return (failed ? 1 : 0);
slouken@10587
   364
}
slouken@1421
   365
slouken@1895
   366
int
slouken@1895
   367
TestCPUInfo(SDL_bool verbose)
slouken@1421
   368
{
slouken@1895
   369
    if (verbose) {
aschiffler@7639
   370
        SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
aschiffler@7639
   371
        SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
aschiffler@7639
   372
        SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
aschiffler@7639
   373
        SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
aschiffler@7639
   374
        SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
aschiffler@7639
   375
        SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
aschiffler@7639
   376
        SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
aschiffler@7639
   377
        SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
aschiffler@7639
   378
        SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
aschiffler@7639
   379
        SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
aschiffler@7639
   380
        SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
slouken@8148
   381
        SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
philipp@10564
   382
        SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
icculus@10620
   383
        SDL_Log("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
slouken@7823
   384
        SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
slouken@1895
   385
    }
slouken@1895
   386
    return (0);
slouken@1421
   387
}
slouken@1421
   388
slouken@1895
   389
int
slouken@3663
   390
TestAssertions(SDL_bool verbose)
slouken@3663
   391
{
slouken@3663
   392
    SDL_assert(1);
slouken@3663
   393
    SDL_assert_release(1);
slouken@3663
   394
    SDL_assert_paranoid(1);
slouken@3663
   395
    SDL_assert(0 || 1);
slouken@3663
   396
    SDL_assert_release(0 || 1);
slouken@3663
   397
    SDL_assert_paranoid(0 || 1);
slouken@3663
   398
slouken@3663
   399
#if 0   /* enable this to test assertion failures. */
slouken@3663
   400
    SDL_assert_release(1 == 2);
slouken@3663
   401
    SDL_assert_release(5 < 4);
slouken@3663
   402
    SDL_assert_release(0 && "This is a test");
slouken@3663
   403
#endif
slouken@3663
   404
slouken@5542
   405
    {
philipp@9383
   406
        const SDL_AssertData *item = SDL_GetAssertionReport();
slouken@5542
   407
        while (item) {
aschiffler@7639
   408
            SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
slouken@5542
   409
                item->condition, item->function, item->filename,
slouken@5542
   410
                item->linenum, item->trigger_count,
slouken@5542
   411
                item->always_ignore ? "yes" : "no");
slouken@5542
   412
            item = item->next;
slouken@5542
   413
        }
slouken@5542
   414
    }
slouken@3663
   415
    return (0);
slouken@3663
   416
}
slouken@3663
   417
slouken@3663
   418
int
slouken@1895
   419
main(int argc, char *argv[])
slouken@1421
   420
{
slouken@1895
   421
    SDL_bool verbose = SDL_TRUE;
slouken@1895
   422
    int status = 0;
slouken@1421
   423
aschiffler@7639
   424
    /* Enable standard application logging */
aschiffler@7639
   425
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
   426
slouken@1895
   427
    if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
slouken@1895
   428
        verbose = SDL_FALSE;
slouken@1895
   429
    }
slouken@1895
   430
    if (verbose) {
aschiffler@7639
   431
        SDL_Log("This system is running %s\n", SDL_GetPlatform());
slouken@1895
   432
    }
slouken@1421
   433
slouken@1895
   434
    status += TestTypes(verbose);
slouken@1895
   435
    status += TestEndian(verbose);
slouken@10587
   436
    status += Test64Bit(verbose);
slouken@1895
   437
    status += TestCPUInfo(verbose);
slouken@3663
   438
    status += TestAssertions(verbose);
slouken@3663
   439
slouken@1895
   440
    return status;
slouken@1421
   441
}