testplatform.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*
  2. Copyright (C) 1997-2019 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. int
  23. TestTypes(SDL_bool verbose)
  24. {
  25. int error = 0;
  26. SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
  27. SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
  28. SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
  29. SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
  30. SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
  31. SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
  32. SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
  33. SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
  34. SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
  35. SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
  36. SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
  37. SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
  38. SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
  39. SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
  40. SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
  41. SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 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("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
  343. SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
  344. }
  345. return (0);
  346. }
  347. int
  348. TestAssertions(SDL_bool verbose)
  349. {
  350. SDL_assert(1);
  351. SDL_assert_release(1);
  352. SDL_assert_paranoid(1);
  353. SDL_assert(0 || 1);
  354. SDL_assert_release(0 || 1);
  355. SDL_assert_paranoid(0 || 1);
  356. #if 0 /* enable this to test assertion failures. */
  357. SDL_assert_release(1 == 2);
  358. SDL_assert_release(5 < 4);
  359. SDL_assert_release(0 && "This is a test");
  360. #endif
  361. {
  362. const SDL_AssertData *item = SDL_GetAssertionReport();
  363. while (item) {
  364. SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
  365. item->condition, item->function, item->filename,
  366. item->linenum, item->trigger_count,
  367. item->always_ignore ? "yes" : "no");
  368. item = item->next;
  369. }
  370. }
  371. return (0);
  372. }
  373. int
  374. main(int argc, char *argv[])
  375. {
  376. SDL_bool verbose = SDL_TRUE;
  377. int status = 0;
  378. /* Enable standard application logging */
  379. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  380. if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
  381. verbose = SDL_FALSE;
  382. }
  383. if (verbose) {
  384. SDL_Log("This system is running %s\n", SDL_GetPlatform());
  385. }
  386. status += TestTypes(verbose);
  387. status += TestEndian(verbose);
  388. status += Test64Bit(verbose);
  389. status += TestCPUInfo(verbose);
  390. status += TestAssertions(verbose);
  391. return status;
  392. }