@samitouri / QOSamiQemu / commits / 47f8b74ab1

fpu: Export FloatFmt structures

Export most of the FloatFmt structures. Skip float16_params_ahp and the floatx80 precisions. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed Apr 25, 2026 at 21:52 UTC 47f8b74ab14400fccb2b4de7f77806496c281699
2 files changed +56 -47
fpu/softfloat.c
+8 -47
@@ -457,45 +457,6 @@ typedef struct {
457 #define DECOMPOSED_BINARY_POINT 63
458 #define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT)
459
460 -/* Format-specific handling of exp == exp_max */
461 -typedef enum __attribute__((__packed__)) {
462 - /* exp==max, frac==0 ? infinity : nan; this is ieee standard. */
463 - float_expmax_ieee,
464 - /* exp==max is a normal number; no infinity or nan representation. */
465 - float_expmax_normal,
466 - /* exp==max, frac==max ? nan : normal; no infinity representation. */
467 - float_expmax_e4m3,
468 -} FloatFmtExpMaxKind;
469 -
470 -/*
471 - * Structure holding all of the relevant parameters for a format.
472 - * exp_size: the size of the exponent field
473 - * exp_bias: the offset applied to the exponent field
474 - * exp_max: the maximum normalised exponent
475 - * frac_size: the size of the fraction field
476 - * frac_shift: shift to normalise the fraction with DECOMPOSED_BINARY_POINT
477 - * The following are computed based the size of fraction
478 - * round_mask: bits below lsb which must be rounded
479 - * The following optional modifiers are available:
480 - * exp_max_kind: affects how exp == exp_max is interpreted
481 - * has_explicit_bit: has an explicit integer bit; this affects whether
482 - * the float_status floatx80_behaviour handling applies
483 - * overflow_raises_invalid: for float_expmax_normal, raise invalid
484 - * instead of overflow.
485 - */
486 -typedef struct {
487 - int exp_size;
488 - int exp_bias;
489 - int exp_re_bias;
490 - int exp_max;
491 - int frac_size;
492 - int frac_shift;
493 - FloatFmtExpMaxKind exp_max_kind;
494 - bool has_explicit_bit;
495 - bool overflow_raises_invalid;
496 - uint64_t round_mask;
497 -} FloatFmt;
498 -
460 /* Expand fields based on the size of exponent and fraction */
461 #define FLOAT_PARAMS_(E) \
462 .exp_size = E, \
@@ -509,12 +470,12 @@ typedef struct {
470 .frac_shift = (-F - 1) & 63, \
471 .round_mask = (1ull << ((-F - 1) & 63)) - 1
472
512 -static const FloatFmt float4_e2m1_params = {
473 +const FloatFmt float4_e2m1_params = {
474 FLOAT_PARAMS(2, 1),
475 .exp_max_kind = float_expmax_normal,
476 };
477
517 -static const FloatFmt float8_e4m3_params = {
478 +const FloatFmt float8_e4m3_params = {
479 FLOAT_PARAMS(4, 3),
480 .exp_max_kind = float_expmax_e4m3
481 };
@@ -522,11 +483,11 @@ static const FloatFmt float8_e4m3_params = {
483 /* 110 << frac_shift, with the implicit bit set */
484 #define E4M3_NORMAL_FRAC_MAX 0xe000000000000000ull
485
525 -static const FloatFmt float8_e5m2_params = {
486 +const FloatFmt float8_e5m2_params = {
487 FLOAT_PARAMS(5, 2)
488 };
489
529 -static const FloatFmt float16_params = {
490 +const FloatFmt float16_params = {
491 FLOAT_PARAMS(5, 10)
492 };
493
@@ -536,19 +497,19 @@ static const FloatFmt float16_params_ahp = {
497 .overflow_raises_invalid = true,
498 };
499
539 -static const FloatFmt bfloat16_params = {
500 +const FloatFmt bfloat16_params = {
501 FLOAT_PARAMS(8, 7)
502 };
503
543 -static const FloatFmt float32_params = {
504 +const FloatFmt float32_params = {
505 FLOAT_PARAMS(8, 23)
506 };
507
547 -static const FloatFmt float64_params = {
508 +const FloatFmt float64_params = {
509 FLOAT_PARAMS(11, 52)
510 };
511
551 -static const FloatFmt float128_params = {
512 +const FloatFmt float128_params = {
513 FLOAT_PARAMS(15, 112)
514 };
515
include/fpu/softfloat-parts.h
+48
@@ -18,6 +18,54 @@
18 #ifndef SOFTFLOAT_PARTS_H
19 #define SOFTFLOAT_PARTS_H
20
21 +/* Format-specific handling of exp == exp_max */
22 +typedef enum __attribute__((__packed__)) {
23 + /* exp==max, frac==0 ? infinity : nan; this is ieee standard. */
24 + float_expmax_ieee,
25 + /* exp==max is a normal number; no infinity or nan representation. */
26 + float_expmax_normal,
27 + /* exp==max, frac==max ? nan : normal; no infinity representation. */
28 + float_expmax_e4m3,
29 +} FloatFmtExpMaxKind;
30 +
31 +/*
32 + * Structure holding all of the relevant parameters for a format.
33 + * exp_size: the size of the exponent field
34 + * exp_bias: the offset applied to the exponent field
35 + * exp_max: the maximum normalised exponent
36 + * frac_size: the size of the fraction field
37 + * frac_shift: shift to normalise the fraction with DECOMPOSED_BINARY_POINT
38 + * The following are computed based the size of fraction
39 + * round_mask: bits below lsb which must be rounded
40 + * The following optional modifiers are available:
41 + * exp_max_kind: affects how exp == exp_max is interpreted
42 + * has_explicit_bit: has an explicit integer bit; this affects whether
43 + * the float_status floatx80_behaviour handling applies
44 + * overflow_raises_invalid: for float_expmax_normal, raise invalid
45 + * instead of overflow.
46 + */
47 +typedef struct {
48 + int exp_size;
49 + int exp_bias;
50 + int exp_re_bias;
51 + int exp_max;
52 + int frac_size;
53 + int frac_shift;
54 + FloatFmtExpMaxKind exp_max_kind;
55 + bool has_explicit_bit;
56 + bool overflow_raises_invalid;
57 + uint64_t round_mask;
58 +} FloatFmt;
59 +
60 +extern const FloatFmt float4_e2m1_params;
61 +extern const FloatFmt float8_e4m3_params;
62 +extern const FloatFmt float8_e5m2_params;
63 +extern const FloatFmt float16_params;
64 +extern const FloatFmt bfloat16_params;
65 +extern const FloatFmt float32_params;
66 +extern const FloatFmt float64_params;
67 +extern const FloatFmt float128_params;
68 +
69 /*
70 * Classify a floating point number. Everything above float_class_qnan
71 * is a NaN so cls >= float_class_qnan is any NaN.