1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include "ieee754int.h"
34#include "ieee754sp.h"
35#include "ieee754dp.h"
36
37#define DP_EBIAS 1023
38#define DP_EMIN (-1022)
39#define DP_EMAX 1023
40
41#define SP_EBIAS 127
42#define SP_EMIN (-126)
43#define SP_EMAX 127
44
45
46
47
48
49#if (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) || defined(__MIPSEL__)
50#define SPSTR(s, b, m) {m, b, s}
51#define DPSTR(s, b, mh, ml) {ml, mh, b, s}
52#endif
53
54#ifdef __MIPSEB__
55#define SPSTR(s, b, m) {s, b, m}
56#define DPSTR(s, b, mh, ml) {s, b, mh, ml}
57#endif
58
59const struct ieee754dp_konst __ieee754dp_spcvals[] = {
60 DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 0),
61 DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 0),
62 DPSTR(0, DP_EBIAS, 0, 0),
63 DPSTR(1, DP_EBIAS, 0, 0),
64 DPSTR(0, 3 + DP_EBIAS, 0x40000, 0),
65 DPSTR(1, 3 + DP_EBIAS, 0x40000, 0),
66 DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0, 0),
67 DPSTR(1, DP_EMAX + 1 + DP_EBIAS, 0, 0),
68 DPSTR(0, DP_EMAX+1+DP_EBIAS, 0x7FFFF, 0xFFFFFFFF),
69 DPSTR(0, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),
70 DPSTR(1, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF),
71 DPSTR(0, DP_EMIN + DP_EBIAS, 0, 0),
72 DPSTR(1, DP_EMIN + DP_EBIAS, 0, 0),
73 DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 1),
74 DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 1),
75 DPSTR(0, 31 + DP_EBIAS, 0, 0),
76 DPSTR(0, 63 + DP_EBIAS, 0, 0),
77};
78
79const struct ieee754sp_konst __ieee754sp_spcvals[] = {
80 SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 0),
81 SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 0),
82 SPSTR(0, SP_EBIAS, 0),
83 SPSTR(1, SP_EBIAS, 0),
84 SPSTR(0, 3 + SP_EBIAS, 0x200000),
85 SPSTR(1, 3 + SP_EBIAS, 0x200000),
86 SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0),
87 SPSTR(1, SP_EMAX + 1 + SP_EBIAS, 0),
88 SPSTR(0, SP_EMAX+1+SP_EBIAS, 0x3FFFFF),
89 SPSTR(0, SP_EMAX + SP_EBIAS, 0x7FFFFF),
90 SPSTR(1, SP_EMAX + SP_EBIAS, 0x7FFFFF),
91 SPSTR(0, SP_EMIN + SP_EBIAS, 0),
92 SPSTR(1, SP_EMIN + SP_EBIAS, 0),
93 SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 1),
94 SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 1),
95 SPSTR(0, 31 + SP_EBIAS, 0),
96 SPSTR(0, 63 + SP_EBIAS, 0),
97};
98
99
100int ieee754si_xcpt(int r, const char *op, ...)
101{
102 struct ieee754xctx ax;
103
104 if (!TSTX())
105 return r;
106 ax.op = op;
107 ax.rt = IEEE754_RT_SI;
108 ax.rv.si = r;
109 va_start(ax.ap, op);
110 ieee754_xcpt(&ax);
111 va_end(ax.ap);
112 return ax.rv.si;
113}
114
115s64 ieee754di_xcpt(s64 r, const char *op, ...)
116{
117 struct ieee754xctx ax;
118
119 if (!TSTX())
120 return r;
121 ax.op = op;
122 ax.rt = IEEE754_RT_DI;
123 ax.rv.di = r;
124 va_start(ax.ap, op);
125 ieee754_xcpt(&ax);
126 va_end(ax.ap);
127 return ax.rv.di;
128}
129