From 42db7b64ced989748dadeec1cc4c648c22ab46ef Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Sun, 14 Apr 2024 22:14:12 +0300 Subject: [PATCH] simplifications in softfloat3e code --- .../8086-SSE/s_propagateNaNExtF80UI.c | 19 +++++++++---------- bochs/cpu/softfloat3e/Makefile.in | 4 ++-- bochs/cpu/softfloat3e/extF80_div.c | 4 +--- bochs/cpu/softfloat3e/extF80_extract.c | 4 +--- bochs/cpu/softfloat3e/extF80_mul.c | 5 ++--- bochs/cpu/softfloat3e/extF80_rem.c | 4 +--- bochs/cpu/softfloat3e/extF80_roundToInt.c | 4 +--- bochs/cpu/softfloat3e/extF80_scale.c | 7 ++----- bochs/cpu/softfloat3e/extF80_sqrt.c | 4 +--- .../{8086-SSE => include}/specialize.h | 5 ++--- bochs/cpu/softfloat3e/s_addMagsExtF80.c | 4 +--- .../cpu/softfloat3e/s_normRoundPackToExtF80.c | 3 +-- bochs/cpu/softfloat3e/s_subMagsExtF80.c | 5 ++--- 13 files changed, 26 insertions(+), 46 deletions(-) rename bochs/cpu/softfloat3e/{8086-SSE => include}/specialize.h (99%) diff --git a/bochs/cpu/softfloat3e/8086-SSE/s_propagateNaNExtF80UI.c b/bochs/cpu/softfloat3e/8086-SSE/s_propagateNaNExtF80UI.c index 808522f26..fa83fa24f 100644 --- a/bochs/cpu/softfloat3e/8086-SSE/s_propagateNaNExtF80UI.c +++ b/bochs/cpu/softfloat3e/8086-SSE/s_propagateNaNExtF80UI.c @@ -48,19 +48,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | result. If either original floating-point value is a signaling NaN, the | invalid exception is raised. *----------------------------------------------------------------------------*/ -struct uint128 +extFloat80_t softfloat_propagateNaNExtF80UI( uint16_t uiA64, uint64_t uiA0, uint16_t uiB64, uint64_t uiB0, - struct softfloat_status_t *status -) + struct softfloat_status_t *status) { bool isSigNaNA, isSigNaNB; uint64_t uiNonsigA0, uiNonsigB0; uint16_t uiMagA64, uiMagB64; - struct uint128 uiZ; + extFloat80_t z; /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ @@ -93,11 +92,11 @@ struct uint128 if (uiB0 < uiA0) goto returnA; if (uiA64 < uiB64) goto returnA; returnB: - uiZ.v64 = uiB64; - uiZ.v0 = uiNonsigB0; - return uiZ; + z.signExp = uiB64; + z.signif = uiNonsigB0; + return z; returnA: - uiZ.v64 = uiA64; - uiZ.v0 = uiNonsigA0; - return uiZ; + z.signExp = uiA64; + z.signif = uiNonsigA0; + return z; } diff --git a/bochs/cpu/softfloat3e/Makefile.in b/bochs/cpu/softfloat3e/Makefile.in index d8b5acb7e..e64094de0 100644 --- a/bochs/cpu/softfloat3e/Makefile.in +++ b/bochs/cpu/softfloat3e/Makefile.in @@ -40,7 +40,7 @@ SOFTFLOAT_OPTS = \ -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 DELETE = @RMCOMMAND@ -C_INCLUDES = -I. -I../.. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include +C_INCLUDES = -I. -I../.. -I$(SOURCE_DIR)/include COMPILE_C = \ $(CXX) @DASH@c @CFLAGS@ \ -DSOFTFLOAT_FAST_INT64 $(SOFTFLOAT_OPTS) $(C_INCLUDES) @OFP@$@ @@ -271,7 +271,7 @@ $(OBJS_ALL): \ $(SOURCE_DIR)/include/primitives.h $(OBJS_SPECIALIZE) $(OBJS_OTHERS): \ $(SOURCE_DIR)/include/softfloat_types.h $(SOURCE_DIR)/include/internals.h \ - $(SOURCE_DIR)/$(SPECIALIZE_TYPE)/specialize.h \ + $(SOURCE_DIR)/include/specialize.h \ $(SOURCE_DIR)/include/softfloat.h @GNU_MAKE_ONLY@$(OBJS_PRIMITIVES) $(OBJS_OTHERS): %$(OBJ): $(SOURCE_DIR)/%.c diff --git a/bochs/cpu/softfloat3e/extF80_div.c b/bochs/cpu/softfloat3e/extF80_div.c index b4b761a74..888b17ba1 100644 --- a/bochs/cpu/softfloat3e/extF80_div.c +++ b/bochs/cpu/softfloat3e/extF80_div.c @@ -62,7 +62,6 @@ extFloat80_t extF80_div(extFloat80_t a, extFloat80_t b, struct softfloat_status_ uint32_t q; struct uint128 term; uint64_t sigZExtra; - struct uint128 uiZ; // handle unsupported extended double-precision floating encodings if (extF80_isUnsupported(a) || extF80_isUnsupported(b)) @@ -180,8 +179,7 @@ extFloat80_t extF80_div(extFloat80_t a, extFloat80_t b, struct softfloat_status_ /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ propagateNaN: - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ invalid: diff --git a/bochs/cpu/softfloat3e/extF80_extract.c b/bochs/cpu/softfloat3e/extF80_extract.c index e355dad34..e944f8e31 100644 --- a/bochs/cpu/softfloat3e/extF80_extract.c +++ b/bochs/cpu/softfloat3e/extF80_extract.c @@ -53,7 +53,6 @@ extFloat80_t extF80_extract(extFloat80_t *a, struct softfloat_status_t *status) bool signA; int32_t expA; uint64_t sigA; - struct uint128 uiZ; struct exp32_sig64 normExpSig; /*------------------------------------------------------------------------ @@ -75,8 +74,7 @@ extFloat80_t extF80_extract(extFloat80_t *a, struct softfloat_status_t *status) *------------------------------------------------------------------------*/ if (expA == 0x7FFF) { if (sigA<<1) { - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, 0, 0, status); - *a = packToExtF80(uiZ.v64, uiZ.v0); + *a = softfloat_propagateNaNExtF80UI(uiA64, uiA0, 0, 0, status); return *a; } return packToExtF80(0, 0x7FFF, BX_CONST64(0x8000000000000000)); diff --git a/bochs/cpu/softfloat3e/extF80_mul.c b/bochs/cpu/softfloat3e/extF80_mul.c index e56396fba..713b40bf3 100644 --- a/bochs/cpu/softfloat3e/extF80_mul.c +++ b/bochs/cpu/softfloat3e/extF80_mul.c @@ -55,7 +55,7 @@ extFloat80_t extF80_mul(extFloat80_t a, extFloat80_t b, struct softfloat_status_ uint64_t magBits; struct exp32_sig64 normExpSig; int32_t expZ; - struct uint128 sig128Z, uiZ; + struct uint128 sig128Z; uint16_t uiZ64; uint64_t uiZ0; @@ -135,8 +135,7 @@ extFloat80_t extF80_mul(extFloat80_t a, extFloat80_t b, struct softfloat_status_ /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ propagateNaN: - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ infArg: diff --git a/bochs/cpu/softfloat3e/extF80_rem.c b/bochs/cpu/softfloat3e/extF80_rem.c index 4abc103dc..fc446179f 100644 --- a/bochs/cpu/softfloat3e/extF80_rem.c +++ b/bochs/cpu/softfloat3e/extF80_rem.c @@ -57,7 +57,6 @@ extFloat80_t extF80_rem(extFloat80_t a, extFloat80_t b, struct softfloat_status_ uint64_t q64; struct uint128 term, altRem, meanRem; bool signRem; - struct uint128 uiZ; // handle unsupported extended double-precision floating encodings if (extF80_isUnsupported(a) || extF80_isUnsupported(b)) @@ -183,8 +182,7 @@ extFloat80_t extF80_rem(extFloat80_t a, extFloat80_t b, struct softfloat_status_ /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ propagateNaN: - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ invalid: diff --git a/bochs/cpu/softfloat3e/extF80_roundToInt.c b/bochs/cpu/softfloat3e/extF80_roundToInt.c index 0728d5211..142bc8810 100644 --- a/bochs/cpu/softfloat3e/extF80_roundToInt.c +++ b/bochs/cpu/softfloat3e/extF80_roundToInt.c @@ -47,7 +47,6 @@ extFloat80_t uint64_t sigA; uint16_t uiZ64; uint64_t sigZ; - struct uint128 uiZ; uint64_t lastBitMask, roundBitsMask; // handle unsupported extended double-precision floating encodings @@ -66,8 +65,7 @@ extFloat80_t *------------------------------------------------------------------------*/ if (0x403E <= exp) { if ((exp == 0x7FFF) && (uint64_t) (sigA<<1)) { - uiZ = softfloat_propagateNaNExtF80UI(uiA64, sigA, 0, 0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, sigA, 0, 0, status); } return a; } diff --git a/bochs/cpu/softfloat3e/extF80_scale.c b/bochs/cpu/softfloat3e/extF80_scale.c index 837e911dd..f4f58ca2f 100644 --- a/bochs/cpu/softfloat3e/extF80_scale.c +++ b/bochs/cpu/softfloat3e/extF80_scale.c @@ -59,7 +59,6 @@ extFloat80_t extF80_scale(extFloat80_t a, extFloat80_t b, softfloat_status_t *st bool signB; int32_t expB; uint64_t sigB; - struct uint128 uiZ; struct exp32_sig64 normExpSig; // handle unsupported extended double-precision floating encodings @@ -86,8 +85,7 @@ invalid: if (expA == 0x7FFF) { if ((sigA<<1) || ((expB == 0x7FFF) && (sigB<<1))) { - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); } if ((expB == 0x7FFF) && signB) goto invalid; if (sigB && !expB) softfloat_raiseFlags(status, softfloat_flag_denormal); @@ -95,8 +93,7 @@ invalid: } if (expB == 0x7FFF) { if (sigB<<1) { - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); } if ((expA | sigA) == 0) { if (! signB) goto invalid; diff --git a/bochs/cpu/softfloat3e/extF80_sqrt.c b/bochs/cpu/softfloat3e/extF80_sqrt.c index b8e723720..e8011e2ea 100644 --- a/bochs/cpu/softfloat3e/extF80_sqrt.c +++ b/bochs/cpu/softfloat3e/extF80_sqrt.c @@ -46,7 +46,6 @@ extFloat80_t extF80_sqrt(extFloat80_t a, struct softfloat_status_t *status) bool signA; int32_t expA; uint64_t sigA; - struct uint128 uiZ; struct exp32_sig64 normExpSig; int32_t expZ; uint32_t sig32A, recipSqrt32, sig32Z; @@ -70,8 +69,7 @@ extFloat80_t extF80_sqrt(extFloat80_t a, struct softfloat_status_t *status) *------------------------------------------------------------------------*/ if (expA == 0x7FFF) { if (sigA & UINT64_C(0x7FFFFFFFFFFFFFFF)) { - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, 0, 0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, 0, 0, status); } if (! signA) return a; goto invalid; diff --git a/bochs/cpu/softfloat3e/8086-SSE/specialize.h b/bochs/cpu/softfloat3e/include/specialize.h similarity index 99% rename from bochs/cpu/softfloat3e/8086-SSE/specialize.h rename to bochs/cpu/softfloat3e/include/specialize.h index fb6e0efb8..bc45ca0c8 100644 --- a/bochs/cpu/softfloat3e/8086-SSE/specialize.h +++ b/bochs/cpu/softfloat3e/include/specialize.h @@ -220,14 +220,13 @@ struct uint128 softfloat_commonNaNToExtF80UI(const struct commonNaN *aPtr); | result. If either original floating-point value is a signaling NaN, the | invalid exception is raised. *----------------------------------------------------------------------------*/ -struct uint128 +extFloat80_t softfloat_propagateNaNExtF80UI( uint16_t uiA64, uint64_t uiA0, uint16_t uiB64, uint64_t uiB0, - struct softfloat_status_t *status -); + struct softfloat_status_t *status); /*---------------------------------------------------------------------------- | The bit pattern for a default generated 128-bit floating-point NaN. diff --git a/bochs/cpu/softfloat3e/s_addMagsExtF80.c b/bochs/cpu/softfloat3e/s_addMagsExtF80.c index b95580566..ea23357e5 100644 --- a/bochs/cpu/softfloat3e/s_addMagsExtF80.c +++ b/bochs/cpu/softfloat3e/s_addMagsExtF80.c @@ -50,7 +50,6 @@ extFloat80_t softfloat_addMagsExtF80(uint16_t uiA64, uint64_t uiA0, uint16_t uiB struct exp32_sig64 normExpSig; int32_t expZ; struct uint64_extra sig64Extra; - struct uint128 uiZ; /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ @@ -143,6 +142,5 @@ extFloat80_t softfloat_addMagsExtF80(uint16_t uiA64, uint64_t uiA0, uint16_t uiB /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ propagateNaN: - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); } diff --git a/bochs/cpu/softfloat3e/s_normRoundPackToExtF80.c b/bochs/cpu/softfloat3e/s_normRoundPackToExtF80.c index a32250019..c404ffba3 100644 --- a/bochs/cpu/softfloat3e/s_normRoundPackToExtF80.c +++ b/bochs/cpu/softfloat3e/s_normRoundPackToExtF80.c @@ -44,8 +44,7 @@ extFloat80_t uint64_t sig, uint64_t sigExtra, uint8_t roundingPrecision, - struct softfloat_status_t *status -) + struct softfloat_status_t *status) { int8_t shiftDist; struct uint128 sig128; diff --git a/bochs/cpu/softfloat3e/s_subMagsExtF80.c b/bochs/cpu/softfloat3e/s_subMagsExtF80.c index e0c1542a9..215342815 100644 --- a/bochs/cpu/softfloat3e/s_subMagsExtF80.c +++ b/bochs/cpu/softfloat3e/s_subMagsExtF80.c @@ -49,7 +49,7 @@ extFloat80_t int32_t expDiff; int32_t expZ; uint64_t sigExtra; - struct uint128 sig128, uiZ; + struct uint128 sig128; struct exp32_sig64 normExpSig; /*------------------------------------------------------------------------ @@ -150,6 +150,5 @@ extFloat80_t /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ propagateNaN: - uiZ = softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); - return packToExtF80(uiZ.v64, uiZ.v0); + return softfloat_propagateNaNExtF80UI(uiA64, uiA0, uiB64, uiB0, status); }