testautomation_intrinsics.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /**
  2. * Intrinsics test suite
  3. */
  4. #ifdef HAVE_BUILD_CONFIG
  5. /* Disable intrinsics that are unsupported by the current compiler */
  6. #include "SDL_build_config.h"
  7. #endif
  8. #include <SDL3/SDL.h>
  9. #include <SDL3/SDL_intrin.h>
  10. #include <SDL3/SDL_test.h>
  11. #include "testautomation_suites.h"
  12. // FIXME: missing tests for loongarch lsx/lasx
  13. // FIXME: missing tests for powerpc altivec
  14. /* ================= Test Case Implementation ================== */
  15. /* Helper functions */
  16. static int allocate_random_uint_arrays(Uint32 **dest, Uint32 **a, Uint32 **b, size_t *size) {
  17. size_t i;
  18. *size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
  19. *dest = SDL_malloc(sizeof(Uint32) * *size);
  20. *a = SDL_malloc(sizeof(Uint32) * *size);
  21. *b = SDL_malloc(sizeof(Uint32) * *size);
  22. if (!*dest || !*a || !*b) {
  23. SDLTest_AssertCheck(false, "SDL_malloc failed");
  24. return -1;
  25. }
  26. for (i = 0; i < *size; ++i) {
  27. (*a)[i] = SDLTest_RandomUint32();
  28. (*b)[i] = SDLTest_RandomUint32();
  29. }
  30. return 0;
  31. }
  32. static int allocate_random_float_arrays(float **dest, float **a, float **b, size_t *size) {
  33. size_t i;
  34. *size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
  35. *dest = SDL_malloc(sizeof(float) * *size);
  36. *a = SDL_malloc(sizeof(float) * *size);
  37. *b = SDL_malloc(sizeof(float) * *size);
  38. if (!*dest || !*a || !*b) {
  39. SDLTest_AssertCheck(false, "SDL_malloc failed");
  40. return -1;
  41. }
  42. for (i = 0; i < *size; ++i) {
  43. (*a)[i] = SDLTest_RandomUnitFloat();
  44. (*b)[i] = SDLTest_RandomUnitFloat();
  45. }
  46. return 0;
  47. }
  48. static int allocate_random_double_arrays(double **dest, double **a, double **b, size_t *size) {
  49. size_t i;
  50. *size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
  51. *dest = SDL_malloc(sizeof(double) * *size);
  52. *a = SDL_malloc(sizeof(double) * *size);
  53. *b = SDL_malloc(sizeof(double) * *size);
  54. if (!*dest || !*a || !*b) {
  55. SDLTest_AssertCheck(false, "SDL_malloc failed");
  56. return -1;
  57. }
  58. for (i = 0; i < *size; ++i) {
  59. (*a)[i] = SDLTest_RandomUnitDouble();
  60. (*b)[i] = SDLTest_RandomUnitDouble();
  61. }
  62. return 0;
  63. }
  64. static void free_arrays(void *dest, void *a, void *b) {
  65. SDL_free(dest);
  66. SDL_free(a);
  67. SDL_free(b);
  68. }
  69. /**
  70. * Verify element-wise addition of 2 int arrays.
  71. */
  72. static void verify_uints_addition(const Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size, const char *desc) {
  73. size_t i;
  74. int all_good = 1;
  75. for (i = 0; i < size; ++i) {
  76. Uint32 expected = a[i] + b[i];
  77. if (dest[i] != expected) {
  78. SDLTest_AssertCheck(false, "%" SDL_PRIs32 " + %" SDL_PRIs32 " = %" SDL_PRIs32 ", expected %" SDL_PRIs32 " ([%" SDL_PRIu32 "/%" SDL_PRIu32 "] %s)",
  79. a[i], b[i], dest[i], expected, (Uint32)i, (Uint32)size, desc);
  80. all_good = 0;
  81. }
  82. }
  83. if (all_good) {
  84. SDLTest_AssertCheck(true, "All int additions were correct (%s)", desc);
  85. }
  86. }
  87. /**
  88. * Verify element-wise multiplication of 2 uint arrays.
  89. */
  90. static void verify_uints_multiplication(const Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size, const char *desc) {
  91. size_t i;
  92. int all_good = 1;
  93. for (i = 0; i < size; ++i) {
  94. Uint32 expected = a[i] * b[i];
  95. if (dest[i] != expected) {
  96. SDLTest_AssertCheck(false, "%" SDL_PRIu32 " * %" SDL_PRIu32 " = %" SDL_PRIu32 ", expected %" SDL_PRIu32 " ([%" SDL_PRIu32 "/%" SDL_PRIu32 "] %s)",
  97. a[i], b[i], dest[i], expected, (Uint32)i, (Uint32)size, desc);
  98. all_good = 0;
  99. }
  100. }
  101. if (all_good) {
  102. SDLTest_AssertCheck(true, "All int multiplication were correct (%s)", desc);
  103. }
  104. }
  105. /**
  106. * Verify element-wise addition of 2 float arrays.
  107. */
  108. static void verify_floats_addition(const float *dest, const float *a, const float *b, size_t size, const char *desc) {
  109. size_t i;
  110. int all_good = 1;
  111. for (i = 0; i < size; ++i) {
  112. float expected = a[i] + b[i];
  113. float abs_error = SDL_fabsf(dest[i] - expected);
  114. if (abs_error > 1.0e-5f) {
  115. SDLTest_AssertCheck(false, "%g + %g = %g, expected %g (error = %g) ([%" SDL_PRIu32 "/%" SDL_PRIu32 "] %s)",
  116. a[i], b[i], dest[i], expected, abs_error, (Uint32) i, (Uint32) size, desc);
  117. all_good = 0;
  118. }
  119. }
  120. if (all_good) {
  121. SDLTest_AssertCheck(true, "All float additions were correct (%s)", desc);
  122. }
  123. }
  124. /**
  125. * Verify element-wise addition of 2 double arrays.
  126. */
  127. static void verify_doubles_addition(const double *dest, const double *a, const double *b, size_t size, const char *desc) {
  128. size_t i;
  129. int all_good = 1;
  130. for (i = 0; i < size; ++i) {
  131. double expected = a[i] + b[i];
  132. double abs_error = SDL_fabs(dest[i] - expected);
  133. if (abs_error > 1.0e-5) {
  134. SDLTest_AssertCheck(abs_error < 1.0e-5f, "%g + %g = %g, expected %g (error = %g) ([%" SDL_PRIu32 "/%" SDL_PRIu32 "] %s)",
  135. a[i], b[i], dest[i], expected, abs_error, (Uint32) i, (Uint32) size, desc);
  136. all_good = false;
  137. }
  138. }
  139. if (all_good) {
  140. SDLTest_AssertCheck(true, "All double additions were correct (%s)", desc);
  141. }
  142. }
  143. /* Intrinsic kernels */
  144. static void kernel_uints_add_cpu(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  145. for (; size; --size, ++dest, ++a, ++b) {
  146. *dest = *a + *b;
  147. }
  148. }
  149. static void kernel_uints_mul_cpu(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  150. for (; size; --size, ++dest, ++a, ++b) {
  151. *dest = *a * *b;
  152. }
  153. }
  154. static void kernel_floats_add_cpu(float *dest, const float *a, const float *b, size_t size) {
  155. for (; size; --size, ++dest, ++a, ++b) {
  156. *dest = *a + *b;
  157. }
  158. }
  159. static void kernel_doubles_add_cpu(double *dest, const double *a, const double *b, size_t size) {
  160. for (; size; --size, ++dest, ++a, ++b) {
  161. *dest = *a + *b;
  162. }
  163. }
  164. #ifdef SDL_MMX_INTRINSICS
  165. SDL_TARGETING("mmx") static void kernel_uints_add_mmx(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  166. for (; size >= 2; size -= 2, dest += 2, a += 2, b += 2) {
  167. *(__m64*)dest = _mm_add_pi32(*(__m64*)a, *(__m64*)b);
  168. }
  169. if (size) {
  170. *dest = *a + *b;
  171. }
  172. _mm_empty();
  173. }
  174. #endif
  175. #ifdef SDL_SSE_INTRINSICS
  176. SDL_TARGETING("sse") static void kernel_floats_add_sse(float *dest, const float *a, const float *b, size_t size) {
  177. for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
  178. _mm_storeu_ps(dest, _mm_add_ps(_mm_loadu_ps(a), _mm_loadu_ps (b)));
  179. }
  180. for (; size; size--, ++dest, ++a, ++b) {
  181. *dest = *a + *b;
  182. }
  183. }
  184. #endif
  185. #ifdef SDL_SSE2_INTRINSICS
  186. SDL_TARGETING("sse2") static void kernel_doubles_add_sse2(double *dest, const double *a, const double *b, size_t size) {
  187. for (; size >= 2; size -= 2, dest += 2, a += 2, b += 2) {
  188. _mm_storeu_pd(dest, _mm_add_pd(_mm_loadu_pd(a), _mm_loadu_pd(b)));
  189. }
  190. if (size) {
  191. *dest = *a + *b;
  192. }
  193. }
  194. #endif
  195. #ifdef SDL_SSE3_INTRINSICS
  196. SDL_TARGETING("sse3") static void kernel_uints_add_sse3(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  197. for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
  198. _mm_storeu_si128((__m128i*)dest, _mm_add_epi32(_mm_lddqu_si128((__m128i*)a), _mm_lddqu_si128((__m128i*)b)));
  199. }
  200. for (;size; --size, ++dest, ++a, ++b) {
  201. *dest = *a + *b;
  202. }
  203. }
  204. #endif
  205. #ifdef SDL_SSE4_1_INTRINSICS
  206. SDL_TARGETING("sse4.1") static void kernel_uints_mul_sse4_1(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  207. for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
  208. _mm_storeu_si128((__m128i*)dest, _mm_mullo_epi32(_mm_lddqu_si128((__m128i*)a), _mm_lddqu_si128((__m128i*)b)));
  209. }
  210. for (;size; --size, ++dest, ++a, ++b) {
  211. *dest = *a * *b;
  212. }
  213. }
  214. #endif
  215. #ifdef SDL_SSE4_2_INTRINSICS
  216. SDL_TARGETING("sse4.2") static Uint32 calculate_crc32c_sse4_2(const char *text) {
  217. Uint32 crc32c = ~0u;
  218. size_t len = SDL_strlen(text);
  219. #if defined(__x86_64__) || defined(_M_X64)
  220. for (; len >= 8; len -= 8, text += 8) {
  221. crc32c = (Uint32)_mm_crc32_u64(crc32c, *(Sint64*)text);
  222. }
  223. if (len >= 4) {
  224. crc32c = (Uint32)_mm_crc32_u32(crc32c, *(Sint32*)text);
  225. len -= 4;
  226. text += 4;
  227. }
  228. #else
  229. for (; len >= 4; len -= 4, text += 4) {
  230. crc32c = (Uint32)_mm_crc32_u32(crc32c, *(Sint32*)text);
  231. }
  232. #endif
  233. if (len >= 2) {
  234. crc32c = (Uint32)_mm_crc32_u16(crc32c, *(Sint16*)text);
  235. len -= 2;
  236. text += 2;
  237. }
  238. if (len) {
  239. crc32c = (Uint32)_mm_crc32_u8(crc32c, *text);
  240. }
  241. return ~crc32c;
  242. }
  243. #endif
  244. #ifdef SDL_AVX_INTRINSICS
  245. SDL_TARGETING("avx") static void kernel_floats_add_avx(float *dest, const float *a, const float *b, size_t size) {
  246. for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
  247. _mm256_storeu_ps(dest, _mm256_add_ps(_mm256_loadu_ps(a), _mm256_loadu_ps(b)));
  248. }
  249. for (; size; size--, ++dest, ++a, ++b) {
  250. *dest = *a + *b;
  251. }
  252. }
  253. #endif
  254. #ifdef SDL_AVX2_INTRINSICS
  255. SDL_TARGETING("avx2") static void kernel_uints_add_avx2(Uint32 *dest, const Uint32 *a, const Uint32 *b, size_t size) {
  256. for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
  257. _mm256_storeu_si256((__m256i*)dest, _mm256_add_epi32(_mm256_loadu_si256((__m256i*)a), _mm256_loadu_si256((__m256i*)b)));
  258. }
  259. for (; size; size--, ++dest, ++a, ++b) {
  260. *dest = *a + *b;
  261. }
  262. }
  263. #endif
  264. #ifdef SDL_AVX512F_INTRINSICS
  265. SDL_TARGETING("avx512f") static void kernel_floats_add_avx512f(float *dest, const float *a, const float *b, size_t size) {
  266. for (; size >= 16; size -= 16, dest += 16, a += 16, b += 16) {
  267. _mm512_storeu_ps(dest, _mm512_add_ps(_mm512_loadu_ps(a), _mm512_loadu_ps(b)));
  268. }
  269. for (; size; --size) {
  270. *dest++ = *a++ + *b++;
  271. }
  272. }
  273. #endif
  274. /* Test case functions */
  275. static int SDLCALL intrinsics_selftest(void *arg)
  276. {
  277. {
  278. size_t size;
  279. Uint32 *dest, *a, *b;
  280. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  281. return TEST_ABORTED;
  282. }
  283. kernel_uints_mul_cpu(dest, a, b, size);
  284. verify_uints_multiplication(dest, a, b, size, "CPU");
  285. free_arrays(dest, a, b);
  286. }
  287. {
  288. size_t size;
  289. Uint32 *dest, *a, *b;
  290. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  291. return TEST_ABORTED;
  292. }
  293. kernel_uints_add_cpu(dest, a, b, size);
  294. verify_uints_addition(dest, a, b, size, "CPU");
  295. free_arrays(dest, a, b);
  296. }
  297. {
  298. size_t size;
  299. float *dest, *a, *b;
  300. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  301. return TEST_ABORTED;
  302. }
  303. kernel_floats_add_cpu(dest, a, b, size);
  304. verify_floats_addition(dest, a, b, size, "CPU");
  305. free_arrays(dest, a, b);
  306. }
  307. {
  308. size_t size;
  309. double *dest, *a, *b;
  310. if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
  311. return TEST_ABORTED;
  312. }
  313. kernel_doubles_add_cpu(dest, a, b, size);
  314. verify_doubles_addition(dest, a, b, size, "CPU");
  315. free_arrays(dest, a, b);
  316. }
  317. return TEST_COMPLETED;
  318. }
  319. static int SDLCALL intrinsics_testMMX(void *arg)
  320. {
  321. if (SDL_HasMMX()) {
  322. SDLTest_AssertCheck(true, "CPU of test machine has MMX support.");
  323. #ifdef SDL_MMX_INTRINSICS
  324. {
  325. size_t size;
  326. Uint32 *dest, *a, *b;
  327. SDLTest_AssertCheck(true, "Test executable uses MMX intrinsics.");
  328. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  329. return TEST_ABORTED;
  330. }
  331. kernel_uints_add_mmx(dest, a, b, size);
  332. verify_uints_addition(dest, a, b, size, "MMX");
  333. free_arrays(dest, a, b);
  334. return TEST_COMPLETED;
  335. }
  336. #else
  337. SDLTest_AssertCheck(true, "Test executable does NOT use MMX intrinsics.");
  338. #endif
  339. } else {
  340. SDLTest_AssertCheck(true, "CPU of test machine has NO MMX support.");
  341. }
  342. return TEST_SKIPPED;
  343. }
  344. static int SDLCALL intrinsics_testSSE(void *arg)
  345. {
  346. if (SDL_HasSSE()) {
  347. SDLTest_AssertCheck(true, "CPU of test machine has SSE support.");
  348. #ifdef SDL_SSE_INTRINSICS
  349. {
  350. size_t size;
  351. float *dest, *a, *b;
  352. SDLTest_AssertCheck(true, "Test executable uses SSE intrinsics.");
  353. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  354. return TEST_ABORTED;
  355. }
  356. kernel_floats_add_sse(dest, a, b, size);
  357. verify_floats_addition(dest, a, b, size, "SSE");
  358. free_arrays(dest, a, b);
  359. return TEST_COMPLETED;
  360. }
  361. #else
  362. SDLTest_AssertCheck(true, "Test executable does NOT use SSE intrinsics.");
  363. #endif
  364. } else {
  365. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE support.");
  366. }
  367. return TEST_SKIPPED;
  368. }
  369. static int SDLCALL intrinsics_testSSE2(void *arg)
  370. {
  371. if (SDL_HasSSE2()) {
  372. SDLTest_AssertCheck(true, "CPU of test machine has SSE2 support.");
  373. #ifdef SDL_SSE2_INTRINSICS
  374. {
  375. size_t size;
  376. double *dest, *a, *b;
  377. SDLTest_AssertCheck(true, "Test executable uses SSE2 intrinsics.");
  378. if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
  379. return TEST_ABORTED;
  380. }
  381. kernel_doubles_add_sse2(dest, a, b, size);
  382. verify_doubles_addition(dest, a, b, size, "SSE2");
  383. free_arrays(dest, a, b);
  384. return TEST_COMPLETED;
  385. }
  386. #else
  387. SDLTest_AssertCheck(true, "Test executable does NOT use SSE2 intrinsics.");
  388. #endif
  389. } else {
  390. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE2 support.");
  391. }
  392. return TEST_SKIPPED;
  393. }
  394. static int SDLCALL intrinsics_testSSE3(void *arg)
  395. {
  396. if (SDL_HasSSE3()) {
  397. SDLTest_AssertCheck(true, "CPU of test machine has SSE3 support.");
  398. #ifdef SDL_SSE3_INTRINSICS
  399. {
  400. size_t size;
  401. Uint32 *dest, *a, *b;
  402. SDLTest_AssertCheck(true, "Test executable uses SSE3 intrinsics.");
  403. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  404. return TEST_ABORTED;
  405. }
  406. kernel_uints_add_sse3(dest, a, b, size);
  407. verify_uints_addition(dest, a, b, size, "SSE3");
  408. free_arrays(dest, a, b);
  409. return TEST_COMPLETED;
  410. }
  411. #else
  412. SDLTest_AssertCheck(true, "Test executable does NOT use SSE3 intrinsics.");
  413. #endif
  414. } else {
  415. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE3 support.");
  416. }
  417. return TEST_SKIPPED;
  418. }
  419. static int SDLCALL intrinsics_testSSE4_1(void *arg)
  420. {
  421. if (SDL_HasSSE41()) {
  422. SDLTest_AssertCheck(true, "CPU of test machine has SSE4.1 support.");
  423. #ifdef SDL_SSE4_1_INTRINSICS
  424. {
  425. size_t size;
  426. Uint32 *dest, *a, *b;
  427. SDLTest_AssertCheck(true, "Test executable uses SSE4.1 intrinsics.");
  428. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  429. return TEST_ABORTED;
  430. }
  431. kernel_uints_mul_sse4_1(dest, a, b, size);
  432. verify_uints_multiplication(dest, a, b, size, "SSE4.1");
  433. free_arrays(dest, a, b);
  434. return TEST_COMPLETED;
  435. }
  436. #else
  437. SDLTest_AssertCheck(true, "Test executable does NOT use SSE4.1 intrinsics.");
  438. #endif
  439. } else {
  440. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE4.1 support.");
  441. }
  442. return TEST_SKIPPED;
  443. }
  444. static int SDLCALL intrinsics_testSSE4_2(void *arg)
  445. {
  446. if (SDL_HasSSE42()) {
  447. SDLTest_AssertCheck(true, "CPU of test machine has SSE4.2 support.");
  448. #ifdef SDL_SSE4_2_INTRINSICS
  449. {
  450. struct {
  451. const char *input;
  452. Uint32 crc32c;
  453. } references[] = {
  454. {"", 0x00000000},
  455. {"Hello world", 0x72b51f78},
  456. {"Simple DirectMedia Layer", 0x56f85341, },
  457. };
  458. size_t i;
  459. SDLTest_AssertCheck(true, "Test executable uses SSE4.2 intrinsics.");
  460. for (i = 0; i < SDL_arraysize(references); ++i) {
  461. Uint32 actual = calculate_crc32c_sse4_2(references[i].input);
  462. SDLTest_AssertCheck(actual == references[i].crc32c, "CRC32-C(\"%s\")=0x%08x, got 0x%08x",
  463. references[i].input, references[i].crc32c, actual);
  464. }
  465. return TEST_COMPLETED;
  466. }
  467. #else
  468. SDLTest_AssertCheck(true, "Test executable does NOT use SSE4.2 intrinsics.");
  469. #endif
  470. } else {
  471. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE4.2 support.");
  472. }
  473. return TEST_SKIPPED;
  474. }
  475. static int SDLCALL intrinsics_testAVX(void *arg)
  476. {
  477. if (SDL_HasAVX()) {
  478. SDLTest_AssertCheck(true, "CPU of test machine has AVX support.");
  479. #ifdef SDL_AVX_INTRINSICS
  480. {
  481. size_t size;
  482. float *dest, *a, *b;
  483. SDLTest_AssertCheck(true, "Test executable uses AVX intrinsics.");
  484. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  485. return TEST_ABORTED;
  486. }
  487. kernel_floats_add_avx(dest, a, b, size);
  488. verify_floats_addition(dest, a, b, size, "AVX");
  489. free_arrays(dest, a, b);
  490. return TEST_COMPLETED;
  491. }
  492. #else
  493. SDLTest_AssertCheck(true, "Test executable does NOT use AVX intrinsics.");
  494. #endif
  495. } else {
  496. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX support.");
  497. }
  498. return TEST_SKIPPED;
  499. }
  500. static int SDLCALL intrinsics_testAVX2(void *arg)
  501. {
  502. if (SDL_HasAVX2()) {
  503. SDLTest_AssertCheck(true, "CPU of test machine has AVX2 support.");
  504. #ifdef SDL_AVX2_INTRINSICS
  505. {
  506. size_t size;
  507. Uint32 *dest, *a, *b;
  508. SDLTest_AssertCheck(true, "Test executable uses AVX2 intrinsics.");
  509. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  510. return TEST_ABORTED;
  511. }
  512. kernel_uints_add_avx2(dest, a, b, size);
  513. verify_uints_addition(dest, a, b, size, "AVX2");
  514. free_arrays(dest, a, b);
  515. return TEST_COMPLETED;
  516. }
  517. #else
  518. SDLTest_AssertCheck(true, "Test executable does NOT use AVX2 intrinsics.");
  519. #endif
  520. } else {
  521. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX2 support.");
  522. }
  523. return TEST_SKIPPED;
  524. }
  525. static int SDLCALL intrinsics_testAVX512F(void *arg)
  526. {
  527. if (SDL_HasAVX512F()) {
  528. SDLTest_AssertCheck(true, "CPU of test machine has AVX512F support.");
  529. #ifdef SDL_AVX512F_INTRINSICS
  530. {
  531. size_t size;
  532. float *dest, *a, *b;
  533. SDLTest_AssertCheck(true, "Test executable uses AVX512F intrinsics.");
  534. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  535. return TEST_ABORTED;
  536. }
  537. kernel_floats_add_avx512f(dest, a, b, size);
  538. verify_floats_addition(dest, a, b, size, "AVX512F");
  539. free_arrays(dest, a, b);
  540. return TEST_COMPLETED;
  541. }
  542. #else
  543. SDLTest_AssertCheck(true, "Test executable does NOT use AVX512F intrinsics.");
  544. #endif
  545. } else {
  546. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX512F support.");
  547. }
  548. return TEST_SKIPPED;
  549. }
  550. /* ================= Test References ================== */
  551. /* Intrinsics test cases */
  552. static const SDLTest_TestCaseReference intrinsicsTest1 = {
  553. intrinsics_selftest, "intrinsics_selftest", "Intrinsics testautomation selftest", TEST_ENABLED
  554. };
  555. static const SDLTest_TestCaseReference intrinsicsTest2 = {
  556. intrinsics_testMMX, "intrinsics_testMMX", "Tests MMX intrinsics", TEST_ENABLED
  557. };
  558. static const SDLTest_TestCaseReference intrinsicsTest3 = {
  559. intrinsics_testSSE, "intrinsics_testSSE", "Tests SSE intrinsics", TEST_ENABLED
  560. };
  561. static const SDLTest_TestCaseReference intrinsicsTest4 = {
  562. intrinsics_testSSE2, "intrinsics_testSSE2", "Tests SSE2 intrinsics", TEST_ENABLED
  563. };
  564. static const SDLTest_TestCaseReference intrinsicsTest5 = {
  565. intrinsics_testSSE3, "intrinsics_testSSE3", "Tests SSE3 intrinsics", TEST_ENABLED
  566. };
  567. static const SDLTest_TestCaseReference intrinsicsTest6 = {
  568. intrinsics_testSSE4_1, "intrinsics_testSSE4.1", "Tests SSE4.1 intrinsics", TEST_ENABLED
  569. };
  570. static const SDLTest_TestCaseReference intrinsicsTest7 = {
  571. intrinsics_testSSE4_2, "intrinsics_testSSE4.2", "Tests SSE4.2 intrinsics", TEST_ENABLED
  572. };
  573. static const SDLTest_TestCaseReference intrinsicsTest8 = {
  574. intrinsics_testAVX, "intrinsics_testAVX", "Tests AVX intrinsics", TEST_ENABLED
  575. };
  576. static const SDLTest_TestCaseReference intrinsicsTest9 = {
  577. intrinsics_testAVX2, "intrinsics_testAVX2", "Tests AVX2 intrinsics", TEST_ENABLED
  578. };
  579. static const SDLTest_TestCaseReference intrinsicsTest10 = {
  580. intrinsics_testAVX512F, "intrinsics_testAVX512F", "Tests AVX512F intrinsics", TEST_ENABLED
  581. };
  582. /* Sequence of Platform test cases */
  583. static const SDLTest_TestCaseReference *platformTests[] = {
  584. &intrinsicsTest1,
  585. &intrinsicsTest2,
  586. &intrinsicsTest3,
  587. &intrinsicsTest4,
  588. &intrinsicsTest5,
  589. &intrinsicsTest6,
  590. &intrinsicsTest7,
  591. &intrinsicsTest8,
  592. &intrinsicsTest9,
  593. &intrinsicsTest10,
  594. NULL
  595. };
  596. /* Platform test suite (global) */
  597. SDLTest_TestSuiteReference intrinsicsTestSuite = {
  598. "Intrinsics",
  599. NULL,
  600. platformTests,
  601. NULL
  602. };