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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [apps/] [testfloat/] [testfloat.c] - Blame information for rev 583

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

Line No. Rev Author Line
1 349 julius
 
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 425 julius
#include "cpu-utils.h" // OR1k support C library
36 349 julius
#include "milieu.h"
37
#include "printf.h"
38
#include "spr-defs.h"
39
#include "int.h"
40
#include "fail.h"
41
#include "softfloat.h"
42
#include "testCases.h"
43
#include "testLoops.h"
44
#include "systflags.h" // defines fpcsr_flags global
45
#include "testFunction.h"
46
                                                                 /*
47
static void catchSIGINT( int signalCode )
48
{
49
 
50
    if ( stop ) exit( EXIT_FAILURE );
51
    stop = TRUE;
52
 
53
}
54
*/
55
 
56
// Clear flags in floating point control/status reg (FPCSR), and enable
57
// exception
58
void inline or1k_enable_fpee(void)
59
{
60
  // Read the FPCSR
61
  unsigned int spr = SPR_FPCSR;
62
  unsigned int value;
63
  // Read the SPR
64
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
65
 
66
  // Clear flags in FPCSR
67
  value &= ~(SPR_FPCSR_ALLF);
68
 
69
  // Re-enable floating point exceptions
70
  value |= SPR_FPCSR_FPEE;
71
 
72
  // Write value back to FPCSR
73
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
74
 
75
}
76
  // Interrupt handler for floating point exceptions
77
  // Just copy out the flags and go back to work...
78
 
79
void float_except_handler(void)
80
{
81
 
82
  // Read the FPCSR
83
  unsigned int spr = SPR_FPCSR;
84
  unsigned int value;
85
 
86
  // Clear the global we'll use 
87
  fpcsr_flags = 0;
88
  // Read the SPR
89
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
90
 
91
  // Extract the flags from OR1K's FPCSR, put into testfloat's flags format  
92
  if (value & SPR_FPCSR_IXF)
93
    fpcsr_flags |= float_flag_inexact;
94
 
95
  if (value & SPR_FPCSR_UNF)
96
    fpcsr_flags |= float_flag_underflow;
97
 
98
  if (value & SPR_FPCSR_OVF)
99
    fpcsr_flags |= float_flag_overflow;
100
 
101
  if (value & SPR_FPCSR_DZF)
102
    fpcsr_flags |= float_flag_divbyzero;
103
 
104
  if (value & SPR_FPCSR_IVF)
105
    fpcsr_flags |= float_flag_invalid;
106
 
107
  //  printf("testfloat: getting flags, FPCSR: 0x%x, softfloatflags: 0x%x\n", 
108
  //         value & SPR_FPCSR_ALLF, flags);
109
 
110
  // This clears flags and re-enables FPEE bit
111
  or1k_enable_fpee();
112
 
113
}
114
 
115
// Running this bare metal standalone for OR1K - hard set the configuration
116
int
117
main( int argc, char **argv )
118
{
119
  //    char *argPtr; // Unused variable
120
    flag functionArgument;
121
    uint8 functionCode;
122
    int8 operands, roundingPrecision, roundingMode;
123
 
124
    // Add exception handler for floating point exception
125
    add_handler(0xd, float_except_handler);
126
 
127
    // Enable floating point exceptions in FPCSR
128
    or1k_enable_fpee();
129
 
130
    // If we have UART init it:
131
#ifdef _UART_H_
132
    uart_init(DEFAULT_UART);
133
#endif
134
 
135
    printf("testfloat\n");
136
 
137
    fail_programName = "testfloat";
138
    //if ( argc <= 1 ) goto writeHelpMessage;
139
    testCases_setLevel( 1 );
140
    trueName = "soft";
141
    testName = "syst";
142
    errorStop = FALSE;
143
    forever = FALSE;
144
    maxErrorCount = 0;
145
    trueFlagsPtr = &float_exception_flags;
146
    testFlagsFunctionPtr = syst_float_flags_clear;
147
    tininessModeName = 0;
148
    operands = 0;
149
    roundingPrecision = 0;
150
    roundingMode = 0;// ROUND_DOWN// - for only round down tests ; 
151
                     //0 - for do all rounding modes 
152
    // "all" setting:
153
    functionArgument = TRUE;
154
    functionCode = 0; // See testFunction.c for list. 
155
    // 0 = all possible functions
156
    // 9 = float32_to_int32
157
    // 10 = float32_to_int32_round_to_zero
158
    // 17 = float32_add
159
    // 18 = float32_sub
160
    // 19 = float32_mul
161
    // 20 = float32_div
162
    // 23 = float32_eq
163
    // 24 = float32_le
164
    // 25 = float32_lt
165
 
166
    operands = 0;
167
 
168
    if ( ! functionArgument ) fail( "Function argument required" );
169
    //    (void) signal( SIGINT, catchSIGINT );
170
    //    (void) signal( SIGTERM, catchSIGINT );
171
    if ( functionCode ) {
172
        if ( forever ) {
173
            if ( ! roundingPrecision ) roundingPrecision = 80;
174
            if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
175
        }
176
        testFunction( functionCode, roundingPrecision, roundingMode );
177
    }
178
    else {
179
 
180
      for ( functionCode = 1;
181
                  functionCode < NUM_FUNCTIONS;
182
                  ++functionCode
183
                ) {
184
        //printf("trying function %d\n",functionCode);
185
                if ( functionExists[ functionCode ] ) {
186
                    testFunction(
187
                        functionCode, roundingPrecision, roundingMode );
188
                }
189
            }
190
 
191
    }
192
    exitWithStatus();
193
 
194
    // Should never reach here
195
    return 1;
196
 
197
}
198
 

powered by: WebSVN 2.1.0

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