Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-12-10 Thread Martin Liška

On 12/09/2014 03:15 PM, Richard Biener wrote:

On Mon, Dec 8, 2014 at 5:52 PM, Martin Liška  wrote:

On 11/28/2014 10:32 AM, Richard Biener wrote:


On Thu, Nov 27, 2014 at 6:08 PM, Martin Liška  wrote:


On 11/21/2014 04:21 PM, Martin Liška wrote:



On 11/21/2014 04:02 PM, Richard Biener wrote:



On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:


Hello.

Ok, this is simplified, one can use sreal a = 12345 and it works ;)


that's a  new API, right?  There is no max () and I think that using
LONG_MIN here is asking for trouble (host dependence).  The
comment in the file says the max should be
sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?



Sure, sreal can store much bigger(smaller) numbers :)


Where do you need sreal::to_double?  The host shouldn't perform
double calculations so it can be only for dumping?  In which case
the user should have used sreal::dump (), maybe with extra
arguments.



That new function was request from Honza, only for debugging purpose.
I agree that dump should this kind of job.

If no other problem, I will run tests once more and commit it.
Thanks,
Martin




-#define SREAL_MAX_EXP (INT_MAX / 4)
+#define SREAL_MAX_EXP (INT_MAX / 8)

this change doesn't look necessary anymore?

Btw, it's also odd that...

#define SREAL_PART_BITS 32
...
#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)

thus all m_sig values fit in 32bits but we still use a uint64_t m_sig
...
(the implementation uses 64bit for internal computations, but still
the storage is wasteful?)

Of course the way normalize() works requires that storage to be
64bits to store unnormalized values.

I'd say ok with the SREAL_MAX_EXP change reverted.



Hi.

You are right, this change was done because I used one bit for
m_negative
(bitfield), not needed any more.

Final version attached.

Thank you,
Martin


Thanks,
Richard.





Otherwise looks good to me and sorry for not noticing the above
earlier.

Thanks,
Richard.


Thanks,
Martin



  };

  extern void debug (sreal &ref);
@@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const
sreal
&b)

  inline sreal &operator-= (sreal &a, const sreal &b)
  {
-return a = a - b;
+  return a = a - b;
  }

  inline sreal &operator/= (sreal &a, const sreal &b)
  {
-return a = a / b;
+  return a = a / b;
  }

  inline sreal &operator*= (sreal &a, const sreal &b)
--
2.1.2










Hello.

After IRC discussions, I decided to give sreal another refactoring where
I
use int64_t for m_sig.

This approach looks much easier and straightforward. I would like to
ask folk for comments?



I think you want to exclude LONG_MIN (how do you know that LONG_MIN
is min(int64_t)?) as a valid value for m_sig - after all SREAL_MIN_SIG
makes it symmetric.  Or simply use abs_hwi at



Hello.

I decided to use abs_hwi.


That will ICE if you do

   sreal x (- __LONG_MAX__ - 1);

maybe that's the only case though.

  sreal::normalize ()
  {
+  int64_t s = m_sig < 0 ? -1 : 1;
+  HOST_WIDE_INT sig = abs_hwi (m_sig);
+
if (m_sig == 0)
...
  }
+
+  m_sig = s * sig;
  }

it's a bit awkward to strip the sign and then put it back on this way.  Also
now using a signed 'sig' where it was unsigned before.  And keeping
the first test using m_sig instead of sig.

I'd simply have used 'unsigned HOST_WIDE_INT sig = absu_hwi (m_sig);'
instead.

The rest of the patch is ok with the above change.

Thanks,
Richard.


Hello.

You are right that unsigned type would be more suitable.
I send final version that I plan to commit.

Thanks,
Martin






+  int64_t s = m_sig < 0 ? -1 : 1;
+  uint64_t sig = m_sig == LONG_MIN ? LONG_MAX : std::abs (m_sig);

-#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
-#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
+#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 2))
+#define SREAL_MAX_SIG (((uint64_t) 1 << (SREAL_PART_BITS - 1)) - 1)

shouldn't this also be -2 in the last line?



It's correct, in the first line, I s/'SREAL_PART_BITS - 1'/'SREAL_PART_BITS
- 2' and
second one is also decremented: s/'SREAL_PART_BITS'/'REAL_PART_BITS - 1'.



That is, you effectively use the MSB as a sign bit?



Yes. It uses signed integer with MSB as a sign bit.



Btw, a further change would be to make m_sig 'signed int', matching
the "real" storage requirements according to SREAL_PART_BITS.
This would of course still require temporaries used for computation
to be 64bits and it would require normalization to work on the
temporaries.  But then we'd get down to 8 bytes storage ...



Agree, we can shrink the size for future.

I've been running tests, I hope this implementation is much nicer than
having bool m_negative. What do you think about trunk acceptation?

Thanks,
Martin




Richard.



I am able to run profiled bootstrap on x86_64-linux-pc and ppc64-linux-pc
and new regression is introduced.

Tha

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-12-09 Thread Richard Biener
On Mon, Dec 8, 2014 at 5:52 PM, Martin Liška  wrote:
> On 11/28/2014 10:32 AM, Richard Biener wrote:
>>
>> On Thu, Nov 27, 2014 at 6:08 PM, Martin Liška  wrote:
>>>
>>> On 11/21/2014 04:21 PM, Martin Liška wrote:


 On 11/21/2014 04:02 PM, Richard Biener wrote:
>
>
> On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:
>
>> Hello.
>>
>> Ok, this is simplified, one can use sreal a = 12345 and it works ;)
>>
>>> that's a  new API, right?  There is no max () and I think that using
>>> LONG_MIN here is asking for trouble (host dependence).  The
>>> comment in the file says the max should be
>>> sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
>>> sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?
>>>
>>
>> Sure, sreal can store much bigger(smaller) numbers :)
>>
>>> Where do you need sreal::to_double?  The host shouldn't perform
>>> double calculations so it can be only for dumping?  In which case
>>> the user should have used sreal::dump (), maybe with extra
>>> arguments.
>>>
>>
>> That new function was request from Honza, only for debugging purpose.
>> I agree that dump should this kind of job.
>>
>> If no other problem, I will run tests once more and commit it.
>> Thanks,
>> Martin
>
>
>
> -#define SREAL_MAX_EXP (INT_MAX / 4)
> +#define SREAL_MAX_EXP (INT_MAX / 8)
>
> this change doesn't look necessary anymore?
>
> Btw, it's also odd that...
>
>#define SREAL_PART_BITS 32
> ...
>#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
>#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
>
> thus all m_sig values fit in 32bits but we still use a uint64_t m_sig
> ...
> (the implementation uses 64bit for internal computations, but still
> the storage is wasteful?)
>
> Of course the way normalize() works requires that storage to be
> 64bits to store unnormalized values.
>
> I'd say ok with the SREAL_MAX_EXP change reverted.
>

 Hi.

 You are right, this change was done because I used one bit for
 m_negative
 (bitfield), not needed any more.

 Final version attached.

 Thank you,
 Martin

> Thanks,
> Richard.
>
>
>>
>>> Otherwise looks good to me and sorry for not noticing the above
>>> earlier.
>>>
>>> Thanks,
>>> Richard.
>>>
 Thanks,
 Martin


>>  };
>>
>>  extern void debug (sreal &ref);
>> @@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const
>> sreal
>> &b)
>>
>>  inline sreal &operator-= (sreal &a, const sreal &b)
>>  {
>> -return a = a - b;
>> +  return a = a - b;
>>  }
>>
>>  inline sreal &operator/= (sreal &a, const sreal &b)
>>  {
>> -return a = a / b;
>> +  return a = a / b;
>>  }
>>
>>  inline sreal &operator*= (sreal &a, const sreal &b)
>> --
>> 2.1.2
>>
>>

>>

>>>
>>> Hello.
>>>
>>> After IRC discussions, I decided to give sreal another refactoring where
>>> I
>>> use int64_t for m_sig.
>>>
>>> This approach looks much easier and straightforward. I would like to
>>> ask folk for comments?
>>
>>
>> I think you want to exclude LONG_MIN (how do you know that LONG_MIN
>> is min(int64_t)?) as a valid value for m_sig - after all SREAL_MIN_SIG
>> makes it symmetric.  Or simply use abs_hwi at
>
>
> Hello.
>
> I decided to use abs_hwi.

That will ICE if you do

  sreal x (- __LONG_MAX__ - 1);

maybe that's the only case though.

 sreal::normalize ()
 {
+  int64_t s = m_sig < 0 ? -1 : 1;
+  HOST_WIDE_INT sig = abs_hwi (m_sig);
+
   if (m_sig == 0)
...
 }
+
+  m_sig = s * sig;
 }

