3 ===============================================================================
5 This C source file is part of TestFloat, Release 2a, a package of programs
6 for testing the correctness of floating-point arithmetic complying to the
7 IEC/IEEE Standard for Floating-Point.
9 Written by John R. Hauser. More information is available through the Web
10 page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
12 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
13 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
14 TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
15 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
16 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
18 Derivative works are acceptable, even for commercial purposes, so long as
19 (1) they include prominent notice that the work is derivative, and (2) they
20 include prominent notice akin to these four paragraphs for those parts of
21 this code that are retained.
23 ===============================================================================
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
34 #include "softfloat.h"
35 #include "slowfloat.h"
36 #include "testCases.h"
37 #include "testLoops.h"
39 static void catchSIGINT( int signalCode )
42 if ( stop ) exit( EXIT_FAILURE );
47 int8 clearFlags( void )
51 flags = float_exception_flags;
52 float_exception_flags = 0;
77 FLOAT32_TO_INT32_ROUND_TO_ZERO,
80 FLOAT32_TO_INT64_ROUND_TO_ZERO,
103 FLOAT64_TO_INT32_ROUND_TO_ZERO,
106 FLOAT64_TO_INT64_ROUND_TO_ZERO,
115 FLOAT64_ROUND_TO_INT,
125 FLOAT64_EQ_SIGNALING,
130 FLOATX80_TO_INT32_ROUND_TO_ZERO,
133 FLOATX80_TO_INT64_ROUND_TO_ZERO,
138 FLOATX80_TO_FLOAT128,
140 FLOATX80_ROUND_TO_INT,
150 FLOATX80_EQ_SIGNALING,
156 FLOAT128_TO_INT32_ROUND_TO_ZERO,
159 FLOAT128_TO_INT64_ROUND_TO_ZERO,
164 FLOAT128_TO_FLOATX80,
166 FLOAT128_ROUND_TO_INT,
176 FLOAT128_EQ_SIGNALING,
185 flag roundingPrecision, roundingMode;
186 flag tininessMode, tininessModeAtReducedPrecision;
187 } functions[ NUM_FUNCTIONS ] = {
188 { 0, 0, 0, 0, 0, 0 },
189 { "int32_to_float32", 1, FALSE, TRUE, FALSE, FALSE },
190 { "int32_to_float64", 1, FALSE, FALSE, FALSE, FALSE },
192 { "int32_to_floatx80", 1, FALSE, FALSE, FALSE, FALSE },
195 { "int32_to_float128", 1, FALSE, FALSE, FALSE, FALSE },
198 { "int64_to_float32", 1, FALSE, TRUE, FALSE, FALSE },
199 { "int64_to_float64", 1, FALSE, TRUE, FALSE, FALSE },
201 { "int64_to_floatx80", 1, FALSE, FALSE, FALSE, FALSE },
204 { "int64_to_float128", 1, FALSE, FALSE, FALSE, FALSE },
207 { "float32_to_int32", 1, FALSE, TRUE, FALSE, FALSE },
208 { "float32_to_int32_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
210 { "float32_to_int64", 1, FALSE, TRUE, FALSE, FALSE },
211 { "float32_to_int64_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
213 { "float32_to_float64", 1, FALSE, FALSE, FALSE, FALSE },
215 { "float32_to_floatx80", 1, FALSE, FALSE, FALSE, FALSE },
218 { "float32_to_float128", 1, FALSE, FALSE, FALSE, FALSE },
220 { "float32_round_to_int", 1, FALSE, TRUE, FALSE, FALSE },
221 { "float32_add", 2, FALSE, TRUE, FALSE, FALSE },
222 { "float32_sub", 2, FALSE, TRUE, FALSE, FALSE },
223 { "float32_mul", 2, FALSE, TRUE, TRUE, FALSE },
224 { "float32_div", 2, FALSE, TRUE, FALSE, FALSE },
225 { "float32_rem", 2, FALSE, FALSE, FALSE, FALSE },
226 { "float32_sqrt", 1, FALSE, TRUE, FALSE, FALSE },
227 { "float32_eq", 2, FALSE, FALSE, FALSE, FALSE },
228 { "float32_le", 2, FALSE, FALSE, FALSE, FALSE },
229 { "float32_lt", 2, FALSE, FALSE, FALSE, FALSE },
230 { "float32_eq_signaling", 2, FALSE, FALSE, FALSE, FALSE },
231 { "float32_le_quiet", 2, FALSE, FALSE, FALSE, FALSE },
232 { "float32_lt_quiet", 2, FALSE, FALSE, FALSE, FALSE },
233 { "float64_to_int32", 1, FALSE, TRUE, FALSE, FALSE },
234 { "float64_to_int32_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
236 { "float64_to_int64", 1, FALSE, TRUE, FALSE, FALSE },
237 { "float64_to_int64_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
239 { "float64_to_float32", 1, FALSE, TRUE, TRUE, FALSE },
241 { "float64_to_floatx80", 1, FALSE, FALSE, FALSE, FALSE },
244 { "float64_to_float128", 1, FALSE, FALSE, FALSE, FALSE },
246 { "float64_round_to_int", 1, FALSE, TRUE, FALSE, FALSE },
247 { "float64_add", 2, FALSE, TRUE, FALSE, FALSE },
248 { "float64_sub", 2, FALSE, TRUE, FALSE, FALSE },
249 { "float64_mul", 2, FALSE, TRUE, TRUE, FALSE },
250 { "float64_div", 2, FALSE, TRUE, FALSE, FALSE },
251 { "float64_rem", 2, FALSE, FALSE, FALSE, FALSE },
252 { "float64_sqrt", 1, FALSE, TRUE, FALSE, FALSE },
253 { "float64_eq", 2, FALSE, FALSE, FALSE, FALSE },
254 { "float64_le", 2, FALSE, FALSE, FALSE, FALSE },
255 { "float64_lt", 2, FALSE, FALSE, FALSE, FALSE },
256 { "float64_eq_signaling", 2, FALSE, FALSE, FALSE, FALSE },
257 { "float64_le_quiet", 2, FALSE, FALSE, FALSE, FALSE },
258 { "float64_lt_quiet", 2, FALSE, FALSE, FALSE, FALSE },
260 { "floatx80_to_int32", 1, FALSE, TRUE, FALSE, FALSE },
261 { "floatx80_to_int32_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
263 { "floatx80_to_int64", 1, FALSE, TRUE, FALSE, FALSE },
264 { "floatx80_to_int64_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
266 { "floatx80_to_float32", 1, FALSE, TRUE, TRUE, FALSE },
267 { "floatx80_to_float64", 1, FALSE, TRUE, TRUE, FALSE },
269 { "floatx80_to_float128", 1, FALSE, FALSE, FALSE, FALSE },
271 { "floatx80_round_to_int", 1, FALSE, TRUE, FALSE, FALSE },
272 { "floatx80_add", 2, TRUE, TRUE, FALSE, TRUE },
273 { "floatx80_sub", 2, TRUE, TRUE, FALSE, TRUE },
274 { "floatx80_mul", 2, TRUE, TRUE, TRUE, TRUE },
275 { "floatx80_div", 2, TRUE, TRUE, FALSE, TRUE },
276 { "floatx80_rem", 2, FALSE, FALSE, FALSE, FALSE },
277 { "floatx80_sqrt", 1, TRUE, TRUE, FALSE, FALSE },
278 { "floatx80_eq", 2, FALSE, FALSE, FALSE, FALSE },
279 { "floatx80_le", 2, FALSE, FALSE, FALSE, FALSE },
280 { "floatx80_lt", 2, FALSE, FALSE, FALSE, FALSE },
281 { "floatx80_eq_signaling", 2, FALSE, FALSE, FALSE, FALSE },
282 { "floatx80_le_quiet", 2, FALSE, FALSE, FALSE, FALSE },
283 { "floatx80_lt_quiet", 2, FALSE, FALSE, FALSE, FALSE },
286 { "float128_to_int32", 1, FALSE, TRUE, FALSE, FALSE },
287 { "float128_to_int32_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
289 { "float128_to_int64", 1, FALSE, TRUE, FALSE, FALSE },
290 { "float128_to_int64_round_to_zero", 1, FALSE, FALSE, FALSE, FALSE },
292 { "float128_to_float32", 1, FALSE, TRUE, TRUE, FALSE },
293 { "float128_to_float64", 1, FALSE, TRUE, TRUE, FALSE },
295 { "float128_to_floatx80", 1, FALSE, TRUE, TRUE, FALSE },
297 { "float128_round_to_int", 1, FALSE, TRUE, FALSE, FALSE },
298 { "float128_add", 2, FALSE, TRUE, FALSE, FALSE },
299 { "float128_sub", 2, FALSE, TRUE, FALSE, FALSE },
300 { "float128_mul", 2, FALSE, TRUE, TRUE, FALSE },
301 { "float128_div", 2, FALSE, TRUE, FALSE, FALSE },
302 { "float128_rem", 2, FALSE, FALSE, FALSE, FALSE },
303 { "float128_sqrt", 1, FALSE, TRUE, FALSE, FALSE },
304 { "float128_eq", 2, FALSE, FALSE, FALSE, FALSE },
305 { "float128_le", 2, FALSE, FALSE, FALSE, FALSE },
306 { "float128_lt", 2, FALSE, FALSE, FALSE, FALSE },
307 { "float128_eq_signaling", 2, FALSE, FALSE, FALSE, FALSE },
308 { "float128_le_quiet", 2, FALSE, FALSE, FALSE, FALSE },
309 { "float128_lt_quiet", 2, FALSE, FALSE, FALSE, FALSE },
314 ROUND_NEAREST_EVEN = 1,
321 TININESS_BEFORE_ROUNDING = 1,
322 TININESS_AFTER_ROUNDING,
329 int8 roundingPrecision,
337 functionName = functions[ functionCode ].name;
338 if ( roundingPrecision == 32 ) {
339 roundingPrecisionName = "32";
341 else if ( roundingPrecision == 64 ) {
342 roundingPrecisionName = "64";
344 else if ( roundingPrecision == 80 ) {
345 roundingPrecisionName = "80";
348 roundingPrecisionName = 0;
351 floatx80_rounding_precision = roundingPrecision;
352 slow_floatx80_rounding_precision = roundingPrecision;
354 switch ( roundingMode ) {
356 roundingModeName = 0;
357 roundingCode = float_round_nearest_even;
359 case ROUND_NEAREST_EVEN:
360 roundingModeName = "nearest_even";
361 roundingCode = float_round_nearest_even;
364 roundingModeName = "to_zero";
365 roundingCode = float_round_to_zero;
368 roundingModeName = "down";
369 roundingCode = float_round_down;
372 roundingModeName = "up";
373 roundingCode = float_round_up;
376 float_rounding_mode = roundingCode;
377 slow_float_rounding_mode = roundingCode;
378 switch ( tininessMode ) {
380 tininessModeName = 0;
381 tininessCode = float_tininess_after_rounding;
383 case TININESS_BEFORE_ROUNDING:
384 tininessModeName = "before";
385 tininessCode = float_tininess_before_rounding;
387 case TININESS_AFTER_ROUNDING:
388 tininessModeName = "after";
389 tininessCode = float_tininess_after_rounding;
392 float_detect_tininess = tininessCode;
393 slow_float_detect_tininess = tininessCode;
394 fputs( "Testing ", stderr );
395 writeFunctionName( stderr );
396 fputs( ".\n", stderr );
397 switch ( functionCode ) {
398 case INT32_TO_FLOAT32:
399 test_a_int32_z_float32( slow_int32_to_float32, int32_to_float32 );
401 case INT32_TO_FLOAT64:
402 test_a_int32_z_float64( slow_int32_to_float64, int32_to_float64 );
405 case INT32_TO_FLOATX80:
406 test_a_int32_z_floatx80( slow_int32_to_floatx80, int32_to_floatx80 );
410 case INT32_TO_FLOAT128:
411 test_a_int32_z_float128( slow_int32_to_float128, int32_to_float128 );
415 case INT64_TO_FLOAT32:
416 test_a_int64_z_float32( slow_int64_to_float32, int64_to_float32 );
418 case INT64_TO_FLOAT64:
419 test_a_int64_z_float64( slow_int64_to_float64, int64_to_float64 );
422 case INT64_TO_FLOATX80:
423 test_a_int64_z_floatx80( slow_int64_to_floatx80, int64_to_floatx80 );
427 case INT64_TO_FLOAT128:
428 test_a_int64_z_float128( slow_int64_to_float128, int64_to_float128 );
432 case FLOAT32_TO_INT32:
433 test_a_float32_z_int32( slow_float32_to_int32, float32_to_int32 );
435 case FLOAT32_TO_INT32_ROUND_TO_ZERO:
436 test_a_float32_z_int32(
437 slow_float32_to_int32_round_to_zero,
438 float32_to_int32_round_to_zero
442 case FLOAT32_TO_INT64:
443 test_a_float32_z_int64( slow_float32_to_int64, float32_to_int64 );
445 case FLOAT32_TO_INT64_ROUND_TO_ZERO:
446 test_a_float32_z_int64(
447 slow_float32_to_int64_round_to_zero,
448 float32_to_int64_round_to_zero
452 case FLOAT32_TO_FLOAT64:
453 test_a_float32_z_float64(
454 slow_float32_to_float64, float32_to_float64 );
457 case FLOAT32_TO_FLOATX80:
458 test_a_float32_z_floatx80(
459 slow_float32_to_floatx80, float32_to_floatx80 );
463 case FLOAT32_TO_FLOAT128:
464 test_a_float32_z_float128(
465 slow_float32_to_float128, float32_to_float128 );
468 case FLOAT32_ROUND_TO_INT:
469 test_az_float32( slow_float32_round_to_int, float32_round_to_int );
472 test_abz_float32( slow_float32_add, float32_add );
475 test_abz_float32( slow_float32_sub, float32_sub );
478 test_abz_float32( slow_float32_mul, float32_mul );
481 test_abz_float32( slow_float32_div, float32_div );
484 test_abz_float32( slow_float32_rem, float32_rem );
487 test_az_float32( slow_float32_sqrt, float32_sqrt );
490 test_ab_float32_z_flag( slow_float32_eq, float32_eq );
493 test_ab_float32_z_flag( slow_float32_le, float32_le );
496 test_ab_float32_z_flag( slow_float32_lt, float32_lt );
498 case FLOAT32_EQ_SIGNALING:
499 test_ab_float32_z_flag(
500 slow_float32_eq_signaling, float32_eq_signaling );
502 case FLOAT32_LE_QUIET:
503 test_ab_float32_z_flag( slow_float32_le_quiet, float32_le_quiet );
505 case FLOAT32_LT_QUIET:
506 test_ab_float32_z_flag( slow_float32_lt_quiet, float32_lt_quiet );
508 case FLOAT64_TO_INT32:
509 test_a_float64_z_int32( slow_float64_to_int32, float64_to_int32 );
511 case FLOAT64_TO_INT32_ROUND_TO_ZERO:
512 test_a_float64_z_int32(
513 slow_float64_to_int32_round_to_zero,
514 float64_to_int32_round_to_zero
518 case FLOAT64_TO_INT64:
519 test_a_float64_z_int64( slow_float64_to_int64, float64_to_int64 );
521 case FLOAT64_TO_INT64_ROUND_TO_ZERO:
522 test_a_float64_z_int64(
523 slow_float64_to_int64_round_to_zero,
524 float64_to_int64_round_to_zero
528 case FLOAT64_TO_FLOAT32:
529 test_a_float64_z_float32(
530 slow_float64_to_float32, float64_to_float32 );
533 case FLOAT64_TO_FLOATX80:
534 test_a_float64_z_floatx80(
535 slow_float64_to_floatx80, float64_to_floatx80 );
539 case FLOAT64_TO_FLOAT128:
540 test_a_float64_z_float128(
541 slow_float64_to_float128, float64_to_float128 );
544 case FLOAT64_ROUND_TO_INT:
545 test_az_float64( slow_float64_round_to_int, float64_round_to_int );
548 test_abz_float64( slow_float64_add, float64_add );
551 test_abz_float64( slow_float64_sub, float64_sub );
554 test_abz_float64( slow_float64_mul, float64_mul );
557 test_abz_float64( slow_float64_div, float64_div );
560 test_abz_float64( slow_float64_rem, float64_rem );
563 test_az_float64( slow_float64_sqrt, float64_sqrt );
566 test_ab_float64_z_flag( slow_float64_eq, float64_eq );
569 test_ab_float64_z_flag( slow_float64_le, float64_le );
572 test_ab_float64_z_flag( slow_float64_lt, float64_lt );
574 case FLOAT64_EQ_SIGNALING:
575 test_ab_float64_z_flag(
576 slow_float64_eq_signaling, float64_eq_signaling );
578 case FLOAT64_LE_QUIET:
579 test_ab_float64_z_flag( slow_float64_le_quiet, float64_le_quiet );
581 case FLOAT64_LT_QUIET:
582 test_ab_float64_z_flag( slow_float64_lt_quiet, float64_lt_quiet );
585 case FLOATX80_TO_INT32:
586 test_a_floatx80_z_int32( slow_floatx80_to_int32, floatx80_to_int32 );
588 case FLOATX80_TO_INT32_ROUND_TO_ZERO:
589 test_a_floatx80_z_int32(
590 slow_floatx80_to_int32_round_to_zero,
591 floatx80_to_int32_round_to_zero
595 case FLOATX80_TO_INT64:
596 test_a_floatx80_z_int64( slow_floatx80_to_int64, floatx80_to_int64 );
598 case FLOATX80_TO_INT64_ROUND_TO_ZERO:
599 test_a_floatx80_z_int64(
600 slow_floatx80_to_int64_round_to_zero,
601 floatx80_to_int64_round_to_zero
605 case FLOATX80_TO_FLOAT32:
606 test_a_floatx80_z_float32(
607 slow_floatx80_to_float32, floatx80_to_float32 );
609 case FLOATX80_TO_FLOAT64:
610 test_a_floatx80_z_float64(
611 slow_floatx80_to_float64, floatx80_to_float64 );
614 case FLOATX80_TO_FLOAT128:
615 test_a_floatx80_z_float128(
616 slow_floatx80_to_float128, floatx80_to_float128 );
619 case FLOATX80_ROUND_TO_INT:
620 test_az_floatx80( slow_floatx80_round_to_int, floatx80_round_to_int );
623 test_abz_floatx80( slow_floatx80_add, floatx80_add );
626 test_abz_floatx80( slow_floatx80_sub, floatx80_sub );
629 test_abz_floatx80( slow_floatx80_mul, floatx80_mul );
632 test_abz_floatx80( slow_floatx80_div, floatx80_div );
635 test_abz_floatx80( slow_floatx80_rem, floatx80_rem );
638 test_az_floatx80( slow_floatx80_sqrt, floatx80_sqrt );
641 test_ab_floatx80_z_flag( slow_floatx80_eq, floatx80_eq );
644 test_ab_floatx80_z_flag( slow_floatx80_le, floatx80_le );
647 test_ab_floatx80_z_flag( slow_floatx80_lt, floatx80_lt );
649 case FLOATX80_EQ_SIGNALING:
650 test_ab_floatx80_z_flag(
651 slow_floatx80_eq_signaling, floatx80_eq_signaling );
653 case FLOATX80_LE_QUIET:
654 test_ab_floatx80_z_flag( slow_floatx80_le_quiet, floatx80_le_quiet );
656 case FLOATX80_LT_QUIET:
657 test_ab_floatx80_z_flag( slow_floatx80_lt_quiet, floatx80_lt_quiet );
661 case FLOAT128_TO_INT32:
662 test_a_float128_z_int32( slow_float128_to_int32, float128_to_int32 );
664 case FLOAT128_TO_INT32_ROUND_TO_ZERO:
665 test_a_float128_z_int32(
666 slow_float128_to_int32_round_to_zero,
667 float128_to_int32_round_to_zero
671 case FLOAT128_TO_INT64:
672 test_a_float128_z_int64( slow_float128_to_int64, float128_to_int64 );
674 case FLOAT128_TO_INT64_ROUND_TO_ZERO:
675 test_a_float128_z_int64(
676 slow_float128_to_int64_round_to_zero,
677 float128_to_int64_round_to_zero
681 case FLOAT128_TO_FLOAT32:
682 test_a_float128_z_float32(
683 slow_float128_to_float32, float128_to_float32 );
685 case FLOAT128_TO_FLOAT64:
686 test_a_float128_z_float64(
687 slow_float128_to_float64, float128_to_float64 );
690 case FLOAT128_TO_FLOATX80:
691 test_a_float128_z_floatx80(
692 slow_float128_to_floatx80, float128_to_floatx80 );
695 case FLOAT128_ROUND_TO_INT:
696 test_az_float128( slow_float128_round_to_int, float128_round_to_int );
699 test_abz_float128( slow_float128_add, float128_add );
702 test_abz_float128( slow_float128_sub, float128_sub );
705 test_abz_float128( slow_float128_mul, float128_mul );
708 test_abz_float128( slow_float128_div, float128_div );
711 test_abz_float128( slow_float128_rem, float128_rem );
714 test_az_float128( slow_float128_sqrt, float128_sqrt );
717 test_ab_float128_z_flag( slow_float128_eq, float128_eq );
720 test_ab_float128_z_flag( slow_float128_le, float128_le );
723 test_ab_float128_z_flag( slow_float128_lt, float128_lt );
725 case FLOAT128_EQ_SIGNALING:
726 test_ab_float128_z_flag(
727 slow_float128_eq_signaling, float128_eq_signaling );
729 case FLOAT128_LE_QUIET:
730 test_ab_float128_z_flag( slow_float128_le_quiet, float128_le_quiet );
732 case FLOAT128_LT_QUIET:
733 test_ab_float128_z_flag( slow_float128_lt_quiet, float128_lt_quiet );
737 if ( ( errorStop && anyErrors ) || stop ) exitWithStatus();
744 int8 roundingPrecisionIn,
749 int8 roundingPrecision, roundingMode, tininessMode;
751 roundingPrecision = 32;
753 if ( ! functions[ functionCode ].roundingPrecision ) {
754 roundingPrecision = 0;
756 else if ( roundingPrecisionIn ) {
757 roundingPrecision = roundingPrecisionIn;
759 for ( roundingMode = 1;
760 roundingMode < NUM_ROUNDINGMODES;
763 if ( ! functions[ functionCode ].roundingMode ) {
766 else if ( roundingModeIn ) {
767 roundingMode = roundingModeIn;
769 for ( tininessMode = 1;
770 tininessMode < NUM_TININESSMODES;
773 if ( ( roundingPrecision == 32 )
774 || ( roundingPrecision == 64 ) ) {
775 if ( ! functions[ functionCode ]
776 .tininessModeAtReducedPrecision
780 else if ( tininessModeIn ) {
781 tininessMode = tininessModeIn;
785 if ( ! functions[ functionCode ].tininessMode ) {
788 else if ( tininessModeIn ) {
789 tininessMode = tininessModeIn;
793 functionCode, roundingPrecision, roundingMode, tininessMode
795 if ( tininessModeIn || ! tininessMode ) break;
797 if ( roundingModeIn || ! roundingMode ) break;
799 if ( roundingPrecisionIn || ! roundingPrecision ) break;
800 if ( roundingPrecision == 80 ) {
803 else if ( roundingPrecision == 64 ) {
804 roundingPrecision = 80;
806 else if ( roundingPrecision == 32 ) {
807 roundingPrecision = 64;
814 main( int argc, char **argv )
817 flag functionArgument;
819 int8 operands, roundingPrecision, roundingMode, tininessMode;
821 fail_programName = "testsoftfloat";
822 if ( argc <= 1 ) goto writeHelpMessage;
823 testCases_setLevel( 1 );
829 trueFlagsPtr = &slow_float_exception_flags;
830 testFlagsFunctionPtr = clearFlags;
831 functionArgument = FALSE;
834 roundingPrecision = 0;
839 while ( argc && ( argPtr = argv[ 0 ] ) ) {
840 if ( argPtr[ 0 ] == '-' ) ++argPtr;
841 if ( strcmp( argPtr, "help" ) == 0 ) {
844 "testsoftfloat [<option>...] <function>\n"
845 " <option>: (* is default)\n"
846 " -help --Write this message and exit.\n"
847 " -level <num> --Testing level <num> (1 or 2).\n"
849 " -errors <num> --Stop each function test after <num> errors.\n"
851 " -errorstop --Exit after first function with any error.\n"
852 " -forever --Test one function repeatedly (implies `-level 2').\n"
854 " -precision32 --Only test rounding precision equivalent to float32.\n"
855 " -precision64 --Only test rounding precision equivalent to float64.\n"
856 " -precision80 --Only test maximum rounding precision.\n"
858 " -nearesteven --Only test rounding to nearest/even.\n"
859 " -tozero --Only test rounding to zero.\n"
860 " -down --Only test rounding down.\n"
861 " -up --Only test rounding up.\n"
862 " -tininessbefore --Only test underflow tininess before rounding.\n"
863 " -tininessafter --Only test underflow tininess after rounding.\n"
865 " int32_to_<float> <float>_add <float>_eq\n"
866 " <float>_to_int32 <float>_sub <float>_le\n"
867 " <float>_to_int32_round_to_zero <float>_mul <float>_lt\n"
869 " int64_to_<float> <float>_div <float>_eq_signaling\n"
870 " <float>_to_int64 <float>_rem <float>_le_quiet\n"
871 " <float>_to_int64_round_to_zero <float>_lt_quiet\n"
872 " <float>_to_<float>\n"
873 " <float>_round_to_int\n"
876 " <float>_to_<float> <float>_div <float>_eq_signaling\n"
877 " <float>_round_to_int <float>_rem <float>_le_quiet\n"
878 " <float>_sqrt <float>_lt_quiet\n"
880 " -all1 --All 1-operand functions.\n"
881 " -all2 --All 2-operand functions.\n"
882 " -all --All functions.\n"
884 " float32 --Single precision.\n"
885 " float64 --Double precision.\n"
887 " floatx80 --Extended double precision.\n"
890 " float128 --Quadruple precision.\n"
897 else if ( strcmp( argPtr, "level" ) == 0 ) {
898 if ( argc < 2 ) goto optionError;
899 testCases_setLevel( atoi( argv[ 1 ] ) );
903 else if ( strcmp( argPtr, "level1" ) == 0 ) {
904 testCases_setLevel( 1 );
906 else if ( strcmp( argPtr, "level2" ) == 0 ) {
907 testCases_setLevel( 2 );
909 else if ( strcmp( argPtr, "errors" ) == 0 ) {
912 fail( "`%s' option requires numeric argument", argv[ 0 ] );
914 maxErrorCount = atoi( argv[ 1 ] );
918 else if ( strcmp( argPtr, "errorstop" ) == 0 ) {
921 else if ( strcmp( argPtr, "forever" ) == 0 ) {
922 testCases_setLevel( 2 );
926 else if ( strcmp( argPtr, "precision32" ) == 0 ) {
927 roundingPrecision = 32;
929 else if ( strcmp( argPtr, "precision64" ) == 0 ) {
930 roundingPrecision = 64;
932 else if ( strcmp( argPtr, "precision80" ) == 0 ) {
933 roundingPrecision = 80;
936 else if ( ( strcmp( argPtr, "nearesteven" ) == 0 )
937 || ( strcmp( argPtr, "nearest_even" ) == 0 ) ) {
938 roundingMode = ROUND_NEAREST_EVEN;
940 else if ( ( strcmp( argPtr, "tozero" ) == 0 )
941 || ( strcmp( argPtr, "to_zero" ) == 0 ) ) {
942 roundingMode = ROUND_TO_ZERO;
944 else if ( strcmp( argPtr, "down" ) == 0 ) {
945 roundingMode = ROUND_DOWN;
947 else if ( strcmp( argPtr, "up" ) == 0 ) {
948 roundingMode = ROUND_UP;
950 else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) {
951 tininessMode = TININESS_BEFORE_ROUNDING;
953 else if ( strcmp( argPtr, "tininessafter" ) == 0 ) {
954 tininessMode = TININESS_AFTER_ROUNDING;
956 else if ( strcmp( argPtr, "all1" ) == 0 ) {
957 functionArgument = TRUE;
961 else if ( strcmp( argPtr, "all2" ) == 0 ) {
962 functionArgument = TRUE;
966 else if ( strcmp( argPtr, "all" ) == 0 ) {
967 functionArgument = TRUE;
972 for ( functionCode = 1;
973 functionCode < NUM_FUNCTIONS;
976 if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) {
980 if ( functionCode == NUM_FUNCTIONS ) {
981 fail( "Invalid option or function `%s'", argv[ 0 ] );
983 functionArgument = TRUE;
988 if ( ! functionArgument ) fail( "Function argument required" );
989 (void) signal( SIGINT, catchSIGINT );
990 (void) signal( SIGTERM, catchSIGINT );
991 if ( functionCode ) {
993 if ( ! roundingPrecision ) roundingPrecision = 80;
994 if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
997 functionCode, roundingPrecision, roundingMode, tininessMode );
1000 if ( operands == 1 ) {
1001 for ( functionCode = 1;
1002 functionCode < NUM_FUNCTIONS;
1005 if ( functions[ functionCode ].numInputs == 1 ) {
1015 else if ( operands == 2 ) {
1016 for ( functionCode = 1;
1017 functionCode < NUM_FUNCTIONS;
1020 if ( functions[ functionCode ].numInputs == 2 ) {
1031 for ( functionCode = 1;
1032 functionCode < NUM_FUNCTIONS;
1036 functionCode, roundingPrecision, roundingMode, tininessMode