@samitouri / QOSamiQemu / commits / 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>

Richard Henderson committed Apr 25, 2026 at 23:17 UTC 76de9bde8c321cefdfb51d0aa50c7b0a169b9d52
3 files changed +77 -116
fpu/softfloat-parts-addsub.c.inc
+11 -11
@@ -20,14 +20,14 @@ static void partsN(add_normal)(FloatPartsN *a, FloatPartsN *b)
20 int exp_diff = a->exp - b->exp;
21
22 if (exp_diff > 0) {
23 - frac_shrjam(b, exp_diff);
23 + fracN(shrjam)(b, exp_diff);
24 } else if (exp_diff < 0) {
25 - frac_shrjam(a, -exp_diff);
25 + fracN(shrjam)(a, -exp_diff);
26 a->exp = b->exp;
27 }
28
29 - if (frac_add(a, a, b)) {
30 - frac_shrjam(a, 1);
29 + if (fracN(add)(a, a, b)) {
30 + fracN(shrjam)(a, 1);
31 a->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
32 a->exp += 1;
33 }
@@ -39,20 +39,20 @@ static bool partsN(sub_normal)(FloatPartsN *a, FloatPartsN *b)
39 int shift;
40
41 if (exp_diff > 0) {
42 - frac_shrjam(b, exp_diff);
43 - frac_sub(a, a, b);
42 + fracN(shrjam)(b, exp_diff);
43 + fracN(sub)(a, a, b);
44 } else if (exp_diff < 0) {
45 a->exp = b->exp;
46 a->sign ^= 1;
47 - frac_shrjam(a, -exp_diff);
48 - frac_sub(a, b, a);
49 - } else if (frac_sub(a, a, b)) {
47 + fracN(shrjam)(a, -exp_diff);
48 + fracN(sub)(a, b, a);
49 + } else if (fracN(sub)(a, a, b)) {
50 /* Overflow means that A was less than B. */
51 - frac_neg(a);
51 + fracN(neg)(a);
52 a->sign ^= 1;
53 }
54
55 - shift = frac_normalize(a);
55 + shift = fracN(normalize)(a);
56 if (likely(shift < N)) {
57 a->exp -= shift;
58 return true;
fpu/softfloat-parts.c.inc
+51 -51
@@ -98,7 +98,7 @@ static FloatPartsN *partsN(pick_nan)(FloatPartsN *a, FloatPartsN *b,
98 ret = b;
99 break;
100 }
101 - cmp = frac_cmp(a, b);
101 + cmp = fracN(cmp)(a, b);
102 if (cmp == 0) {
103 cmp = a->sign < b->sign;
104 }
@@ -215,14 +215,14 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status,
215 (status->floatx80_behaviour & floatx80_pseudo_denormal_valid);
216
217 if (unlikely(p->exp == 0)) {
218 - if (likely(frac_eqz(p))) {
218 + if (likely(fracN(eqz)(p))) {
219 p->cls = float_class_zero;
220 } else if (status->flush_inputs_to_zero) {
221 float_raise(float_flag_input_denormal_flushed, status);
222 p->cls = float_class_zero;
223 - frac_clear(p);
223 + fracN(clear)(p);
224 } else {
225 - int shift = frac_normalize(p);
225 + int shift = fracN(normalize)(p);
226 p->cls = float_class_denormal;
227 p->exp = fmt->frac_shift - fmt->exp_bias
228 - shift + !has_pseudo_denormals;
@@ -232,10 +232,10 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status,
232 if (unlikely(p->exp == fmt->exp_max)) {
233 switch (fmt->exp_max_kind) {
234 case float_expmax_ieee:
235 - if (likely(frac_eqz(p))) {
235 + if (likely(fracN(eqz)(p))) {
236 p->cls = float_class_inf;
237 } else {
238 - frac_shl(p, fmt->frac_shift);
238 + fracN(shl)(p, fmt->frac_shift);
239 p->cls = (parts_is_snan_frac(p->frac_hi, status)
240 ? float_class_snan : float_class_qnan);
241 }
@@ -244,7 +244,7 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status,
244 break;
245 case float_expmax_e4m3:
246 if (p->frac_hi == 0b111) {
247 - frac_shl(p, fmt->frac_shift);
247 + fracN(shl)(p, fmt->frac_shift);
248 p->cls = (parts_is_snan_frac(p->frac_hi, status)
249 ? float_class_snan : float_class_qnan);
250 return;
@@ -258,7 +258,7 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status,
258
259 p->cls = float_class_normal;
260 p->exp -= fmt->exp_bias;
261 - frac_shl(p, fmt->frac_shift);
261 + fracN(shl)(p, fmt->frac_shift);
262 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
263 }
264
@@ -344,8 +344,8 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
344 if (likely(exp > 0)) {
345 if (p->frac_lo & round_mask) {
346 flags |= float_flag_inexact;
347 - if (frac_addi(p, p, inc)) {
348 - frac_shr(p, 1);
347 + if (fracN(addi)(p, p, inc)) {
348 + fracN(shr)(p, 1);
349 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
350 exp++;
351 }
@@ -361,13 +361,13 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
361 } else if (overflow_norm) {
362 flags |= float_flag_inexact;
363 exp = exp_max - 1;
364 - frac_allones(p);
364 + fracN(allones)(p);
365 p->frac_lo &= ~round_mask;
366 } else {
367 flags |= float_flag_inexact;
368 p->cls = float_class_inf;
369 exp = exp_max;
370 - frac_clear(p);
370 + fracN(clear)(p);
371 }
372 break;
373
@@ -378,7 +378,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
378 ? float_flag_invalid
379 : float_flag_overflow | float_flag_inexact);
380 exp = exp_max;
381 - frac_allones(p);
381 + fracN(allones)(p);
382 p->frac_lo &= ~round_mask;
383 }
384 break;
@@ -395,26 +395,26 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
395 g_assert_not_reached();
396 }
397 }
398 - frac_shr(p, frac_shift);
398 + fracN(shr)(p, frac_shift);
399 } else if (unlikely(s->rebias_underflow)) {
400 flags |= float_flag_underflow;
401 exp += fmt->exp_re_bias;
402 if (p->frac_lo & round_mask) {
403 flags |= float_flag_inexact;
404 - if (frac_addi(p, p, inc)) {
405 - frac_shr(p, 1);
404 + if (fracN(addi)(p, p, inc)) {
405 + fracN(shr)(p, 1);
406 p->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
407 exp++;
408 }
409 p->frac_lo &= ~round_mask;
410 }
411 - frac_shr(p, frac_shift);
411 + fracN(shr)(p, frac_shift);
412 } else if (s->flush_to_zero &&
413 s->ftz_detection == float_ftz_before_rounding) {
414 flags |= float_flag_output_denormal_flushed;
415 p->cls = float_class_zero;
416 exp = 0;
417 - frac_clear(p);
417 + fracN(clear)(p);
418 } else {
419 bool is_tiny = s->tininess_before_rounding || exp < 0;
420 bool has_pseudo_denormals = fmt->has_explicit_bit &&
@@ -422,10 +422,10 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
422
423 if (!is_tiny) {
424 FloatPartsN discard;
425 - is_tiny = !frac_addi(&discard, p, inc);
425 + is_tiny = !fracN(addi)(&discard, p, inc);
426 }
427
428 - frac_shrjam(p, !has_pseudo_denormals - exp);
428 + fracN(shrjam)(p, !has_pseudo_denormals - exp);
429
430 if (p->frac_lo & round_mask) {
431 /* Need to recompute round-to-even/round-to-odd. */
@@ -452,12 +452,12 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
452 break;
453 }
454 flags |= float_flag_inexact;
455 - frac_addi(p, p, inc);
455 + fracN(addi)(p, p, inc);
456 p->frac_lo &= ~round_mask;
457 }
458
459 exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) && !has_pseudo_denormals;
460 - frac_shr(p, frac_shift);
460 + fracN(shr)(p, frac_shift);
461
462 if (is_tiny) {
463 if (s->flush_to_zero) {
@@ -465,11 +465,11 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s,
465 flags |= float_flag_output_denormal_flushed;
466 p->cls = float_class_zero;
467 exp = 0;
468 - frac_clear(p);
468 + fracN(clear)(p);
469 } else if (flags & float_flag_inexact) {
470 flags |= float_flag_underflow;
471 }
472 - if (exp == 0 && frac_eqz(p)) {
472 + if (exp == 0 && fracN(eqz)(p)) {
473 p->cls = float_class_zero;
474 }
475 }
@@ -487,17 +487,17 @@ static void partsN(uncanon)(FloatPartsN *p, float_status *s,
487 switch (p->cls) {
488 case float_class_zero:
489 p->exp = 0;
490 - frac_clear(p);
490 + fracN(clear)(p);
491 return;
492 case float_class_inf:
493 switch (fmt->exp_max_kind) {
494 case float_expmax_ieee:
495 p->exp = fmt->exp_max;
496 - frac_clear(p);
496 + fracN(clear)(p);
497 break;
498 case float_expmax_e4m3:
499 partsN(uncanon_e4m3_overflow)(p, s, fmt, saturate);
500 - frac_shr(p, fmt->frac_shift);
500 + fracN(shr)(p, fmt->frac_shift);
501 break;
502 case float_expmax_normal:
503 default:
@@ -508,7 +508,7 @@ static void partsN(uncanon)(FloatPartsN *p, float_status *s,
508 case float_class_snan:
509 assert(fmt->exp_max_kind != float_expmax_normal);
510 p->exp = fmt->exp_max;
511 - frac_shr(p, fmt->frac_shift);
511 + fracN(shr)(p, fmt->frac_shift);
512 return;
513 default:
514 break;
@@ -625,12 +625,12 @@ static FloatPartsN *partsN(mul)(FloatPartsN *a, FloatPartsN *b,
625 float_raise(float_flag_input_denormal_used, s);
626 }
627
628 - frac_mulw(&tmp, a, b);
629 - frac_truncjam(a, &tmp);
628 + fracN(mulw)(&tmp, a, b);
629 + fracN(truncjam)(a, &tmp);
630
631 a->exp += b->exp + 1;
632 if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
633 - frac_add(a, a, a);
633 + fracN(add)(a, a, a);
634 a->exp -= 1;
635 }
636
@@ -747,16 +747,16 @@ static FloatPartsN *partsN(muladd_scalbn)(FloatPartsN *a, FloatPartsN *b,
747 /* Perform the multiplication step. */
748 p_widen.sign = a->sign;
749 p_widen.exp = a->exp + b->exp + 1;
750 - frac_mulw(&p_widen, a, b);
750 + fracN(mulw)(&p_widen, a, b);
751 if (!(p_widen.frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
752 - frac_add(&p_widen, &p_widen, &p_widen);
752 + fracW(add)(&p_widen, &p_widen, &p_widen);
753 p_widen.exp -= 1;
754 }
755
756 /* Perform the addition step. */
757 if (c->cls != float_class_zero) {
758 /* Zero-extend C to less significant bits. */
759 - frac_widen(&c_widen, c);
759 + fracN(widen)(&c_widen, c);
760 c_widen.exp = c->exp;
761
762 if (a->sign == c->sign) {
@@ -767,7 +767,7 @@ static FloatPartsN *partsN(muladd_scalbn)(FloatPartsN *a, FloatPartsN *b,
767 }
768
769 /* Narrow with sticky bit, for proper rounding later. */
770 - frac_truncjam(a, &p_widen);
770 + fracN(truncjam)(a, &p_widen);
771 a->sign = p_widen.sign;
772 a->exp = p_widen.exp;
773
@@ -816,7 +816,7 @@ static FloatPartsN *partsN(div)(FloatPartsN *a, FloatPartsN *b,
816 float_raise(float_flag_input_denormal_used, s);
817 }
818 a->sign = sign;
819 - a->exp -= b->exp + frac_div(a, b);
819 + a->exp -= b->exp + fracN(div)(a, b);
820 return a;
821 }
822
@@ -880,7 +880,7 @@ static FloatPartsN *partsN(modrem)(FloatPartsN *a, FloatPartsN *b,
880 if (ab_mask & float_cmask_denormal) {
881 float_raise(float_flag_input_denormal_used, s);
882 }
883 - frac_modrem(a, b, mod_quot);
883 + fracN(modrem)(a, b, mod_quot);
884 return a;
885 }
886
@@ -969,7 +969,7 @@ static void partsN(sqrt)(FloatPartsN *a, float_status *status,
969 exp_odd = a->exp & 1;
970 index = extract64(a->frac_hi, 57, 6) | (!exp_odd << 6);
971 if (!exp_odd) {
972 - frac_shr(a, 1);
972 + fracN(shr)(a, 1);
973 }
974
975 /*
@@ -1110,7 +1110,7 @@ static void partsN(sqrt)(FloatPartsN *a, float_status *status,
1110 /* Convert back from base 4 to base 2. */
1111 a->exp >>= 1;
1112 if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
1113 - frac_add(a, a, a);
1113 + fracN(add)(a, a, a);
1114 } else {
1115 a->exp += 1;
1116 }
@@ -1150,9 +1150,9 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
1150 if (a->exp == -1) {
1151 FloatPartsN tmp;
1152 /* Shift left one, discarding DECOMPOSED_IMPLICIT_BIT */
1153 - frac_add(&tmp, a, a);
1153 + fracN(add)(&tmp, a, a);
1154 /* Anything remaining means frac > 0.5. */
1155 - one = !frac_eqz(&tmp);
1155 + one = !fracN(eqz)(&tmp);
1156 }
1157 break;
1158 case float_round_ties_away:
@@ -1174,7 +1174,7 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
1174 g_assert_not_reached();
1175 }
1176
1177 - frac_clear(a);
1177 + fracN(clear)(a);
1178 a->exp = 0;
1179 if (one) {
1180 a->frac_hi = DECOMPOSED_IMPLICIT_BIT;
@@ -1190,7 +1190,7 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
1190 * which leaves room for sticky and rounding bit.
1191 */
1192 shift_adj = (N - 1) - (a->exp + 2);
1193 - frac_shrjam(a, shift_adj);
1193 + fracN(shrjam)(a, shift_adj);
1194 frac_lsb = 1 << 2;
1195 } else {
1196 /*
@@ -1208,7 +1208,7 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
1208
1209 if (!(a->frac_lo & rnd_mask)) {
1210 /* Fractional bits already clear, undo the shift above. */
1211 - frac_shl(a, shift_adj);
1211 + fracN(shl)(a, shift_adj);
1212 return false;
1213 }
1214
@@ -1236,21 +1236,21 @@ static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
1236 }
1237
1238 if (shift_adj == 0) {
1239 - if (frac_addi(a, a, inc)) {
1240 - frac_shr(a, 1);
1239 + if (fracN(addi)(a, a, inc)) {
1240 + fracN(shr)(a, 1);
1241 a->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
1242 a->exp++;
1243 }
1244 a->frac_lo &= ~rnd_mask;
1245 } else {
1246 - frac_addi(a, a, inc);
1246 + fracN(addi)(a, a, inc);
1247 a->frac_lo &= ~rnd_mask;
1248 /* Be careful shifting back, not to overflow */
1249 - frac_shl(a, shift_adj - 1);
1249 + fracN(shl)(a, shift_adj - 1);
1250 if (a->frac_hi & DECOMPOSED_IMPLICIT_BIT) {
1251 a->exp++;
1252 } else {
1253 - frac_add(a, a, a);
1253 + fracN(add)(a, a, a);
1254 }
1255 }
1256 return true;
@@ -1555,7 +1555,7 @@ static FloatPartsN *partsN(minmax)(FloatPartsN *a, FloatPartsN *b,
1555 /* Compare magnitudes. */
1556 cmp = a_exp - b_exp;
1557 if (cmp == 0) {
1558 - cmp = frac_cmp(a, b);
1558 + cmp = fracN(cmp)(a, b);
1559 }
1560
1561 /*
@@ -1597,7 +1597,7 @@ static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b,
1597 goto a_sign;
1598 }
1599 if (a->exp == b->exp) {
1600 - cmp = frac_cmp(a, b);
1600 + cmp = fracN(cmp)(a, b);
1601 } else if (a->exp < b->exp) {
1602 cmp = float_relation_less;
1603 } else {
fpu/softfloat.c
+15 -54
@@ -774,15 +774,6 @@ static float128 QEMU_FLATTEN float128_pack_raw(const FloatParts128 *p)
774 * Helper functions for softfloat-parts.c.inc, per-size operations.
775 */
776
777 -#define FRAC_GENERIC_64_128(NAME, P) \
778 - _Generic((P), FloatParts64 *: frac64_##NAME, \
779 - FloatParts128 *: frac128_##NAME)
780 -
781 -#define FRAC_GENERIC_64_128_256(NAME, P) \
782 - _Generic((P), FloatParts64 *: frac64_##NAME, \
783 - FloatParts128 *: frac128_##NAME, \
784 - FloatParts256 *: frac256_##NAME)
785 -
777 static bool frac64_add(FloatParts64 *r, FloatParts64 *a, FloatParts64 *b)
778 {
779 return uadd64_overflow(a->frac, b->frac, &r->frac);
@@ -806,8 +797,6 @@ static bool frac256_add(FloatParts256 *r, FloatParts256 *a, FloatParts256 *b)
797 return c;
798 }
799
809 -#define frac_add(R, A, B) FRAC_GENERIC_64_128_256(add, R)(R, A, B)
810 -
800 static bool frac64_addi(FloatParts64 *r, FloatParts64 *a, uint64_t c)
801 {
802 return uadd64_overflow(a->frac, c, &r->frac);
@@ -819,8 +808,6 @@ static bool frac128_addi(FloatParts128 *r, FloatParts128 *a, uint64_t c)
808 return uadd64_overflow(a->frac_hi, c, &r->frac_hi);
809 }
810
822 -#define frac_addi(R, A, C) FRAC_GENERIC_64_128(addi, R)(R, A, C)
823 -
811 static void frac64_allones(FloatParts64 *a)
812 {
813 a->frac = -1;
@@ -831,8 +818,6 @@ static void frac128_allones(FloatParts128 *a)
818 a->frac_hi = a->frac_lo = -1;
819 }
820
834 -#define frac_allones(A) FRAC_GENERIC_64_128(allones, A)(A)
835 -
821 static FloatRelation frac64_cmp(FloatParts64 *a, FloatParts64 *b)
822 {
823 return (a->frac == b->frac ? float_relation_equal
@@ -852,8 +837,6 @@ static FloatRelation frac128_cmp(FloatParts128 *a, FloatParts128 *b)
837 return ta < tb ? float_relation_less : float_relation_greater;
838 }
839
855 -#define frac_cmp(A, B) FRAC_GENERIC_64_128(cmp, A)(A, B)
856 -
840 static void frac64_clear(FloatParts64 *a)
841 {
842 a->frac = 0;
@@ -864,8 +847,6 @@ static void frac128_clear(FloatParts128 *a)
847 a->frac_hi = a->frac_lo = 0;
848 }
849
867 -#define frac_clear(A) FRAC_GENERIC_64_128(clear, A)(A)
868 -
850 static bool frac64_div(FloatParts64 *a, FloatParts64 *b)
851 {
852 uint64_t n1, n0, r, q;
@@ -945,8 +926,6 @@ static bool frac128_div(FloatParts128 *a, FloatParts128 *b)
926 return ret;
927 }
928
948 -#define frac_div(A, B) FRAC_GENERIC_64_128(div, A)(A, B)
949 -
929 static bool frac64_eqz(FloatParts64 *a)
930 {
931 return a->frac == 0;
@@ -957,8 +936,6 @@ static bool frac128_eqz(FloatParts128 *a)
936 return (a->frac_hi | a->frac_lo) == 0;
937 }
938
960 -#define frac_eqz(A) FRAC_GENERIC_64_128(eqz, A)(A)
961 -
939 static void frac64_mulw(FloatParts128 *r, FloatParts64 *a, FloatParts64 *b)
940 {
941 mulu64(&r->frac_lo, &r->frac_hi, a->frac, b->frac);
@@ -970,8 +947,6 @@ static void frac128_mulw(FloatParts256 *r, FloatParts128 *a, FloatParts128 *b)
947 &r->frac_hi, &r->frac_hm, &r->frac_lm, &r->frac_lo);
948 }
949
973 -#define frac_mulw(R, A, B) FRAC_GENERIC_64_128(mulw, A)(R, A, B)
974 -
950 static void frac64_neg(FloatParts64 *a)
951 {
952 a->frac = -a->frac;
@@ -993,8 +968,6 @@ static void frac256_neg(FloatParts256 *a)
968 a->frac_hi = usub64_borrow(0, a->frac_hi, &c);
969 }
970
996 -#define frac_neg(A) FRAC_GENERIC_64_128_256(neg, A)(A)
997 -
971 static int frac64_normalize(FloatParts64 *a)
972 {
973 if (a->frac) {
@@ -1068,8 +1041,6 @@ static int frac256_normalize(FloatParts256 *a)
1041 return ret;
1042 }
1043
1071 -#define frac_normalize(A) FRAC_GENERIC_64_128_256(normalize, A)(A)
1072 -
1044 static void frac64_modrem(FloatParts64 *a, FloatParts64 *b, uint64_t *mod_quot)
1045 {
1046 uint64_t a0, a1, b0, t0, t1, q, quot;
@@ -1248,8 +1219,6 @@ static void frac128_modrem(FloatParts128 *a, FloatParts128 *b,
1219 a->frac_lo = a1 | (a2 != 0);
1220 }
1221
1251 -#define frac_modrem(A, B, Q) FRAC_GENERIC_64_128(modrem, A)(A, B, Q)
1252 -
1222 static void frac64_shl(FloatParts64 *a, int c)
1223 {
1224 a->frac <<= c;
@@ -1273,8 +1242,6 @@ static void frac128_shl(FloatParts128 *a, int c)
1242 a->frac_lo = a1;
1243 }
1244
1276 -#define frac_shl(A, C) FRAC_GENERIC_64_128(shl, A)(A, C)
1277 -
1245 static void frac64_shr(FloatParts64 *a, int c)
1246 {
1247 a->frac >>= c;
@@ -1298,8 +1265,6 @@ static void frac128_shr(FloatParts128 *a, int c)
1265 a->frac_lo = a1;
1266 }
1267
1301 -#define frac_shr(A, C) FRAC_GENERIC_64_128(shr, A)(A, C)
1302 -
1268 static void frac64_shrjam(FloatParts64 *a, int c)
1269 {
1270 uint64_t a0 = a->frac;
@@ -1388,8 +1353,6 @@ static void frac256_shrjam(FloatParts256 *a, int c)
1353 a->frac_hi = a0;
1354 }
1355
1391 -#define frac_shrjam(A, C) FRAC_GENERIC_64_128_256(shrjam, A)(A, C)
1392 -
1356 static bool frac64_sub(FloatParts64 *r, FloatParts64 *a, FloatParts64 *b)
1357 {
1358 return usub64_overflow(a->frac, b->frac, &r->frac);
@@ -1413,8 +1376,6 @@ static bool frac256_sub(FloatParts256 *r, FloatParts256 *a, FloatParts256 *b)
1376 return c;
1377 }
1378
1416 -#define frac_sub(R, A, B) FRAC_GENERIC_64_128_256(sub, R)(R, A, B)
1417 -
1379 static void frac64_truncjam(FloatParts64 *r, FloatParts128 *a)
1380 {
1381 r->frac = a->frac_hi | (a->frac_lo != 0);
@@ -1426,8 +1387,6 @@ static void frac128_truncjam(FloatParts128 *r, FloatParts256 *a)
1387 r->frac_lo = a->frac_hm | ((a->frac_lm | a->frac_lo) != 0);
1388 }
1389
1429 -#define frac_truncjam(R, A) FRAC_GENERIC_64_128(truncjam, R)(R, A)
1430 -
1390 static void frac64_widen(FloatParts128 *r, FloatParts64 *a)
1391 {
1392 r->frac_hi = a->frac;
@@ -1442,8 +1401,6 @@ static void frac128_widen(FloatParts256 *r, FloatParts128 *a)
1401 r->frac_lo = 0;
1402 }
1403
1445 -#define frac_widen(A, B) FRAC_GENERIC_64_128(widen, B)(A, B)
1446 -
1404 /*
1405 * Reciprocal sqrt table. 1 bit of exponent, 6-bits of mantessa.
1406 * From https://git.musl-libc.org/cgit/musl/tree/src/math/sqrt_data.c
@@ -1468,6 +1425,8 @@ static const uint16_t rsqrt_tab[128] = {
1425 0xba91, 0xb9cc, 0xb90a, 0xb84a, 0xb78c, 0xb6d0, 0xb617, 0xb560,
1426 };
1427
1428 +#define fracN(NAME) glue(glue(glue(frac,N),_),NAME)
1429 +#define fracW(NAME) glue(glue(glue(frac,W),_),NAME)
1430 #define partsN(NAME) glue(glue(glue(parts,N),_),NAME)
1431 #define partsW(NAME) glue(glue(glue(parts,W),_),NAME)
1432 #define FloatPartsN glue(FloatParts,N)
@@ -1494,6 +1453,8 @@ static const uint16_t rsqrt_tab[128] = {
1453
1454 #undef N
1455 #undef W
1456 +#undef fracN
1457 +#undef fracW
1458 #undef partsN
1459 #undef partsW
1460 #undef FloatPartsN
@@ -1624,19 +1585,19 @@ static float64 float64r32_pack_raw(FloatParts64 *p)
1585 * The result is denormal for float32, but can be represented
1586 * in normalized form for float64. Adjust, per canonicalize.
1587 */
1627 - int shift = frac_normalize(p);
1588 + int shift = frac64_normalize(p);
1589 p->exp = (float32_params.frac_shift -
1590 float32_params.exp_bias - shift + 1 +
1591 float64_params.exp_bias);
1631 - frac_shr(p, float64_params.frac_shift);
1592 + frac64_shr(p, float64_params.frac_shift);
1593 } else {
1633 - frac_shl(p, float32_params.frac_shift - float64_params.frac_shift);
1594 + frac64_shl(p, float32_params.frac_shift - float64_params.frac_shift);
1595 p->exp += float64_params.exp_bias - float32_params.exp_bias;
1596 }
1597 break;
1598 case float_class_snan:
1599 case float_class_qnan:
1639 - frac_shl(p, float32_params.frac_shift - float64_params.frac_shift);
1600 + frac64_shl(p, float32_params.frac_shift - float64_params.frac_shift);
1601 p->exp = float64_params.exp_max;
1602 break;
1603 case float_class_inf:
@@ -1724,7 +1685,7 @@ static floatx80 floatx80_round_pack_canonical(FloatParts128 *p,
1685
1686 p64.sign = p->sign;
1687 p64.exp = p->exp;
1727 - frac_truncjam(&p64, p);
1688 + frac64_truncjam(&p64, p);
1689 parts64_uncanon_normal(&p64, s, fmt, false);
1690 frac = p64.frac;
1691 exp = p64.exp;
@@ -2698,7 +2659,7 @@ static void parts_float_to_float_narrow(FloatParts64 *a, FloatParts128 *b,
2659 float_raise(float_flag_input_denormal_used, s);
2660 /* fall through */
2661 case float_class_normal:
2701 - frac_truncjam(a, b);
2662 + frac64_truncjam(a, b);
2663 break;
2664 case float_class_snan:
2665 case float_class_qnan:
@@ -2717,7 +2678,7 @@ static void parts_float_to_float_widen(FloatParts128 *a, FloatParts64 *b,
2678 a->cls = b->cls;
2679 a->sign = b->sign;
2680 a->exp = b->exp;
2720 - frac_widen(a, b);
2681 + frac64_widen(a, b);
2682
2683 if (is_nan(a->cls)) {
2684 parts128_return_nan(a, s);
@@ -4939,7 +4900,7 @@ static void parts64_log2(FloatParts64 *a, float_status *s, const FloatFmt *fmt)
4900 FloatParts64 f = {
4901 .cls = float_class_normal, .frac = r
4902 };
4942 - f.exp = f_exp - frac_normalize(&f);
4903 + f.exp = f_exp - frac64_normalize(&f);
4904
4905 if (a_exp < 0) {
4906 parts64_sub_normal(a, &f);
@@ -5010,7 +4971,7 @@ float128 float128_default_nan(float_status *status)
4971 FloatParts128 p;
4972
4973 parts128_default_nan(&p, status);
5013 - frac_shr(&p, float128_params.frac_shift);
4974 + frac128_shr(&p, float128_params.frac_shift);
4975 return float128_pack_raw(&p);
4976 }
4977
@@ -5076,9 +5037,9 @@ float128 float128_silence_nan(float128 a, float_status *status)
5037 FloatParts128 p;
5038
5039 float128_unpack_raw(&p, a);
5079 - frac_shl(&p, float128_params.frac_shift);
5040 + frac128_shl(&p, float128_params.frac_shift);
5041 parts128_silence_nan(&p, status);
5081 - frac_shr(&p, float128_params.frac_shift);
5042 + frac128_shr(&p, float128_params.frac_shift);
5043 return float128_pack_raw(&p);
5044 }
5045