it's a bit awkward to strip the sign and then put it back on this way.  Also
now using a signed 'sig' where it was unsigned before.  And keeping
the first test using m_sig instead of sig.

I'd simply have used 'unsigned HOST_WIDE_INT sig = absu_hwi (m_sig);'
instead.

The rest of the patch is ok with the above change.

Thanks,
Richard.


>>
>> +  int64_t s = m_sig < 0 ? -1 : 1;
>> +  uint64_t sig = m_sig == LONG_MIN ? LONG_MAX : std::abs (m_sig);
>>
>> -#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
>> -#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
>> +#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 2))
>> +#define SREAL_MAX_SIG (((uint64_t) 1 << (SREAL_PART_BITS - 1)) - 1)
>>
>> shouldn't this also be -2 in the last line?
>
>
> It's correct, in the first line, I s/'SREAL_PART_BITS - 1'/'SREAL_PART_BITS
> - 2' and
> second one is also decremented: s/'SREAL_PART_BITS'/'REAL_PART_BITS - 1'.
>
>>
>> That is, you effectively use the MSB as a sign bit?
>
>
> Yes. It uses signed inte

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-12-08 Thread Martin Liška

On 11/28/2014 10:32 AM, Richard Biener wrote:

On Thu, Nov 27, 2014 at 6:08 PM, Martin Liška  wrote:

On 11/21/2014 04:21 PM, Martin Liška wrote:


On 11/21/2014 04:02 PM, Richard Biener wrote:


On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:


Hello.

Ok, this is simplified, one can use sreal a = 12345 and it works ;)


that's a  new API, right?  There is no max () and I think that using
LONG_MIN here is asking for trouble (host dependence).  The
comment in the file says the max should be
sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?



Sure, sreal can store much bigger(smaller) numbers :)


Where do you need sreal::to_double?  The host shouldn't perform
double calculations so it can be only for dumping?  In which case
the user should have used sreal::dump (), maybe with extra
arguments.



That new function was request from Honza, only for debugging purpose.
I agree that dump should this kind of job.

If no other problem, I will run tests once more and commit it.
Thanks,
Martin



-#define SREAL_MAX_EXP (INT_MAX / 4)
+#define SREAL_MAX_EXP (INT_MAX / 8)

this change doesn't look necessary anymore?

Btw, it's also odd that...

   #define SREAL_PART_BITS 32
...
   #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
   #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)

thus all m_sig values fit in 32bits but we still use a uint64_t m_sig ...
(the implementation uses 64bit for internal computations, but still
the storage is wasteful?)

Of course the way normalize() works requires that storage to be
64bits to store unnormalized values.

I'd say ok with the SREAL_MAX_EXP change reverted.



Hi.

You are right, this change was done because I used one bit for m_negative
(bitfield), not needed any more.

Final version attached.

Thank you,
Martin


Thanks,
Richard.





Otherwise looks good to me and sorry for not noticing the above
earlier.

Thanks,
Richard.


Thanks,
Martin



 };

 extern void debug (sreal &ref);
@@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const sreal
&b)

 inline sreal &operator-= (sreal &a, const sreal &b)
 {
-return a = a - b;
+  return a = a - b;
 }

 inline sreal &operator/= (sreal &a, const sreal &b)
 {
-return a = a / b;
+  return a = a / b;
 }

 inline sreal &operator*= (sreal &a, const sreal &b)
--
2.1.2










Hello.

After IRC discussions, I decided to give sreal another refactoring where I
use int64_t for m_sig.

This approach looks much easier and straightforward. I would like to
ask folk for comments?


I think you want to exclude LONG_MIN (how do you know that LONG_MIN
is min(int64_t)?) as a valid value for m_sig - after all SREAL_MIN_SIG
makes it symmetric.  Or simply use abs_hwi at


Hello.

I decided to use abs_hwi.



+  int64_t s = m_sig < 0 ? -1 : 1;
+  uint64_t sig = m_sig == LONG_MIN ? LONG_MAX : std::abs (m_sig);

-#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
-#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
+#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 2))
+#define SREAL_MAX_SIG (((uint64_t) 1 << (SREAL_PART_BITS - 1)) - 1)

shouldn't this also be -2 in the last line?


It's correct, in the first line, I s/'SREAL_PART_BITS - 1'/'SREAL_PART_BITS - 
2' and
second one is also decremented: s/'SREAL_PART_BITS'/'REAL_PART_BITS - 1'.



That is, you effectively use the MSB as a sign bit?


Yes. It uses signed integer with MSB as a sign bit.



Btw, a further change would be to make m_sig 'signed int', matching
the "real" storage requirements according to SREAL_PART_BITS.
This would of course still require temporaries used for computation
to be 64bits and it would require normalization to work on the
temporaries.  But then we'd get down to 8 bytes storage ...


Agree, we can shrink the size for future.

I've been running tests, I hope this implementation is much nicer than
having bool m_negative. What do you think about trunk acceptation?

Thanks,
Martin



Richard.



I am able to run profiled bootstrap on x86_64-linux-pc and ppc64-linux-pc
and new regression is introduced.

Thanks,
Martin




>From c275c48eb5f0f41f546bb7866d70c1fe066d6d62 Mon Sep 17 00:00:00 2001
From: mliska 
Date: Wed, 26 Nov 2014 15:46:42 +0100
Subject: [PATCH] New sreal implementation which uses int64_t as m_sig.

gcc/ChangeLog:

2014-12-08  Martin Liska  

	* sreal.c (sreal::shift_right): New implementation
	for int64_t as m_sig.
	(sreal::normalize): Likewise.
	(sreal::to_int): Likewise.
	(sreal::operator+): Likewise.
	(sreal::operator-): Likewise.
	(sreal::operator*): Likewise.
	(sreal::operator/): Likewise.
	(sreal::signedless_minus): Removed.
	(sreal::signedless_plus): Removed.
	(sreal::debug): const keyword is added.
	* sreal.h (sreal::operator<): New implementation
	for int64_t as m_sig.
	* ipa-inline.c (recursive_inlining): LONG_MIN is replaced
	with sreal::min ().
---
 gcc/ipa-inline.c |   2 +-
 gcc/sreal.c  | 129 ++

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-28 Thread Richard Biener
On Thu, Nov 27, 2014 at 6:08 PM, Martin Liška  wrote:
> On 11/21/2014 04:21 PM, Martin Liška wrote:
>>
>> On 11/21/2014 04:02 PM, Richard Biener wrote:
>>>
>>> On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:
>>>
 Hello.

 Ok, this is simplified, one can use sreal a = 12345 and it works ;)

> that's a  new API, right?  There is no max () and I think that using
> LONG_MIN here is asking for trouble (host dependence).  The
> comment in the file says the max should be
> sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
> sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?
>

 Sure, sreal can store much bigger(smaller) numbers :)

> Where do you need sreal::to_double?  The host shouldn't perform
> double calculations so it can be only for dumping?  In which case
> the user should have used sreal::dump (), maybe with extra
> arguments.
>

 That new function was request from Honza, only for debugging purpose.
 I agree that dump should this kind of job.

 If no other problem, I will run tests once more and commit it.
 Thanks,
 Martin
>>>
>>>
>>> -#define SREAL_MAX_EXP (INT_MAX / 4)
>>> +#define SREAL_MAX_EXP (INT_MAX / 8)
>>>
>>> this change doesn't look necessary anymore?
>>>
>>> Btw, it's also odd that...
>>>
>>>   #define SREAL_PART_BITS 32
>>> ...
>>>   #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
>>>   #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
>>>
>>> thus all m_sig values fit in 32bits but we still use a uint64_t m_sig ...
>>> (the implementation uses 64bit for internal computations, but still
>>> the storage is wasteful?)
>>>
>>> Of course the way normalize() works requires that storage to be
>>> 64bits to store unnormalized values.
>>>
>>> I'd say ok with the SREAL_MAX_EXP change reverted.
>>>
>>
>> Hi.
>>
>> You are right, this change was done because I used one bit for m_negative
>> (bitfield), not needed any more.
>>
>> Final version attached.
>>
>> Thank you,
>> Martin
>>
>>> Thanks,
>>> Richard.
>>>
>>>

> Otherwise looks good to me and sorry for not noticing the above
> earlier.
>
> Thanks,
> Richard.
>
>> Thanks,
>> Martin
>>
>>
 };

 extern void debug (sreal &ref);
 @@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const sreal
 &b)

 inline sreal &operator-= (sreal &a, const sreal &b)
 {
 -return a = a - b;
 +  return a = a - b;
 }

 inline sreal &operator/= (sreal &a, const sreal &b)
 {
 -return a = a / b;
 +  return a = a / b;
 }

 inline sreal &operator*= (sreal &a, const sreal &b)
 --
 2.1.2


