[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 09/19] fpu/softfloat: define decompose structures
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v1 09/19] fpu/softfloat: define decompose structures |
Date: |
Mon, 11 Dec 2017 12:56:55 +0000 |
These structures pave the way for generic softfloat helper routines
that will operate on fully decomposed numbers.
Signed-off-by: Alex Bennée <address@hidden>
---
fpu/softfloat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 71 insertions(+), 1 deletion(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 0850a78149..fe443ff234 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -83,7 +83,7 @@ this code that are retained.
* target-dependent and needs the TARGET_* macros.
*/
#include "qemu/osdep.h"
-
+#include "qemu/bitops.h"
#include "fpu/softfloat.h"
/* We only need stdlib for abort() */
@@ -185,6 +185,76 @@ static inline flag extractFloat64Sign(float64 a)
{
return float64_val(a) >> 63;
}
+
+/*----------------------------------------------------------------------------
+| Classify a floating point number.
+*----------------------------------------------------------------------------*/
+
+typedef enum {
+ float_class_unclassified,
+ float_class_zero,
+ float_class_normal,
+ float_class_inf,
+ float_class_qnan,
+ float_class_snan,
+ float_class_dnan,
+ float_class_msnan, /* maybe silenced */
+} float_class;
+
+/*----------------------------------------------------------------------------
+| Structure holding all of the decomposed parts of a float.
+| The exponent is unbiased and the fraction is normalized.
+*----------------------------------------------------------------------------*/
+
+typedef struct {
+ uint64_t frac : 64;
+ int exp : 32;
+ float_class cls : 8;
+ int : 23;
+ bool sign : 1;
+} decomposed_parts;
+
+#define DECOMPOSED_BINARY_POINT (64 - 2)
+#define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT)
+#define DECOMPOSED_OVERFLOW_BIT (DECOMPOSED_IMPLICIT_BIT << 1)
+
+/* Structure holding all of the relevant parameters for a format. */
+typedef struct {
+ int exp_bias;
+ int exp_max;
+ int frac_shift;
+ uint64_t frac_lsb;
+ uint64_t frac_lsbm1;
+ uint64_t round_mask;
+ uint64_t roundeven_mask;
+} decomposed_params;
+
+#define FRAC_PARAMS(F) \
+ .frac_shift = F, \
+ .frac_lsb = 1ull << (F), \
+ .frac_lsbm1 = 1ull << ((F) - 1), \
+ .round_mask = (1ull << (F)) - 1, \
+ .roundeven_mask = (2ull << (F)) - 1
+
+static const decomposed_params float16_params = {
+ .exp_bias = 0x0f,
+ .exp_max = 0x1f,
+ FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 10)
+};
+
+static const decomposed_params float32_params = {
+ .exp_bias = 0x7f,
+ .exp_max = 0xff,
+ FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 23)
+};
+
+static const decomposed_params float64_params = {
+ .exp_bias = 0x3ff,
+ .exp_max = 0x7ff,
+ FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 52)
+};
+
+
/*----------------------------------------------------------------------------
| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6
| and 7, and returns the properly rounded 32-bit integer corresponding to the
--
2.15.1
- Re: [Qemu-devel] [PATCH v1 05/19] include/fpu/softfloat: add some float16 contants, (continued)
- [Qemu-devel] [PATCH v1 06/19] fpu/softfloat: propagate signalling NaNs in MINMAX, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 04/19] include/fpu/softfloat: implement float16_set_sign helper, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 08/19] fpu/softfloat: move the extract functions to the top of the file, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 07/19] fpu/softfloat: improve comments on ARM NaN propagation, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 09/19] fpu/softfloat: define decompose structures,
Alex Bennée <=
- [Qemu-devel] [PATCH v1 14/19] fpu/softfloat: re-factor round_to_int, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 19/19] fpu/softfloat: re-factor compare, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 17/19] fpu/softfloat: re-factor scalbn, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 10/19] fpu/softfloat: re-factor add/sub, Alex Bennée, 2017/12/11
- [Qemu-devel] [PATCH v1 13/19] fpu/softfloat: re-factor muladd, Alex Bennée, 2017/12/11