testautomation_intrinsics.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. free_arrays(dest, a, b);
  282. return TEST_ABORTED;
  283. }
  284. kernel_uints_mul_cpu(dest, a, b, size);
  285. verify_uints_multiplication(dest, a, b, size, "CPU");
  286. free_arrays(dest, a, b);
  287. }
  288. {
  289. size_t size;
  290. Uint32 *dest, *a, *b;
  291. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  292. free_arrays(dest, a, b);
  293. return TEST_ABORTED;
  294. }
  295. kernel_uints_add_cpu(dest, a, b, size);
  296. verify_uints_addition(dest, a, b, size, "CPU");
  297. free_arrays(dest, a, b);
  298. }
  299. {
  300. size_t size;
  301. float *dest, *a, *b;
  302. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  303. free_arrays(dest, a, b);
  304. return TEST_ABORTED;
  305. }
  306. kernel_floats_add_cpu(dest, a, b, size);
  307. verify_floats_addition(dest, a, b, size, "CPU");
  308. free_arrays(dest, a, b);
  309. }
  310. {
  311. size_t size;
  312. double *dest, *a, *b;
  313. if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
  314. free_arrays(dest, a, b);
  315. return TEST_ABORTED;
  316. }
  317. kernel_doubles_add_cpu(dest, a, b, size);
  318. verify_doubles_addition(dest, a, b, size, "CPU");
  319. free_arrays(dest, a, b);
  320. }
  321. return TEST_COMPLETED;
  322. }
  323. static int SDLCALL intrinsics_testMMX(void *arg)
  324. {
  325. if (SDL_HasMMX()) {
  326. SDLTest_AssertCheck(true, "CPU of test machine has MMX support.");
  327. #ifdef SDL_MMX_INTRINSICS
  328. {
  329. size_t size;
  330. Uint32 *dest, *a, *b;
  331. SDLTest_AssertCheck(true, "Test executable uses MMX intrinsics.");
  332. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  333. free_arrays(dest, a, b);
  334. return TEST_ABORTED;
  335. }
  336. kernel_uints_add_mmx(dest, a, b, size);
  337. verify_uints_addition(dest, a, b, size, "MMX");
  338. free_arrays(dest, a, b);
  339. return TEST_COMPLETED;
  340. }
  341. #else
  342. SDLTest_AssertCheck(true, "Test executable does NOT use MMX intrinsics.");
  343. #endif
  344. } else {
  345. SDLTest_AssertCheck(true, "CPU of test machine has NO MMX support.");
  346. }
  347. return TEST_SKIPPED;
  348. }
  349. static int SDLCALL intrinsics_testSSE(void *arg)
  350. {
  351. if (SDL_HasSSE()) {
  352. SDLTest_AssertCheck(true, "CPU of test machine has SSE support.");
  353. #ifdef SDL_SSE_INTRINSICS
  354. {
  355. size_t size;
  356. float *dest, *a, *b;
  357. SDLTest_AssertCheck(true, "Test executable uses SSE intrinsics.");
  358. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  359. free_arrays(dest, a, b);
  360. return TEST_ABORTED;
  361. }
  362. kernel_floats_add_sse(dest, a, b, size);
  363. verify_floats_addition(dest, a, b, size, "SSE");
  364. free_arrays(dest, a, b);
  365. return TEST_COMPLETED;
  366. }
  367. #else
  368. SDLTest_AssertCheck(true, "Test executable does NOT use SSE intrinsics.");
  369. #endif
  370. } else {
  371. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE support.");
  372. }
  373. return TEST_SKIPPED;
  374. }
  375. static int SDLCALL intrinsics_testSSE2(void *arg)
  376. {
  377. if (SDL_HasSSE2()) {
  378. SDLTest_AssertCheck(true, "CPU of test machine has SSE2 support.");
  379. #ifdef SDL_SSE2_INTRINSICS
  380. {
  381. size_t size;
  382. double *dest, *a, *b;
  383. SDLTest_AssertCheck(true, "Test executable uses SSE2 intrinsics.");
  384. if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
  385. free_arrays(dest, a, b);
  386. return TEST_ABORTED;
  387. }
  388. kernel_doubles_add_sse2(dest, a, b, size);
  389. verify_doubles_addition(dest, a, b, size, "SSE2");
  390. free_arrays(dest, a, b);
  391. return TEST_COMPLETED;
  392. }
  393. #else
  394. SDLTest_AssertCheck(true, "Test executable does NOT use SSE2 intrinsics.");
  395. #endif
  396. } else {
  397. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE2 support.");
  398. }
  399. return TEST_SKIPPED;
  400. }
  401. static int SDLCALL intrinsics_testSSE3(void *arg)
  402. {
  403. if (SDL_HasSSE3()) {
  404. SDLTest_AssertCheck(true, "CPU of test machine has SSE3 support.");
  405. #ifdef SDL_SSE3_INTRINSICS
  406. {
  407. size_t size;
  408. Uint32 *dest, *a, *b;
  409. SDLTest_AssertCheck(true, "Test executable uses SSE3 intrinsics.");
  410. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  411. free_arrays(dest, a, b);
  412. return TEST_ABORTED;
  413. }
  414. kernel_uints_add_sse3(dest, a, b, size);
  415. verify_uints_addition(dest, a, b, size, "SSE3");
  416. free_arrays(dest, a, b);
  417. return TEST_COMPLETED;
  418. }
  419. #else
  420. SDLTest_AssertCheck(true, "Test executable does NOT use SSE3 intrinsics.");
  421. #endif
  422. } else {
  423. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE3 support.");
  424. }
  425. return TEST_SKIPPED;
  426. }
  427. static int SDLCALL intrinsics_testSSE4_1(void *arg)
  428. {
  429. if (SDL_HasSSE41()) {
  430. SDLTest_AssertCheck(true, "CPU of test machine has SSE4.1 support.");
  431. #ifdef SDL_SSE4_1_INTRINSICS
  432. {
  433. size_t size;
  434. Uint32 *dest, *a, *b;
  435. SDLTest_AssertCheck(true, "Test executable uses SSE4.1 intrinsics.");
  436. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  437. free_arrays(dest, a, b);
  438. return TEST_ABORTED;
  439. }
  440. kernel_uints_mul_sse4_1(dest, a, b, size);
  441. verify_uints_multiplication(dest, a, b, size, "SSE4.1");
  442. free_arrays(dest, a, b);
  443. return TEST_COMPLETED;
  444. }
  445. #else
  446. SDLTest_AssertCheck(true, "Test executable does NOT use SSE4.1 intrinsics.");
  447. #endif
  448. } else {
  449. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE4.1 support.");
  450. }
  451. return TEST_SKIPPED;
  452. }
  453. static int SDLCALL intrinsics_testSSE4_2(void *arg)
  454. {
  455. if (SDL_HasSSE42()) {
  456. SDLTest_AssertCheck(true, "CPU of test machine has SSE4.2 support.");
  457. #ifdef SDL_SSE4_2_INTRINSICS
  458. {
  459. struct {
  460. const char *input;
  461. Uint32 crc32c;
  462. } references[] = {
  463. {"", 0x00000000},
  464. {"Hello world", 0x72b51f78},
  465. {"Simple DirectMedia Layer", 0x56f85341, },
  466. };
  467. size_t i;
  468. SDLTest_AssertCheck(true, "Test executable uses SSE4.2 intrinsics.");
  469. for (i = 0; i < SDL_arraysize(references); ++i) {
  470. Uint32 actual = calculate_crc32c_sse4_2(references[i].input);
  471. SDLTest_AssertCheck(actual == references[i].crc32c, "CRC32-C(\"%s\")=0x%08x, got 0x%08x",
  472. references[i].input, references[i].crc32c, actual);
  473. }
  474. return TEST_COMPLETED;
  475. }
  476. #else
  477. SDLTest_AssertCheck(true, "Test executable does NOT use SSE4.2 intrinsics.");
  478. #endif
  479. } else {
  480. SDLTest_AssertCheck(true, "CPU of test machine has NO SSE4.2 support.");
  481. }
  482. return TEST_SKIPPED;
  483. }
  484. static int SDLCALL intrinsics_testAVX(void *arg)
  485. {
  486. if (SDL_HasAVX()) {
  487. SDLTest_AssertCheck(true, "CPU of test machine has AVX support.");
  488. #ifdef SDL_AVX_INTRINSICS
  489. {
  490. size_t size;
  491. float *dest, *a, *b;
  492. SDLTest_AssertCheck(true, "Test executable uses AVX intrinsics.");
  493. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  494. free_arrays(dest, a, b);
  495. return TEST_ABORTED;
  496. }
  497. kernel_floats_add_avx(dest, a, b, size);
  498. verify_floats_addition(dest, a, b, size, "AVX");
  499. free_arrays(dest, a, b);
  500. return TEST_COMPLETED;
  501. }
  502. #else
  503. SDLTest_AssertCheck(true, "Test executable does NOT use AVX intrinsics.");
  504. #endif
  505. } else {
  506. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX support.");
  507. }
  508. return TEST_SKIPPED;
  509. }
  510. static int SDLCALL intrinsics_testAVX2(void *arg)
  511. {
  512. if (SDL_HasAVX2()) {
  513. SDLTest_AssertCheck(true, "CPU of test machine has AVX2 support.");
  514. #ifdef SDL_AVX2_INTRINSICS
  515. {
  516. size_t size;
  517. Uint32 *dest, *a, *b;
  518. SDLTest_AssertCheck(true, "Test executable uses AVX2 intrinsics.");
  519. if (allocate_random_uint_arrays(&dest, &a, &b, &size) < 0) {
  520. free_arrays(dest, a, b);
  521. return TEST_ABORTED;
  522. }
  523. kernel_uints_add_avx2(dest, a, b, size);
  524. verify_uints_addition(dest, a, b, size, "AVX2");
  525. free_arrays(dest, a, b);
  526. return TEST_COMPLETED;
  527. }
  528. #else
  529. SDLTest_AssertCheck(true, "Test executable does NOT use AVX2 intrinsics.");
  530. #endif
  531. } else {
  532. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX2 support.");
  533. }
  534. return TEST_SKIPPED;
  535. }
  536. static int SDLCALL intrinsics_testAVX512F(void *arg)
  537. {
  538. if (SDL_HasAVX512F()) {
  539. SDLTest_AssertCheck(true, "CPU of test machine has AVX512F support.");
  540. #ifdef SDL_AVX512F_INTRINSICS
  541. {
  542. size_t size;
  543. float *dest, *a, *b;
  544. SDLTest_AssertCheck(true, "Test executable uses AVX512F intrinsics.");
  545. if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
  546. free_arrays(dest, a, b);
  547. return TEST_ABORTED;
  548. }
  549. kernel_floats_add_avx512f(dest, a, b, size);
  550. verify_floats_addition(dest, a, b, size, "AVX512F");
  551. free_arrays(dest, a, b);
  552. return TEST_COMPLETED;
  553. }
  554. #else
  555. SDLTest_AssertCheck(true, "Test executable does NOT use AVX512F intrinsics.");
  556. #endif
  557. } else {
  558. SDLTest_AssertCheck(true, "CPU of test machine has NO AVX512F support.");
  559. }
  560. return TEST_SKIPPED;
  561. }
  562. /* ================= Test References ================== */
  563. /* Intrinsics test cases */
  564. static const SDLTest_TestCaseReference intrinsicsTest1 = {
  565. intrinsics_selftest, "intrinsics_selftest", "Intrinsics testautomation selftest", TEST_ENABLED
  566. };
  567. static const SDLTest_TestCaseReference intrinsicsTest2 = {
  568. intrinsics_testMMX, "intrinsics_testMMX", "Tests MMX intrinsics", TEST_ENABLED
  569. };
  570. static const SDLTest_TestCaseReference intrinsicsTest3 = {
  571. intrinsics_testSSE, "intrinsics_testSSE", "Tests SSE intrinsics", TEST_ENABLED
  572. };
  573. static const SDLTest_TestCaseReference intrinsicsTest4 = {
  574. intrinsics_testSSE2, "intrinsics_testSSE2", "Tests SSE2 intrinsics", TEST_ENABLED
  575. };
  576. static const SDLTest_TestCaseReference intrinsicsTest5 = {
  577. intrinsics_testSSE3, "intrinsics_testSSE3", "Tests SSE3 intrinsics", TEST_ENABLED
  578. };
  579. static const SDLTest_TestCaseReference intrinsicsTest6 = {
  580. intrinsics_testSSE4_1, "intrinsics_testSSE4.1", "Tests SSE4.1 intrinsics", TEST_ENABLED
  581. };
  582. static const SDLTest_TestCaseReference intrinsicsTest7 = {
  583. intrinsics_testSSE4_2, "intrinsics_testSSE4.2", "Tests SSE4.2 intrinsics", TEST_ENABLED
  584. };
  585. static const SDLTest_TestCaseReference intrinsicsTest8 = {
  586. intrinsics_testAVX, "intrinsics_testAVX", "Tests AVX intrinsics", TEST_ENABLED
  587. };
  588. static const SDLTest_TestCaseReference intrinsicsTest9 = {
  589. intrinsics_testAVX2, "intrinsics_testAVX2", "Tests AVX2 intrinsics", TEST_ENABLED
  590. };
  591. static const SDLTest_TestCaseReference intrinsicsTest10 = {
  592. intrinsics_testAVX512F, "intrinsics_testAVX512F", "Tests AVX512F intrinsics", TEST_ENABLED
  593. };
  594. /* Sequence of Platform test cases */
  595. static const SDLTest_TestCaseReference *platformTests[] = {
  596. &intrinsicsTest1,
  597. &intrinsicsTest2,
  598. &intrinsicsTest3,
  599. &intrinsicsTest4,
  600. &intrinsicsTest5,
  601. &intrinsicsTest6,
  602. &intrinsicsTest7,
  603. &intrinsicsTest8,
  604. &intrinsicsTest9,
  605. &intrinsicsTest10,
  606. NULL
  607. };
  608. /* Platform test suite (global) */
  609. SDLTest_TestSuiteReference intrinsicsTestSuite = {
  610. "Intrinsics",
  611. NULL,
  612. platformTests,
  613. NULL
  614. };