>>

>>
>
> Hello.
>
> After IRC discussions, I decided to give sreal another refactoring where I
> use int64_t for m_sig.
>
> This approach looks much easier and straightforward. I would like to
> ask folk for comments?

I think you want to exclude LONG_MIN (how do you know that LONG_MIN
is min(int64_t)?) as a valid value for m_sig - after all SREAL_MIN_SIG
makes it symmetric.  Or simply use abs_hwi at

+  int64_t s = m_sig < 0 ? -1 : 1;
+  uint64_t sig = m_sig == LONG_MIN ? LONG_MAX : std::abs (m_sig);

-#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
-#define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
+#define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 2))
+#define SREAL_MAX_SIG (((uint64_t) 1 << (SREAL_PART_BITS - 1)) - 1)

shouldn't this also be -2 in the last line?

That is, you effectively use the MSB as a sign bit?

Btw, a further change would be to make m_sig 'signed int', matching
the "real" storage requirements according to SREAL_PART_BITS.
This would of course still require temporaries used for computation
to be 64bits and it would require normalization to work on the
temporaries.  But then we'd get down to 8 bytes storage ...

Richard.


> I am able to run profiled bootstrap on x86_64-linux-pc and ppc64-linux-pc
> and new regression is introduced.
>
> Thanks,
> Martin
>
>


Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-27 Thread Martin Liška

On 11/21/2014 04:21 PM, Martin Liška wrote:

On 11/21/2014 04:02 PM, Richard Biener wrote:

On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:


Hello.

Ok, this is simplified, one can use sreal a = 12345 and it works ;)


that's a  new API, right?  There is no max () and I think that using
LONG_MIN here is asking for trouble (host dependence).  The
comment in the file says the max should be
sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?



Sure, sreal can store much bigger(smaller) numbers :)


Where do you need sreal::to_double?  The host shouldn't perform
double calculations so it can be only for dumping?  In which case
the user should have used sreal::dump (), maybe with extra
arguments.



That new function was request from Honza, only for debugging purpose.
I agree that dump should this kind of job.

If no other problem, I will run tests once more and commit it.
Thanks,
Martin


-#define SREAL_MAX_EXP (INT_MAX / 4)
+#define SREAL_MAX_EXP (INT_MAX / 8)

this change doesn't look necessary anymore?

Btw, it's also odd that...

  #define SREAL_PART_BITS 32
...
  #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
  #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)

thus all m_sig values fit in 32bits but we still use a uint64_t m_sig ...
(the implementation uses 64bit for internal computations, but still
the storage is wasteful?)

Of course the way normalize() works requires that storage to be
64bits to store unnormalized values.

I'd say ok with the SREAL_MAX_EXP change reverted.



Hi.

You are right, this change was done because I used one bit for m_negative 
(bitfield), not needed any more.

Final version attached.

Thank you,
Martin


Thanks,
Richard.





Otherwise looks good to me and sorry for not noticing the above
earlier.

Thanks,
Richard.


Thanks,
Martin



};

extern void debug (sreal &ref);
@@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const sreal
&b)

inline sreal &operator-= (sreal &a, const sreal &b)
{
-return a = a - b;
+  return a = a - b;
}

inline sreal &operator/= (sreal &a, const sreal &b)
{
-return a = a / b;
+  return a = a / b;
}

inline sreal &operator*= (sreal &a, const sreal &b)
--
2.1.2










Hello.

After IRC discussions, I decided to give sreal another refactoring where I
use int64_t for m_sig.

This approach looks much easier and straightforward. I would like to
ask folk for comments?

I am able to run profiled bootstrap on x86_64-linux-pc and ppc64-linux-pc
and new regression is introduced.

Thanks,
Martin


>From bff0b4b803271788cd90cfd4032ed6d4e6e95707 Mon Sep 17 00:00:00 2001
From: mliska 
Date: Wed, 26 Nov 2014 15:46:42 +0100
Subject: [PATCH] New sreal implementation which uses int64_t as m_sig.

gcc/ChangeLog:

2014-11-27  Martin Liska  

	* sreal.c (sreal::shift_right): New implementation
	for int64_t as m_sig.
	(sreal::normalize): Likewise.
	(sreal::to_int): Likewise.
	(sreal::operator+): Likewise.
	(sreal::operator-): Likewise.
	(sreal::operator*): Likewise.
	(sreal::operator/): Likewise.
	(sreal::signedless_minus): Removed.
	(sreal::signedless_plus): Removed.
	* sreal.h (sreal::operator<): New implementation
	for int64_t as m_sig.
---
 gcc/sreal.c | 129 +++-
 gcc/sreal.h |  52 ++--
 2 files changed, 61 insertions(+), 120 deletions(-)

diff --git a/gcc/sreal.c b/gcc/sreal.c
index 2b5e3ae..304feb0 100644
--- a/gcc/sreal.c
+++ b/gcc/sreal.c
@@ -91,7 +91,7 @@ sreal::shift_right (int s)
 
   m_exp += s;
 
-  m_sig += (uint64_t) 1 << (s - 1);
+  m_sig += (int64_t) 1 << (s - 1);
   m_sig >>= s;
 }
 
@@ -100,43 +100,46 @@ sreal::shift_right (int s)
 void
 sreal::normalize ()
 {
+  int64_t s = m_sig < 0 ? -1 : 1;
+  uint64_t sig = m_sig == LONG_MIN ? LONG_MAX : std::abs (m_sig);
+
   if (m_sig == 0)
 {
-  m_negative = 0;
   m_exp = -SREAL_MAX_EXP;
 }
-  else if (m_sig < SREAL_MIN_SIG)
+  else if (sig < SREAL_MIN_SIG)
 {
   do
 	{
-	  m_sig <<= 1;
+	  sig <<= 1;
 	  m_exp--;
+	  gcc_checking_assert (sig);
 	}
-  while (m_sig < SREAL_MIN_SIG);
+  while (sig < SREAL_MIN_SIG);
 
   /* Check underflow.  */
   if (m_exp < -SREAL_MAX_EXP)
 	{
 	  m_exp = -SREAL_MAX_EXP;
-	  m_sig = 0;
+	  sig = 0;
 	}
 }
-  else if (m_sig > SREAL_MAX_SIG)
+  else if (sig > SREAL_MAX_SIG)
 {
   int last_bit;
   do
 	{
-	  last_bit = m_sig & 1;
-	  m_sig >>= 1;
+	  last_bit = sig & 1;
+	  sig >>= 1;
 	  m_exp++;
 	}
-  while (m_sig > SREAL_MAX_SIG);
+  while (sig > SREAL_MAX_SIG);
 
   /* Round the number.  */
-  m_sig += last_bit;
-  if (m_sig > SREAL_MAX_SIG)
+  sig += last_bit;
+  if (sig > SREAL_MAX_SIG)
 	{
-	  m_sig >>= 1;
+	  sig >>= 1;
 	  m_exp++;
 	}
 
@@ -144,9 +147,11 @@ sreal::normalize ()
   if (m_exp > SREAL_MAX_EXP)
 	{
 	  m_exp = SREAL_MAX_EXP;
-	  m_sig = SREAL_MAX_SIG;
+	  sig = SREAL_MAX_SIG;
 	}
 

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-21 Thread Martin Liška

On 11/21/2014 04:02 PM, Richard Biener wrote:

On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:


Hello.

Ok, this is simplified, one can use sreal a = 12345 and it works ;)


that's a  new API, right?  There is no max () and I think that using
LONG_MIN here is asking for trouble (host dependence).  The
comment in the file says the max should be
sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?



Sure, sreal can store much bigger(smaller) numbers :)


Where do you need sreal::to_double?  The host shouldn't perform
double calculations so it can be only for dumping?  In which case
the user should have used sreal::dump (), maybe with extra
arguments.



That new function was request from Honza, only for debugging purpose.
I agree that dump should this kind of job.

If no other problem, I will run tests once more and commit it.
Thanks,
Martin


-#define SREAL_MAX_EXP (INT_MAX / 4)
+#define SREAL_MAX_EXP (INT_MAX / 8)

this change doesn't look necessary anymore?

Btw, it's also odd that...

  #define SREAL_PART_BITS 32
...
  #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
  #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)

thus all m_sig values fit in 32bits but we still use a uint64_t m_sig ...
(the implementation uses 64bit for internal computations, but still
the storage is wasteful?)

Of course the way normalize() works requires that storage to be
64bits to store unnormalized values.

I'd say ok with the SREAL_MAX_EXP change reverted.



Hi.

You are right, this change was done because I used one bit for 
m_negative (bitfield), not needed any more.


