simplifications in softfloat3e code

This commit is contained in:
Stanislav Shwartsman 2024-04-14 22:14:12 +03:00
parent e4978addd1
commit 42db7b64ce
13 changed files with 26 additions and 46 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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:

View File

@ -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));

View File

@ -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:

View File

@ -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:

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}