fp-test.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * fp-test.c - test QEMU's softfloat implementation using Berkeley's Testfloat
  3. *
  4. * Copyright (C) 2018, Emilio G. Cota <cota@braap.org>
  5. *
  6. * License: GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. *
  9. * This file is derived from testfloat/source/testsoftfloat.c. Its copyright
  10. * info follows:
  11. *
  12. * Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
  13. * University of California. All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions, and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions, and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. *
  25. * 3. Neither the name of the University nor the names of its contributors may
  26. * be used to endorse or promote products derived from this software without
  27. * specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
  30. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
  32. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
  33. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  34. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  36. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. */
  40. #ifndef HW_POISON_H
  41. #error Must define HW_POISON_H to work around TARGET_* poisoning
  42. #endif
  43. #include "qemu/osdep.h"
  44. #include "qemu/cutils.h"
  45. #include <math.h>
  46. #include "fpu/softfloat.h"
  47. #include "platform.h"
  48. #include "fail.h"
  49. #include "slowfloat.h"
  50. #include "functions.h"
  51. #include "genCases.h"
  52. #include "verCases.h"
  53. #include "writeCase.h"
  54. #include "testLoops.h"
  55. typedef float16_t (*abz_f16)(float16_t, float16_t);
  56. typedef bool (*ab_f16_z_bool)(float16_t, float16_t);
  57. typedef float32_t (*abz_f32)(float32_t, float32_t);
  58. typedef bool (*ab_f32_z_bool)(float32_t, float32_t);
  59. typedef float64_t (*abz_f64)(float64_t, float64_t);
  60. typedef bool (*ab_f64_z_bool)(float64_t, float64_t);
  61. typedef void (*abz_extF80M)(const extFloat80_t *, const extFloat80_t *,
  62. extFloat80_t *);
  63. typedef bool (*ab_extF80M_z_bool)(const extFloat80_t *, const extFloat80_t *);
  64. typedef void (*abz_f128M)(const float128_t *, const float128_t *, float128_t *);
  65. typedef bool (*ab_f128M_z_bool)(const float128_t *, const float128_t *);
  66. static const char * const round_mode_names[] = {
  67. [ROUND_NEAR_EVEN] = "even",
  68. [ROUND_MINMAG] = "zero",
  69. [ROUND_MIN] = "down",
  70. [ROUND_MAX] = "up",
  71. [ROUND_NEAR_MAXMAG] = "tieaway",
  72. [ROUND_ODD] = "odd",
  73. };
  74. static unsigned int *test_ops;
  75. static unsigned int n_test_ops;
  76. static unsigned int n_max_errors = 20;
  77. static unsigned int test_round_mode = ROUND_NEAR_EVEN;
  78. static unsigned int *round_modes;
  79. static unsigned int n_round_modes;
  80. static int test_level = 1;
  81. static uint8_t slow_init_flags;
  82. static uint8_t qemu_init_flags;
  83. /* qemu softfloat status */
  84. static float_status qsf;
  85. static const char commands_string[] =
  86. "operations:\n"
  87. " <int>_to_<float> <float>_add <float>_eq\n"
  88. " <float>_to_<int> <float>_sub <float>_le\n"
  89. " <float>_to_<int>_r_minMag <float>_mul <float>_lt\n"
  90. " <float>_to_<float> <float>_mulAdd <float>_eq_signaling\n"
  91. " <float>_roundToInt <float>_div <float>_le_quiet\n"
  92. " <float>_rem <float>_lt_quiet\n"
  93. " <float>_sqrt\n"
  94. " Where <int>: ui32, ui64, i32, i64\n"
  95. " <float>: f16, f32, f64, extF80, f128\n"
  96. " If no operation is provided, all the above are tested\n"
  97. "options:\n"
  98. " -e = max error count per test. Default: 20. Set no limit with 0\n"
  99. " -f = initial FP exception flags (vioux). Default: none\n"
  100. " -l = thoroughness level (1 (default), 2)\n"
  101. " -r = rounding mode (even (default), zero, down, up, tieaway, odd)\n"
  102. " Set to 'all' to test all rounding modes, if applicable\n"
  103. " -s = stop when a test fails";
  104. static void usage_complete(int argc, char *argv[])
  105. {
  106. fprintf(stderr, "Usage: %s [options] [operation1 ...]\n", argv[0]);
  107. fprintf(stderr, "%s\n", commands_string);
  108. exit(EXIT_FAILURE);
  109. }
  110. /* keep wrappers separate but do not bother defining headers for all of them */
  111. #include "wrap.c.inc"
  112. static void not_implemented(void)
  113. {
  114. fprintf(stderr, "Not implemented.\n");
  115. }
  116. static bool blacklisted(unsigned op, int rmode)
  117. {
  118. /* odd has not been implemented for any 80-bit ops */
  119. if (rmode == softfloat_round_odd) {
  120. switch (op) {
  121. case EXTF80_TO_UI32:
  122. case EXTF80_TO_UI64:
  123. case EXTF80_TO_I32:
  124. case EXTF80_TO_I64:
  125. case EXTF80_TO_UI32_R_MINMAG:
  126. case EXTF80_TO_UI64_R_MINMAG:
  127. case EXTF80_TO_I32_R_MINMAG:
  128. case EXTF80_TO_I64_R_MINMAG:
  129. case EXTF80_TO_F16:
  130. case EXTF80_TO_F32:
  131. case EXTF80_TO_F64:
  132. case EXTF80_TO_F128:
  133. case EXTF80_ROUNDTOINT:
  134. case EXTF80_ADD:
  135. case EXTF80_SUB:
  136. case EXTF80_MUL:
  137. case EXTF80_DIV:
  138. case EXTF80_REM:
  139. case EXTF80_SQRT:
  140. case EXTF80_EQ:
  141. case EXTF80_LE:
  142. case EXTF80_LT:
  143. case EXTF80_EQ_SIGNALING:
  144. case EXTF80_LE_QUIET:
  145. case EXTF80_LT_QUIET:
  146. case UI32_TO_EXTF80:
  147. case UI64_TO_EXTF80:
  148. case I32_TO_EXTF80:
  149. case I64_TO_EXTF80:
  150. case F16_TO_EXTF80:
  151. case F32_TO_EXTF80:
  152. case F64_TO_EXTF80:
  153. case F128_TO_EXTF80:
  154. return true;
  155. }
  156. }
  157. return false;
  158. }
  159. static void do_testfloat(int op, int rmode, bool exact)
  160. {
  161. abz_f16 true_abz_f16;
  162. abz_f16 subj_abz_f16;
  163. ab_f16_z_bool true_f16_z_bool;
  164. ab_f16_z_bool subj_f16_z_bool;
  165. abz_f32 true_abz_f32;
  166. abz_f32 subj_abz_f32;
  167. ab_f32_z_bool true_ab_f32_z_bool;
  168. ab_f32_z_bool subj_ab_f32_z_bool;
  169. abz_f64 true_abz_f64;
  170. abz_f64 subj_abz_f64;
  171. ab_f64_z_bool true_ab_f64_z_bool;
  172. ab_f64_z_bool subj_ab_f64_z_bool;
  173. abz_extF80M true_abz_extF80M;
  174. abz_extF80M subj_abz_extF80M;
  175. ab_extF80M_z_bool true_ab_extF80M_z_bool;
  176. ab_extF80M_z_bool subj_ab_extF80M_z_bool;
  177. abz_f128M true_abz_f128M;
  178. abz_f128M subj_abz_f128M;
  179. ab_f128M_z_bool true_ab_f128M_z_bool;
  180. ab_f128M_z_bool subj_ab_f128M_z_bool;
  181. fputs(">> Testing ", stderr);
  182. verCases_writeFunctionName(stderr);
  183. fputs("\n", stderr);
  184. if (blacklisted(op, rmode)) {
  185. not_implemented();
  186. return;
  187. }
  188. switch (op) {
  189. case UI32_TO_F16:
  190. test_a_ui32_z_f16(slow_ui32_to_f16, qemu_ui32_to_f16);
  191. break;
  192. case UI32_TO_F32:
  193. test_a_ui32_z_f32(slow_ui32_to_f32, qemu_ui32_to_f32);
  194. break;
  195. case UI32_TO_F64:
  196. test_a_ui32_z_f64(slow_ui32_to_f64, qemu_ui32_to_f64);
  197. break;
  198. case UI32_TO_EXTF80:
  199. not_implemented();
  200. break;
  201. case UI32_TO_F128:
  202. not_implemented();
  203. break;
  204. case UI64_TO_F16:
  205. test_a_ui64_z_f16(slow_ui64_to_f16, qemu_ui64_to_f16);
  206. break;
  207. case UI64_TO_F32:
  208. test_a_ui64_z_f32(slow_ui64_to_f32, qemu_ui64_to_f32);
  209. break;
  210. case UI64_TO_F64:
  211. test_a_ui64_z_f64(slow_ui64_to_f64, qemu_ui64_to_f64);
  212. break;
  213. case UI64_TO_EXTF80:
  214. not_implemented();
  215. break;
  216. case UI64_TO_F128:
  217. test_a_ui64_z_f128(slow_ui64_to_f128M, qemu_ui64_to_f128M);
  218. break;
  219. case I32_TO_F16:
  220. test_a_i32_z_f16(slow_i32_to_f16, qemu_i32_to_f16);
  221. break;
  222. case I32_TO_F32:
  223. test_a_i32_z_f32(slow_i32_to_f32, qemu_i32_to_f32);
  224. break;
  225. case I32_TO_F64:
  226. test_a_i32_z_f64(slow_i32_to_f64, qemu_i32_to_f64);
  227. break;
  228. case I32_TO_EXTF80:
  229. test_a_i32_z_extF80(slow_i32_to_extF80M, qemu_i32_to_extF80M);
  230. break;
  231. case I32_TO_F128:
  232. test_a_i32_z_f128(slow_i32_to_f128M, qemu_i32_to_f128M);
  233. break;
  234. case I64_TO_F16:
  235. test_a_i64_z_f16(slow_i64_to_f16, qemu_i64_to_f16);
  236. break;
  237. case I64_TO_F32:
  238. test_a_i64_z_f32(slow_i64_to_f32, qemu_i64_to_f32);
  239. break;
  240. case I64_TO_F64:
  241. test_a_i64_z_f64(slow_i64_to_f64, qemu_i64_to_f64);
  242. break;
  243. case I64_TO_EXTF80:
  244. test_a_i64_z_extF80(slow_i64_to_extF80M, qemu_i64_to_extF80M);
  245. break;
  246. case I64_TO_F128:
  247. test_a_i64_z_f128(slow_i64_to_f128M, qemu_i64_to_f128M);
  248. break;
  249. case F16_TO_UI32:
  250. test_a_f16_z_ui32_rx(slow_f16_to_ui32, qemu_f16_to_ui32, rmode, exact);
  251. break;
  252. case F16_TO_UI64:
  253. test_a_f16_z_ui64_rx(slow_f16_to_ui64, qemu_f16_to_ui64, rmode, exact);
  254. break;
  255. case F16_TO_I32:
  256. test_a_f16_z_i32_rx(slow_f16_to_i32, qemu_f16_to_i32, rmode, exact);
  257. break;
  258. case F16_TO_I64:
  259. test_a_f16_z_i64_rx(slow_f16_to_i64, qemu_f16_to_i64, rmode, exact);
  260. break;
  261. case F16_TO_UI32_R_MINMAG:
  262. test_a_f16_z_ui32_x(slow_f16_to_ui32_r_minMag,
  263. qemu_f16_to_ui32_r_minMag, exact);
  264. break;
  265. case F16_TO_UI64_R_MINMAG:
  266. test_a_f16_z_ui64_x(slow_f16_to_ui64_r_minMag,
  267. qemu_f16_to_ui64_r_minMag, exact);
  268. break;
  269. case F16_TO_I32_R_MINMAG:
  270. test_a_f16_z_i32_x(slow_f16_to_i32_r_minMag, qemu_f16_to_i32_r_minMag,
  271. exact);
  272. break;
  273. case F16_TO_I64_R_MINMAG:
  274. test_a_f16_z_i64_x(slow_f16_to_i64_r_minMag, qemu_f16_to_i64_r_minMag,
  275. exact);
  276. break;
  277. case F16_TO_F32:
  278. test_a_f16_z_f32(slow_f16_to_f32, qemu_f16_to_f32);
  279. break;
  280. case F16_TO_F64:
  281. test_a_f16_z_f64(slow_f16_to_f64, qemu_f16_to_f64);
  282. break;
  283. case F16_TO_EXTF80:
  284. not_implemented();
  285. break;
  286. case F16_TO_F128:
  287. not_implemented();
  288. break;
  289. case F16_ROUNDTOINT:
  290. test_az_f16_rx(slow_f16_roundToInt, qemu_f16_roundToInt, rmode, exact);
  291. break;
  292. case F16_ADD:
  293. true_abz_f16 = slow_f16_add;
  294. subj_abz_f16 = qemu_f16_add;
  295. goto test_abz_f16;
  296. case F16_SUB:
  297. true_abz_f16 = slow_f16_sub;
  298. subj_abz_f16 = qemu_f16_sub;
  299. goto test_abz_f16;
  300. case F16_MUL:
  301. true_abz_f16 = slow_f16_mul;
  302. subj_abz_f16 = qemu_f16_mul;
  303. goto test_abz_f16;
  304. case F16_DIV:
  305. true_abz_f16 = slow_f16_div;
  306. subj_abz_f16 = qemu_f16_div;
  307. goto test_abz_f16;
  308. case F16_REM:
  309. not_implemented();
  310. break;
  311. test_abz_f16:
  312. test_abz_f16(true_abz_f16, subj_abz_f16);
  313. break;
  314. case F16_MULADD:
  315. test_abcz_f16(slow_f16_mulAdd, qemu_f16_mulAdd);
  316. break;
  317. case F16_SQRT:
  318. test_az_f16(slow_f16_sqrt, qemu_f16_sqrt);
  319. break;
  320. case F16_EQ:
  321. true_f16_z_bool = slow_f16_eq;
  322. subj_f16_z_bool = qemu_f16_eq;
  323. goto test_ab_f16_z_bool;
  324. case F16_LE:
  325. true_f16_z_bool = slow_f16_le;
  326. subj_f16_z_bool = qemu_f16_le;
  327. goto test_ab_f16_z_bool;
  328. case F16_LT:
  329. true_f16_z_bool = slow_f16_lt;
  330. subj_f16_z_bool = qemu_f16_lt;
  331. goto test_ab_f16_z_bool;
  332. case F16_EQ_SIGNALING:
  333. true_f16_z_bool = slow_f16_eq_signaling;
  334. subj_f16_z_bool = qemu_f16_eq_signaling;
  335. goto test_ab_f16_z_bool;
  336. case F16_LE_QUIET:
  337. true_f16_z_bool = slow_f16_le_quiet;
  338. subj_f16_z_bool = qemu_f16_le_quiet;
  339. goto test_ab_f16_z_bool;
  340. case F16_LT_QUIET:
  341. true_f16_z_bool = slow_f16_lt_quiet;
  342. subj_f16_z_bool = qemu_f16_lt_quiet;
  343. test_ab_f16_z_bool:
  344. test_ab_f16_z_bool(true_f16_z_bool, subj_f16_z_bool);
  345. break;
  346. case F32_TO_UI32:
  347. test_a_f32_z_ui32_rx(slow_f32_to_ui32, qemu_f32_to_ui32, rmode, exact);
  348. break;
  349. case F32_TO_UI64:
  350. test_a_f32_z_ui64_rx(slow_f32_to_ui64, qemu_f32_to_ui64, rmode, exact);
  351. break;
  352. case F32_TO_I32:
  353. test_a_f32_z_i32_rx(slow_f32_to_i32, qemu_f32_to_i32, rmode, exact);
  354. break;
  355. case F32_TO_I64:
  356. test_a_f32_z_i64_rx(slow_f32_to_i64, qemu_f32_to_i64, rmode, exact);
  357. break;
  358. case F32_TO_UI32_R_MINMAG:
  359. test_a_f32_z_ui32_x(slow_f32_to_ui32_r_minMag,
  360. qemu_f32_to_ui32_r_minMag, exact);
  361. break;
  362. case F32_TO_UI64_R_MINMAG:
  363. test_a_f32_z_ui64_x(slow_f32_to_ui64_r_minMag,
  364. qemu_f32_to_ui64_r_minMag, exact);
  365. break;
  366. case F32_TO_I32_R_MINMAG:
  367. test_a_f32_z_i32_x(slow_f32_to_i32_r_minMag, qemu_f32_to_i32_r_minMag,
  368. exact);
  369. break;
  370. case F32_TO_I64_R_MINMAG:
  371. test_a_f32_z_i64_x(slow_f32_to_i64_r_minMag, qemu_f32_to_i64_r_minMag,
  372. exact);
  373. break;
  374. case F32_TO_F16:
  375. test_a_f32_z_f16(slow_f32_to_f16, qemu_f32_to_f16);
  376. break;
  377. case F32_TO_F64:
  378. test_a_f32_z_f64(slow_f32_to_f64, qemu_f32_to_f64);
  379. break;
  380. case F32_TO_EXTF80:
  381. test_a_f32_z_extF80(slow_f32_to_extF80M, qemu_f32_to_extF80M);
  382. break;
  383. case F32_TO_F128:
  384. test_a_f32_z_f128(slow_f32_to_f128M, qemu_f32_to_f128M);
  385. break;
  386. case F32_ROUNDTOINT:
  387. test_az_f32_rx(slow_f32_roundToInt, qemu_f32_roundToInt, rmode, exact);
  388. break;
  389. case F32_ADD:
  390. true_abz_f32 = slow_f32_add;
  391. subj_abz_f32 = qemu_f32_add;
  392. goto test_abz_f32;
  393. case F32_SUB:
  394. true_abz_f32 = slow_f32_sub;
  395. subj_abz_f32 = qemu_f32_sub;
  396. goto test_abz_f32;
  397. case F32_MUL:
  398. true_abz_f32 = slow_f32_mul;
  399. subj_abz_f32 = qemu_f32_mul;
  400. goto test_abz_f32;
  401. case F32_DIV:
  402. true_abz_f32 = slow_f32_div;
  403. subj_abz_f32 = qemu_f32_div;
  404. goto test_abz_f32;
  405. case F32_REM:
  406. true_abz_f32 = slow_f32_rem;
  407. subj_abz_f32 = qemu_f32_rem;
  408. test_abz_f32:
  409. test_abz_f32(true_abz_f32, subj_abz_f32);
  410. break;
  411. case F32_MULADD:
  412. test_abcz_f32(slow_f32_mulAdd, qemu_f32_mulAdd);
  413. break;
  414. case F32_SQRT:
  415. test_az_f32(slow_f32_sqrt, qemu_f32_sqrt);
  416. break;
  417. case F32_EQ:
  418. true_ab_f32_z_bool = slow_f32_eq;
  419. subj_ab_f32_z_bool = qemu_f32_eq;
  420. goto test_ab_f32_z_bool;
  421. case F32_LE:
  422. true_ab_f32_z_bool = slow_f32_le;
  423. subj_ab_f32_z_bool = qemu_f32_le;
  424. goto test_ab_f32_z_bool;
  425. case F32_LT:
  426. true_ab_f32_z_bool = slow_f32_lt;
  427. subj_ab_f32_z_bool = qemu_f32_lt;
  428. goto test_ab_f32_z_bool;
  429. case F32_EQ_SIGNALING:
  430. true_ab_f32_z_bool = slow_f32_eq_signaling;
  431. subj_ab_f32_z_bool = qemu_f32_eq_signaling;
  432. goto test_ab_f32_z_bool;
  433. case F32_LE_QUIET:
  434. true_ab_f32_z_bool = slow_f32_le_quiet;
  435. subj_ab_f32_z_bool = qemu_f32_le_quiet;
  436. goto test_ab_f32_z_bool;
  437. case F32_LT_QUIET:
  438. true_ab_f32_z_bool = slow_f32_lt_quiet;
  439. subj_ab_f32_z_bool = qemu_f32_lt_quiet;
  440. test_ab_f32_z_bool:
  441. test_ab_f32_z_bool(true_ab_f32_z_bool, subj_ab_f32_z_bool);
  442. break;
  443. case F64_TO_UI32:
  444. test_a_f64_z_ui32_rx(slow_f64_to_ui32, qemu_f64_to_ui32, rmode, exact);
  445. break;
  446. case F64_TO_UI64:
  447. test_a_f64_z_ui64_rx(slow_f64_to_ui64, qemu_f64_to_ui64, rmode, exact);
  448. break;
  449. case F64_TO_I32:
  450. test_a_f64_z_i32_rx(slow_f64_to_i32, qemu_f64_to_i32, rmode, exact);
  451. break;
  452. case F64_TO_I64:
  453. test_a_f64_z_i64_rx(slow_f64_to_i64, qemu_f64_to_i64, rmode, exact);
  454. break;
  455. case F64_TO_UI32_R_MINMAG:
  456. test_a_f64_z_ui32_x(slow_f64_to_ui32_r_minMag,
  457. qemu_f64_to_ui32_r_minMag, exact);
  458. break;
  459. case F64_TO_UI64_R_MINMAG:
  460. test_a_f64_z_ui64_x(slow_f64_to_ui64_r_minMag,
  461. qemu_f64_to_ui64_r_minMag, exact);
  462. break;
  463. case F64_TO_I32_R_MINMAG:
  464. test_a_f64_z_i32_x(slow_f64_to_i32_r_minMag, qemu_f64_to_i32_r_minMag,
  465. exact);
  466. break;
  467. case F64_TO_I64_R_MINMAG:
  468. test_a_f64_z_i64_x(slow_f64_to_i64_r_minMag, qemu_f64_to_i64_r_minMag,
  469. exact);
  470. break;
  471. case F64_TO_F16:
  472. test_a_f64_z_f16(slow_f64_to_f16, qemu_f64_to_f16);
  473. break;
  474. case F64_TO_F32:
  475. test_a_f64_z_f32(slow_f64_to_f32, qemu_f64_to_f32);
  476. break;
  477. case F64_TO_EXTF80:
  478. test_a_f64_z_extF80(slow_f64_to_extF80M, qemu_f64_to_extF80M);
  479. break;
  480. case F64_TO_F128:
  481. test_a_f64_z_f128(slow_f64_to_f128M, qemu_f64_to_f128M);
  482. break;
  483. case F64_ROUNDTOINT:
  484. test_az_f64_rx(slow_f64_roundToInt, qemu_f64_roundToInt, rmode, exact);
  485. break;
  486. case F64_ADD:
  487. true_abz_f64 = slow_f64_add;
  488. subj_abz_f64 = qemu_f64_add;
  489. goto test_abz_f64;
  490. case F64_SUB:
  491. true_abz_f64 = slow_f64_sub;
  492. subj_abz_f64 = qemu_f64_sub;
  493. goto test_abz_f64;
  494. case F64_MUL:
  495. true_abz_f64 = slow_f64_mul;
  496. subj_abz_f64 = qemu_f64_mul;
  497. goto test_abz_f64;
  498. case F64_DIV:
  499. true_abz_f64 = slow_f64_div;
  500. subj_abz_f64 = qemu_f64_div;
  501. goto test_abz_f64;
  502. case F64_REM:
  503. true_abz_f64 = slow_f64_rem;
  504. subj_abz_f64 = qemu_f64_rem;
  505. test_abz_f64:
  506. test_abz_f64(true_abz_f64, subj_abz_f64);
  507. break;
  508. case F64_MULADD:
  509. test_abcz_f64(slow_f64_mulAdd, qemu_f64_mulAdd);
  510. break;
  511. case F64_SQRT:
  512. test_az_f64(slow_f64_sqrt, qemu_f64_sqrt);
  513. break;
  514. case F64_EQ:
  515. true_ab_f64_z_bool = slow_f64_eq;
  516. subj_ab_f64_z_bool = qemu_f64_eq;
  517. goto test_ab_f64_z_bool;
  518. case F64_LE:
  519. true_ab_f64_z_bool = slow_f64_le;
  520. subj_ab_f64_z_bool = qemu_f64_le;
  521. goto test_ab_f64_z_bool;
  522. case F64_LT:
  523. true_ab_f64_z_bool = slow_f64_lt;
  524. subj_ab_f64_z_bool = qemu_f64_lt;
  525. goto test_ab_f64_z_bool;
  526. case F64_EQ_SIGNALING:
  527. true_ab_f64_z_bool = slow_f64_eq_signaling;
  528. subj_ab_f64_z_bool = qemu_f64_eq_signaling;
  529. goto test_ab_f64_z_bool;
  530. case F64_LE_QUIET:
  531. true_ab_f64_z_bool = slow_f64_le_quiet;
  532. subj_ab_f64_z_bool = qemu_f64_le_quiet;
  533. goto test_ab_f64_z_bool;
  534. case F64_LT_QUIET:
  535. true_ab_f64_z_bool = slow_f64_lt_quiet;
  536. subj_ab_f64_z_bool = qemu_f64_lt_quiet;
  537. test_ab_f64_z_bool:
  538. test_ab_f64_z_bool(true_ab_f64_z_bool, subj_ab_f64_z_bool);
  539. break;
  540. case EXTF80_TO_UI32:
  541. not_implemented();
  542. break;
  543. case EXTF80_TO_UI64:
  544. not_implemented();
  545. break;
  546. case EXTF80_TO_I32:
  547. test_a_extF80_z_i32_rx(slow_extF80M_to_i32, qemu_extF80M_to_i32, rmode,
  548. exact);
  549. break;
  550. case EXTF80_TO_I64:
  551. test_a_extF80_z_i64_rx(slow_extF80M_to_i64, qemu_extF80M_to_i64, rmode,
  552. exact);
  553. break;
  554. case EXTF80_TO_UI32_R_MINMAG:
  555. not_implemented();
  556. break;
  557. case EXTF80_TO_UI64_R_MINMAG:
  558. not_implemented();
  559. break;
  560. case EXTF80_TO_I32_R_MINMAG:
  561. test_a_extF80_z_i32_x(slow_extF80M_to_i32_r_minMag,
  562. qemu_extF80M_to_i32_r_minMag, exact);
  563. break;
  564. case EXTF80_TO_I64_R_MINMAG:
  565. test_a_extF80_z_i64_x(slow_extF80M_to_i64_r_minMag,
  566. qemu_extF80M_to_i64_r_minMag, exact);
  567. break;
  568. case EXTF80_TO_F16:
  569. not_implemented();
  570. break;
  571. case EXTF80_TO_F32:
  572. test_a_extF80_z_f32(slow_extF80M_to_f32, qemu_extF80M_to_f32);
  573. break;
  574. case EXTF80_TO_F64:
  575. test_a_extF80_z_f64(slow_extF80M_to_f64, qemu_extF80M_to_f64);
  576. break;
  577. case EXTF80_TO_F128:
  578. test_a_extF80_z_f128(slow_extF80M_to_f128M, qemu_extF80M_to_f128M);
  579. break;
  580. case EXTF80_ROUNDTOINT:
  581. test_az_extF80_rx(slow_extF80M_roundToInt, qemu_extF80M_roundToInt,
  582. rmode, exact);
  583. break;
  584. case EXTF80_ADD:
  585. true_abz_extF80M = slow_extF80M_add;
  586. subj_abz_extF80M = qemu_extF80M_add;
  587. goto test_abz_extF80;
  588. case EXTF80_SUB:
  589. true_abz_extF80M = slow_extF80M_sub;
  590. subj_abz_extF80M = qemu_extF80M_sub;
  591. goto test_abz_extF80;
  592. case EXTF80_MUL:
  593. true_abz_extF80M = slow_extF80M_mul;
  594. subj_abz_extF80M = qemu_extF80M_mul;
  595. goto test_abz_extF80;
  596. case EXTF80_DIV:
  597. true_abz_extF80M = slow_extF80M_div;
  598. subj_abz_extF80M = qemu_extF80M_div;
  599. goto test_abz_extF80;
  600. case EXTF80_REM:
  601. true_abz_extF80M = slow_extF80M_rem;
  602. subj_abz_extF80M = qemu_extF80M_rem;
  603. test_abz_extF80:
  604. test_abz_extF80(true_abz_extF80M, subj_abz_extF80M);
  605. break;
  606. case EXTF80_SQRT:
  607. test_az_extF80(slow_extF80M_sqrt, qemu_extF80M_sqrt);
  608. break;
  609. case EXTF80_EQ:
  610. true_ab_extF80M_z_bool = slow_extF80M_eq;
  611. subj_ab_extF80M_z_bool = qemu_extF80M_eq;
  612. goto test_ab_extF80_z_bool;
  613. case EXTF80_LE:
  614. true_ab_extF80M_z_bool = slow_extF80M_le;
  615. subj_ab_extF80M_z_bool = qemu_extF80M_le;
  616. goto test_ab_extF80_z_bool;
  617. case EXTF80_LT:
  618. true_ab_extF80M_z_bool = slow_extF80M_lt;
  619. subj_ab_extF80M_z_bool = qemu_extF80M_lt;
  620. goto test_ab_extF80_z_bool;
  621. case EXTF80_EQ_SIGNALING:
  622. true_ab_extF80M_z_bool = slow_extF80M_eq_signaling;
  623. subj_ab_extF80M_z_bool = qemu_extF80M_eq_signaling;
  624. goto test_ab_extF80_z_bool;
  625. case EXTF80_LE_QUIET:
  626. true_ab_extF80M_z_bool = slow_extF80M_le_quiet;
  627. subj_ab_extF80M_z_bool = qemu_extF80M_le_quiet;
  628. goto test_ab_extF80_z_bool;
  629. case EXTF80_LT_QUIET:
  630. true_ab_extF80M_z_bool = slow_extF80M_lt_quiet;
  631. subj_ab_extF80M_z_bool = qemu_extF80M_lt_quiet;
  632. test_ab_extF80_z_bool:
  633. test_ab_extF80_z_bool(true_ab_extF80M_z_bool, subj_ab_extF80M_z_bool);
  634. break;
  635. case F128_TO_UI32:
  636. test_a_f128_z_ui32_rx(slow_f128M_to_ui32, qemu_f128M_to_ui32, rmode,
  637. exact);
  638. break;
  639. case F128_TO_UI64:
  640. test_a_f128_z_ui64_rx(slow_f128M_to_ui64, qemu_f128M_to_ui64, rmode,
  641. exact);
  642. break;
  643. case F128_TO_I32:
  644. test_a_f128_z_i32_rx(slow_f128M_to_i32, qemu_f128M_to_i32, rmode,
  645. exact);
  646. break;
  647. case F128_TO_I64:
  648. test_a_f128_z_i64_rx(slow_f128M_to_i64, qemu_f128M_to_i64, rmode,
  649. exact);
  650. break;
  651. case F128_TO_UI32_R_MINMAG:
  652. test_a_f128_z_ui32_x(slow_f128M_to_ui32_r_minMag,
  653. qemu_f128M_to_ui32_r_minMag, exact);
  654. break;
  655. case F128_TO_UI64_R_MINMAG:
  656. test_a_f128_z_ui64_x(slow_f128M_to_ui64_r_minMag,
  657. qemu_f128M_to_ui64_r_minMag, exact);
  658. break;
  659. case F128_TO_I32_R_MINMAG:
  660. test_a_f128_z_i32_x(slow_f128M_to_i32_r_minMag,
  661. qemu_f128M_to_i32_r_minMag, exact);
  662. break;
  663. case F128_TO_I64_R_MINMAG:
  664. test_a_f128_z_i64_x(slow_f128M_to_i64_r_minMag,
  665. qemu_f128M_to_i64_r_minMag, exact);
  666. break;
  667. case F128_TO_F16:
  668. not_implemented();
  669. break;
  670. case F128_TO_F32:
  671. test_a_f128_z_f32(slow_f128M_to_f32, qemu_f128M_to_f32);
  672. break;
  673. case F128_TO_F64:
  674. test_a_f128_z_f64(slow_f128M_to_f64, qemu_f128M_to_f64);
  675. break;
  676. case F128_TO_EXTF80:
  677. test_a_f128_z_extF80(slow_f128M_to_extF80M, qemu_f128M_to_extF80M);
  678. break;
  679. case F128_ROUNDTOINT:
  680. test_az_f128_rx(slow_f128M_roundToInt, qemu_f128M_roundToInt, rmode,
  681. exact);
  682. break;
  683. case F128_ADD:
  684. true_abz_f128M = slow_f128M_add;
  685. subj_abz_f128M = qemu_f128M_add;
  686. goto test_abz_f128;
  687. case F128_SUB:
  688. true_abz_f128M = slow_f128M_sub;
  689. subj_abz_f128M = qemu_f128M_sub;
  690. goto test_abz_f128;
  691. case F128_MUL:
  692. true_abz_f128M = slow_f128M_mul;
  693. subj_abz_f128M = qemu_f128M_mul;
  694. goto test_abz_f128;
  695. case F128_DIV:
  696. true_abz_f128M = slow_f128M_div;
  697. subj_abz_f128M = qemu_f128M_div;
  698. goto test_abz_f128;
  699. case F128_REM:
  700. true_abz_f128M = slow_f128M_rem;
  701. subj_abz_f128M = qemu_f128M_rem;
  702. test_abz_f128:
  703. test_abz_f128(true_abz_f128M, subj_abz_f128M);
  704. break;
  705. case F128_MULADD:
  706. not_implemented();
  707. break;
  708. case F128_SQRT:
  709. test_az_f128(slow_f128M_sqrt, qemu_f128M_sqrt);
  710. break;
  711. case F128_EQ:
  712. true_ab_f128M_z_bool = slow_f128M_eq;
  713. subj_ab_f128M_z_bool = qemu_f128M_eq;
  714. goto test_ab_f128_z_bool;
  715. case F128_LE:
  716. true_ab_f128M_z_bool = slow_f128M_le;
  717. subj_ab_f128M_z_bool = qemu_f128M_le;
  718. goto test_ab_f128_z_bool;
  719. case F128_LT:
  720. true_ab_f128M_z_bool = slow_f128M_lt;
  721. subj_ab_f128M_z_bool = qemu_f128M_lt;
  722. goto test_ab_f128_z_bool;
  723. case F128_EQ_SIGNALING:
  724. true_ab_f128M_z_bool = slow_f128M_eq_signaling;
  725. subj_ab_f128M_z_bool = qemu_f128M_eq_signaling;
  726. goto test_ab_f128_z_bool;
  727. case F128_LE_QUIET:
  728. true_ab_f128M_z_bool = slow_f128M_le_quiet;
  729. subj_ab_f128M_z_bool = qemu_f128M_le_quiet;
  730. goto test_ab_f128_z_bool;
  731. case F128_LT_QUIET:
  732. true_ab_f128M_z_bool = slow_f128M_lt_quiet;
  733. subj_ab_f128M_z_bool = qemu_f128M_lt_quiet;
  734. test_ab_f128_z_bool:
  735. test_ab_f128_z_bool(true_ab_f128M_z_bool, subj_ab_f128M_z_bool);
  736. break;
  737. }
  738. if ((verCases_errorStop && verCases_anyErrors)) {
  739. verCases_exitWithStatus();
  740. }
  741. }
  742. static unsigned int test_name_to_op(const char *arg)
  743. {
  744. unsigned int i;
  745. /* counting begins at 1 */
  746. for (i = 1; i < NUM_FUNCTIONS; i++) {
  747. const char *name = functionInfos[i].namePtr;
  748. if (name && !strcmp(name, arg)) {
  749. return i;
  750. }
  751. }
  752. return 0;
  753. }
  754. static unsigned int round_name_to_mode(const char *name)
  755. {
  756. int i;
  757. /* counting begins at 1 */
  758. for (i = 1; i < NUM_ROUNDINGMODES; i++) {
  759. if (!strcmp(round_mode_names[i], name)) {
  760. return i;
  761. }
  762. }
  763. return 0;
  764. }
  765. static int set_init_flags(const char *flags)
  766. {
  767. const char *p;
  768. for (p = flags; *p != '\0'; p++) {
  769. switch (*p) {
  770. case 'v':
  771. slow_init_flags |= softfloat_flag_invalid;
  772. qemu_init_flags |= float_flag_invalid;
  773. break;
  774. case 'i':
  775. slow_init_flags |= softfloat_flag_infinite;
  776. qemu_init_flags |= float_flag_divbyzero;
  777. break;
  778. case 'o':
  779. slow_init_flags |= softfloat_flag_overflow;
  780. qemu_init_flags |= float_flag_overflow;
  781. break;
  782. case 'u':
  783. slow_init_flags |= softfloat_flag_underflow;
  784. qemu_init_flags |= float_flag_underflow;
  785. break;
  786. case 'x':
  787. slow_init_flags |= softfloat_flag_inexact;
  788. qemu_init_flags |= float_flag_inexact;
  789. break;
  790. default:
  791. return 1;
  792. }
  793. }
  794. return 0;
  795. }
  796. static uint_fast8_t slow_clear_flags(void)
  797. {
  798. uint8_t prev = slowfloat_exceptionFlags;
  799. slowfloat_exceptionFlags = slow_init_flags;
  800. return prev;
  801. }
  802. static uint_fast8_t qemu_clear_flags(void)
  803. {
  804. uint8_t prev = qemu_flags_to_sf(qsf.float_exception_flags);
  805. qsf.float_exception_flags = qemu_init_flags;
  806. return prev;
  807. }
  808. static void parse_args(int argc, char *argv[])
  809. {
  810. unsigned int i;
  811. int c;
  812. for (;;) {
  813. c = getopt(argc, argv, "he:f:l:r:s");
  814. if (c < 0) {
  815. break;
  816. }
  817. switch (c) {
  818. case 'h':
  819. usage_complete(argc, argv);
  820. exit(EXIT_SUCCESS);
  821. case 'e':
  822. if (qemu_strtoui(optarg, NULL, 0, &n_max_errors)) {
  823. fprintf(stderr, "fatal: invalid max error count\n");
  824. exit(EXIT_FAILURE);
  825. }
  826. break;
  827. case 'f':
  828. if (set_init_flags(optarg)) {
  829. fprintf(stderr, "fatal: flags must be a subset of 'vioux'\n");
  830. exit(EXIT_FAILURE);
  831. }
  832. break;
  833. case 'l':
  834. if (qemu_strtoi(optarg, NULL, 0, &test_level)) {
  835. fprintf(stderr, "fatal: invalid test level\n");
  836. exit(EXIT_FAILURE);
  837. }
  838. break;
  839. case 'r':
  840. if (!strcmp(optarg, "all")) {
  841. test_round_mode = 0;
  842. } else {
  843. test_round_mode = round_name_to_mode(optarg);
  844. if (test_round_mode == 0) {
  845. fprintf(stderr, "fatal: invalid rounding mode\n");
  846. exit(EXIT_FAILURE);
  847. }
  848. }
  849. break;
  850. case 's':
  851. verCases_errorStop = true;
  852. break;
  853. case '?':
  854. /* invalid option or missing argument; getopt prints error info */
  855. exit(EXIT_FAILURE);
  856. }
  857. }
  858. /* set rounding modes */
  859. if (test_round_mode == 0) {
  860. /* test all rounding modes; note that counting begins at 1 */
  861. n_round_modes = NUM_ROUNDINGMODES - 1;
  862. round_modes = g_malloc_n(n_round_modes, sizeof(*round_modes));
  863. for (i = 0; i < n_round_modes; i++) {
  864. round_modes[i] = i + 1;
  865. }
  866. } else {
  867. n_round_modes = 1;
  868. round_modes = g_malloc(sizeof(*round_modes));
  869. round_modes[0] = test_round_mode;
  870. }
  871. /* set test ops */
  872. if (optind == argc) {
  873. /* test all ops; note that counting begins at 1 */
  874. n_test_ops = NUM_FUNCTIONS - 1;
  875. test_ops = g_malloc_n(n_test_ops, sizeof(*test_ops));
  876. for (i = 0; i < n_test_ops; i++) {
  877. test_ops[i] = i + 1;
  878. }
  879. } else {
  880. n_test_ops = argc - optind;
  881. test_ops = g_malloc_n(n_test_ops, sizeof(*test_ops));
  882. for (i = 0; i < n_test_ops; i++) {
  883. const char *name = argv[i + optind];
  884. unsigned int op = test_name_to_op(name);
  885. if (op == 0) {
  886. fprintf(stderr, "fatal: invalid op '%s'\n", name);
  887. exit(EXIT_FAILURE);
  888. }
  889. test_ops[i] = op;
  890. }
  891. }
  892. }
  893. static void QEMU_NORETURN run_test(void)
  894. {
  895. unsigned int i;
  896. genCases_setLevel(test_level);
  897. verCases_maxErrorCount = n_max_errors;
  898. testLoops_trueFlagsFunction = slow_clear_flags;
  899. testLoops_subjFlagsFunction = qemu_clear_flags;
  900. for (i = 0; i < n_test_ops; i++) {
  901. unsigned int op = test_ops[i];
  902. int j;
  903. if (functionInfos[op].namePtr == NULL) {
  904. continue;
  905. }
  906. verCases_functionNamePtr = functionInfos[op].namePtr;
  907. for (j = 0; j < n_round_modes; j++) {
  908. int attrs = functionInfos[op].attribs;
  909. int round = round_modes[j];
  910. int rmode = roundingModes[round];
  911. int k;
  912. verCases_roundingCode = 0;
  913. slowfloat_roundingMode = rmode;
  914. qsf.float_rounding_mode = sf_rounding_to_qemu(rmode);
  915. if (attrs & (FUNC_ARG_ROUNDINGMODE | FUNC_EFF_ROUNDINGMODE)) {
  916. /* print rounding mode if the op is affected by it */
  917. verCases_roundingCode = round;
  918. } else if (j > 0) {
  919. /* if the op is not sensitive to rounding, move on */
  920. break;
  921. }
  922. /* QEMU doesn't have !exact */
  923. verCases_exact = true;
  924. verCases_usesExact = !!(attrs & FUNC_ARG_EXACT);
  925. for (k = 0; k < 3; k++) {
  926. int prec80 = 32;
  927. int l;
  928. if (k == 1) {
  929. prec80 = 64;
  930. } else if (k == 2) {
  931. prec80 = 80;
  932. }
  933. verCases_roundingPrecision = 0;
  934. slow_extF80_roundingPrecision = prec80;
  935. qsf.floatx80_rounding_precision = prec80;
  936. if (attrs & FUNC_EFF_ROUNDINGPRECISION) {
  937. verCases_roundingPrecision = prec80;
  938. } else if (k > 0) {
  939. /* if the op is not sensitive to prec80, move on */
  940. break;
  941. }
  942. /* note: the count begins at 1 */
  943. for (l = 1; l < NUM_TININESSMODES; l++) {
  944. int tmode = tininessModes[l];
  945. verCases_tininessCode = 0;
  946. slowfloat_detectTininess = tmode;
  947. qsf.tininess_before_rounding = sf_tininess_to_qemu(tmode);
  948. if (attrs & FUNC_EFF_TININESSMODE ||
  949. ((attrs & FUNC_EFF_TININESSMODE_REDUCEDPREC) &&
  950. prec80 && prec80 < 80)) {
  951. verCases_tininessCode = l;
  952. } else if (l > 1) {
  953. /* if the op is not sensitive to tininess, move on */
  954. break;
  955. }
  956. do_testfloat(op, rmode, true);
  957. }
  958. }
  959. }
  960. }
  961. verCases_exitWithStatus();
  962. /* old compilers might miss that we exited */
  963. g_assert_not_reached();
  964. }
  965. int main(int argc, char *argv[])
  966. {
  967. parse_args(argc, argv);
  968. fail_programName = argv[0];
  969. run_test(); /* does not return */
  970. }