Final version attached.

Thank you,
Martin


Thanks,
Richard.





Otherwise looks good to me and sorry for not noticing the above
earlier.

Thanks,
Richard.


Thanks,
Martin



};

extern void debug (sreal &ref);
@@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const sreal
&b)

inline sreal &operator-= (sreal &a, const sreal &b)
{
-return a = a - b;
+  return a = a - b;
}

inline sreal &operator/= (sreal &a, const sreal &b)
{
-return a = a / b;
+  return a = a / b;
}

inline sreal &operator*= (sreal &a, const sreal &b)
--
2.1.2








>From b28e4264b5f9965ca5ab4f52ce6f4c9df00d4800 Mon Sep 17 00:00:00 2001
From: mliska 
Date: Fri, 21 Nov 2014 12:07:40 +0100
Subject: [PATCH 1/2] Negative numbers added for sreal class.

gcc/ChangeLog:

2014-11-13  Martin Liska  

	* predict.c (propagate_freq): More elegant sreal API is used.
	(estimate_bb_frequencies): Precomputed constants replaced by integer
	constants.
	* sreal.c (sreal::normalize): New function.
	(sreal::to_int): Likewise.
	(sreal::operator+): Likewise.
	(sreal::operator-): Likewise.
	* sreal.h: Definition of new functions added.
---
 gcc/predict.c |  30 
 gcc/sreal.c   | 114 --
 gcc/sreal.h   |  82 +-
 3 files changed, 174 insertions(+), 52 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 779af11..0cfe4a9 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
 		   1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
-static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
+static sreal real_almost_one, real_br_prob_base,
 	 real_inv_br_prob_base, real_one_half, real_bb_freq_max;
 
 static void combine_predictions_for_insn (rtx_insn *, basic_block);
@@ -2541,13 +2541,13 @@ propagate_freq (basic_block head, bitmap tovisit)
 	bb->count = bb->frequency = 0;
 }
 
-  BLOCK_INFO (head)->frequency = real_one;
+  BLOCK_INFO (head)->frequency = 1;
   last = head;
   for (bb = head; bb; bb = nextbb)
 {
   edge_iterator ei;
-  sreal cyclic_probability = real_zero;
-  sreal frequency = real_zero;
+  sreal cyclic_probability = 0;
+  sreal frequency = 0;
 
   nextbb = BLOCK_INFO (bb)->next;
   BLOCK_INFO (bb)->next = NULL;
@@ -2572,13 +2572,13 @@ propagate_freq (basic_block head, bitmap tovisit)
   * BLOCK_INFO (e->src)->frequency /
   REG_BR_PROB_BASE);  */
 
-		sreal tmp (e->probability, 0);
+		sreal tmp = e->probability;
 		tmp *= BLOCK_INFO (e->src)->frequency;
 		tmp *= real_inv_br_prob_base;
 		frequency += tmp;
 	  }
 
-	  if (cyclic_probability == real_zero)
+	  if (cyclic_probability == 0)
 	{
 	  BLOCK_INFO (bb)->frequency = frequency;
 	}
@@ -2590,7 +2590,7 @@ propagate_freq (basic_block head, bitmap tovisit)
 	  /* BLOCK_INFO (bb)->frequency = frequency
 	  / (1 - cyclic_probability) */
 
-	  cyclic_probability = real_one - cyclic_probability;
+	  cyclic_probability = sreal (1) - cyclic_probability;
 	  BLOCK_INFO (bb)->frequency = frequency / cyclic_probability;
 	}
 	}
@@ -2604,7 +2604,7 @@ propagate_freq (basic_block head, bitmap tovisit)
 	 = (

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-21 Thread Richard Biener
On Fri, Nov 21, 2014 at 3:39 PM, Martin Liška  wrote:

> Hello.
>
> Ok, this is simplified, one can use sreal a = 12345 and it works ;)
>
>> that's a  new API, right?  There is no max () and I think that using
>> LONG_MIN here is asking for trouble (host dependence).  The
>> comment in the file says the max should be
>> sreal (SREAL_MAX_SIG, SREAL_MAX_EXP) and the min
>> sreal (-SREAL_MAX_SIG, SREAL_MAX_EXP)?
>>
>
> Sure, sreal can store much bigger(smaller) numbers :)
>
>> Where do you need sreal::to_double?  The host shouldn't perform
>> double calculations so it can be only for dumping?  In which case
>> the user should have used sreal::dump (), maybe with extra
>> arguments.
>>
>
> That new function was request from Honza, only for debugging purpose.
> I agree that dump should this kind of job.
>
> If no other problem, I will run tests once more and commit it.
> Thanks,
> Martin

-#define SREAL_MAX_EXP (INT_MAX / 4)
+#define SREAL_MAX_EXP (INT_MAX / 8)

this change doesn't look necessary anymore?

Btw, it's also odd that...

 #define SREAL_PART_BITS 32
...
 #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
 #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)

thus all m_sig values fit in 32bits but we still use a uint64_t m_sig ...
(the implementation uses 64bit for internal computations, but still
the storage is wasteful?)

Of course the way normalize() works requires that storage to be
64bits to store unnormalized values.

I'd say ok with the SREAL_MAX_EXP change reverted.

Thanks,
Richard.


>
>> Otherwise looks good to me and sorry for not noticing the above
>> earlier.
>>
>> Thanks,
>> Richard.
>>
>>> Thanks,
>>> Martin
>>>
>>>
>};
>
>extern void debug (sreal &ref);
> @@ -76,12 +133,12 @@ inline sreal &operator+= (sreal &a, const sreal
> &b)
>
>inline sreal &operator-= (sreal &a, const sreal &b)
>{
> -return a = a - b;
> +  return a = a - b;
>}
>
>inline sreal &operator/= (sreal &a, const sreal &b)
>{
> -return a = a / b;
> +  return a = a / b;
>}
>
>inline sreal &operator*= (sreal &a, const sreal &b)
> --
> 2.1.2
>
>
>>>
>


Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-21 Thread Martin Liška

On 11/21/2014 01:03 PM, Richard Biener wrote:

On Fri, Nov 21, 2014 at 12:21 PM, Martin Liška  wrote:

On 11/14/2014 11:48 AM, Richard Biener wrote:


On Thu, Nov 13, 2014 at 1:35 PM, mliska  wrote:


gcc/ChangeLog:

2014-11-13  Martin Liska  

  * predict.c (propagate_freq): More elegant sreal API is used.
  (estimate_bb_frequencies): New static constants defined by sreal
  replace precomputed ones.
  * sreal.c (sreal::normalize): New function.
  (sreal::to_int): Likewise.
  (sreal::operator+): Likewise.
  (sreal::operator-): Likewise.
  * sreal.h: Definition of new functions added.



Please use gcc_checking_assert()s everywhere.  sreal is supposed
to be fast... (I see it has current uses of gcc_assert - you may want
to mass-convert them as a followup).


---
   gcc/predict.c | 30 +++-
   gcc/sreal.c   | 56 
   gcc/sreal.h   | 75
---
   3 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 0215e91..0f640f5 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see

   /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
 1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
-static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
+static sreal real_almost_one, real_br_prob_base,
   real_inv_br_prob_base, real_one_half, real_bb_freq_max;

   static void combine_predictions_for_insn (rtx_insn *, basic_block);
@@ -2528,13 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
  bb->count = bb->frequency = 0;
   }

-  BLOCK_INFO (head)->frequency = real_one;
+  BLOCK_INFO (head)->frequency = sreal::one ();
 last = head;
 for (bb = head; bb; bb = nextbb)
   {
 edge_iterator ei;
-  sreal cyclic_probability = real_zero;
-  sreal frequency = real_zero;
+  sreal cyclic_probability = sreal::zero ();
+  sreal frequency = sreal::zero ();

 nextbb = BLOCK_INFO (bb)->next;
 BLOCK_INFO (bb)->next = NULL;
@@ -2559,13 +2559,13 @@ propagate_freq (basic_block head, bitmap tovisit)
* BLOCK_INFO (e->src)->frequency /
REG_BR_PROB_BASE);  */

-   sreal tmp (e->probability, 0);
+   sreal tmp = e->probability;
  tmp *= BLOCK_INFO (e->src)->frequency;
  tmp *= real_inv_br_prob_base;
  frequency += tmp;
}

- if (cyclic_probability == real_zero)
+ if (cyclic_probability == sreal::zero ())
  {
BLOCK_INFO (bb)->frequency = frequency;
  }
@@ -2577,7 +2577,7 @@ propagate_freq (basic_block head, bitmap tovisit)
/* BLOCK_INFO (bb)->frequency = frequency
/ (1 - cyclic_probability)
*/

