Files
qemu/fpu/softfloat-parts-addsub.c.inc
Richard Henderson 76de9bde8c fpu: Drop FRAC_GENERIC_64_128{_256}
This requires more complexity to handle const selectors, and
an indirection macro for each function.  Easier to just use
the preprocessor.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2026-04-30 08:07:42 +10:00

63 lines
1.7 KiB
C++

/*
* Floating point arithmetic implementation
*
* 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(add_normal)(FloatPartsN *a, FloatPartsN *b)
{
int exp_diff = a->exp - b->exp;
if (exp_diff > 0) {
fracN(shrjam)(b, exp_diff);
} else if (exp_diff < 0) {
fracN(shrjam)(a, -exp_diff);
a->exp = b->exp;
}
if (fracN(add)(a, a, b)) {
fracN(shrjam)(a, 1);
a->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
a->exp += 1;
}
}
static bool partsN(sub_normal)(FloatPartsN *a, FloatPartsN *b)
{
int exp_diff = a->exp - b->exp;
int shift;
if (exp_diff > 0) {
fracN(shrjam)(b, exp_diff);
fracN(sub)(a, a, b);
} else if (exp_diff < 0) {
a->exp = b->exp;
a->sign ^= 1;
fracN(shrjam)(a, -exp_diff);
fracN(sub)(a, b, a);
} else if (fracN(sub)(a, a, b)) {
/* Overflow means that A was less than B. */
fracN(neg)(a);
a->sign ^= 1;
}
shift = fracN(normalize)(a);
if (likely(shift < N)) {
a->exp -= shift;
return true;
}
a->cls = float_class_zero;
return false;
}