timesoftfloat.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,091 行 · 第 1/5 页

C
2,091
字号
/*============================================================================This C source file is part of the SoftFloat IEC/IEEE Floating-point ArithmeticPackage, Release 2b.Written by John R. Hauser.THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort hasbeen made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMESRESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONSAND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMOREEFFECTIVELY INDEMNIFY THE AUTHOR, JOHN HAUSER, (possibly via similar legalwarning) AGAINST ALL LOSSES, COSTS, OR OTHER PROBLEMS INCURRED BY THEIRCUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.Derivative works are acceptable, even for commercial purposes, so long as(1) the source code for the derivative work includes prominent notice thatthe work is derivative, and (2) the source code includes prominent notice withthese four paragraphs for those parts of this code that are retained.=============================================================================*/#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <stdio.h>#include <time.h>#include "milieu.h"#include "softfloat.h"enum {    minIterations = 1000};static void fail( const char *message, ... ){    va_list varArgs;    fputs( "timesoftfloat: ", stderr );    va_start( varArgs, message );    vfprintf( stderr, message, varArgs );    va_end( varArgs );    fputs( ".\n", stderr );    exit( EXIT_FAILURE );}static char *functionName;static char *roundingPrecisionName, *roundingModeName, *tininessModeName;static void reportTime( int32 count, long clocks ){    printf(        "%8.1f kops/s: %s",        ( count / ( ( (float) clocks ) / CLOCKS_PER_SEC ) ) / 1000,        functionName    );    if ( roundingModeName ) {        if ( roundingPrecisionName ) {            fputs( ", precision ", stdout );            fputs( roundingPrecisionName, stdout );        }        fputs( ", rounding ", stdout );        fputs( roundingModeName, stdout );        if ( tininessModeName ) {            fputs( ", tininess ", stdout );            fputs( tininessModeName, stdout );            fputs( " rounding", stdout );        }    }    fputc( '\n', stdout );}enum {    numInputs_int32 = 32};static const int32 inputs_int32[ numInputs_int32 ] = {    0xFFFFBB79, 0x405CF80F, 0x00000000, 0xFFFFFD04,    0xFFF20002, 0x0C8EF795, 0xF00011FF, 0x000006CA,    0x00009BFE, 0xFF4862E3, 0x9FFFEFFE, 0xFFFFFFB7,    0x0BFF7FFF, 0x0000F37A, 0x0011DFFE, 0x00000006,    0xFFF02006, 0xFFFFF7D1, 0x10200003, 0xDE8DF765,    0x00003E02, 0x000019E8, 0x0008FFFE, 0xFFFFFB5C,    0xFFDF7FFE, 0x07C42FBF, 0x0FFFE3FF, 0x040B9F13,    0xBFFFFFF8, 0x0001BF56, 0x000017F6, 0x000A908A};static void time_a_int32_z_float32( float32 function( int32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int32[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}static void time_a_int32_z_float64( float64 function( int32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int32[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#ifdef FLOATX80static void time_a_int32_z_floatx80( floatx80 function( int32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int32[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#endif#ifdef FLOAT128static void time_a_int32_z_float128( float128 function( int32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int32[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int32 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#endifenum {    numInputs_int64 = 32};static const int64 inputs_int64[ numInputs_int64 ] = {    LIT64( 0xFBFFC3FFFFFFFFFF ),    LIT64( 0x0000000003C589BC ),    LIT64( 0x00000000400013FE ),    LIT64( 0x0000000000186171 ),    LIT64( 0xFFFFFFFFFFFEFBFA ),    LIT64( 0xFFFFFD79E6DFFC73 ),    LIT64( 0x0000000010001DFF ),    LIT64( 0xDD1A0F0C78513710 ),    LIT64( 0xFFFF83FFFFFEFFFE ),    LIT64( 0x00756EBD1AD0C1C7 ),    LIT64( 0x0003FDFFFFFFFFBE ),    LIT64( 0x0007D0FB2C2CA951 ),    LIT64( 0x0007FC0007FFFFFE ),    LIT64( 0x0000001F942B18BB ),    LIT64( 0x0000080101FFFFFE ),    LIT64( 0xFFFFFFFFFFFF0978 ),    LIT64( 0x000000000008BFFF ),    LIT64( 0x0000000006F5AF08 ),    LIT64( 0xFFDEFF7FFFFFFFFE ),    LIT64( 0x0000000000000003 ),    LIT64( 0x3FFFFFFFFF80007D ),    LIT64( 0x0000000000000078 ),    LIT64( 0xFFF80000007FDFFD ),    LIT64( 0x1BBC775B78016AB0 ),    LIT64( 0xFFF9001FFFFFFFFE ),    LIT64( 0xFFFD4767AB98E43F ),    LIT64( 0xFFFFFEFFFE00001E ),    LIT64( 0xFFFFFFFFFFF04EFD ),    LIT64( 0x07FFFFFFFFFFF7FF ),    LIT64( 0xFFFC9EAA38F89050 ),    LIT64( 0x00000020FBFFFFFE ),    LIT64( 0x0000099AE6455357 )};static void time_a_int64_z_float32( float32 function( int64 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int64[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int64[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}static void time_a_int64_z_float64( float64 function( int64 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int64[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int64[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#ifdef FLOATX80static void time_a_int64_z_floatx80( floatx80 function( int64 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int64[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int64[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#endif#ifdef FLOAT128static void time_a_int64_z_float128( float128 function( int64 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_int64[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_int64[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_int64 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}#endifenum {    numInputs_float32 = 32};static const float32 inputs_float32[ numInputs_float32 ] = {    0x4EFA0000, 0xC1D0B328, 0x80000000, 0x3E69A31E,    0xAF803EFF, 0x3F800000, 0x17BF8000, 0xE74A301A,    0x4E010003, 0x7EE3C75D, 0xBD803FE0, 0xBFFEFF00,    0x7981F800, 0x431FFFFC, 0xC100C000, 0x3D87EFFF,    0x4103FEFE, 0xBC000007, 0xBF01F7FF, 0x4E6C6B5C,    0xC187FFFE, 0xC58B9F13, 0x4F88007F, 0xDF004007,    0xB7FFD7FE, 0x7E8001FB, 0x46EFFBFF, 0x31C10000,    0xDB428661, 0x33F89B1F, 0xA3BFEFFF, 0x537BFFBE};static void time_a_float32_z_int32( int32 function( float32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_float32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 );        }        count += minIterations;    } while ( clock() - startClock < CLOCKS_PER_SEC );    inputNum = 0;    startClock = clock();    for ( i = count; i; --i ) {        function( inputs_float32[ inputNum ] );        inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 );    }    endClock = clock();    reportTime( count, endClock - startClock );}static void time_a_float32_z_int64( int64 function( float32 ) ){    clock_t startClock, endClock;    int32 count, i;    int8 inputNum;    count = 0;    inputNum = 0;    startClock = clock();    do {        for ( i = minIterations; i; --i ) {            function( inputs_float32[ inputNum ] );            inputNum = ( inputNum + 1 ) & ( numInputs_float32 - 1 );        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?