timesoftfloat.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,051 行 · 第 1/3 页
C
1,051 行
{ "float32_eq_signaling", 2, FALSE, FALSE }, { "float32_le_quiet", 2, FALSE, FALSE }, { "float32_lt_quiet", 2, FALSE, FALSE }, { "float64_to_int32", 1, TRUE, FALSE }, { "float64_to_int32_round_to_zero", 1, FALSE, FALSE }, { "float64_to_float32", 1, TRUE, TRUE, }, { "float64_round_to_int", 1, TRUE, FALSE }, { "float64_add", 2, TRUE, FALSE }, { "float64_sub", 2, TRUE, FALSE }, { "float64_mul", 2, TRUE, TRUE, }, { "float64_div", 2, TRUE, FALSE }, { "float64_rem", 2, FALSE, FALSE }, { "float64_sqrt", 1, TRUE, FALSE }, { "float64_eq", 2, FALSE, FALSE }, { "float64_le", 2, FALSE, FALSE }, { "float64_lt", 2, FALSE, FALSE }, { "float64_eq_signaling", 2, FALSE, FALSE }, { "float64_le_quiet", 2, FALSE, FALSE }, { "float64_lt_quiet", 2, FALSE, FALSE }};enum { ROUND_NEAREST_EVEN = 1, ROUND_TO_ZERO, ROUND_DOWN, ROUND_UP, NUM_ROUNDINGMODES};enum { TININESS_BEFORE_ROUNDING = 1, TININESS_AFTER_ROUNDING, NUM_TININESSMODES};static void timeFunctionVariety( uint8 functionCode, int8 roundingMode, int8 tininessMode ){ uint8 roundingCode; int8 tininessCode; functionName = functions[ functionCode ].name; switch ( roundingMode ) { case 0: roundingModeName = 0; roundingCode = float_round_nearest_even; break; case ROUND_NEAREST_EVEN: roundingModeName = "nearest_even"; roundingCode = float_round_nearest_even; break; case ROUND_TO_ZERO: roundingModeName = "to_zero"; roundingCode = float_round_to_zero; break; case ROUND_DOWN: roundingModeName = "down"; roundingCode = float_round_down; break; case ROUND_UP: roundingModeName = "up"; roundingCode = float_round_up; break; } float_rounding_mode = roundingCode; switch ( tininessMode ) { case 0: tininessModeName = 0; tininessCode = float_tininess_after_rounding; break; case TININESS_BEFORE_ROUNDING: tininessModeName = "before"; tininessCode = float_tininess_before_rounding; break; case TININESS_AFTER_ROUNDING: tininessModeName = "after"; tininessCode = float_tininess_after_rounding; break; } float_detect_tininess = tininessCode; switch ( functionCode ) { case INT32_TO_FLOAT32: time_a_int32_z_float32( int32_to_float32 ); break; case INT32_TO_FLOAT64: time_a_int32_z_float64( int32_to_float64 ); break; case FLOAT32_TO_INT32: time_a_float32_z_int32( float32_to_int32 ); break; case FLOAT32_TO_INT32_ROUND_TO_ZERO: time_a_float32_z_int32( float32_to_int32_round_to_zero ); break; case FLOAT32_TO_FLOAT64: time_a_float32_z_float64( float32_to_float64 ); break; case FLOAT32_ROUND_TO_INT: time_az_float32( float32_round_to_int ); break; case FLOAT32_ADD: time_abz_float32( float32_add ); break; case FLOAT32_SUB: time_abz_float32( float32_sub ); break; case FLOAT32_MUL: time_abz_float32( float32_mul ); break; case FLOAT32_DIV: time_abz_float32( float32_div ); break; case FLOAT32_REM: time_abz_float32( float32_rem ); break; case FLOAT32_SQRT: time_az_float32_pos( float32_sqrt ); break; case FLOAT32_EQ: time_ab_float32_z_flag( float32_eq ); break; case FLOAT32_LE: time_ab_float32_z_flag( float32_le ); break; case FLOAT32_LT: time_ab_float32_z_flag( float32_lt ); break; case FLOAT32_EQ_SIGNALING: time_ab_float32_z_flag( float32_eq_signaling ); break; case FLOAT32_LE_QUIET: time_ab_float32_z_flag( float32_le_quiet ); break; case FLOAT32_LT_QUIET: time_ab_float32_z_flag( float32_lt_quiet ); break; case FLOAT64_TO_INT32: time_a_float64_z_int32( float64_to_int32 ); break; case FLOAT64_TO_INT32_ROUND_TO_ZERO: time_a_float64_z_int32( float64_to_int32_round_to_zero ); break; case FLOAT64_TO_FLOAT32: time_a_float64_z_float32( float64_to_float32 ); break; case FLOAT64_ROUND_TO_INT: time_az_float64( float64_round_to_int ); break; case FLOAT64_ADD: time_abz_float64( float64_add ); break; case FLOAT64_SUB: time_abz_float64( float64_sub ); break; case FLOAT64_MUL: time_abz_float64( float64_mul ); break; case FLOAT64_DIV: time_abz_float64( float64_div ); break; case FLOAT64_REM: time_abz_float64( float64_rem ); break; case FLOAT64_SQRT: time_az_float64_pos( float64_sqrt ); break; case FLOAT64_EQ: time_ab_float64_z_flag( float64_eq ); break; case FLOAT64_LE: time_ab_float64_z_flag( float64_le ); break; case FLOAT64_LT: time_ab_float64_z_flag( float64_lt ); break; case FLOAT64_EQ_SIGNALING: time_ab_float64_z_flag( float64_eq_signaling ); break; case FLOAT64_LE_QUIET: time_ab_float64_z_flag( float64_le_quiet ); break; case FLOAT64_LT_QUIET: time_ab_float64_z_flag( float64_lt_quiet ); break; }}static void timeFunction( uint8 functionCode, int8 roundingModeIn, int8 tininessModeIn ){ int8 roundingMode, tininessMode; for ( roundingMode = 1; roundingMode < NUM_ROUNDINGMODES; ++roundingMode ) { if ( ! functions[ functionCode ].roundingMode ) { roundingMode = 0; } else if ( roundingModeIn ) { roundingMode = roundingModeIn; } for ( tininessMode = 1; tininessMode < NUM_TININESSMODES; ++tininessMode ) { if ( ! functions[ functionCode ].tininessMode ) { tininessMode = 0; } else if ( tininessModeIn ) { tininessMode = tininessModeIn; } timeFunctionVariety( functionCode, roundingMode, tininessMode ); if ( tininessModeIn || ! tininessMode ) break; } if ( roundingModeIn || ! roundingMode ) break; }}main( int argc, char **argv ){ char *argPtr; flag functionArgument; uint8 functionCode; int8 operands, roundingMode, tininessMode; if ( argc <= 1 ) goto writeHelpMessage; functionArgument = FALSE; functionCode = 0; operands = 0; roundingMode = 0; tininessMode = 0; --argc; ++argv; while ( argc && ( argPtr = argv[ 0 ] ) ) { if ( argPtr[ 0 ] == '-' ) ++argPtr; if ( strcmp( argPtr, "help" ) == 0 ) { writeHelpMessage: fputs("timesoftfloat [<option>...] <function>\n"" <option>: (* is default)\n"" -help --Write this message and exit.\n"" -nearesteven --Only time rounding to nearest/even.\n"" -tozero --Only time rounding to zero.\n"" -down --Only time rounding down.\n"" -up --Only time rounding up.\n"" -tininessbefore --Only time underflow tininess before rounding.\n"" -tininessafter --Only time underflow tininess after rounding.\n"" <function>:\n"" int32_to_<float> <float>_add <float>_eq\n"" <float>_to_int32 <float>_sub <float>_le\n"" <float>_to_int32_round_to_zero <float>_mul <float>_lt\n"" <float>_to_<float> <float>_div <float>_eq_signaling\n"" <float>_round_to_int <float>_rem <float>_le_quiet\n"" <float>_sqrt <float>_lt_quiet\n"" -all1 --All 1-operand functions.\n"" -all2 --All 2-operand functions.\n"" -all --All functions.\n"" <float>:\n"" float32 --Single precision.\n"" float64 --Double precision.\n", stdout ); return EXIT_SUCCESS; } else if ( ( strcmp( argPtr, "nearesteven" ) == 0 ) || ( strcmp( argPtr, "nearest_even" ) == 0 ) ) { roundingMode = ROUND_NEAREST_EVEN; } else if ( ( strcmp( argPtr, "tozero" ) == 0 ) || ( strcmp( argPtr, "to_zero" ) == 0 ) ) { roundingMode = ROUND_TO_ZERO; } else if ( strcmp( argPtr, "down" ) == 0 ) { roundingMode = ROUND_DOWN; } else if ( strcmp( argPtr, "up" ) == 0 ) { roundingMode = ROUND_UP; } else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) { tininessMode = TININESS_BEFORE_ROUNDING; } else if ( strcmp( argPtr, "tininessafter" ) == 0 ) { tininessMode = TININESS_AFTER_ROUNDING; } else if ( strcmp( argPtr, "all1" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 1; } else if ( strcmp( argPtr, "all2" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 2; } else if ( strcmp( argPtr, "all" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 0; } else { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) { break; } } if ( functionCode == NUM_FUNCTIONS ) { fail( "Invalid option or function `%s'", argv[ 0 ] ); } functionArgument = TRUE; } --argc; ++argv; } if ( ! functionArgument ) fail( "Function argument required" ); if ( functionCode ) { timeFunction( functionCode, roundingMode, tininessMode ); } else if ( operands == 1 ) { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( functions[ functionCode ].numInputs == 1 ) { timeFunction( functionCode, roundingMode, tininessMode ); } } } else if ( operands == 2 ) { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( functions[ functionCode ].numInputs == 2 ) { timeFunction( functionCode, roundingMode, tininessMode ); } } } else { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { timeFunction( functionCode, roundingMode, tininessMode ); } } return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?