fp-test.c 34 KB

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