- cyclic_probability = real_one - cyclic_probability;
+ cyclic_probability = sreal::one () - cyclic_probability;
BLOCK_INFO (bb)->frequency = frequency /
cyclic_probability;
  }
  }
@@ -2591,7 +2591,7 @@ propagate_freq (basic_block head, bitmap tovisit)
   = ((e->probability * BLOCK_INFO (bb)->frequency)
   / REG_BR_PROB_BASE); */

- sreal tmp (e->probability, 0);
+ sreal tmp = e->probability;
tmp *= BLOCK_INFO (bb)->frequency;
EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
  }
@@ -2873,13 +2873,11 @@ estimate_bb_frequencies (bool force)
 if (!real_values_initialized)
   {
real_values_initialized = 1;
- real_zero = sreal (0, 0);
- real_one = sreal (1, 0);
- real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
- real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
+ real_br_prob_base = REG_BR_PROB_BASE;
+ real_bb_freq_max = BB_FREQ_MAX;
real_one_half = sreal (1, -1);
- real_inv_br_prob_base = real_one / real_br_prob_base;
- real_almost_one = real_one - real_inv_br_prob_base;
+ real_inv_br_prob_base = sreal::one () / real_br_prob_base;
+ real_almost_one = sreal::one () - real_inv_br_prob_base;
  }

 mark_dfs_back_edges ();
@@ -2897,7 +2895,7 @@ estimate_bb_frequencies (bool force)

FOR_EACH_EDGE (e, ei, bb->succs)
  {
- EDGE_INFO (e)->back_edge_prob = sreal (e->probability, 0);
+ EDGE_INFO (e)->back_edge_prob = e->probability;
EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;
  }
  }
@@ -2906,7 +2904,7 @@ estimate_bb_frequencies (bool force)
to outermost to examine frequencies for back edges.  */
 estimate_loops ();

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-21 Thread Richard Biener
On Fri, Nov 21, 2014 at 12:21 PM, Martin Liška  wrote:
> On 11/14/2014 11:48 AM, Richard Biener wrote:
>>
>> On Thu, Nov 13, 2014 at 1:35 PM, mliska  wrote:
>>>
>>> gcc/ChangeLog:
>>>
>>> 2014-11-13  Martin Liska  
>>>
>>>  * predict.c (propagate_freq): More elegant sreal API is used.
>>>  (estimate_bb_frequencies): New static constants defined by sreal
>>>  replace precomputed ones.
>>>  * sreal.c (sreal::normalize): New function.
>>>  (sreal::to_int): Likewise.
>>>  (sreal::operator+): Likewise.
>>>  (sreal::operator-): Likewise.
>>>  * sreal.h: Definition of new functions added.
>>
>>
>> Please use gcc_checking_assert()s everywhere.  sreal is supposed
>> to be fast... (I see it has current uses of gcc_assert - you may want
>> to mass-convert them as a followup).
>>
>>> ---
>>>   gcc/predict.c | 30 +++-
>>>   gcc/sreal.c   | 56 
>>>   gcc/sreal.h   | 75
>>> ---
>>>   3 files changed, 126 insertions(+), 35 deletions(-)
>>>
>>> diff --git a/gcc/predict.c b/gcc/predict.c
>>> index 0215e91..0f640f5 100644
>>> --- a/gcc/predict.c
>>> +++ b/gcc/predict.c
>>> @@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see
>>>
>>>   /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
>>> 1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
>>> -static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
>>> +static sreal real_almost_one, real_br_prob_base,
>>>   real_inv_br_prob_base, real_one_half, real_bb_freq_max;
>>>
>>>   static void combine_predictions_for_insn (rtx_insn *, basic_block);
>>> @@ -2528,13 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
>>>  bb->count = bb->frequency = 0;
>>>   }
>>>
>>> -  BLOCK_INFO (head)->frequency = real_one;
>>> +  BLOCK_INFO (head)->frequency = sreal::one ();
>>> last = head;
>>> for (bb = head; bb; bb = nextbb)
>>>   {
>>> edge_iterator ei;
>>> -  sreal cyclic_probability = real_zero;
>>> -  sreal frequency = real_zero;
>>> +  sreal cyclic_probability = sreal::zero ();
>>> +  sreal frequency = sreal::zero ();
>>>
>>> nextbb = BLOCK_INFO (bb)->next;
>>> BLOCK_INFO (bb)->next = NULL;
>>> @@ -2559,13 +2559,13 @@ propagate_freq (basic_block head, bitmap tovisit)
>>>* BLOCK_INFO (e->src)->frequency /
>>>REG_BR_PROB_BASE);  */
>>>
>>> -   sreal tmp (e->probability, 0);
>>> +   sreal tmp = e->probability;
>>>  tmp *= BLOCK_INFO (e->src)->frequency;
>>>  tmp *= real_inv_br_prob_base;
>>>  frequency += tmp;
>>>}
>>>
>>> - if (cyclic_probability == real_zero)
>>> + if (cyclic_probability == sreal::zero ())
>>>  {
>>>BLOCK_INFO (bb)->frequency = frequency;
>>>  }
>>> @@ -2577,7 +2577,7 @@ propagate_freq (basic_block head, bitmap tovisit)
>>>/* BLOCK_INFO (bb)->frequency = frequency
>>>/ (1 - cyclic_probability)
>>> */
>>>
>>> - cyclic_probability = real_one - cyclic_probability;
>>> + cyclic_probability = sreal::one () - cyclic_probability;
>>>BLOCK_INFO (bb)->frequency = frequency /
>>> cyclic_probability;
>>>  }
>>>  }
>>> @@ -2591,7 +2591,7 @@ propagate_freq (basic_block head, bitmap tovisit)
>>>   = ((e->probability * BLOCK_INFO (bb)->frequency)
>>>   / REG_BR_PROB_BASE); */
>>>
>>> - sreal tmp (e->probability, 0);
>>> + sreal tmp = e->probability;
>>>tmp *= BLOCK_INFO (bb)->frequency;
>>>EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
>>>  }
>>> @@ -2873,13 +2873,11 @@ estimate_bb_frequencies (bool force)
>>> if (!real_values_initialized)
>>>   {
>>>real_values_initialized = 1;
>>> - real_zero = sreal (0, 0);
>>> - real_one = sreal (1, 0);
>>> - real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
>>> - real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
>>> + real_br_prob_base = REG_BR_PROB_BASE;
>>> + real_bb_freq_max = BB_FREQ_MAX;
>>>real_one_half = sreal (1, -1);
>>> - real_inv_br_prob_base = real_one / real_br_prob_base;
>>> - real_almost_one = real_one - real_inv_br_prob_base;
>>> + real_inv_br_prob_base = sreal::one () / real_br_prob_base;
>>> + real_almost_one = sreal::one () - real_inv_br_prob_base;
>>>  }
>>>
>>> mark_dfs_back_edges ();
>>> @@ -2897,7 +2895,7 @@ estimate_bb_frequencies (bool force)
>>>
>>>FOR_EACH_EDGE (e, ei, bb->succs)
>>>  {
>>> - EDGE_INFO (e)->back_edge_prob = sre

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-21 Thread Martin Liška

On 11/14/2014 11:48 AM, Richard Biener wrote:

On Thu, Nov 13, 2014 at 1:35 PM, mliska  wrote:

gcc/ChangeLog:

2014-11-13  Martin Liska  

 * predict.c (propagate_freq): More elegant sreal API is used.
 (estimate_bb_frequencies): New static constants defined by sreal
 replace precomputed ones.
 * sreal.c (sreal::normalize): New function.
 (sreal::to_int): Likewise.
 (sreal::operator+): Likewise.
 (sreal::operator-): Likewise.
 * sreal.h: Definition of new functions added.


Please use gcc_checking_assert()s everywhere.  sreal is supposed
to be fast... (I see it has current uses of gcc_assert - you may want
to mass-convert them as a followup).


---
  gcc/predict.c | 30 +++-
  gcc/sreal.c   | 56 
  gcc/sreal.h   | 75 ---
  3 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 0215e91..0f640f5 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see

  /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
-static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
+static sreal real_almost_one, real_br_prob_base,
  real_inv_br_prob_base, real_one_half, real_bb_freq_max;

  static void combine_predictions_for_insn (rtx_insn *, basic_block);
@@ -2528,13 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
 bb->count = bb->frequency = 0;
  }

-  BLOCK_INFO (head)->frequency = real_one;
+  BLOCK_INFO (head)->frequency = sreal::one ();
last = head;
for (bb = head; bb; bb = nextbb)
  {
edge_iterator ei;
-  sreal cyclic_probability = real_zero;
-  sreal frequency = real_zero;
+  sreal cyclic_probability = sreal::zero ();
+  sreal frequency = sreal::zero ();

nextbb = BLOCK_INFO (bb)->next;
BLOCK_INFO (bb)->next = NULL;
@@ -2559,13 +2559,13 @@ propagate_freq (basic_block head, bitmap tovisit)
   * BLOCK_INFO (e->src)->frequency /
   REG_BR_PROB_BASE);  */

-   sreal tmp (e->probability, 0);
+   sreal tmp = e->probability;
 tmp *= BLOCK_INFO (e->src)->frequency;
 tmp *= real_inv_br_prob_base;
 frequency += tmp;
   }

- if (cyclic_probability == real_zero)
+ if (cyclic_probability == sreal::zero ())
 {
   BLOCK_INFO (bb)->frequency = frequency;
 }
@@ -2577,7 +2577,7 @@ propagate_freq (basic_block head, bitmap tovisit)
   /* BLOCK_INFO (bb)->frequency = frequency
   / (1 - cyclic_probability) */

- cyclic_probability = real_one - cyclic_probability;
+ cyclic_probability = sreal::one () - cyclic_probability;
   BLOCK_INFO (bb)->frequency = frequency / cyclic_probability;
 }
 }
@@ -2591,7 +2591,7 @@ propagate_freq (basic_block head, bitmap tovisit)
  = ((e->probability * BLOCK_INFO (bb)->frequency)
  / REG_BR_PROB_BASE); */

- sreal tmp (e->probability, 0);
+ sreal tmp = e->probability;
   tmp *= BLOCK_INFO (bb)->frequency;
   EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
 }
@@ -2873,13 +2873,11 @@ estimate_bb_frequencies (bool force)
if (!real_values_initialized)
  {
   real_values_initialized = 1;
- real_zero = sreal (0, 0);
- real_one = sreal (1, 0);
- real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
- real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
+ real_br_prob_base = REG_BR_PROB_BASE;
+ real_bb_freq_max = BB_FREQ_MAX;
   real_one_half = sreal (1, -1);
- real_inv_br_prob_base = real_one / real_br_prob_base;
- real_almost_one = real_one - real_inv_br_prob_base;
+ real_inv_br_prob_base = sreal::one () / real_br_prob_base;
+ real_almost_one = sreal::one () - real_inv_br_prob_base;
 }

mark_dfs_back_edges ();
@@ -2897,7 +2895,7 @@ estimate_bb_frequencies (bool force)

   FOR_EACH_EDGE (e, ei, bb->succs)
 {
- EDGE_INFO (e)->back_edge_prob = sreal (e->probability, 0);
+ EDGE_INFO (e)->back_edge_prob = e->probability;
   EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;
 }
 }
@@ -2906,7 +2904,7 @@ estimate_bb_frequencies (bool force)
   to outermost to examine frequencies for back edges.  */
estimate_loops ();

-  freq_max = real_zero;
+  freq_max = sreal::zero ();
FOR_EACH_BB_FN (bb, cfun)
 if (freq_max < BLOCK_INFO (bb)->frequency)
   

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-14 Thread Richard Biener
On Thu, Nov 13, 2014 at 1:35 PM, mliska  wrote:
> gcc/ChangeLog:
>
> 2014-11-13  Martin Liska  
>
> * predict.c (propagate_freq): More elegant sreal API is used.
> (estimate_bb_frequencies): New static constants defined by sreal
> replace precomputed ones.
> * sreal.c (sreal::normalize): New function.
> (sreal::to_int): Likewise.
> (sreal::operator+): Likewise.
> (sreal::operator-): Likewise.
> * sreal.h: Definition of new functions added.

Please use gcc_checking_assert()s everywhere.  sreal is supposed
to be fast... (I see it has current uses of gcc_assert - you may want
to mass-convert them as a followup).

> ---
>  gcc/predict.c | 30 +++-
>  gcc/sreal.c   | 56 
>  gcc/sreal.h   | 75 
> ---
>  3 files changed, 126 insertions(+), 35 deletions(-)
>
> diff --git a/gcc/predict.c b/gcc/predict.c
> index 0215e91..0f640f5 100644
> --- a/gcc/predict.c
> +++ b/gcc/predict.c
> @@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see
>
>  /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
>1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
> -static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
> +static sreal real_almost_one, real_br_prob_base,
>  real_inv_br_prob_base, real_one_half, real_bb_freq_max;
>
>  static void combine_predictions_for_insn (rtx_insn *, basic_block);
> @@ -2528,13 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
> bb->count = bb->frequency = 0;
>  }
>
> -  BLOCK_INFO (head)->frequency = real_one;
> +  BLOCK_INFO (head)->frequency = sreal::one ();
>last = head;
>for (bb = head; bb; bb = nextbb)
>  {
>edge_iterator ei;
> -  sreal cyclic_probability = real_zero;
> -  sreal frequency = real_zero;
> +  sreal cyclic_probability = sreal::zero ();
> +  sreal frequency = sreal::zero ();
>
>nextbb = BLOCK_INFO (bb)->next;
>BLOCK_INFO (bb)->next = NULL;
> @@ -2559,13 +2559,13 @@ propagate_freq (basic_block head, bitmap tovisit)
>   * BLOCK_INFO (e->src)->frequency /
>   REG_BR_PROB_BASE);  */
>
> -   sreal tmp (e->probability, 0);
> +   sreal tmp = e->probability;
> tmp *= BLOCK_INFO (e->src)->frequency;
> tmp *= real_inv_br_prob_base;
> frequency += tmp;
>   }
>
> - if (cyclic_probability == real_zero)
> + if (cyclic_probability == sreal::zero ())
> {
>   BLOCK_INFO (bb)->frequency = frequency;
> }
> @@ -2577,7 +2577,7 @@ propagate_freq (basic_block head, bitmap tovisit)
>   /* BLOCK_INFO (bb)->frequency = frequency
>   / (1 - cyclic_probability) */
>
> - cyclic_probability = real_one - cyclic_probability;
> + cyclic_probability = sreal::one () - cyclic_probability;
>   BLOCK_INFO (bb)->frequency = frequency / cyclic_probability;
> }
> }
> @@ -2591,7 +2591,7 @@ propagate_freq (basic_block head, bitmap tovisit)
>  = ((e->probability * BLOCK_INFO (bb)->frequency)
>  / REG_BR_PROB_BASE); */
>
> - sreal tmp (e->probability, 0);
> + sreal tmp = e->probability;
>   tmp *= BLOCK_INFO (bb)->frequency;
>   EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
> }
> @@ -2873,13 +2873,11 @@ estimate_bb_frequencies (bool force)
>if (!real_values_initialized)
>  {
>   real_values_initialized = 1;
> - real_zero = sreal (0, 0);
> - real_one = sreal (1, 0);
> - real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
> - real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
> + real_br_prob_base = REG_BR_PROB_BASE;
> + real_bb_freq_max = BB_FREQ_MAX;
>   real_one_half = sreal (1, -1);
> - real_inv_br_prob_base = real_one / real_br_prob_base;
> - real_almost_one = real_one - real_inv_br_prob_base;
> + real_inv_br_prob_base = sreal::one () / real_br_prob_base;
> + real_almost_one = sreal::one () - real_inv_br_prob_base;
> }
>
>mark_dfs_back_edges ();
> @@ -2897,7 +2895,7 @@ estimate_bb_frequencies (bool force)
>
>   FOR_EACH_EDGE (e, ei, bb->succs)
> {
> - EDGE_INFO (e)->back_edge_prob = sreal (e->probability, 0);
> + EDGE_INFO (e)->back_edge_prob = e->probability;
>   EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;
> }
> }
> @@ -2906,7 +2904,7 @@ estimate_bb_frequencies (bool force)
>   to outermost to examine frequencies for back edges.  */
>estimate_loops ();
>
> -  freq_max = real_zero;
> +  freq_max = s

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-13 Thread Trevor Saunders
On Fri, Nov 14, 2014 at 12:40:23AM +0100, Jan Hubicka wrote:
> Hello,
> in general I like this addition - I was not aware that sreal has no support 
> for negative values.
> This would be serious maintainance burden if sreals was used for profile 
> updating - it is very
> easy to get negative temporaries while dong the updates.
> > gcc/ChangeLog:
> > 
> > 2014-11-13  Martin Liska  
> > 
> > * predict.c (propagate_freq): More elegant sreal API is used.
> > (estimate_bb_frequencies): New static constants defined by sreal
> > replace precomputed ones.
> > * sreal.c (sreal::normalize): New function.
> > (sreal::to_int): Likewise.
> > (sreal::operator+): Likewise.
> > (sreal::operator-): Likewise.
> > * sreal.h: Definition of new functions added.
> > diff --git a/gcc/sreal.c b/gcc/sreal.c
> > index 3f5456a..89b9c4d 100644
> > --- a/gcc/sreal.c
> > +++ b/gcc/sreal.c
> > @@ -1,4 +1,4 @@
> > -/* Simple data type for positive real numbers for the GNU compiler.
> > +/* Simple data type for real numbers for the GNU compiler.
> > Copyright (C) 2002-2014 Free Software Foundation, Inc.
> >  
> >  This file is part of GCC.
> > @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public 
> > License
> >  along with GCC; see the file COPYING3.  If not see
> >  .  */
> >  
> > -/* This library supports positive real numbers and 0;
> > +/* This library supports real numbers;
> > inf and nan are NOT supported.
> > It is written to be simple and fast.
> >  
> > @@ -102,6 +102,7 @@ sreal::normalize ()
> >  {
> >if (m_sig == 0)
> >  {
> > +  m_negative = 0;
> >m_exp = -SREAL_MAX_EXP;
> >  }
> >else if (m_sig < SREAL_MIN_SIG)
> > @@ -153,15 +154,17 @@ sreal::normalize ()
> >  int64_t
> >  sreal::to_int () const
> >  {
> > +  int64_t sign = m_negative ? -1 : 1;
> > +
> >if (m_exp <= -SREAL_BITS)
> >  return 0;
> >if (m_exp >= SREAL_PART_BITS)
> > -return INTTYPE_MAXIMUM (int64_t);
> > +return sign * INTTYPE_MAXIMUM (int64_t);
> >if (m_exp > 0)
> > -return m_sig << m_exp;
> > +return sign * (m_sig << m_exp);
> >if (m_exp < 0)
> > -return m_sig >> -m_exp;
> > -  return m_sig;
> > +return sign * (m_sig >> -m_exp);
> > +  return sign * m_sig;
> >  }
> >  
> >  /* Return *this + other.  */
> > @@ -169,9 +172,19 @@ sreal::to_int () const
> >  sreal
> >  sreal::operator+ (const sreal &other) const
> >  {
> > +  const sreal *a_p = this, *b_p = &other, *bb;
> > +
> > +  if (m_negative && !other.m_negative)
> > +return other + *a_p;
> > +
> > +  if (!m_negative && other.m_negative)
> > +return *a_p - -other;
> > +
> > +  gcc_assert (m_negative == other.m_negative);
> 
> I wonder what kind of code this winds into - you need recursive inlining to 
> fix
> this and it won't be clear to inliner that the recursion depth is 1.  Perhaps

maybe tail recurse optimizer is smart enough to see it can use a jump,
and then it might not be too bad.

> having an inline private function for signedless + and - and implementing real
> operators by this would factor the code better.
> 
> I wonder if there is not a faster implementation given that this code is on
> way to internal loops of inliner.  If significand was signed, some of these 
> operations
> would just work, right?

I believe so, but I haven't actually proved it to myself (I also
suggested going this route).

