Skip to content
Snippets Groups Projects
Commit e35d297f authored by Jan Hubicka's avatar Jan Hubicka
Browse files

Fix sreal::to_int and implement sreal::to_nearest_int

while exploring new loop estimate dumps, I noticed that loop iterating 1.8
times by profile is etimated as iterating once instead of 2 by nb_estimate.
While nb_estimate should really be a sreal and I will convert it incrementally,
I found problem is in previous patch doing:

+	  *nit = (snit + 0.5).to_int ();

this does not work for sreal because it has only constructor from integer, so
first 0.5 is rounded to 0 and then added to snit.

Some code uses sreal(1, -1) which produces 0.5, but it reuqires unnecessary
addition, so I decided to add to_nearest_int.  Testing it I noticed that to_int
is buggy:
  (sreal(3)/2).to_int () == 1
while
  (sreal(-3)/2).to_int () == -2

Fix is easy, we need to correctly shift in positive values.  This patch fixes
it and adds the to_nearest_int alternative.

gcc/ChangeLog:

	* sreal.cc (sreal::to_nearest_int): New.
	(sreal_verify_basics): Verify also to_nearest_int.
	(verify_aritmetics): Likewise.
	(sreal_verify_conversions): New.
	(sreal_cc_tests): Call sreal_verify_conversions.
	* sreal.h: (sreal::to_nearest_int): Declare
parent 65ff4a45
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment