test/testplatform.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 06 Nov 2016 14:13:28 -0800
changeset 10588 cc83da0cb986
parent 10587 513f0e80a7dd
child 10620 c37e02dd1a9b
permissions -rw-r--r--
Shifting a value by more than its bits isn't defined and has varying behavior depending on compiler and platform
slouken@5535
     1
/*
slouken@9998
     2
  Copyright (C) 1997-2016 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@1895
    33
    if (badsize(sizeof(Uint8), 1)) {
slouken@1895
    34
        if (verbose)
aschiffler@7639
    35
            SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
slouken@3687
    36
                   (unsigned int)sizeof(Uint8));
slouken@1895
    37
        ++error;
slouken@1895
    38
    }
slouken@1895
    39
    if (badsize(sizeof(Uint16), 2)) {
slouken@1895
    40
        if (verbose)
aschiffler@7639
    41
            SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
slouken@3687
    42
                   (unsigned int)sizeof(Uint16));
slouken@1895
    43
        ++error;
slouken@1895
    44
    }
slouken@1895
    45
    if (badsize(sizeof(Uint32), 4)) {
slouken@1895
    46
        if (verbose)
aschiffler@7639
    47
            SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
slouken@3687
    48
                   (unsigned int)sizeof(Uint32));
slouken@1895
    49
        ++error;
slouken@1895
    50
    }
slouken@1895
    51
    if (badsize(sizeof(Uint64), 8)) {
slouken@1895
    52
        if (verbose)
aschiffler@7639
    53
            SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
slouken@3687
    54
                   (unsigned int)sizeof(Uint64));
slouken@1895
    55
        ++error;
slouken@1895
    56
    }
slouken@1895
    57
    if (verbose && !error)
aschiffler@7639
    58
        SDL_Log("All data types are the expected size.\n");
slouken@1421
    59
slouken@1895
    60
    return (error ? 1 : 0);
slouken@1421
    61
}
slouken@1421
    62
slouken@1895
    63
int
slouken@1895
    64
TestEndian(SDL_bool verbose)
slouken@1421
    65
{
slouken@1895
    66
    int error = 0;
slouken@1895
    67
    Uint16 value = 0x1234;
slouken@1895
    68
    int real_byteorder;
slouken@1895
    69
    Uint16 value16 = 0xCDAB;
slouken@1895
    70
    Uint16 swapped16 = 0xABCD;
slouken@1895
    71
    Uint32 value32 = 0xEFBEADDE;
slouken@1895
    72
    Uint32 swapped32 = 0xDEADBEEF;
slouken@1895
    73
    Uint64 value64, swapped64;
slouken@5512
    74
slouken@1895
    75
    value64 = 0xEFBEADDE;
slouken@1895
    76
    value64 <<= 32;
slouken@1895
    77
    value64 |= 0xCDAB3412;
slouken@1895
    78
    swapped64 = 0x1234ABCD;
slouken@1895
    79
    swapped64 <<= 32;
slouken@1895
    80
    swapped64 |= 0xDEADBEEF;
slouken@1421
    81
slouken@1895
    82
    if (verbose) {
aschiffler@7639
    83
        SDL_Log("Detected a %s endian machine.\n",
slouken@1895
    84
               (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    85
    }
slouken@1895
    86
    if ((*((char *) &value) >> 4) == 0x1) {
slouken@1895
    87
        real_byteorder = SDL_BIG_ENDIAN;
slouken@1895
    88
    } else {
slouken@1895
    89
        real_byteorder = SDL_LIL_ENDIAN;
slouken@1895
    90
    }
slouken@1895
    91
    if (real_byteorder != SDL_BYTEORDER) {
slouken@1895
    92
        if (verbose) {
aschiffler@7639
    93
            SDL_Log("Actually a %s endian machine!\n",
slouken@1895
    94
                   (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
slouken@1895
    95
        }
slouken@1895
    96
        ++error;
slouken@1895
    97
    }
slouken@1895
    98
    if (verbose) {
aschiffler@7639
    99
        SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
slouken@1895
   100
               SDL_Swap16(value16));
slouken@1895
   101
    }
slouken@1895
   102
    if (SDL_Swap16(value16) != swapped16) {
slouken@1895
   103
        if (verbose) {
aschiffler@7639
   104
            SDL_Log("16 bit value swapped incorrectly!\n");
slouken@1895
   105
        }
slouken@1895
   106
        ++error;
slouken@1895
   107
    }
slouken@1895
   108
    if (verbose) {
aschiffler@7639
   109
        SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
slouken@1895
   110
               SDL_Swap32(value32));
slouken@1895
   111
    }
slouken@1895
   112
    if (SDL_Swap32(value32) != swapped32) {
slouken@1895
   113
        if (verbose) {
aschiffler@7639
   114
            SDL_Log("32 bit value swapped incorrectly!\n");
slouken@1895
   115
        }
slouken@1895
   116
        ++error;
slouken@1895
   117
    }
slouken@1895
   118
    if (verbose) {
urkle@9260
   119
        SDL_Log("Value 64 = 0x%"SDL_PRIX64", swapped = 0x%"SDL_PRIX64"\n", value64,
slouken@1895
   120
               SDL_Swap64(value64));
slouken@1895
   121
    }
slouken@1895
   122
    if (SDL_Swap64(value64) != swapped64) {
slouken@1895
   123
        if (verbose) {
aschiffler@7639
   124
            SDL_Log("64 bit value swapped incorrectly!\n");
slouken@1895
   125
        }
slouken@1895
   126
        ++error;
slouken@1895
   127
    }
slouken@1895
   128
    return (error ? 1 : 0);
slouken@1421
   129
}
slouken@1421
   130
slouken@10587
   131
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   132
{
slouken@10587
   133
    (*(long long *)result) = ((*(long long *)a) * (*(long long *)b));
slouken@10587
   134
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   135
}
slouken@10587
   136
slouken@10587
   137
static int TST_alldiv (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   138
{
slouken@10587
   139
    (*(long long *)result) = ((*(long long *)a) / (*(long long *)b));
slouken@10587
   140
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   141
}
slouken@10587
   142
slouken@10587
   143
static int TST_allrem (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   144
{
slouken@10587
   145
    (*(long long *)result) = ((*(long long *)a) % (*(long long *)b));
slouken@10587
   146
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   147
}
slouken@10587
   148
slouken@10587
   149
static int TST_ualldiv (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   150
{
slouken@10587
   151
    (*(unsigned long long *)result) = ((*(unsigned long long *)a) / (*(unsigned long long *)b));
slouken@10587
   152
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   153
}
slouken@10587
   154
slouken@10587
   155
static int TST_uallrem (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   156
{
slouken@10587
   157
    (*(unsigned long long *)result) = ((*(unsigned long long *)a) % (*(unsigned long long *)b));
slouken@10587
   158
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   159
}
slouken@10587
   160
slouken@10587
   161
static int TST_allshl (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   162
{
slouken@10587
   163
    (*(long long *)result) = (*(long long *)a) << arg;
slouken@10587
   164
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   165
}
slouken@10587
   166
slouken@10587
   167
static int TST_aullshl (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   168
{
slouken@10587
   169
    (*(unsigned long long *)result) = (*(unsigned long long *)a) << arg;
slouken@10587
   170
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   171
}
slouken@10587
   172
slouken@10587
   173
static int TST_allshr (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   174
{
slouken@10587
   175
    (*(long long *)result) = (*(long long *)a) >> arg;
slouken@10587
   176
    return (*(long long *)result) == (*(long long *)expected);
slouken@10587
   177
}
slouken@10587
   178
slouken@10587
   179
static int TST_aullshr (void *a, void *b, int arg, void *result, void *expected)
slouken@10587
   180
{
slouken@10587
   181
    (*(unsigned long long *)result) = (*(unsigned long long *)a) >> arg;
slouken@10587
   182
    return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
slouken@10587
   183
}
slouken@10587
   184
slouken@10587
   185
slouken@10587
   186
typedef int (*LL_Intrinsic)(void *a, void *b, int arg, void *result, void *expected);
slouken@10587
   187
slouken@10587
   188
typedef struct {
slouken@10587
   189
    const char *operation;
slouken@10587
   190
    LL_Intrinsic routine;
slouken@10587
   191
    unsigned long long a, b;
slouken@10587
   192
    int arg;
slouken@10587
   193
    unsigned long long expected_result;
slouken@10587
   194
} LL_Test;
slouken@10587
   195
slouken@10587
   196
static LL_Test LL_Tests[] = 
slouken@10587
   197
{
slouken@10588
   198
    /* UNDEFINED {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   199
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   200
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFF00000000ll},
slouken@10587
   201
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFE00000000ll},
slouken@10587
   202
    {"_allshl",   &TST_allshl,   0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   203
slouken@10587
   204
    {"_allshr",   &TST_allshr,   0xAAAAAAAA55555555ll,                  0ll, 63, 0xFFFFFFFFFFFFFFFFll},
slouken@10588
   205
    /* UNDEFINED {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0xFFFFFFFFFFFFFFFFll}, */
slouken@10587
   206
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   207
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   208
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   209
    {"_allshr",   &TST_allshr,   0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10588
   210
    /* UNDEFINED {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   211
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll,  1, 0x2FAFAFAFAFAFAFAFll},
slouken@10587
   212
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 32, 0x000000005F5F5F5Fll},
slouken@10587
   213
    {"_allshr",   &TST_allshr,   0x5F5F5F5F5F5F5F5Fll,                  0ll, 33, 0x000000002FAFAFAFll},
slouken@10587
   214
slouken@10588
   215
    /* UNDEFINED {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   216
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   217
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0xFFFFFFFF00000000ll},
slouken@10587
   218
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0xFFFFFFFE00000000ll},
slouken@10587
   219
    {"_aullshl",  &TST_aullshl,  0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   220
slouken@10588
   221
    /* UNDEFINED {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 65, 0x0000000000000000ll}, */
slouken@10587
   222
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll,  1, 0x7FFFFFFFFFFFFFFFll},
slouken@10587
   223
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 32, 0x00000000FFFFFFFFll},
slouken@10587
   224
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll, 33, 0x000000007FFFFFFFll},
slouken@10587
   225
    {"_aullshr",  &TST_aullshr,  0xFFFFFFFFFFFFFFFFll,                  0ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   226
slouken@10587
   227
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll,  0, 0x0000000000000000ll},
slouken@10587
   228
    {"_allmul",   &TST_allmul,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   229
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   230
    {"_allmul",   &TST_allmul,   0x0000000000000001ll, 0x000000000FFFFFFFll,  0, 0x000000000FFFFFFFll},
slouken@10587
   231
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFF0ll},
slouken@10587
   232
    {"_allmul",   &TST_allmul,   0x0000000000000010ll, 0x000000000FFFFFFFll,  0, 0x00000000FFFFFFF0ll},
slouken@10587
   233
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000000000100ll,  0, 0x0000000FFFFFFF00ll},
slouken@10587
   234
    {"_allmul",   &TST_allmul,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000FFFFFFF00ll},
slouken@10587
   235
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000010000000ll,  0, 0x00FFFFFFF0000000ll},
slouken@10587
   236
    {"_allmul",   &TST_allmul,   0x0000000010000000ll, 0x000000000FFFFFFFll,  0, 0x00FFFFFFF0000000ll},
slouken@10587
   237
    {"_allmul",   &TST_allmul,   0x000000000FFFFFFFll, 0x0000000080000000ll,  0, 0x07FFFFFF80000000ll},
slouken@10587
   238
    {"_allmul",   &TST_allmul,   0x0000000080000000ll, 0x000000000FFFFFFFll,  0, 0x07FFFFFF80000000ll},
slouken@10587
   239
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0xFFFFFFFF00000000ll},
slouken@10587
   240
    {"_allmul",   &TST_allmul,   0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFF00000000ll},
slouken@10587
   241
    {"_allmul",   &TST_allmul,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   242
    {"_allmul",   &TST_allmul,   0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   243
    {"_allmul",   &TST_allmul,   0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll,  0, 0xFFFFFFFE00000001ll},
slouken@10587
   244
slouken@10587
   245
    {"_alldiv",   &TST_alldiv,   0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   246
    {"_alldiv",   &TST_alldiv,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   247
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   248
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   249
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   250
    {"_alldiv",   &TST_alldiv,   0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000001ll},
slouken@10587
   251
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   252
    {"_alldiv",   &TST_alldiv,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   253
    {"_alldiv",   &TST_alldiv,   0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFFFll},
slouken@10587
   254
    {"_alldiv",   &TST_alldiv,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   255
    {"_alldiv",   &TST_alldiv,   0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   256
    {"_alldiv",   &TST_alldiv,   0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   257
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   258
    {"_alldiv",   &TST_alldiv,   0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000080000008ll},
slouken@10587
   259
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xC000000080000008ll},
slouken@10587
   260
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000000000007FFFll},
slouken@10587
   261
    {"_alldiv",   &TST_alldiv,   0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000001ll},
slouken@10587
   262
slouken@10587
   263
    {"_allrem",   &TST_allrem,   0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   264
    {"_allrem",   &TST_allrem,   0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   265
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   266
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   267
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   268
    {"_allrem",   &TST_allrem,   0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   269
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   270
    {"_allrem",   &TST_allrem,   0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   271
    {"_allrem",   &TST_allrem,   0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x000000000000000Fll},
slouken@10587
   272
    {"_allrem",   &TST_allrem,   0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000100ll},
slouken@10587
   273
    {"_allrem",   &TST_allrem,   0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x0000000000000000ll},
slouken@10587
   274
    {"_allrem",   &TST_allrem,   0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   275
    {"_allrem",   &TST_allrem,   0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0xFFFFFFFFFFFFFFFEll},
slouken@10587
   276
    {"_allrem",   &TST_allrem,   0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   277
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   278
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000FFFF0000FFEEll},
slouken@10587
   279
    {"_allrem",   &TST_allrem,   0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000000ll},
slouken@10587
   280
slouken@10587
   281
slouken@10587
   282
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   283
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   284
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   285
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0xFFFFFFFFFFFFFFFFll},
slouken@10587
   286
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   287
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000001ll},
slouken@10587
   288
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   289
    {"_ualldiv",  &TST_ualldiv,  0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   290
    {"_ualldiv",  &TST_ualldiv,  0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x00000000FFFFFFFFll},
slouken@10587
   291
    {"_ualldiv",  &TST_ualldiv,  0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   292
    {"_ualldiv",  &TST_ualldiv,  0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   293
    {"_ualldiv",  &TST_ualldiv,  0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x000000000FFFFFFFll},
slouken@10587
   294
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x00000001FFFFFFFFll},
slouken@10587
   295
    {"_ualldiv",  &TST_ualldiv,  0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   296
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x0000000000000000ll},
slouken@10587
   297
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000000000007FFFll},
slouken@10587
   298
    {"_ualldiv",  &TST_ualldiv,  0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000001ll},
slouken@10587
   299
slouken@10587
   300
    {"_uallrem",  &TST_uallrem,  0x0000000000000000ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   301
    {"_uallrem",  &TST_uallrem,  0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   302
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   303
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   304
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000001ll},
slouken@10587
   305
    {"_uallrem",  &TST_uallrem,  0x0000000000000001ll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   306
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll,  0, 0x0000000000000000ll},
slouken@10587
   307
    {"_uallrem",  &TST_uallrem,  0x000000000FFFFFFFll, 0x0000000000000001ll,  0, 0x0000000000000000ll},
slouken@10587
   308
    {"_uallrem",  &TST_uallrem,  0x0000000FFFFFFFFFll, 0x0000000000000010ll,  0, 0x000000000000000Fll},
slouken@10587
   309
    {"_uallrem",  &TST_uallrem,  0x0000000000000100ll, 0x000000000FFFFFFFll,  0, 0x0000000000000100ll},
slouken@10587
   310
    {"_uallrem",  &TST_uallrem,  0x00FFFFFFF0000000ll, 0x0000000010000000ll,  0, 0x0000000000000000ll},
slouken@10587
   311
    {"_uallrem",  &TST_uallrem,  0x07FFFFFF80000000ll, 0x0000000080000000ll,  0, 0x0000000000000000ll},
slouken@10587
   312
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll,  0, 0x000000007FFFFFFEll},
slouken@10587
   313
    {"_uallrem",  &TST_uallrem,  0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0xFFFFFFFEFFFFFFF0ll},
slouken@10587
   314
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll,  0, 0x7FFFFFFEFFFFFFF0ll},
slouken@10587
   315
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll,  0, 0x0000FFFF0000FFEEll},
slouken@10587
   316
    {"_uallrem",  &TST_uallrem,  0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll,  0, 0x0000000000000000ll},
slouken@10587
   317
slouken@10587
   318
    {NULL}
slouken@10587
   319
};
slouken@10587
   320
slouken@10587
   321
int
slouken@10587
   322
Test64Bit (SDL_bool verbose)
slouken@10587
   323
{
slouken@10587
   324
    LL_Test *t;
slouken@10587
   325
    int failed = 0;
slouken@10587
   326
slouken@10587
   327
    for (t = LL_Tests; t->routine != NULL; t++) {
slouken@10587
   328
        unsigned long long result = 0;
slouken@10587
   329
        unsigned int *al = (unsigned int *)&t->a;
slouken@10587
   330
        unsigned int *bl = (unsigned int *)&t->b;
slouken@10587
   331
        unsigned int *el = (unsigned int *)&t->expected_result;
slouken@10587
   332
        unsigned int *rl = (unsigned int *)&result;
slouken@10587
   333
slouken@10587
   334
        if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) {
slouken@10587
   335
            if (verbose)
slouken@10587
   336
                SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n",
slouken@10587
   337
                        t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]);
slouken@10587
   338
            ++failed;
slouken@10587
   339
        }
slouken@10587
   340
    }
slouken@10587
   341
    if (verbose && (failed == 0))
slouken@10587
   342
        SDL_Log("All 64bit instrinsic tests passed\n");
slouken@10587
   343
    return (failed ? 1 : 0);
slouken@10587
   344
}
slouken@1421
   345
slouken@1895
   346
int
slouken@1895
   347
TestCPUInfo(SDL_bool verbose)
slouken@1421
   348
{
slouken@1895
   349
    if (verbose) {
aschiffler@7639
   350
        SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
aschiffler@7639
   351
        SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
aschiffler@7639
   352
        SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
aschiffler@7639
   353
        SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
aschiffler@7639
   354
        SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
aschiffler@7639
   355
        SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
aschiffler@7639
   356
        SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
aschiffler@7639
   357
        SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
aschiffler@7639
   358
        SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
aschiffler@7639
   359
        SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
aschiffler@7639
   360
        SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
slouken@8148
   361
        SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
philipp@10564
   362
        SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
slouken@7823
   363
        SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
slouken@1895
   364
    }
slouken@1895
   365
    return (0);
slouken@1421
   366
}
slouken@1421
   367
slouken@1895
   368
int
slouken@3663
   369
TestAssertions(SDL_bool verbose)
slouken@3663
   370
{
slouken@3663
   371
    SDL_assert(1);
slouken@3663
   372
    SDL_assert_release(1);
slouken@3663
   373
    SDL_assert_paranoid(1);
slouken@3663
   374
    SDL_assert(0 || 1);
slouken@3663
   375
    SDL_assert_release(0 || 1);
slouken@3663
   376
    SDL_assert_paranoid(0 || 1);
slouken@3663
   377
slouken@3663
   378
#if 0   /* enable this to test assertion failures. */
slouken@3663
   379
    SDL_assert_release(1 == 2);
slouken@3663
   380
    SDL_assert_release(5 < 4);
slouken@3663
   381
    SDL_assert_release(0 && "This is a test");
slouken@3663
   382
#endif
slouken@3663
   383
slouken@5542
   384
    {
philipp@9383
   385
        const SDL_AssertData *item = SDL_GetAssertionReport();
slouken@5542
   386
        while (item) {
aschiffler@7639
   387
            SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
slouken@5542
   388
                item->condition, item->function, item->filename,
slouken@5542
   389
                item->linenum, item->trigger_count,
slouken@5542
   390
                item->always_ignore ? "yes" : "no");
slouken@5542
   391
            item = item->next;
slouken@5542
   392
        }
slouken@5542
   393
    }
slouken@3663
   394
    return (0);
slouken@3663
   395
}
slouken@3663
   396
slouken@3663
   397
int
slouken@1895
   398
main(int argc, char *argv[])
slouken@1421
   399
{
slouken@1895
   400
    SDL_bool verbose = SDL_TRUE;
slouken@1895
   401
    int status = 0;
slouken@1421
   402
aschiffler@7639
   403
    /* Enable standard application logging */
aschiffler@7639
   404
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
   405
slouken@1895
   406
    if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
slouken@1895
   407
        verbose = SDL_FALSE;
slouken@1895
   408
    }
slouken@1895
   409
    if (verbose) {
aschiffler@7639
   410
        SDL_Log("This system is running %s\n", SDL_GetPlatform());
slouken@1895
   411
    }
slouken@1421
   412
slouken@1895
   413
    status += TestTypes(verbose);
slouken@1895
   414
    status += TestEndian(verbose);
slouken@10587
   415
    status += Test64Bit(verbose);
slouken@1895
   416
    status += TestCPUInfo(verbose);
slouken@3663
   417
    status += TestAssertions(verbose);
slouken@3663
   418
slouken@1895
   419
    return status;
slouken@1421
   420
}