fpu: Hoist nan check in partsN_addsub
The nan test had been down below because it was unlikely. But if we have to have one anyway because of denormals, we might as well take care of them right away. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Richard Henderson committed
Apr 26, 2026 at 16:23 UTC
af25a775c65354efa7cee8fe5de7e6997af6e536
1 file changed
+5
-14
fpu/softfloat-parts.c.inc
+5
-14
@@ -530,13 +530,15 @@ FloatPartsN partsN(addsub)(const FloatPartsN *a_orig,
530
{
531
int ab_mask = float_cmask(a_orig->cls) | float_cmask(b_orig->cls);
532
533
+ if (unlikely(ab_mask & float_cmask_anynan)) {
534
+ return partsN(pick_nan)(a_orig, b_orig, s);
535
+ }
536
+
537
/*
538
* For addition and subtraction, we will consume an
539
* input denormal unless the other input is a NaN.
540
*/
537
- if (!(ab_mask & float_cmask_anynan)) {
538
- record_denormals_used(ab_mask, s);
539
- }
541
+ record_denormals_used(ab_mask, s);
542
543
FloatPartsN a = *a_orig;
544
FloatPartsN b = *b_orig;
@@ -558,10 +560,6 @@ FloatPartsN partsN(addsub)(const FloatPartsN *a_orig,
560
return a;
561
}
562
561
- if (unlikely(ab_mask & float_cmask_anynan)) {
562
- goto p_nan;
563
- }
564
-
563
if (ab_mask & float_cmask_inf) {
564
if (a.cls != float_class_inf) {
565
/* N - Inf */
@@ -586,10 +584,6 @@ FloatPartsN partsN(addsub)(const FloatPartsN *a_orig,
584
return a;
585
}
586
589
- if (unlikely(ab_mask & float_cmask_anynan)) {
590
- goto p_nan;
591
- }
592
-
587
if (ab_mask & float_cmask_inf) {
588
a.cls = float_class_inf;
589
return a;
@@ -604,9 +598,6 @@ FloatPartsN partsN(addsub)(const FloatPartsN *a_orig,
598
g_assert(a.cls == float_class_zero);
599
g_assert(is_anynorm(b.cls));
600
return b;
607
-
608
- p_nan:
609
- return partsN(pick_nan)(a_orig, b_orig, s);
601
}
602
603
/*