1 #define ASSERT(EXPRESSION) \
4 fprintf (stderr, "%s:%d: assertion failed - %s\n", \
5 __FILE__, __LINE__, #EXPRESSION); \
10 #define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)
13 #include "softfloat.h"
14 #include "systfloat.h"
15 #include "systmodes.h"
17 /* #define SIM_FPU_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE) */
29 syst_float_flags_clear ()
35 switch ((sim_fpu_status
) (flags
& i
))
37 case sim_fpu_status_denorm
:
39 case sim_fpu_status_invalid_snan
:
40 case sim_fpu_status_invalid_qnan
:
41 case sim_fpu_status_invalid_isi
:
42 case sim_fpu_status_invalid_idi
:
43 case sim_fpu_status_invalid_zdz
:
44 case sim_fpu_status_invalid_imz
:
45 case sim_fpu_status_invalid_cvi
:
46 case sim_fpu_status_invalid_cmp
:
47 case sim_fpu_status_invalid_sqrt
:
48 old_flags
|= float_flag_invalid
; /* v */
50 case sim_fpu_status_inexact
:
51 old_flags
|= float_flag_inexact
; /* x */
53 case sim_fpu_status_overflow
:
54 old_flags
|= float_flag_overflow
; /* o */
56 case sim_fpu_status_underflow
:
57 old_flags
|= float_flag_underflow
; /* u */
59 case sim_fpu_status_invalid_div0
:
60 old_flags
|= float_flag_divbyzero
; /* z */
62 case sim_fpu_status_rounded
:
72 sim_fpu_round rounding_mode
;
75 syst_float_set_rounding_mode(int8 mode
)
79 case float_round_nearest_even
:
80 rounding_mode
= sim_fpu_round_near
;
82 case float_round_down
:
83 rounding_mode
= sim_fpu_round_down
;
86 rounding_mode
= sim_fpu_round_up
;
88 case float_round_to_zero
:
89 rounding_mode
= sim_fpu_round_zero
;
96 syst_int32_to_float32(int32 a
)
100 flags
|= sim_fpu_i32to (&s
, a
, rounding_mode
);
101 flags
|= sim_fpu_round_32 (&s
, rounding_mode
, 0);
102 sim_fpu_to32 (&z
, &s
);
107 syst_int32_to_float64( int32 a
)
111 flags
|= sim_fpu_i32to (&s
, a
, rounding_mode
);
112 sim_fpu_to64 (&z
, &s
);
117 syst_float32_to_int32_round_to_zero( float32 a
)
121 sim_fpu_32to (&s
, a
);
122 flags
|= sim_fpu_to32i (&z
, &s
, sim_fpu_round_zero
);
127 syst_float32_to_float64 (float32 a
)
131 sim_fpu_32to (&s
, a
);
132 flags
|= sim_fpu_round_64 (&s
, rounding_mode
, 0);
133 sim_fpu_to64 (&z
, &s
);
137 float32
syst_float32_add( float32 a
, float32 b
)
143 sim_fpu_32to (&A
, a
);
144 sim_fpu_32to (&B
, b
);
146 fprintf (stdout
, "\n ");
147 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
148 fprintf (stdout
, "\n+ ");
149 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
150 fprintf (stdout
, "\n= ");
152 flags
|= sim_fpu_add (&ans
, &A
, &B
);
153 flags
|= sim_fpu_round_32 (&ans
, rounding_mode
, 0);
155 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
156 fprintf (stdout
, "\n");
158 sim_fpu_to32 (&z
, &ans
);
162 float32
syst_float32_sub( float32 a
, float32 b
)
168 sim_fpu_32to (&A
, a
);
169 sim_fpu_32to (&B
, b
);
171 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
172 fprintf (stdout
, " + ");
173 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
174 fprintf (stdout
, " = ");
176 flags
|= sim_fpu_sub (&ans
, &A
, &B
);
177 flags
|= sim_fpu_round_32 (&ans
, rounding_mode
, 0);
179 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
180 fprintf (stdout
, "\n");
182 sim_fpu_to32 (&z
, &ans
);
186 float32
syst_float32_mul( float32 a
, float32 b
)
192 sim_fpu_32to (&A
, a
);
193 sim_fpu_32to (&B
, b
);
195 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
196 fprintf (stdout
, " + ");
197 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
198 fprintf (stdout
, " = ");
200 flags
|= sim_fpu_mul (&ans
, &A
, &B
);
202 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
204 flags
|= sim_fpu_round_32 (&ans
, rounding_mode
, 0);
206 sim_fpu_print_status (flags
, (sim_fpu_print_func
*) fprintf
, stdout
);
207 fprintf (stdout
, "\n");
209 sim_fpu_to32 (&z
, &ans
);
213 float32
syst_float32_div( float32 a
, float32 b
)
219 sim_fpu_32to (&A
, a
);
220 sim_fpu_32to (&B
, b
);
221 flags
|= sim_fpu_div (&ans
, &A
, &B
);
222 flags
|= sim_fpu_round_32 (&ans
, rounding_mode
, 0);
223 sim_fpu_to32 (&z
, &ans
);
227 float32
syst_float32_sqrt( float32 a
)
232 sim_fpu_32to (&A
, a
);
234 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
235 fprintf (stdout
, " sqrt> ");
237 flags
|= sim_fpu_sqrt (&ans
, &A
);
239 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
241 flags
|= sim_fpu_round_32 (&ans
, rounding_mode
, 0);
243 fprintf (stdout
, " (%x)\n", flags
);
245 sim_fpu_to32 (&z
, &ans
);
249 flag
syst_float32_eq( float32 a
, float32 b
)
254 sim_fpu_32to (&A
, a
);
255 sim_fpu_32to (&B
, b
);
256 flags
|= (sim_fpu_eq (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);
260 flag
syst_float32_eq_signaling( float32 a
, float32 b
)
265 sim_fpu_32to (&A
, a
);
266 sim_fpu_32to (&B
, b
);
267 flags
|= sim_fpu_eq (&is
, &A
, &B
);
271 flag
syst_float32_le( float32 a
, float32 b
)
276 sim_fpu_32to (&A
, a
);
277 sim_fpu_32to (&B
, b
);
278 flags
|= sim_fpu_le (&is
, &A
, &B
);
282 flag
syst_float32_le_quiet( float32 a
, float32 b
)
287 sim_fpu_32to (&A
, a
);
288 sim_fpu_32to (&B
, b
);
289 flags
|= (sim_fpu_le (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);
293 flag
syst_float32_lt( float32 a
, float32 b
)
298 sim_fpu_32to (&A
, a
);
299 sim_fpu_32to (&B
, b
);
300 flags
|= sim_fpu_lt (&is
, &A
, &B
);
304 flag
syst_float32_lt_quiet( float32 a
, float32 b
)
309 sim_fpu_32to (&A
, a
);
310 sim_fpu_32to (&B
, b
);
311 flags
|= (sim_fpu_lt (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);
315 int32
syst_float64_to_int32_round_to_zero( float64 a
)
319 sim_fpu_64to (&s
, a
);
320 flags
|= sim_fpu_to32i (&z
, &s
, sim_fpu_round_zero
);
324 float32
syst_float64_to_float32( float64 a
)
328 sim_fpu_64to (&s
, a
);
330 sim_fpu_print_fpu (&s
, (sim_fpu_print_func
*) fprintf
, stdout
);
331 fprintf (stdout
, " -> ");
333 flags
|= sim_fpu_round_32 (&s
, rounding_mode
, 0);
335 sim_fpu_print_fpu (&s
, (sim_fpu_print_func
*) fprintf
, stdout
);
336 sim_fpu_print_status (flags
, (sim_fpu_print_func
*) fprintf
, stdout
);
339 sim_fpu_to32 (&z
, &s
);
343 float64
syst_float64_add( float64 a
, float64 b
)
349 sim_fpu_64to (&A
, a
);
350 sim_fpu_64to (&B
, b
);
352 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
353 fprintf (stdout
, " + ");
354 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
355 fprintf (stdout
, " = ");
357 flags
|= sim_fpu_add (&ans
, &A
, &B
);
359 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
361 flags
|= sim_fpu_round_64 (&ans
, rounding_mode
, 0);
363 fprintf (stdout
, " (%x)\n", flags
);
365 sim_fpu_to64 (&z
, &ans
);
369 float64
syst_float64_sub( float64 a
, float64 b
)
375 sim_fpu_64to (&A
, a
);
376 sim_fpu_64to (&B
, b
);
378 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
379 fprintf (stdout
, " + ");
380 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
381 fprintf (stdout
, " = ");
383 flags
|= sim_fpu_sub (&ans
, &A
, &B
);
385 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
387 flags
|= sim_fpu_round_64 (&ans
, rounding_mode
, 0);
389 fprintf (stdout
, " (%x)\n", flags
);
391 sim_fpu_to64 (&z
, &ans
);
395 float64
syst_float64_mul( float64 a
, float64 b
)
401 sim_fpu_64to (&A
, a
);
402 sim_fpu_64to (&B
, b
);
404 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
405 fprintf (stdout
, " * ");
406 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
407 fprintf (stdout
, " = ");
409 flags
|= sim_fpu_mul (&ans
, &A
, &B
);
411 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
413 flags
|= sim_fpu_round_64 (&ans
, rounding_mode
, 0);
415 sim_fpu_print_status (flags
, (sim_fpu_print_func
*) fprintf
, stdout
);
416 fprintf (stdout
, "\n");
418 sim_fpu_to64 (&z
, &ans
);
422 float64
syst_float64_div( float64 a
, float64 b
)
428 sim_fpu_64to (&A
, a
);
429 sim_fpu_64to (&B
, b
);
431 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
432 fprintf (stdout
, " + ");
433 sim_fpu_print_fpu (&B
, (sim_fpu_print_func
*) fprintf
, stdout
);
434 fprintf (stdout
, " = ");
436 flags
|= sim_fpu_div (&ans
, &A
, &B
);
438 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
440 flags
|= sim_fpu_round_64 (&ans
, rounding_mode
, 0);
442 sim_fpu_print_status (flags
, (sim_fpu_print_func
*) fprintf
, stdout
);
443 fprintf (stdout
, "\n");
445 sim_fpu_to64 (&z
, &ans
);
449 float64
syst_float64_sqrt( float64 a
)
454 sim_fpu_64to (&A
, a
);
456 sim_fpu_print_fpu (&A
, (sim_fpu_print_func
*) fprintf
, stdout
);
460 flags
|= sim_fpu_sqrt (&ans
, &A
);
462 sim_fpu_print_fpu (&ans
, (sim_fpu_print_func
*) fprintf
, stdout
);
464 flags
|= sim_fpu_round_64 (&ans
, rounding_mode
, 0);
466 sim_fpu_print_status (flags
, (sim_fpu_print_func
*) fprintf
, stdout
);
467 fprintf (stdout
, "\n");
469 sim_fpu_to64 (&z
, &ans
);
473 flag
syst_float64_eq( float64 a
, float64 b
)
478 sim_fpu_64to (&A
, a
);
479 sim_fpu_64to (&B
, b
);
480 flags
|= (sim_fpu_eq (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);
484 flag
syst_float64_eq_signaling( float64 a
, float64 b
)
489 sim_fpu_64to (&A
, a
);
490 sim_fpu_64to (&B
, b
);
491 flags
|= sim_fpu_eq (&is
, &A
, &B
);
495 flag
syst_float64_le( float64 a
, float64 b
)
500 sim_fpu_64to (&A
, a
);
501 sim_fpu_64to (&B
, b
);
502 flags
|= sim_fpu_le (&is
, &A
, &B
);
506 flag
syst_float64_le_quiet( float64 a
, float64 b
)
511 sim_fpu_64to (&A
, a
);
512 sim_fpu_64to (&B
, b
);
513 flags
|= (sim_fpu_le (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);
517 flag
syst_float64_lt( float64 a
, float64 b
)
522 sim_fpu_64to (&A
, a
);
523 sim_fpu_64to (&B
, b
);
524 flags
|= sim_fpu_lt (&is
, &A
, &B
);
528 flag
syst_float64_lt_quiet( float64 a
, float64 b
)
533 sim_fpu_64to (&A
, a
);
534 sim_fpu_64to (&B
, b
);
535 flags
|= (sim_fpu_lt (&is
, &A
, &B
) & ~sim_fpu_status_invalid_qnan
);