fpu: Split FloatParts{64,128} to softfloat-parts.h
Begin exposing the intermediate representation of softfloat. Start with just the representation structures. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Richard Henderson committed
Apr 25, 2026 at 20:47 UTC
7a8bb2218a105816a479992e4bdb3dd5be36c839
2 files changed
+90
-67
fpu/softfloat.c
+2
-67
@@ -83,6 +83,7 @@ this code that are retained.
83
#include <math.h>
84
#include "qemu/bitops.h"
85
#include "fpu/softfloat.h"
86
+#include "fpu/softfloat-parts.h"
87
88
/* We only need stdlib for abort() */
89
@@ -396,39 +397,6 @@ float64_gen2(float64 xa, float64 xb, float_status *s,
397
return soft(ua.s, ub.s, s);
398
}
399
399
-/*
400
- * Classify a floating point number. Everything above float_class_qnan
401
- * is a NaN so cls >= float_class_qnan is any NaN.
402
- *
403
- * Note that we canonicalize denormals, so most code should treat
404
- * class_normal and class_denormal identically.
405
- */
406
-
407
-typedef enum __attribute__ ((__packed__)) {
408
- float_class_unclassified,
409
- float_class_zero,
410
- float_class_normal,
411
- float_class_denormal, /* input was a non-squashed denormal */
412
- float_class_inf,
413
- float_class_qnan, /* all NaNs from here */
414
- float_class_snan,
415
-} FloatClass;
416
-
417
-#define float_cmask(bit) (1u << (bit))
418
-
419
-enum {
420
- float_cmask_zero = float_cmask(float_class_zero),
421
- float_cmask_normal = float_cmask(float_class_normal),
422
- float_cmask_denormal = float_cmask(float_class_denormal),
423
- float_cmask_inf = float_cmask(float_class_inf),
424
- float_cmask_qnan = float_cmask(float_class_qnan),
425
- float_cmask_snan = float_cmask(float_class_snan),
426
-
427
- float_cmask_infzero = float_cmask_zero | float_cmask_inf,
428
- float_cmask_anynan = float_cmask_qnan | float_cmask_snan,
429
- float_cmask_anynorm = float_cmask_normal | float_cmask_denormal,
430
-};
431
-
400
/* Flags for parts_minmax. */
401
enum {
402
/* Set for minimum; clear for maximum. */
@@ -474,40 +442,7 @@ static inline bool is_anynorm(FloatClass c)
442
return float_cmask(c) & float_cmask_anynorm;
443
}
444
477
-/*
478
- * Structure holding all of the decomposed parts of a float.
479
- * The exponent is unbiased and the fraction is normalized.
480
- *
481
- * The fraction words are stored in big-endian word ordering,
482
- * so that truncation from a larger format to a smaller format
483
- * can be done simply by ignoring subsequent elements.
484
- */
485
-
486
-typedef struct {
487
- FloatClass cls;
488
- bool sign;
489
- int32_t exp;
490
- union {
491
- /* Routines that know the structure may reference the singular name. */
492
- uint64_t frac;
493
- /*
494
- * Routines expanded with multiple structures reference "hi" and "lo"
495
- * depending on the operation. In FloatParts64, "hi" and "lo" are
496
- * both the same word and aliased here.
497
- */
498
- uint64_t frac_hi;
499
- uint64_t frac_lo;
500
- };
501
-} FloatParts64;
502
-
503
-typedef struct {
504
- FloatClass cls;
505
- bool sign;
506
- int32_t exp;
507
- uint64_t frac_hi;
508
- uint64_t frac_lo;
509
-} FloatParts128;
510
-
445
+/* FloatParts256 is entirely internal, for parts128_mul* */
446
typedef struct {
447
FloatClass cls;
448
bool sign;
include/fpu/softfloat-parts.h
new
+88
@@ -0,0 +1,88 @@
1
+/*
2
+ * Floating point intermediate representation
3
+ *
4
+ * The code in this source file is derived from release 2a of the SoftFloat
5
+ * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and
6
+ * some later contributions) are provided under that license, as detailed below.
7
+ * It has subsequently been modified by contributors to the QEMU Project,
8
+ * so some portions are provided under:
9
+ * the SoftFloat-2a license
10
+ * the BSD license
11
+ * GPL-v2-or-later
12
+ *
13
+ * Any future contributions to this file after December 1st 2014 will be
14
+ * taken to be licensed under the Softfloat-2a license unless specifically
15
+ * indicated otherwise.
16
+ */
17
+
18
+#ifndef SOFTFLOAT_PARTS_H
19
+#define SOFTFLOAT_PARTS_H
20
+
21
+/*
22
+ * Classify a floating point number. Everything above float_class_qnan
23
+ * is a NaN so cls >= float_class_qnan is any NaN.
24
+ *
25
+ * Note that we canonicalize denormals, so most code should treat
26
+ * class_normal and class_denormal identically.
27
+ */
28
+
29
+typedef enum __attribute__ ((__packed__)) {
30
+ float_class_unclassified,
31
+ float_class_zero,
32
+ float_class_normal,
33
+ float_class_denormal, /* input was a non-squashed denormal */
34
+ float_class_inf,
35
+ float_class_qnan, /* all NaNs from here */
36
+ float_class_snan,
37
+} FloatClass;
38
+
39
+#define float_cmask(bit) (1u << (bit))
40
+
41
+enum {
42
+ float_cmask_zero = float_cmask(float_class_zero),
43
+ float_cmask_normal = float_cmask(float_class_normal),
44
+ float_cmask_denormal = float_cmask(float_class_denormal),
45
+ float_cmask_inf = float_cmask(float_class_inf),
46
+ float_cmask_qnan = float_cmask(float_class_qnan),
47
+ float_cmask_snan = float_cmask(float_class_snan),
48
+
49
+ float_cmask_infzero = float_cmask_zero | float_cmask_inf,
50
+ float_cmask_anynan = float_cmask_qnan | float_cmask_snan,
51
+ float_cmask_anynorm = float_cmask_normal | float_cmask_denormal,
52
+};
53
+
54
+/*
55
+ * Structure holding all of the decomposed parts of a float.
56
+ * The exponent is unbiased and the fraction is normalized.
57
+ *
58
+ * The fraction words are stored in big-endian word ordering,
59
+ * so that truncation from a larger format to a smaller format
60
+ * can be done simply by ignoring subsequent elements.
61
+ */
62
+
63
+typedef struct {
64
+ FloatClass cls;
65
+ bool sign;
66
+ int32_t exp;
67
+ union {
68
+ /* Routines that know the structure may reference the singular name. */
69
+ uint64_t frac;
70
+ /*
71
+ * Routines expanded with multiple structures reference "hi" and "lo"
72
+ * depending on the operation. In FloatParts64, "hi" and "lo" are
73
+ * both the same word and aliased here.
74
+ */
75
+ uint64_t frac_hi;
76
+ uint64_t frac_lo;
77
+ };
78
+} FloatParts64;
79
+
80
+typedef struct {
81
+ FloatClass cls;
82
+ bool sign;
83
+ int32_t exp;
84
+ uint64_t frac_hi;
85
+ uint64_t frac_lo;
86
+} FloatParts128;
87
+
88
+#endif