I'll try and look in this in more depth, but so many things to do and a
bunch of my time the next few days will be at family events.

Trev

> > diff --git a/gcc/sreal.h b/gcc/sreal.h
> > index 461e28b..bfed3c7 100644
> > --- a/gcc/sreal.h
> > +++ b/gcc/sreal.h
> > @@ -1,4 +1,4 @@
> > -/* Definitions for simple data type for positive real numbers.
> > +/* Definitions for simple data type for real numbers.
> > Copyright (C) 2002-2014 Free Software Foundation, Inc.
> >  
> >  This file is part of GCC.
> > @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3.  If not see
> >  
> >  #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
> >  #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
> > -#define SREAL_MAX_EXP (INT_MAX / 4)
> > +#define SREAL_MAX_EXP (INT_MAX / 8)
> >  
> >  #define SREAL_BITS SREAL_PART_BITS
> >  
> > @@ -34,10 +34,21 @@ class sreal
> >  {
> >  public:
> >/* Construct an uninitialized sreal.  */
> > -  sreal () : m_sig (-1), m_exp (-1) {}
> > +  sreal () : m_sig (-1), m_exp (-1), m_negative (0) {}
> >  
> >/* Construct a sreal.  */
> > -  sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); 
> > }
> > +  sreal (int64_t sig, int exp = 0) : m_exp (exp)
> > +  {
> > +m_negative = sig < 0;
> > +
> > +// TODO: speed up
> I think we do not need to care about this; expression folding should
> > +if (sig < 0)
> > +  sig = -sig;
> > +
> > +m_sig = (uint64_t) sig;
> > +
> > +normalize ();
> > +  }
> 
> We probably want sreal conversion fr

Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-13 Thread Jeff Law

On 11/13/14 05:35, mliska wrote:

gcc/ChangeLog:

2014-11-13  Martin Liska  

* predict.c (propagate_freq): More elegant sreal API is used.
(estimate_bb_frequencies): New static constants defined by sreal
replace precomputed ones.
* sreal.c (sreal::normalize): New function.
(sreal::to_int): Likewise.
(sreal::operator+): Likewise.
(sreal::operator-): Likewise.
* sreal.h: Definition of new functions added.

Shouldn't this be moving forward independent of the fibheap changes?



---
  gcc/predict.c | 30 +++-
  gcc/sreal.c   | 56 
  gcc/sreal.h   | 75 ---
  3 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 0215e91..0f640f5 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see

  /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
   1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
-static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
+static sreal real_almost_one, real_br_prob_base,
 real_inv_br_prob_base, real_one_half, real_bb_freq_max;

Update comment to reflect the remaining values.

Implementation of the arithmetics seems sane in the sense that we're 
just using basic identities to put everything into a canonical form then 
calling back into one of the existing functions.


If this is supposed to be small and fast, do we pay a noticeable penalty 
for canonicalizing then another call?  Would we be better off (for 
example) directly handling a + b with a negative and b positive?


I think it's OK to assume we can apply these identities as we're 
building a minimalist real implementation.   Obviously if we were 
building an IEEE compliant implementation, this would all be 
considerably more complex ;-)





