OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [testfloat/] [testfloat.c] - Blame information for rev 363

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 234 jeremybenn
 
2
/*
3
===============================================================================
4
 
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.
8
 
9
Written by John R. Hauser.  More information is available through the Web
10
page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
11
 
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.
17
 
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.
22
 
23
Modified for use with or1ksim's testsuite.
24
 
25
Contributor Julius Baxter <julius.baxter@orsoc.se>
26
 
27
 
28
===============================================================================
29
*/
30
                                                                 /*
31
#include <stdlib.h>
32
#include <signal.h>
33
#include <string.h>
34
                                                                 */
35
#include "support.h" // OR1k support C library
36
#include "milieu.h"
37
#include "fail.h"
38
#include "softfloat.h"
39
#include "testCases.h"
40
#include "testLoops.h"
41
#include "systflags.h"
42
#include "testFunction.h"
43
                                                                 /*
44
static void catchSIGINT( int signalCode )
45
{
46
 
47
    if ( stop ) exit( EXIT_FAILURE );
48
    stop = TRUE;
49
 
50
}
51
*/
52
 
53
// Running this bare metal standalone for OR1K - hard set the configuration
54
int
55
main( int argc, char **argv )
56
{
57
  //    char *argPtr; // Unused variable
58
    flag functionArgument;
59
    uint8 functionCode;
60
    int8 operands, roundingPrecision, roundingMode;
61
 
62
    fail_programName = "testfloat";
63
    //if ( argc <= 1 ) goto writeHelpMessage;
64
    testCases_setLevel( 1 );
65
    trueName = "soft";
66
    testName = "syst";
67
    errorStop = FALSE;
68
    forever = FALSE;
69
    maxErrorCount = 20;
70
    trueFlagsPtr = &float_exception_flags;
71
    testFlagsFunctionPtr = syst_float_flags_clear;
72
    tininessModeName = 0;
73
    functionArgument = FALSE;
74
    functionCode = 0;
75
    operands = 0;
76
    roundingPrecision = 0;
77
    roundingMode = 0;
78
    // "all" setting:
79
    functionArgument = TRUE;
80
    functionCode = 0;
81
    operands = 0;
82
    /*
83
    --argc;
84
    ++argv;
85
    while ( argc && ( argPtr = argv[ 0 ] ) ) {
86
        if ( argPtr[ 0 ] == '-' ) ++argPtr;
87
        if ( strcmp( argPtr, "help" ) == 0 ) {
88
 writeHelpMessage:
89
            fputs(
90
"testfloat [<option>...] <function>\n"
91
"  <option>:  (* is default)\n"
92
"    -help            --Write this message and exit.\n"
93
"    -list            --List all testable functions and exit.\n"
94
"    -level <num>     --Testing level <num> (1 or 2).\n"
95
" *  -level 1\n"
96
"    -errors <num>    --Stop each function test after <num> errors.\n"
97
" *  -errors 20\n"
98
"    -errorstop       --Exit after first function with any error.\n"
99
"    -forever         --Test one function repeatedly (implies `-level 2').\n"
100
"    -checkNaNs       --Check for bitwise correctness of NaN results.\n"
101
#ifdef FLOATX80
102
"    -precision32     --Only test rounding precision equivalent to float32.\n"
103
"    -precision64     --Only test rounding precision equivalent to float64.\n"
104
"    -precision80     --Only test maximum rounding precision.\n"
105
#endif
106
"    -nearesteven     --Only test rounding to nearest/even.\n"
107
"    -tozero          --Only test rounding to zero.\n"
108
"    -down            --Only test rounding down.\n"
109
"    -up              --Only test rounding up.\n"
110
"    -tininessbefore  --Underflow tininess detected before rounding.\n"
111
"    -tininessafter   --Underflow tininess detected after rounding.\n"
112
"  <function>:\n"
113
"    int32_to_<float>                 <float>_add   <float>_eq\n"
114
"    <float>_to_int32                 <float>_sub   <float>_le\n"
115
"    <float>_to_int32_round_to_zero   <float>_mul   <float>_lt\n"
116
#ifdef BITS64
117
"    int64_to_<float>                 <float>_div   <float>_eq_signaling\n"
118
"    <float>_to_int64                 <float>_rem   <float>_le_quiet\n"
119
"    <float>_to_int64_round_to_zero                 <float>_lt_quiet\n"
120
"    <float>_to_<float>\n"
121
"    <float>_round_to_int\n"
122
"    <float>_sqrt\n"
123
#else
124
"    <float>_to_<float>               <float>_div   <float>_eq_signaling\n"
125
"    <float>_round_to_int             <float>_rem   <float>_le_quiet\n"
126
"    <float>_sqrt                                   <float>_lt_quiet\n"
127
#endif
128
"    -all1            --All 1-operand functions.\n"
129
"    -all2            --All 2-operand functions.\n"
130
"    -all             --All functions.\n"
131
"  <float>:\n"
132
"    float32          --Single precision.\n"
133
"    float64          --Double precision.\n"
134
#ifdef FLOATX80
135
"    floatx80         --Extended double precision.\n"
136
#endif
137
#ifdef FLOAT128
138
"    float128         --Quadruple precision.\n"
139
#endif
140
                ,
141
                stdout
142
            );
143
            return EXIT_SUCCESS;
144
        }
145
        else if ( strcmp( argPtr, "list" ) == 0 ) {
146
            for ( functionCode = 1;
147
                  functionCode < NUM_FUNCTIONS;
148
                  ++functionCode
149
                ) {
150
                if ( functionExists[ functionCode ] ) {
151
                    puts( functions[ functionCode ].name );
152
                }
153
            }
154
            return EXIT_SUCCESS;
155
        }
156
        else if ( strcmp( argPtr, "level" ) == 0 ) {
157
            if ( argc < 2 ) goto optionError;
158
            testCases_setLevel( atoi( argv[ 1 ] ) );
159
            --argc;
160
            ++argv;
161
        }
162
        else if ( strcmp( argPtr, "level1" ) == 0 ) {
163
            testCases_setLevel( 1 );
164
        }
165
        else if ( strcmp( argPtr, "level2" ) == 0 ) {
166
            testCases_setLevel( 2 );
167
        }
168
        else if ( strcmp( argPtr, "errors" ) == 0 ) {
169
            if ( argc < 2 ) {
170
     optionError:
171
                fail( "`%s' option requires numeric argument", argv[ 0 ] );
172
            }
173
            maxErrorCount = atoi( argv[ 1 ] );
174
            --argc;
175
            ++argv;
176
        }
177
        else if ( strcmp( argPtr, "errorstop" ) == 0 ) {
178
            errorStop = TRUE;
179
        }
180
        else if ( strcmp( argPtr, "forever" ) == 0 ) {
181
            testCases_setLevel( 2 );
182
            forever = TRUE;
183
        }
184
        else if (    ( strcmp( argPtr, "checkNaNs" ) == 0 )
185
                  || ( strcmp( argPtr, "checknans" ) == 0 ) ) {
186
            checkNaNs = TRUE;
187
        }
188
#ifdef FLOATX80
189
        else if ( strcmp( argPtr, "precision32" ) == 0 ) {
190
            roundingPrecision = 32;
191
        }
192
        else if ( strcmp( argPtr, "precision64" ) == 0 ) {
193
            roundingPrecision = 64;
194
        }
195
        else if ( strcmp( argPtr, "precision80" ) == 0 ) {
196
            roundingPrecision = 80;
197
        }
198
#endif
199
        else if (    ( strcmp( argPtr, "nearesteven" ) == 0 )
200
                  || ( strcmp( argPtr, "nearest_even" ) == 0 ) ) {
201
            roundingMode = ROUND_NEAREST_EVEN;
202
        }
203
        else if (    ( strcmp( argPtr, "tozero" ) == 0 )
204
                  || ( strcmp( argPtr, "to_zero" ) == 0 ) ) {
205
            roundingMode = ROUND_TO_ZERO;
206
        }
207
        else if ( strcmp( argPtr, "down" ) == 0 ) {
208
            roundingMode = ROUND_DOWN;
209
        }
210
        else if ( strcmp( argPtr, "up" ) == 0 ) {
211
            roundingMode = ROUND_UP;
212
        }
213
        else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) {
214
            float_detect_tininess = float_tininess_before_rounding;
215
        }
216
        else if ( strcmp( argPtr, "tininessafter" ) == 0 ) {
217
            float_detect_tininess = float_tininess_after_rounding;
218
        }
219
        else if ( strcmp( argPtr, "all1" ) == 0 ) {
220
            functionArgument = TRUE;
221
            functionCode = 0;
222
            operands = 1;
223
        }
224
        else if ( strcmp( argPtr, "all2" ) == 0 ) {
225
            functionArgument = TRUE;
226
            functionCode = 0;
227
            operands = 2;
228
        }
229
        else if ( strcmp( argPtr, "all" ) == 0 ) {
230
            functionArgument = TRUE;
231
            functionCode = 0;
232
            operands = 0;
233
        }
234
        else {
235
            for ( functionCode = 1;
236
                  functionCode < NUM_FUNCTIONS;
237
                  ++functionCode
238
                ) {
239
                if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) {
240
                    break;
241
                }
242
            }
243
            if ( functionCode == NUM_FUNCTIONS ) {
244
                fail( "Invalid option or function `%s'", argv[ 0 ] );
245
            }
246
            if ( ! functionExists[ functionCode ] ) {
247
                fail(
248
                    "Function `%s' is not supported or cannot be tested",
249
                    argPtr
250
                );
251
            }
252
            functionArgument = TRUE;
253
        }
254
        --argc;
255
        ++argv;
256
    }
257
    */
258
    if ( ! functionArgument ) fail( "Function argument required" );
259
    //    (void) signal( SIGINT, catchSIGINT );
260
    //    (void) signal( SIGTERM, catchSIGINT );
261
    if ( functionCode ) {
262
        if ( forever ) {
263
            if ( ! roundingPrecision ) roundingPrecision = 80;
264
            if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
265
        }
266
        testFunction( functionCode, roundingPrecision, roundingMode );
267
    }
268
    else {
269
 
270
            for ( functionCode = 1;
271
                  functionCode < NUM_FUNCTIONS;
272
                  ++functionCode
273
                ) {
274
                if ( functionExists[ functionCode ] ) {
275
                    testFunction(
276
                        functionCode, roundingPrecision, roundingMode );
277
                }
278
            }
279
 
280
    }
281
    exitWithStatus();
282
 
283
    // Should never reach here
284
    return 1;
285
 
286
}
287
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.