mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
softfloat: Move round_to_int_and_pack to softfloat-parts.c.inc
Rename to parts$N_float_to_sint. Reimplement float128_to_int{32,64}{_round_to_zero} with FloatParts128. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
afc34931eb
commit
463b3f0d7f
2 changed files with 145 additions and 284 deletions
|
@ -751,3 +751,67 @@ static void partsN(round_to_int)(FloatPartsN *a, FloatRoundMode rmode,
|
|||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the result of converting the floating-point value `a' to
|
||||
* the two's complement integer format. The conversion is performed
|
||||
* according to the IEC/IEEE Standard for Binary Floating-Point
|
||||
* Arithmetic---which means in particular that the conversion is
|
||||
* rounded according to the current rounding mode. If `a' is a NaN,
|
||||
* the largest positive integer is returned. Otherwise, if the
|
||||
* conversion overflows, the largest integer with the same sign as `a'
|
||||
* is returned.
|
||||
*/
|
||||
static int64_t partsN(float_to_sint)(FloatPartsN *p, FloatRoundMode rmode,
|
||||
int scale, int64_t min, int64_t max,
|
||||
float_status *s)
|
||||
{
|
||||
int flags = 0;
|
||||
uint64_t r;
|
||||
|
||||
switch (p->cls) {
|
||||
case float_class_snan:
|
||||
case float_class_qnan:
|
||||
flags = float_flag_invalid;
|
||||
r = max;
|
||||
break;
|
||||
|
||||
case float_class_inf:
|
||||
flags = float_flag_invalid;
|
||||
r = p->sign ? min : max;
|
||||
break;
|
||||
|
||||
case float_class_zero:
|
||||
return 0;
|
||||
|
||||
case float_class_normal:
|
||||
/* TODO: N - 2 is frac_size for rounding; could use input fmt. */
|
||||
if (parts_round_to_int_normal(p, rmode, scale, N - 2)) {
|
||||
flags = float_flag_inexact;
|
||||
}
|
||||
|
||||
if (p->exp <= DECOMPOSED_BINARY_POINT) {
|
||||
r = p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp);
|
||||
} else {
|
||||
r = UINT64_MAX;
|
||||
}
|
||||
if (p->sign) {
|
||||
if (r <= -(uint64_t)min) {
|
||||
r = -r;
|
||||
} else {
|
||||
flags = float_flag_invalid;
|
||||
r = min;
|
||||
}
|
||||
} else if (r > max) {
|
||||
flags = float_flag_invalid;
|
||||
r = max;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
float_raise(flags, s);
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue