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