fpu/next, mostly bits s390x tcg will need
cover fpu/next, mostly bits s390x tcg will need
Hi,
Here is the current status of fpu/next. I intend to send the PR in next week as there are bits in it blocking work for s390. This is the last chance to pipe up with any objections.
The following patches need review
0004/tests fp add wrapping for f128_to_ui32.patch 0005/tests fp enable f128_to_ui 32 64 tests in float t.patch
Alex Bennée (2):
tests/fp: add wrapping for f128_to_ui32 tests/fp: enable f128_to_ui[32/64] tests in float-to-uint
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 | 93 ++++++++++++++++++++++++++++++++++++++--- include/fpu/softfloat.h | 15 ++++++- tests/.gitignore | 1 + tests/Makefile.include | 7 ++-- tests/fp/fp-test.c | 46 +++++++++++++++----- tests/fp/wrap.inc.c | 1 + 6 files changed, 143 insertions(+), 20 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/6 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 + 1 file changed, 1 insertion(+)
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
PATCH 2/6 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
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
PATCH 3/6 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 +++++++++++++++++++++++++++++ include/fpu/softfloat.h | 1 + 2 files changed, 30 insertions(+)
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
PATCH 4/6 tests/fp: add wrapping for f128_to_ui32
In reply to Alex BennéeNeeded to test: softfloat: add float128_is_{normal,denormal}
--- tests/fp/fp-test.c | 3 ++- tests/fp/wrap.inc.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
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
Re: [Qemu-devel] [PATCH v1 4/6] tests/fp: add wrapping for f128_to_ui32
Quoted 1 line · Alex Bennée
Needed to test: softfloat: add float128_is_{normal,denormal}
Eh?
Quoted 6 lines
Signed-off-by Alex Bennée <[email protected]>--- tests/fp/fp-test.c | 3 ++- tests/fp/wrap.inc.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
But the rest of the patch matches $SUBJECT, so
r~
Re: [Qemu-devel] [PATCH v1 4/6] tests/fp: add wrapping for f128_to_ui32
Quoted 2 lines · Richard Henderson
Quoted 1 line · Alex Bennée
Needed to test: softfloat: add float128_is_{normal,denormal}
Obviously I was reading the title of the other patch.. will fix.
Quoted 10 lines
Eh?
Quoted 6 lines
Signed-off-by Alex Bennée <[email protected]>--- tests/fp/fp-test.c | 3 ++- tests/fp/wrap.inc.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
Quoted 5 lines
But the rest of the patch matches $SUBJECT, so
Reviewed-by Richard Henderson <[email protected]>r~
--
Alex Bennée
PATCH 5/6 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
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
Re: [Qemu-devel] [PATCH v1 5/6] tests/fp: enable f128_to_ui[32/64] tests in float-to-uint
Quoted 7 lines · Alex Bennée
We've just added
f128_to_ui32and we missed out thef128_to_ui64tests last time.Signed-off-by Alex Bennée <[email protected]>--- tests/Makefile.include | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
r~
PATCH 6/6 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 | 64 ++++++++++++++++++++++++++++++++++++++++++---- tests/fp/fp-test.c | 43 ++++++++++++++++++++++++------- 2 files changed, 93 insertions(+), 14 deletions(-)
fpu/softfloat.c +59 -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,8 @@ 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 ;default :abort ();break ;
@@ -3536,8 +3563,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 +3584,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 +7023,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 +7043,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 +7056,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 +7099,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
Re: [Qemu-devel] [PATCH v1 6/6] softfloat: Support float_round_to_odd more places
fpu/softfloat.c static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig, · line 3557
Quoted 8 lines · Alex Bennée
fpu/softfloat.c +2
-0@@ -3526,6 +3551,8 @@ 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 ;default :abort ();
I clearly missed a break here.
Since this didn't kill fp-test, are we missing a float128_to_float32 test?
r~
Re: [Qemu-devel] [PATCH v1 6/6] softfloat: Support float_round_to_odd more places
Quoted 12 lines · Richard Henderson
fpu/softfloat.c static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig, · line 3557
Quoted 8 lines · Alex Bennée
fpu/softfloat.c +2
-0@@ -3526,6 +3551,8 @@ 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 ;default :abort ();I clearly missed a break here.
Quoted 2 lines
Since this didn't kill fp-test, are we missing a
float128_to_float32test?
Ahh yes missing that:
10:11:17 [alex@zen:~/l/q/b/a/t/fp] fpu/next + ./fp-test f16_to_f32 f64_to_f32 f128_to_f32 -r odd
Quoted 1 line
Quoted 1 line
Testing
f16_to_f32
408 tests total.
408 tests performed.
In 408 tests, no errors found in f16_to_f32.
Quoted 1 line
Quoted 1 line
Testing
f64_to_f32, rounding odd, tininess before rounding
768 tests total.
768 tests performed.
In 768 tests, no errors found in f64_to_f32, rounding odd, tininess before rounding.
Quoted 1 line
Quoted 1 line
Testing
f64_to_f32, rounding odd, tininess after rounding
768 tests total.
768 tests performed.
In 768 tests, no errors found in f64_to_f32, rounding odd, tininess after rounding.
Quoted 1 line
Quoted 1 line
Testing
f128_to_f32, rounding odd, tininess before rounding
936 tests total.
fish: “./fp-test f16_to_f32 f64_to_f32…” terminated by signal SIGABRT (Abort)
I'll patch it up and fix.
Quoted 3 lines
r~
--
Alex Bennée
Re: [Qemu-devel] [PATCH v1 6/6] softfloat: Support float_round_to_odd more places
In reply to Richard HendersonQuoted 12 lines · Richard Henderson
fpu/softfloat.c static float32 roundAndPackFloat32(flag zSign, int zExp, uint32_t zSig, · line 3557
Quoted 8 lines · Alex Bennée
fpu/softfloat.c +2
-0@@ -3526,6 +3551,8 @@ 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 ;default :abort ();I clearly missed a break here.
Quoted 2 lines
Since this didn't kill fp-test, are we missing a
float128_to_float32test?
So I've not got -r all against all tests but adding it to make mulAdd take even longer to run so maybe I'll not bother for mulAdd.
Quoted 3 lines
r~
--
Alex Bennée