🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

466 lines
22 KiB

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