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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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