On Wed, 29 Aug 2018, Jan Hubicka wrote:

> Hi,
> this patch reduces memory use of sreal by converting m_sig from int64_t to
> int32_t.  This requires me to reduce SREAL_PART_BITS from 32 to 31 so there is
> space for sign. There is comment "SREAL_PART_BITS has to be an even number."
> but I found no reason for that comment. It is possible that I missed something
> obvious but I read the normalization and operations and didn't noticed 
> anything
> that would rely on this.
> 
> Of course we need 2*SREAL_PART_BITS for temporary calcuations so perhaps at
> some time SREAL_PART_BITS meant that.
> 
> There is some effect on code of tramp3d but manual inspection of dumps did not
> show anything important, just small differences in roundoff errors.
> 
> Bootstrapped/regtested x86_64-linux, OK?

OK.

> Honza
> 
>       * sreal.h (SREAL_PART_BITS): Change to 31; remove seemingly unnecessary
>       comment that it has to be even number.
>       (class sreal): Change m_sig type to int32_t.
>       * sreal.c (sreal::dump, sreal::to_int, opreator+, operator-): Use
>       int64_t for temporary calculations.
>       (sreal_verify_basics): Drop one bit from minimum and maximum.
> Index: sreal.h
> ===================================================================
> --- sreal.h   (revision 263952)
> +++ sreal.h   (working copy)
> @@ -20,8 +20,7 @@ along with GCC; see the file COPYING3.
>  #ifndef GCC_SREAL_H
>  #define GCC_SREAL_H
>  
> -/* SREAL_PART_BITS has to be an even number.  */
> -#define SREAL_PART_BITS 32
> +#define SREAL_PART_BITS 31
>  
>  #define UINT64_BITS  64
>  
> @@ -137,7 +136,7 @@ private:
>    static sreal signedless_plus (const sreal &a, const sreal &b, bool 
> negative);
>    static sreal signedless_minus (const sreal &a, const sreal &b, bool 
> negative);
>  
> -  int64_t m_sig;                     /* Significant.  */
> +  int32_t m_sig;                     /* Significant.  */
>    signed int m_exp;                  /* Exponent.  */
>  };
>  
> Index: sreal.c
> ===================================================================
> --- sreal.c   (revision 263952)
> +++ sreal.c   (working copy)
> @@ -64,7 +64,7 @@ along with GCC; see the file COPYING3.
>  void
>  sreal::dump (FILE *file) const
>  {
> -  fprintf (file, "(%" PRIi64 " * 2^%d)", m_sig, m_exp);
> +  fprintf (file, "(%" PRIi64 " * 2^%d)", (int64_t)m_sig, m_exp);
>  }
>  
>  DEBUG_FUNCTION void
> @@ -114,7 +114,7 @@ sreal::to_int () const
>    if (m_exp >= SREAL_PART_BITS)
>      return sign * INTTYPE_MAXIMUM (int64_t);
>    if (m_exp > 0)
> -    return sign * (SREAL_ABS (m_sig) << m_exp);
> +    return sign * (SREAL_ABS ((int64_t)m_sig) << m_exp);
>    if (m_exp < 0)
>      return m_sig >> -m_exp;
>    return m_sig;
> @@ -167,7 +167,7 @@ sreal::operator+ (const sreal &other) co
>        bb = &tmp;
>      }
>  
> -  r_sig = a_p->m_sig + bb->m_sig;
> +  r_sig = a_p->m_sig + (int64_t)bb->m_sig;
>    sreal r (r_sig, r_exp);
>    return r;
>  }
> @@ -211,7 +211,7 @@ sreal::operator- (const sreal &other) co
>        bb = &tmp;
>      }
>  
> -  r_sig = sign * ((int64_t) a_p->m_sig - bb->m_sig);
> +  r_sig = sign * ((int64_t) a_p->m_sig - (int64_t)bb->m_sig);
>    sreal r (r_sig, r_exp);
>    return r;
>  }
> @@ -277,15 +277,15 @@ namespace selftest {
>  static void
>  sreal_verify_basics (void)
>  {
> -  sreal minimum = INT_MIN;
> -  sreal maximum = INT_MAX;
> +  sreal minimum = INT_MIN/2;
> +  sreal maximum = INT_MAX/2;
>  
>    sreal seven = 7;
>    sreal minus_two = -2;
>    sreal minus_nine = -9;
>  
> -  ASSERT_EQ (INT_MIN, minimum.to_int ());
> -  ASSERT_EQ (INT_MAX, maximum.to_int ());
> +  ASSERT_EQ (INT_MIN/2, minimum.to_int ());
> +  ASSERT_EQ (INT_MAX/2, maximum.to_int ());
>  
>    ASSERT_FALSE (minus_two < minus_two);
>    ASSERT_FALSE (seven < seven);
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)

Reply via email to