2020-10-23 23:47:04 +00:00
|
|
|
/*
|
|
|
|
* QEMU float support
|
|
|
|
*
|
|
|
|
* The code in this source file is derived from release 2a of the SoftFloat
|
|
|
|
* IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and
|
|
|
|
* some later contributions) are provided under that license, as detailed below.
|
|
|
|
* It has subsequently been modified by contributors to the QEMU Project,
|
|
|
|
* so some portions are provided under:
|
|
|
|
* the SoftFloat-2a license
|
|
|
|
* the BSD license
|
|
|
|
* GPL-v2-or-later
|
|
|
|
*
|
|
|
|
* Any future contributions to this file after December 1st 2014 will be
|
|
|
|
* taken to be licensed under the Softfloat-2a license unless specifically
|
|
|
|
* indicated otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void partsN(return_nan)(FloatPartsN *a, float_status *s)
|
|
|
|
{
|
|
|
|
switch (a->cls) {
|
|
|
|
case float_class_snan:
|
|
|
|
float_raise(float_flag_invalid, s);
|
|
|
|
if (s->default_nan_mode) {
|
|
|
|
parts_default_nan(a, s);
|
|
|
|
} else {
|
|
|
|
parts_silence_nan(a, s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case float_class_qnan:
|
|
|
|
if (s->default_nan_mode) {
|
|
|
|
parts_default_nan(a, s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
2020-10-24 00:03:11 +00:00
|
|
|
|
|
|
|
static FloatPartsN *partsN(pick_nan)(FloatPartsN *a, FloatPartsN *b,
|
|
|
|
float_status *s)
|
|
|
|
{
|
|
|
|
if (is_snan(a->cls) || is_snan(b->cls)) {
|
|
|
|
float_raise(float_flag_invalid, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->default_nan_mode) {
|
|
|
|
parts_default_nan(a, s);
|
|
|
|
} else {
|
|
|
|
int cmp = frac_cmp(a, b);
|
|
|
|
if (cmp == 0) {
|
|
|
|
cmp = a->sign < b->sign;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pickNaN(a->cls, b->cls, cmp > 0, s)) {
|
|
|
|
a = b;
|
|
|
|
}
|
|
|
|
if (is_snan(a->cls)) {
|
|
|
|
parts_silence_nan(a, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|