softfloat updates, mostly for s390x
The following changes since commit ef80b99ce7ffbd66b3efd493f4ca99f8abf59e79:
Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-next-220219-1' into staging (2019-02-25 14:04:20 +0000)
are available in the Git repository at:
https://github.com/stsquad/qemu.git tags/pull-fpu-next-260219-1
for you to fetch changes up to bf30e8662cd2ee8b750945591cb34a31784fb994:
tests/Makefile.include: test all rounding modes of softfloat (2019-02-26 14:08:03 +0000)
----------------------------------------------------------------
Softloat updates, mostly in preparation for s390x usage
----------------------------------------------------------------
Alex Bennée (3):
tests/fp: add wrapping for f128_to_ui32
tests/fp: enable f128_to_ui[32/64] tests in float-to-uint tests/Makefile.include: test all rounding modes of softfloat
David Hildenbrand (2):
softfloat: add float128_is_{normal,denormal}
softfloat: Implement float128_to_uint32
Eric Blake (1):
tests: Ignore fp test outputs
Richard Henderson (1):
softfloat: Support float_round_to_odd more places
fpu/softfloat.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++--- include/fpu/softfloat.h | 15 ++++++-- tests/.gitignore | 1 + tests/Makefile.include | 15 ++++---- tests/fp/fp-test.c | 46 ++++++++++++++++++------ tests/fp/wrap.inc.c | 1 + 6 files changed, 148 insertions(+), 24 deletions(-)
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 1/7] tests: Ignore fp test outputs
From: Eric Blake <[email protected]>
Commit 2cade3d wired up new tests, but did not exclude the new *.out files produced by running the tests.
tests/.gitignore +1 -0
@@ -5,6 +5,7 @@ benchmark-crypto-hmac check-* !check-*.c !check-*.sh +fp/*.out qht-bench rcutorture test-*
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 6/7] softfloat: Support float_round_to_odd more places
In reply to Alex BennéeFrom: Richard Henderson <[email protected]>
Previously this was only supported for roundAndPackFloat64.
New support in round_canonical, round_to_int, float128_round_to_int, roundAndPackFloat32, roundAndPackInt32, roundAndPackInt64, roundAndPackUint64. This does not include any of the floatx80 routines, as we do not have users for that rounding mode there.
Message-Id: <[email protected]>
fpu/softfloat.c +60 -5
@@ -696,6 +696,7 @@ static FloatParts sf_canonicalize(FloatParts part, const FloatFmt *parm,static FloatParts round_canonical (FloatParts p,float_status *s,const FloatFmt *parm) { +const uint64_t frac_lsb = parm->frac_lsb;const uint64_t frac_lsbm1 = parm->frac_lsbm1;const uint64_t round_mask = parm->round_mask;const uint64_t roundeven_mask = parm->roundeven_mask;
@@ -731,6 +732,10 @@ static FloatParts round_canonical(FloatParts p, float_status *s, inc = p.sign ? round_mask :0 ; overflow_norm = !p.sign;break ; +case float_round_to_odd: + overflow_norm = true; + inc = frac & frac_lsb ?0 : round_mask; +break ;default :g_assert_not_reached (); }
@@ -778,9 +783,14 @@ static FloatParts round_canonical(FloatParts p, float_status *s,shift64RightJamming (frac,1 - exp, &frac);if (frac & round_mask) {/* Need to recompute round-to-even. */ -if (s->float_rounding_mode == float_round_nearest_even) { +switch (s->float_rounding_mode) { +case float_round_nearest_even: inc = ((frac & roundeven_mask) != frac_lsbm1 ? frac_lsbm1 :0 ); +break ; +case float_round_to_odd: + inc = frac & frac_lsb ?0 : round_mask; +break ; } flags |= float_flag_inexact; frac += inc;
@@ -1988,6 +1998,9 @@ static FloatParts round_to_int(FloatParts a, int rmode,case float_round_down: one = a.sign;break ; +case float_round_to_odd: + one = true; +break ;default :g_assert_not_reached (); }
@@ -2021,6 +2034,9 @@ static FloatParts round_to_int(FloatParts a, int rmode,case float_round_down: inc = a.sign ? rnd_mask :0 ;break ; +case float_round_to_odd: + inc = a.frac & frac_lsb ?0 : rnd_mask; +break ;default :g_assert_not_reached (); }
@@ -3314,6 +3330,9 @@ static int32_t roundAndPackInt32(flag zSign, uint64_t absZ, float_status *statuscase float_round_down: roundIncrement = zSign ?0x7f :0 ;break ; +case float_round_to_odd: + roundIncrement = absZ &0x80 ?0 :0x7f ; +break ;default :abort (); }
@@ -3368,6 +3387,9 @@ static int64_t roundAndPackInt64(flag zSign, uint64_t absZ0, uint64_t absZ1,case float_round_down: increment = zSign && absZ1;break ; +case float_round_to_odd: + increment = !(absZ0 &1 ) && absZ1; +break ;default :abort (); }
@@ -3424,6 +3446,9 @@ static int64_t roundAndPackUint64(flag zSign, uint64_t absZ0,case float_round_down: increment = zSign && absZ1;break ; +case float_round_to_odd: + increment = !(absZ0 &1 ) && absZ1; +break ;default :abort (); }
@@ -3526,6 +3551,9 @@ static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig,case float_round_down: roundIncrement = zSign ?0x7f :0 ;break ; +case float_round_to_odd: + roundIncrement = zSig &0x80 ?0 :0x7f ; +break ;default :abort ();break ;
@@ -3536,8 +3564,10 @@ static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig, || ( ( zExp == 0xFD ) && ( (int32_t) ( zSig + roundIncrement ) < 0 ) ) ) { +bool overflow_to_inf = roundingMode != float_round_to_odd && + roundIncrement !=0 ;float_raise (float_flag_overflow | float_flag_inexact, status); -return packFloat32 ( zSign,0xFF , - ( roundIncrement ==0 )); +return packFloat32 (zSign,0xFF , -!overflow_to_inf); }if ( zExp <0 ) {if (status->flush_to_zero) {
@@ -3555,6 +3585,13 @@ static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig,if (isTiny && roundBits) {float_raise (float_flag_underflow, status); } +if (roundingMode == float_round_to_odd) { +/* +* For round-to-odd case, the roundIncrement depends on +* zSig which just changed. +*/ + roundIncrement = zSig &0x80 ?0 :0x7f ; + } } }if (roundBits) {
@@ -6987,6 +7024,15 @@ float128 float128_round_to_int(float128 a, float_status *status)add128 (z.high, z.low,0 , roundBitsMask, &z.high, &z.low); }break ; +case float_round_to_odd: +/* +* Note that if lastBitMask == 0, the last bit is the lsb +* of high, and roundBitsMask == -1. +*/ +if ((lastBitMask ? z.low & lastBitMask : z.high &1 ) ==0 ) { +add128 (z.high, z.low,0 , roundBitsMask, &z.high, &z.low); + } +break ;default :abort (); }
@@ -6998,7 +7044,7 @@ float128 float128_round_to_int(float128 a, float_status *status) status->float_exception_flags |= float_flag_inexact; aSign =extractFloat128Sign ( a );switch (status->float_rounding_mode) { -case float_round_nearest_even: +case float_round_nearest_even:if ( ( aExp ==0x3FFE ) && (extractFloat128Frac0 ( a ) | extractFloat128Frac1( a ) )
@@ -7011,14 +7057,17 @@ float128 float128_round_to_int(float128 a, float_status *status)return packFloat128 (aSign,0x3FFF ,0 ,0 ); }break ; -case float_round_down: +case float_round_down:return aSign ?packFloat128 (1 ,0x3FFF ,0 ,0 ) :packFloat128 (0 ,0 ,0 ,0 ); -case float_round_up: +case float_round_up:return aSign ?packFloat128 (1 ,0 ,0 ,0 ) :packFloat128 (0 ,0x3FFF ,0 ,0 ); + +case float_round_to_odd: +return packFloat128 (aSign,0x3FFF ,0 ,0 ); }return packFloat128 ( aSign,0 ,0 ,0 ); }
@@ -7051,6 +7100,12 @@ float128 float128_round_to_int(float128 a, float_status *status) z.high += roundBitsMask; }break ; +case float_round_to_odd: +if ((z.high & lastBitMask) ==0 ) { + z.high |= (a.low !=0 ); + z.high += roundBitsMask; + } +break ;default :abort (); }
tests/fp/fp-test.c +34 -9
51 lines not on this page · raw message
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 7/7] tests/Makefile.include: test all rounding modes of softfloat
In reply to Alex BennéeWe missed a bug in a recent patch as we were not testing all the rounding modes for all operations. However enabling all rounding modes for mulAdd does slow down the already slowest test and doesn't really buy us much additional coverage so lets allow the default test flags to be overridden.
tests/Makefile.include +4 -4
@@ -898,12 +898,12 @@ $(FP_TEST_BIN): # The full test suite can take a bit of time, default to a quick run # "-l 2 -r all" can take more than a day for some operations and is best # run manually -FP_TL=-l 1 +FP_TL=-l 1 -r all -# $1 = tests, $2 = description +# $1 = tests, $2 = description, $3 = test flags test-softfloat = $(call quiet-command, \ cd $(BUILD_DIR)/tests/fp && \ - ./fp-test -s $(FP_TL) $1 > $2.out 2>&1 || \ + ./fp-test -s $(if $3,$3,$(FP_TL)) $1 > $2.out 2>&1 || \ (cat $2.out && exit 1;), \ "FLOAT TEST", $2)
@@ -984,7 +984,7 @@ check-softfloat-compare: $(SF_COMPARE_RULES) check-softfloat-mulAdd: $(FP_TEST_BIN) $(call test-softfloat, \ f16_mulAdd f32_mulAdd f64_mulAdd f128_mulAdd, \ - mulAdd) + mulAdd,-l 1) # FIXME: extF80_rem (broken) check-softfloat-rem: $(FP_TEST_BIN)
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 3/7] softfloat: Implement float128_to_uint32
In reply to Alex BennéeFrom: David Hildenbrand <[email protected]>
Handling it just like float128_to_uint32_round_to_zero, that hopefully is free of bugs :)
Documentation basically copied from float128_to_uint64
fpu/softfloat.c +29 -0
@@ -6792,6 +6792,35 @@ uint32_t float128_to_uint32_round_to_zero(float128 a, float_status *status)return res; } +/*---------------------------------------------------------------------------- +| Returns the result of converting the quadruple-precision floating-point value +| `a' to the 32-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN, the largest +| positive integer is returned. If the conversion overflows, the +| largest unsigned integer is returned. If 'a' is negative, the value is +| rounded and zero is returned; negative values that do not round to zero +| will raise the inexact exception. +*----------------------------------------------------------------------------*/ + +uint32_t float128_to_uint32 (float128 a,float_status *status) +{ +uint64_t v; +uint32_t res; +int old_exc_flags =get_float_exception_flags (status); + + v =float128_to_uint64 (a, status); +if (v >0xffffffff ) { + res =0xffffffff ; + }else { +return v; + } +set_float_exception_flags (old_exc_flags, status); +float_raise (float_flag_invalid, status); +return res; +} +/*---------------------------------------------------------------------------- | Returns the result of converting the quadruple-precision floating-point | value `a' to the single-precision floating-point format. The conversion
include/fpu/softfloat.h +1 -0
@@ -878,6 +878,7 @@ int64_t float128_to_int64(float128, float_status *status);int64_t float128_to_int64_round_to_zero (float128 ,float_status *status);uint64_t float128_to_uint64 (float128 ,float_status *status);uint64_t float128_to_uint64_round_to_zero (float128 ,float_status *status); +uint32_t float128_to_uint32 (float128 ,float_status *status);uint32_t float128_to_uint32_round_to_zero (float128 ,float_status *status);float32 float128_to_float32 (float128 ,float_status *status);float64 float128_to_float64 (float128 ,float_status *status);
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 2/7] softfloat: add float128_is_{normal, denormal}
In reply to Alex BennéeFrom: David Hildenbrand <[email protected]>
Needed on s390x, to test for the data class of a number. So it will gain soon a user.
A number is considered normal if the exponent is neither 0 nor all 1's. That can be checked by adding 1 to the exponent, and comparing against
Quoted 1 line
= 2 after dropping an eventual overflow into the sign bit.
While at it, convert the other floatXX_is_normal functions to use a similar, less error prone calculation, as suggested by Richard H.
include/fpu/softfloat.h +12 -2
@@ -466,7 +466,7 @@ static inline int float32_is_zero_or_denormal(float32 a)static inline bool float32_is_normal (float32 a) { -return ((float32_val (a) +0x00800000 ) &0x7fffffff ) >=0x01000000 ; +return (((float32_val (a) >>23 ) +1 ) &0xff ) >=2 ; }static inline bool float32_is_denormal (float32 a)
@@ -622,7 +622,7 @@ static inline int float64_is_zero_or_denormal(float64 a)static inline bool float64_is_normal (float64 a) { -return ((float64_val (a) + (1ULL <<52 )) &-1ULL >>1 ) >=1ULL <<53 ; +return (((float64_val (a) >>52 ) +1 ) &0x7ff ) >=2 ; }static inline bool float64_is_denormal (float64 a)
@@ -940,6 +940,16 @@ static inline int float128_is_zero_or_denormal(float128 a)return (a.high &0x7fff000000000000LL ) ==0 ; } +static inline bool float128_is_normal (float128 a) +{ +return (((a.high >>48 ) +1 ) &0x7fff ) >=2 ; +} + +static inline bool float128_is_denormal (float128 a) +{ +return float128_is_zero_or_denormal (a) && !float128_is_zero (a); +} +static inline int float128_is_any_nan (float128 a) { return ((a.high >> 48) & 0x7fff) == 0x7fff &&
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 4/7] tests/fp: add wrapping for f128_to_ui32
In reply to Alex BennéeNeeded to test: softfloat: Implement float128_to_uint32
tests/fp/fp-test.c +2 -1
@@ -622,7 +622,8 @@ static void do_testfloat(int op, int rmode, bool exact)test_ab_extF80_z_bool (true_ab_extF80M_z_bool, subj_ab_extF80M_z_bool);break ;case F128_TO_UI32 : -not_implemented (); +test_a_f128_z_ui32_rx (slow_f128M_to_ui32, qemu_f128M_to_ui32, rmode, + exact);break ;case F128_TO_UI64 : test_a_f128_z_ui64_rx(slow_f128M_to_ui64, qemu_f128M_to_ui64, rmode,
tests/fp/wrap.inc.c +1 -0
@@ -367,6 +367,7 @@ WRAP_80_TO_INT_MINMAG(qemu_extF80M_to_i64_r_minMag, WRAP_128_TO_INT(qemu_f128M_to_i32, float128_to_int32, int_fast32_t) WRAP_128_TO_INT(qemu_f128M_to_i64, float128_to_int64, int_fast64_t) +WRAP_128_TO_INT(qemu_f128M_to_ui32, float128_to_uint32, uint_fast32_t) WRAP_128_TO_INT(qemu_f128M_to_ui64, float128_to_uint64, uint_fast64_t)#undef WRAP_128_TO_INT
Signature · 1 line
2.20.1
[Qemu-devel] [PULL 5/7] tests/fp: enable f128_to_ui[32/64] tests in float-to-uint
In reply to Alex BennéeWe've just added f128_to_ui32 and we missed out the f128_to_ui64 tests last time.
tests/Makefile.include +4 -3
@@ -909,8 +909,7 @@ test-softfloat = $(call quiet-command, \ # Conversion Routines: # FIXME: i32_to_extF80 (broken), i64_to_extF80 (broken) -# ui32_to_f128 (not implemented), f128_to_ui32 (not implemented) -# extF80_roundToInt (broken) +# ui32_to_f128 (not implemented), extF80_roundToInt (broken) # check-softfloat-conv: $(FP_TEST_BIN) $(call test-softfloat, \
@@ -939,9 +938,11 @@ check-softfloat-conv: $(FP_TEST_BIN) f16_to_ui32 f16_to_ui32_r_minMag \ f32_to_ui32 f32_to_ui32_r_minMag \ f64_to_ui32 f64_to_ui32_r_minMag \ + f128_to_ui32 f128_to_ui32_r_minMag \ f16_to_ui64 f16_to_ui64_r_minMag \ f32_to_ui64 f32_to_ui64_r_minMag \ - f64_to_ui64 f64_to_ui64_r_minMag, \ + f64_to_ui64 f64_to_ui64_r_minMag \ + f128_to_ui64 f128_to_ui64_r_minMag, \ float-to-uint) $(call test-softfloat, \ f16_roundToInt f32_roundToInt \
Signature · 1 line
2.20.1
Peter Maydell
AppliedQuoted 9 lines · Alex Bennée
The following changes since commit
ef80b99ce7ffbd66b3efd493f4ca99f8abf59e79:Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-next-220219-1' into staging (2019-02-25 14:04:20 +0000)
are available in the Git repository at:
https://github.com/stsquad/qemu.git tags/pull-fpu-next-260219-1
Quoted 8 lines
for you to fetch changes up to
bf30e8662cd2ee8b750945591cb34a31784fb994:tests/Makefile.include: test all rounding modes of softfloat (2019-02-26 14:08:03 +0000)
----------------------------------------------------------------
Softloat updates, mostly in preparation for s390x usage----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.
-- PMM