🛠️🐜 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.

443 lines
22 KiB

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