diff mbox series

[25/72] softfloat: Rearrange FloatParts64

Message ID 20210508014802.892561-26-richard.henderson@linaro.org
State New
Headers show
Series Convert floatx80 and float128 to FloatParts | expand

Commit Message

Richard Henderson May 8, 2021, 1:47 a.m. UTC
Shuffle the fraction to the end, otherwise sort by size.
Add frac_hi and frac_lo members to alias frac.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 fpu/softfloat.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Alex Bennée May 11, 2021, 1:57 p.m. UTC | #1
Richard Henderson <richard.henderson@linaro.org> writes:

> Shuffle the fraction to the end, otherwise sort by size.
> Add frac_hi and frac_lo members to alias frac.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  fpu/softfloat.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
> index 2123453d40..2d6f61ee7a 100644
> --- a/fpu/softfloat.c
> +++ b/fpu/softfloat.c
> @@ -511,10 +511,19 @@ static inline __attribute__((unused)) bool is_qnan(FloatClass c)
>   */
>  
>  typedef struct {
> -    uint64_t frac;
> -    int32_t  exp;
>      FloatClass cls;
>      bool sign;
> +    int32_t exp;
> +    union {
> +        /* Routines that know the structure may reference the singular name. */
> +        uint64_t frac;
> +        /*
> +         * Routines expanded with multiple structures reference "hi" and "lo".
> +         * In this structure, the one word is both highest and lowest.
> +         */
> +        uint64_t frac_hi;
> +        uint64_t frac_lo;

This confuses me. Is this because it could be frac_hi or frac_lo at the
"top" of the structure because of endian issues?

> +    };
>  } FloatParts64;
>  
>  #define DECOMPOSED_BINARY_POINT    63
Richard Henderson May 11, 2021, 3:04 p.m. UTC | #2
On 5/11/21 8:57 AM, Alex Bennée wrote:
>> +    union {
>> +        /* Routines that know the structure may reference the singular name. */
>> +        uint64_t frac;
>> +        /*
>> +         * Routines expanded with multiple structures reference "hi" and "lo".
>> +         * In this structure, the one word is both highest and lowest.
>> +         */
>> +        uint64_t frac_hi;
>> +        uint64_t frac_lo;
> 
> This confuses me. Is this because it could be frac_hi or frac_lo at the
> "top" of the structure because of endian issues?

Nothing about endianness.  There is exactly one element, so it is both the 
"first" and "last", both "high" and "low".

Generic code will examine the "high" word when looking at overflow and things 
related, and the "low" word when doing rounding.

This anonymous union gives the same element 3 different names.

r~
Alex Bennée May 12, 2021, 11:08 a.m. UTC | #3
Richard Henderson <richard.henderson@linaro.org> writes:

> On 5/11/21 8:57 AM, Alex Bennée wrote:
>>> +    union {
>>> +        /* Routines that know the structure may reference the singular name. */
>>> +        uint64_t frac;
>>> +        /*
>>> +         * Routines expanded with multiple structures reference "hi" and "lo".
>>> +         * In this structure, the one word is both highest and lowest.
>>> +         */
>>> +        uint64_t frac_hi;
>>> +        uint64_t frac_lo;
>> This confuses me. Is this because it could be frac_hi or frac_lo at
>> the
>> "top" of the structure because of endian issues?
>
> Nothing about endianness.  There is exactly one element, so it is both
> the "first" and "last", both "high" and "low".
>
> Generic code will examine the "high" word when looking at overflow and
> things related, and the "low" word when doing rounding.
>
> This anonymous union gives the same element 3 different names.

Right, that makes things clearer. How about:

  Routines expanded with multiple structures reference "hi" and "lo"
  depending on the operation. In the case of FloatParts64 they are both
  the same word but aliased here to make the code easier to follow.

?

Either way have a:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
diff mbox series

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 2123453d40..2d6f61ee7a 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -511,10 +511,19 @@  static inline __attribute__((unused)) bool is_qnan(FloatClass c)
  */
 
 typedef struct {
-    uint64_t frac;
-    int32_t  exp;
     FloatClass cls;
     bool sign;
+    int32_t exp;
+    union {
+        /* Routines that know the structure may reference the singular name. */
+        uint64_t frac;
+        /*
+         * Routines expanded with multiple structures reference "hi" and "lo".
+         * In this structure, the one word is both highest and lowest.
+         */
+        uint64_t frac_hi;
+        uint64_t frac_lo;
+    };
 } FloatParts64;
 
 #define DECOMPOSED_BINARY_POINT    63