Message ID | 20200924012453.659757-3-richard.henderson@linaro.org |
---|---|
State | New |
Headers | show |
Series | softfloat: Implement float128_muladd | expand |
On 24.09.20 03:24, Richard Henderson wrote: > Use our Int128, which wraps the compiler's __int128_t, > instead of open-coding left shifts and arithmetic. > We'd need to extend Int128 to have unsigned operations > to replace more than these three. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > include/fpu/softfloat-macros.h | 39 +++++++++++++++++----------------- > 1 file changed, 20 insertions(+), 19 deletions(-) > > diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h > index 57845f8af0..95d88d05b8 100644 > --- a/include/fpu/softfloat-macros.h > +++ b/include/fpu/softfloat-macros.h > @@ -84,6 +84,7 @@ this code that are retained. > > #include "fpu/softfloat-types.h" > #include "qemu/host-utils.h" > +#include "qemu/int128.h" > > /*---------------------------------------------------------------------------- > | Shifts `a' right by the number of bits given in `count'. If any nonzero > @@ -352,13 +353,11 @@ static inline void shortShift128Left(uint64_t a0, uint64_t a1, int count, > static inline void shift128Left(uint64_t a0, uint64_t a1, int count, > uint64_t *z0Ptr, uint64_t *z1Ptr) > { > - if (count < 64) { > - *z1Ptr = a1 << count; > - *z0Ptr = count == 0 ? a0 : (a0 << count) | (a1 >> (-count & 63)); > - } else { > - *z1Ptr = 0; > - *z0Ptr = a1 << (count - 64); > - } > + Int128 a = int128_make128(a1, a0); > + Int128 z = int128_lshift(a, count); > + > + *z0Ptr = int128_gethi(z); > + *z1Ptr = int128_getlo(z); > } > > /*---------------------------------------------------------------------------- > @@ -405,15 +404,15 @@ static inline void > *----------------------------------------------------------------------------*/ > > static inline void > - add128( > - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) > +add128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, > + uint64_t *z0Ptr, uint64_t *z1Ptr) > { > - uint64_t z1; > - > - z1 = a1 + b1; > - *z1Ptr = z1; > - *z0Ptr = a0 + b0 + ( z1 < a1 ); > + Int128 a = int128_make128(a1, a0); > + Int128 b = int128_make128(b1, b0); > + Int128 z = int128_add(a, b); > > + *z0Ptr = int128_gethi(z); > + *z1Ptr = int128_getlo(z); > } > > /*---------------------------------------------------------------------------- > @@ -463,13 +462,15 @@ static inline void > *----------------------------------------------------------------------------*/ > > static inline void > - sub128( > - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) > +sub128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, > + uint64_t *z0Ptr, uint64_t *z1Ptr) > { > + Int128 a = int128_make128(a1, a0); > + Int128 b = int128_make128(b1, b0); > + Int128 z = int128_sub(a, b); > > - *z1Ptr = a1 - b1; > - *z0Ptr = a0 - b0 - ( a1 < b1 ); > - > + *z0Ptr = int128_gethi(z); > + *z1Ptr = int128_getlo(z); > } > > /*---------------------------------------------------------------------------- > Reviewed-by: David Hildenbrand <david@redhat.com> -- Thanks, David / dhildenb
diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 57845f8af0..95d88d05b8 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -84,6 +84,7 @@ this code that are retained. #include "fpu/softfloat-types.h" #include "qemu/host-utils.h" +#include "qemu/int128.h" /*---------------------------------------------------------------------------- | Shifts `a' right by the number of bits given in `count'. If any nonzero @@ -352,13 +353,11 @@ static inline void shortShift128Left(uint64_t a0, uint64_t a1, int count, static inline void shift128Left(uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr) { - if (count < 64) { - *z1Ptr = a1 << count; - *z0Ptr = count == 0 ? a0 : (a0 << count) | (a1 >> (-count & 63)); - } else { - *z1Ptr = 0; - *z0Ptr = a1 << (count - 64); - } + Int128 a = int128_make128(a1, a0); + Int128 z = int128_lshift(a, count); + + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*---------------------------------------------------------------------------- @@ -405,15 +404,15 @@ static inline void *----------------------------------------------------------------------------*/ static inline void - add128( - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) +add128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, + uint64_t *z0Ptr, uint64_t *z1Ptr) { - uint64_t z1; - - z1 = a1 + b1; - *z1Ptr = z1; - *z0Ptr = a0 + b0 + ( z1 < a1 ); + Int128 a = int128_make128(a1, a0); + Int128 b = int128_make128(b1, b0); + Int128 z = int128_add(a, b); + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*---------------------------------------------------------------------------- @@ -463,13 +462,15 @@ static inline void *----------------------------------------------------------------------------*/ static inline void - sub128( - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) +sub128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, + uint64_t *z0Ptr, uint64_t *z1Ptr) { + Int128 a = int128_make128(a1, a0); + Int128 b = int128_make128(b1, b0); + Int128 z = int128_sub(a, b); - *z1Ptr = a1 - b1; - *z0Ptr = a0 - b0 - ( a1 < b1 ); - + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*----------------------------------------------------------------------------
Use our Int128, which wraps the compiler's __int128_t, instead of open-coding left shifts and arithmetic. We'd need to extend Int128 to have unsigned operations to replace more than these three. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- include/fpu/softfloat-macros.h | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-)