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

Subversion Repositories openrisc

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

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
#include <stdio.h>
31
                                                                 */
32
#include "support.h" // OR1k support C library
33
#include "milieu.h"
34
#include "softfloat.h"
35
#include "writeHex.h"
36
 
37
void writeHex_flag( flag a/*, FILE *stream */ )
38
{
39
 
40
    putchar( a ? '1' : '0' );
41
 
42
}
43
 
44
static void writeHex_bits8( bits8 a/*, FILE *stream */ )
45
{
46
    int digit;
47
 
48
    digit = ( a>>4 ) & 0xF;
49
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
50
    putchar( '0' + digit );
51
    digit = a & 0xF;
52
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
53
    putchar( '0' + digit );
54
 
55
}
56
 
57
static void writeHex_bits12( int16 a/*, FILE *stream */ )
58
{
59
    int digit;
60
 
61
    digit = ( a>>8 ) & 0xF;
62
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
63
    putchar( '0' + digit );
64
    digit = ( a>>4 ) & 0xF;
65
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
66
    putchar( '0' + digit );
67
    digit = a & 0xF;
68
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
69
    putchar( '0' + digit );
70
 
71
}
72
 
73
static void writeHex_bits16( bits16 a/*, FILE *stream */ )
74
{
75
    int digit;
76
 
77
    digit = ( a>>12 ) & 0xF;
78
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
79
    putchar( '0' + digit );
80
    digit = ( a>>8 ) & 0xF;
81
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
82
    putchar( '0' + digit );
83
    digit = ( a>>4 ) & 0xF;
84
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
85
    putchar( '0' + digit );
86
    digit = a & 0xF;
87
    if ( 9 < digit ) digit += 'A' - ( '0' + 10 );
88
    putchar( '0' + digit );
89
 
90
}
91
 
92
void writeHex_bits32( bits32 a/*, FILE *stream */ )
93
{
94
 
95
    writeHex_bits16( a>>16 );
96
    writeHex_bits16( a );
97
 
98
}
99
 
100
#ifdef BITS64
101
 
102
void writeHex_bits64( bits64 a/*, FILE *stream */ )
103
{
104
 
105
    writeHex_bits32( a>>32 );
106
    writeHex_bits32( a );
107
 
108
}
109
 
110
#endif
111
 
112
void writeHex_float32( float32 a/*, FILE *stream */ )
113
{
114
 
115
    putchar( ( ( (sbits32) a ) < 0 ) ? '8' : '0' );
116
    writeHex_bits8( a>>23 );
117
    putchar( '.' );
118
    writeHex_bits8( ( a>>16 ) & 0x7F );
119
    writeHex_bits16( a );
120
 
121
}
122
 
123
#ifdef BITS64
124
 
125
void writeHex_float64( float64 a/*, FILE *stream */ )
126
{
127
 
128
    writeHex_bits12( a>>52 );
129
    putchar( '.' );
130
    writeHex_bits12( a>>40 );
131
    writeHex_bits8( a>>32 );
132
    writeHex_bits32( a );
133
 
134
}
135
 
136
#else
137
 
138
void writeHex_float64( float64 a/*, FILE *stream */ )
139
{
140
 
141
    writeHex_bits12( a.high>>20 );
142
    putchar( '.' );
143
    writeHex_bits12( a.high>>8 );
144
    writeHex_bits8( a.high );
145
    writeHex_bits32( a.low );
146
 
147
}
148
 
149
#endif
150
 
151
#ifdef FLOATX80
152
 
153
void writeHex_floatx80( floatx80 a/*, FILE *stream */ )
154
{
155
 
156
    writeHex_bits16( a.high );
157
    putchar( '.' );
158
    writeHex_bits64( a.low );
159
 
160
}
161
 
162
#endif
163
 
164
#ifdef FLOAT128
165
 
166
void writeHex_float128( float128 a/*, FILE *stream */ )
167
{
168
 
169
    writeHex_bits16( a.high>>48 );
170
    putchar( '.' );
171
    writeHex_bits16( a.high>>32 );
172
    writeHex_bits32( a.high );
173
    writeHex_bits64( a.low );
174
 
175
}
176
 
177
#endif
178
 
179
void writeHex_float_flags( uint8 flags/*, FILE *stream */ )
180
{
181
 
182
    putchar( flags & float_flag_invalid   ? 'v' : '.' );
183
    putchar( flags & float_flag_divbyzero ? 'z' : '.' );
184
    putchar( flags & float_flag_overflow  ? 'o' : '.' );
185
    putchar( flags & float_flag_underflow ? 'u' : '.' );
186
    putchar( flags & float_flag_inexact   ? 'x' : '.' );
187
 
188
}
189
 

powered by: WebSVN 2.1.0

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