@@ -34,10 +34,21 @@ class sreal
  {
  public:
/* Construct an uninitialized sreal.  */
-  sreal () : m_sig (-1), m_exp (-1) {}
+  sreal () : m_sig (-1), m_exp (-1), m_negative (0) {}

/* Construct a sreal.  */
-  sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); }
+  sreal (int64_t sig, int exp = 0) : m_exp (exp)
+  {
+m_negative = sig < 0;
+
+// TODO: speed up
+if (sig < 0)
+  sig = -sig;
Not sure what you really need to do here.  You could test and flip the 
sign bit, but  I'm pretty sure that's already handled for you in GCC, at 
least in the cases that are likely to matter.


So one thing that comes to mind is that it looks like we have +-0.  THey 
compare unequal and have an ordering.  Not sure if that's desirable or not.


I assume the shift method is used by one of the other patches in the 
series.  RIght?


So with the comment fix, some comment about handling of +-0, I think 
this is good to go and can go in independently of the rest of the patch 
series.


jeff


Re: [PATCH 8/9] Negative numbers added for sreal class.

2014-11-13 Thread Jan Hubicka
Hello,
in general I like this addition - I was not aware that sreal has no support for 
negative values.
This would be serious maintainance burden if sreals was used for profile 
updating - it is very
easy to get negative temporaries while dong the updates.
> gcc/ChangeLog:
> 
> 2014-11-13  Martin Liska  
> 
>   * predict.c (propagate_freq): More elegant sreal API is used.
>   (estimate_bb_frequencies): New static constants defined by sreal
>   replace precomputed ones.
>   * sreal.c (sreal::normalize): New function.
>   (sreal::to_int): Likewise.
>   (sreal::operator+): Likewise.
>   (sreal::operator-): Likewise.
>   * sreal.h: Definition of new functions added.
> diff --git a/gcc/sreal.c b/gcc/sreal.c
> index 3f5456a..89b9c4d 100644
> --- a/gcc/sreal.c
> +++ b/gcc/sreal.c
> @@ -1,4 +1,4 @@
> -/* Simple data type for positive real numbers for the GNU compiler.
> +/* Simple data type for real numbers for the GNU compiler.
> Copyright (C) 2002-2014 Free Software Foundation, Inc.
>  
>  This file is part of GCC.
> @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public 
> License
>  along with GCC; see the file COPYING3.  If not see
>  .  */
>  
> -/* This library supports positive real numbers and 0;
> +/* This library supports real numbers;
> inf and nan are NOT supported.
> It is written to be simple and fast.
>  
> @@ -102,6 +102,7 @@ sreal::normalize ()
>  {
>if (m_sig == 0)
>  {
> +  m_negative = 0;
>m_exp = -SREAL_MAX_EXP;
>  }
>else if (m_sig < SREAL_MIN_SIG)
> @@ -153,15 +154,17 @@ sreal::normalize ()
>  int64_t
>  sreal::to_int () const
>  {
> +  int64_t sign = m_negative ? -1 : 1;
> +
>if (m_exp <= -SREAL_BITS)
>  return 0;
>if (m_exp >= SREAL_PART_BITS)
> -return INTTYPE_MAXIMUM (int64_t);
> +return sign * INTTYPE_MAXIMUM (int64_t);
>if (m_exp > 0)
> -return m_sig << m_exp;
> +return sign * (m_sig << m_exp);
>if (m_exp < 0)
> -return m_sig >> -m_exp;
> -  return m_sig;
> +return sign * (m_sig >> -m_exp);
> +  return sign * m_sig;
>  }
>  
>  /* Return *this + other.  */
> @@ -169,9 +172,19 @@ sreal::to_int () const
>  sreal
>  sreal::operator+ (const sreal &other) const
>  {
> +  const sreal *a_p = this, *b_p = &other, *bb;
> +
> +  if (m_negative && !other.m_negative)
> +return other + *a_p;
> +
> +  if (!m_negative && other.m_negative)
> +return *a_p - -other;
> +
> +  gcc_assert (m_negative == other.m_negative);

I wonder what kind of code this winds into - you need recursive inlining to fix
this and it won't be clear to inliner that the recursion depth is 1.  Perhaps
having an inline private function for signedless + and - and implementing real
operators by this would factor the code better.

I wonder if there is not a faster implementation given that this code is on
way to internal loops of inliner.  If significand was signed, some of these 
operations
would just work, right?
> diff --git a/gcc/sreal.h b/gcc/sreal.h
> index 461e28b..bfed3c7 100644
> --- a/gcc/sreal.h
> +++ b/gcc/sreal.h
> @@ -1,4 +1,4 @@
> -/* Definitions for simple data type for positive real numbers.
> +/* Definitions for simple data type for real numbers.
> Copyright (C) 2002-2014 Free Software Foundation, Inc.
>  
>  This file is part of GCC.
> @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3.  If not see
>  
>  #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
>  #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
> -#define SREAL_MAX_EXP (INT_MAX / 4)
> +#define SREAL_MAX_EXP (INT_MAX / 8)
>  
>  #define SREAL_BITS SREAL_PART_BITS
>  
> @@ -34,10 +34,21 @@ class sreal
>  {
>  public:
>/* Construct an uninitialized sreal.  */
> -  sreal () : m_sig (-1), m_exp (-1) {}
> +  sreal () : m_sig (-1), m_exp (-1), m_negative (0) {}
>  
>/* Construct a sreal.  */
> -  sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); }
> +  sreal (int64_t sig, int exp = 0) : m_exp (exp)
> +  {
> +m_negative = sig < 0;
> +
> +// TODO: speed up
I think we do not need to care about this; expression folding should
> +if (sig < 0)
> +  sig = -sig;
> +
> +m_sig = (uint64_t) sig;
> +
> +normalize ();
> +  }

We probably want sreal conversion from both signed and unsigned ints?
For debugging output it would be very useful to also have conversion to double.
The dump method is bit unhandy to use.
>  
>void dump (FILE *) const;
>int64_t to_int () const;
> @@ -49,13 +60,58 @@ public:
>  
>bool operator< (const sreal &other) const
>{
> -return m_exp < other.m_exp
> +if (m_negative != other.m_negative)
> +  return m_negative > other.m_negative;
I guess negative zero is smaller than positive, but I do not see why that would 
be problem

Again, I would preffer C++ person to glance over this.

Honza


[PATCH 8/9] Negative numbers added for sreal class.

2014-11-13 Thread mliska
gcc/ChangeLog:

2014-11-13  Martin Liska  

* predict.c (propagate_freq): More elegant sreal API is used.
(estimate_bb_frequencies): New static constants defined by sreal
replace precomputed ones.
* sreal.c (sreal::normalize): New function.
(sreal::to_int): Likewise.
(sreal::operator+): Likewise.
(sreal::operator-): Likewise.
* sreal.h: Definition of new functions added.
---
 gcc/predict.c | 30 +++-
 gcc/sreal.c   | 56 
 gcc/sreal.h   | 75 ---
 3 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index 0215e91..0f640f5 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* real constants: 0, 1, 1-1/REG_BR_PROB_BASE, REG_BR_PROB_BASE,
   1/REG_BR_PROB_BASE, 0.5, BB_FREQ_MAX.  */
-static sreal real_zero, real_one, real_almost_one, real_br_prob_base,
+static sreal real_almost_one, real_br_prob_base,
 real_inv_br_prob_base, real_one_half, real_bb_freq_max;
 
 static void combine_predictions_for_insn (rtx_insn *, basic_block);
@@ -2528,13 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
bb->count = bb->frequency = 0;
 }
 
-  BLOCK_INFO (head)->frequency = real_one;
+  BLOCK_INFO (head)->frequency = sreal::one ();
   last = head;
   for (bb = head; bb; bb = nextbb)
 {
   edge_iterator ei;
-  sreal cyclic_probability = real_zero;
-  sreal frequency = real_zero;
+  sreal cyclic_probability = sreal::zero ();
+  sreal frequency = sreal::zero ();
 
   nextbb = BLOCK_INFO (bb)->next;
   BLOCK_INFO (bb)->next = NULL;
@@ -2559,13 +2559,13 @@ propagate_freq (basic_block head, bitmap tovisit)
  * BLOCK_INFO (e->src)->frequency /
  REG_BR_PROB_BASE);  */
 
-   sreal tmp (e->probability, 0);
+   sreal tmp = e->probability;
tmp *= BLOCK_INFO (e->src)->frequency;
tmp *= real_inv_br_prob_base;
frequency += tmp;
  }
 
- if (cyclic_probability == real_zero)
+ if (cyclic_probability == sreal::zero ())
{
  BLOCK_INFO (bb)->frequency = frequency;
}
@@ -2577,7 +2577,7 @@ propagate_freq (basic_block head, bitmap tovisit)
  /* BLOCK_INFO (bb)->frequency = frequency
  / (1 - cyclic_probability) */
 
- cyclic_probability = real_one - cyclic_probability;
+ cyclic_probability = sreal::one () - cyclic_probability;
  BLOCK_INFO (bb)->frequency = frequency / cyclic_probability;
}
}
@@ -2591,7 +2591,7 @@ propagate_freq (basic_block head, bitmap tovisit)
 = ((e->probability * BLOCK_INFO (bb)->frequency)
 / REG_BR_PROB_BASE); */
 
- sreal tmp (e->probability, 0);
+ sreal tmp = e->probability;
  tmp *= BLOCK_INFO (bb)->frequency;
  EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
}
@@ -2873,13 +2873,11 @@ estimate_bb_frequencies (bool force)
   if (!real_values_initialized)
 {
  real_values_initialized = 1;
- real_zero = sreal (0, 0);
- real_one = sreal (1, 0);
- real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
- real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
+ real_br_prob_base = REG_BR_PROB_BASE;
+ real_bb_freq_max = BB_FREQ_MAX;
  real_one_half = sreal (1, -1);
- real_inv_br_prob_base = real_one / real_br_prob_base;
- real_almost_one = real_one - real_inv_br_prob_base;
+ real_inv_br_prob_base = sreal::one () / real_br_prob_base;
+ real_almost_one = sreal::one () - real_inv_br_prob_base;
}
 
   mark_dfs_back_edges ();
@@ -2897,7 +2895,7 @@ estimate_bb_frequencies (bool force)
 
  FOR_EACH_EDGE (e, ei, bb->succs)
{
- EDGE_INFO (e)->back_edge_prob = sreal (e->probability, 0);
+ EDGE_INFO (e)->back_edge_prob = e->probability;
  EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;
}
}
@@ -2906,7 +2904,7 @@ estimate_bb_frequencies (bool force)
  to outermost to examine frequencies for back edges.  */
   estimate_loops ();
 
-  freq_max = real_zero;
+  freq_max = sreal::zero ();
   FOR_EACH_BB_FN (bb, cfun)
if (freq_max < BLOCK_INFO (bb)->frequency)
  freq_max = BLOCK_INFO (bb)->frequency;
diff --git a/gcc/sreal.c b/gcc/sreal.c
index 3f5456a..89b9c4d 100644
--- a/gcc/sreal.c
+++ b/gcc/sreal.c
@@ -1,4 +1,4 @@
-/* Simple data type for positive real numbers for the GNU compiler.
+/* Simple data type for real numbers for the GNU compiler.
Copyright (C) 2002-2014 Free