cgen-fpu.h revision 1.1.1.1 1 1.1 christos /* CGEN fpu support
2 1.1 christos Copyright (C) 1999 Cygnus Solutions.
3 1.1 christos Copyright (C) 2010 Doug Evans. */
4 1.1 christos
5 1.1 christos #ifndef CGEN_FPU_H
6 1.1 christos #define CGEN_FPU_H
7 1.1 christos
8 1.1 christos /* Floating point support is a little more complicated.
9 1.1 christos We want to support using either host fp insns or an accurate fp library.
10 1.1 christos We also want to support easily added variants (e.g. modified ieee).
11 1.1 christos This is done by vectoring all calls through a table. */
12 1.1 christos
13 1.1 christos typedef USI SF;
14 1.1 christos typedef UDI DF;
15 1.1 christos typedef struct { SI parts[3]; } XF;
16 1.1 christos typedef struct { SI parts[4]; } TF;
17 1.1 christos
18 1.1 christos #ifndef TARGET_EXT_FP_WORDS
19 1.1 christos #define TARGET_EXT_FP_WORDS 4
20 1.1 christos #endif
21 1.1 christos
22 1.1 christos /* Supported floating point conversion kinds (rounding modes).
23 1.1 christos FIXME: The IEEE rounding modes need to be implemented. */
24 1.1 christos
25 1.1 christos typedef enum {
26 1.1 christos FPCONV_DEFAULT = 0,
27 1.1 christos FPCONV_TIES_TO_EVEN = 1,
28 1.1 christos FPCONV_TIES_TO_AWAY = 2,
29 1.1 christos FPCONV_TOWARD_ZERO = 3,
30 1.1 christos FPCONV_TOWARD_POSITIVE = 4,
31 1.1 christos FPCONV_TOWARD_NEGATIVE = 5
32 1.1 christos } CGEN_FPCONV_KIND;
33 1.1 christos
34 1.1 christos /* forward decl */
35 1.1 christos typedef struct cgen_fp_ops CGEN_FP_OPS;
36 1.1 christos
37 1.1 christos /* Instance of an fpu. */
38 1.1 christos
39 1.1 christos typedef struct {
40 1.1 christos /* Usually a pointer back to the SIM_CPU struct. */
41 1.1 christos void* owner;
42 1.1 christos /* Pointer to ops struct, rather than copy of it, to avoid bloating
43 1.1 christos SIM_CPU struct. */
44 1.1 christos CGEN_FP_OPS* ops;
45 1.1 christos } CGEN_FPU;
46 1.1 christos
47 1.1 christos /* result of cmp */
48 1.1 christos
49 1.1 christos typedef enum {
50 1.1 christos /* ??? May wish to distinguish qnan/snan here. */
51 1.1 christos FP_CMP_EQ, FP_CMP_LT, FP_CMP_GT, FP_CMP_NAN
52 1.1 christos } CGEN_FP_CMP;
53 1.1 christos
54 1.1 christos /* error handler */
55 1.1 christos
56 1.1 christos typedef void (CGEN_FPU_ERROR_FN) (CGEN_FPU*, int);
57 1.1 christos
58 1.1 christos /* fpu operation table */
59 1.1 christos
60 1.1 christos struct cgen_fp_ops {
61 1.1 christos
62 1.1 christos /* error (e.g. signalling nan) handler, supplied by owner */
63 1.1 christos
64 1.1 christos CGEN_FPU_ERROR_FN *error;
65 1.1 christos
66 1.1 christos /* basic SF ops */
67 1.1 christos
68 1.1 christos SF (*addsf) (CGEN_FPU*, SF, SF);
69 1.1 christos SF (*subsf) (CGEN_FPU*, SF, SF);
70 1.1 christos SF (*mulsf) (CGEN_FPU*, SF, SF);
71 1.1 christos SF (*divsf) (CGEN_FPU*, SF, SF);
72 1.1 christos SF (*negsf) (CGEN_FPU*, SF);
73 1.1 christos SF (*abssf) (CGEN_FPU*, SF);
74 1.1 christos SF (*sqrtsf) (CGEN_FPU*, SF);
75 1.1 christos SF (*invsf) (CGEN_FPU*, SF);
76 1.1 christos SF (*cossf) (CGEN_FPU*, SF);
77 1.1 christos SF (*sinsf) (CGEN_FPU*, SF);
78 1.1 christos SF (*minsf) (CGEN_FPU*, SF, SF);
79 1.1 christos SF (*maxsf) (CGEN_FPU*, SF, SF);
80 1.1 christos
81 1.1 christos /* ??? to be revisited */
82 1.1 christos CGEN_FP_CMP (*cmpsf) (CGEN_FPU*, SF, SF);
83 1.1 christos int (*eqsf) (CGEN_FPU*, SF, SF);
84 1.1 christos int (*nesf) (CGEN_FPU*, SF, SF);
85 1.1 christos int (*ltsf) (CGEN_FPU*, SF, SF);
86 1.1 christos int (*lesf) (CGEN_FPU*, SF, SF);
87 1.1 christos int (*gtsf) (CGEN_FPU*, SF, SF);
88 1.1 christos int (*gesf) (CGEN_FPU*, SF, SF);
89 1.1 christos
90 1.1 christos /* basic DF ops */
91 1.1 christos
92 1.1 christos DF (*adddf) (CGEN_FPU*, DF, DF);
93 1.1 christos DF (*subdf) (CGEN_FPU*, DF, DF);
94 1.1 christos DF (*muldf) (CGEN_FPU*, DF, DF);
95 1.1 christos DF (*divdf) (CGEN_FPU*, DF, DF);
96 1.1 christos DF (*negdf) (CGEN_FPU*, DF);
97 1.1 christos DF (*absdf) (CGEN_FPU*, DF);
98 1.1 christos DF (*sqrtdf) (CGEN_FPU*, DF);
99 1.1 christos DF (*invdf) (CGEN_FPU*, DF);
100 1.1 christos DF (*cosdf) (CGEN_FPU*, DF);
101 1.1 christos DF (*sindf) (CGEN_FPU*, DF);
102 1.1 christos DF (*mindf) (CGEN_FPU*, DF, DF);
103 1.1 christos DF (*maxdf) (CGEN_FPU*, DF, DF);
104 1.1 christos
105 1.1 christos /* ??? to be revisited */
106 1.1 christos CGEN_FP_CMP (*cmpdf) (CGEN_FPU*, DF, DF);
107 1.1 christos int (*eqdf) (CGEN_FPU*, DF, DF);
108 1.1 christos int (*nedf) (CGEN_FPU*, DF, DF);
109 1.1 christos int (*ltdf) (CGEN_FPU*, DF, DF);
110 1.1 christos int (*ledf) (CGEN_FPU*, DF, DF);
111 1.1 christos int (*gtdf) (CGEN_FPU*, DF, DF);
112 1.1 christos int (*gedf) (CGEN_FPU*, DF, DF);
113 1.1 christos
114 1.1 christos /* SF/DF conversion ops */
115 1.1 christos
116 1.1 christos DF (*fextsfdf) (CGEN_FPU*, int, SF);
117 1.1 christos SF (*ftruncdfsf) (CGEN_FPU*, int, DF);
118 1.1 christos
119 1.1 christos SF (*floatsisf) (CGEN_FPU*, int, SI);
120 1.1 christos SF (*floatdisf) (CGEN_FPU*, int, DI);
121 1.1 christos SF (*ufloatsisf) (CGEN_FPU*, int, USI);
122 1.1 christos SF (*ufloatdisf) (CGEN_FPU*, int, UDI);
123 1.1 christos
124 1.1 christos SI (*fixsfsi) (CGEN_FPU*, int, SF);
125 1.1 christos DI (*fixsfdi) (CGEN_FPU*, int, SF);
126 1.1 christos USI (*ufixsfsi) (CGEN_FPU*, int, SF);
127 1.1 christos UDI (*ufixsfdi) (CGEN_FPU*, int, SF);
128 1.1 christos
129 1.1 christos DF (*floatsidf) (CGEN_FPU*, int, SI);
130 1.1 christos DF (*floatdidf) (CGEN_FPU*, int, DI);
131 1.1 christos DF (*ufloatsidf) (CGEN_FPU*, int, USI);
132 1.1 christos DF (*ufloatdidf) (CGEN_FPU*, int, UDI);
133 1.1 christos
134 1.1 christos SI (*fixdfsi) (CGEN_FPU*, int, DF);
135 1.1 christos DI (*fixdfdi) (CGEN_FPU*, int, DF);
136 1.1 christos USI (*ufixdfsi) (CGEN_FPU*, int, DF);
137 1.1 christos UDI (*ufixdfdi) (CGEN_FPU*, int, DF);
138 1.1 christos
139 1.1 christos /* XF mode support (kept separate 'cus not always present) */
140 1.1 christos
141 1.1 christos XF (*addxf) (CGEN_FPU*, XF, XF);
142 1.1 christos XF (*subxf) (CGEN_FPU*, XF, XF);
143 1.1 christos XF (*mulxf) (CGEN_FPU*, XF, XF);
144 1.1 christos XF (*divxf) (CGEN_FPU*, XF, XF);
145 1.1 christos XF (*negxf) (CGEN_FPU*, XF);
146 1.1 christos XF (*absxf) (CGEN_FPU*, XF);
147 1.1 christos XF (*sqrtxf) (CGEN_FPU*, XF);
148 1.1 christos XF (*invxf) (CGEN_FPU*, XF);
149 1.1 christos XF (*cosxf) (CGEN_FPU*, XF);
150 1.1 christos XF (*sinxf) (CGEN_FPU*, XF);
151 1.1 christos XF (*minxf) (CGEN_FPU*, XF, XF);
152 1.1 christos XF (*maxxf) (CGEN_FPU*, XF, XF);
153 1.1 christos
154 1.1 christos CGEN_FP_CMP (*cmpxf) (CGEN_FPU*, XF, XF);
155 1.1 christos int (*eqxf) (CGEN_FPU*, XF, XF);
156 1.1 christos int (*nexf) (CGEN_FPU*, XF, XF);
157 1.1 christos int (*ltxf) (CGEN_FPU*, XF, XF);
158 1.1 christos int (*lexf) (CGEN_FPU*, XF, XF);
159 1.1 christos int (*gtxf) (CGEN_FPU*, XF, XF);
160 1.1 christos int (*gexf) (CGEN_FPU*, XF, XF);
161 1.1 christos
162 1.1 christos XF (*extsfxf) (CGEN_FPU*, int, SF);
163 1.1 christos XF (*extdfxf) (CGEN_FPU*, int, DF);
164 1.1 christos SF (*truncxfsf) (CGEN_FPU*, int, XF);
165 1.1 christos DF (*truncxfdf) (CGEN_FPU*, int, XF);
166 1.1 christos
167 1.1 christos XF (*floatsixf) (CGEN_FPU*, int, SI);
168 1.1 christos XF (*floatdixf) (CGEN_FPU*, int, DI);
169 1.1 christos XF (*ufloatsixf) (CGEN_FPU*, int, USI);
170 1.1 christos XF (*ufloatdixf) (CGEN_FPU*, int, UDI);
171 1.1 christos
172 1.1 christos SI (*fixxfsi) (CGEN_FPU*, int, XF);
173 1.1 christos DI (*fixxfdi) (CGEN_FPU*, int, XF);
174 1.1 christos USI (*ufixxfsi) (CGEN_FPU*, int, XF);
175 1.1 christos UDI (*ufixxfdi) (CGEN_FPU*, int, XF);
176 1.1 christos
177 1.1 christos /* TF mode support (kept separate 'cus not always present) */
178 1.1 christos
179 1.1 christos TF (*addtf) (CGEN_FPU*, TF, TF);
180 1.1 christos TF (*subtf) (CGEN_FPU*, TF, TF);
181 1.1 christos TF (*multf) (CGEN_FPU*, TF, TF);
182 1.1 christos TF (*divtf) (CGEN_FPU*, TF, TF);
183 1.1 christos TF (*negtf) (CGEN_FPU*, TF);
184 1.1 christos TF (*abstf) (CGEN_FPU*, TF);
185 1.1 christos TF (*sqrttf) (CGEN_FPU*, TF);
186 1.1 christos TF (*invtf) (CGEN_FPU*, TF);
187 1.1 christos TF (*costf) (CGEN_FPU*, TF);
188 1.1 christos TF (*sintf) (CGEN_FPU*, TF);
189 1.1 christos TF (*mintf) (CGEN_FPU*, TF, TF);
190 1.1 christos TF (*maxtf) (CGEN_FPU*, TF, TF);
191 1.1 christos
192 1.1 christos CGEN_FP_CMP (*cmptf) (CGEN_FPU*, TF, TF);
193 1.1 christos int (*eqtf) (CGEN_FPU*, TF, TF);
194 1.1 christos int (*netf) (CGEN_FPU*, TF, TF);
195 1.1 christos int (*lttf) (CGEN_FPU*, TF, TF);
196 1.1 christos int (*letf) (CGEN_FPU*, TF, TF);
197 1.1 christos int (*gttf) (CGEN_FPU*, TF, TF);
198 1.1 christos int (*getf) (CGEN_FPU*, TF, TF);
199 1.1 christos
200 1.1 christos TF (*extsftf) (CGEN_FPU*, int, SF);
201 1.1 christos TF (*extdftf) (CGEN_FPU*, int, DF);
202 1.1 christos SF (*trunctfsf) (CGEN_FPU*, int, TF);
203 1.1 christos DF (*trunctfdf) (CGEN_FPU*, int, TF);
204 1.1 christos
205 1.1 christos TF (*floatsitf) (CGEN_FPU*, int, SI);
206 1.1 christos TF (*floatditf) (CGEN_FPU*, int, DI);
207 1.1 christos TF (*ufloatsitf) (CGEN_FPU*, int, USI);
208 1.1 christos TF (*ufloatditf) (CGEN_FPU*, int, UDI);
209 1.1 christos
210 1.1 christos SI (*fixtfsi) (CGEN_FPU*, int, TF);
211 1.1 christos DI (*fixtfdi) (CGEN_FPU*, int, TF);
212 1.1 christos USI (*ufixtfsi) (CGEN_FPU*, int, TF);
213 1.1 christos UDI (*ufixtfdi) (CGEN_FPU*, int, TF);
214 1.1 christos
215 1.1 christos };
216 1.1 christos
217 1.1 christos extern void cgen_init_accurate_fpu (SIM_CPU*, CGEN_FPU*, CGEN_FPU_ERROR_FN*);
218 1.1 christos
219 1.1 christos BI cgen_sf_snan_p (CGEN_FPU*, SF);
220 1.1 christos BI cgen_df_snan_p (CGEN_FPU*, DF);
221 1.1 christos
222 1.1 christos /* no-op fp error handler */
223 1.1 christos extern CGEN_FPU_ERROR_FN cgen_fpu_ignore_errors;
224 1.1 christos
225 1.1 christos #endif /* CGEN_FPU_H */
226