Re: where exactly c++,c fail and Ada gets thru'
- From: Martin Krischik <krischik@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Apr 2006 09:03:59 +0200
Maciej Sobczak wrote:
Martin Krischik wrote:
The point is - of corse - it that the semantic tree of the Ada
compiler contains the information that X will be in the range of (1 ..
5) and then the optimizer can easily calculate that (1 .. 5) + 3 < 10
and then optimize away the check.
The sematinc tree of the C++ will contain the information that X is in
the range of (-2*32 .. +2*32-1) and that is a pretty useless
information to the optimizer.
Except that the optimizer is not limited to use only this information.
With the two example ranges (1..5 and 1..10) the result of inlining will
be that the following operations - all operating on the single value -
will be placed one after another:
1. compare against 5
2. add 3
3. compare against 10
It doesn't take a rocket scientist to deduce that the third operation
has a dead branch and can be therefore eliminated.
But it is the callers responsibility to check the input parameter before
calling the function. That way range checks need only be performed on input
and type convertions. Remember that Ada defines + as:
function "+" is (L, R: in Integer'Base) return Integer'Base;
Back to my example: If you call F(3) no check is needed. The caller knows
that 3 is in range and the callee knows that X + 3 is in range. Of course:
If the optimizer spots that is a different story.
Now I do wonder if REH managed some template/boolean magic to get the same
result on C++.
Martin
--
mailto://krischik@xxxxxxxxxxxxxxxxxxxxx
Ada programming at: http://ada.krischik.com
.
- Follow-Ups:
- References:
- where exactly c++,c fail and Ada gets thru'
- From: Ananth the Boss
- Re: where exactly c++,c fail and Ada gets thru'
- From: jimmaureenrogers@xxxxxxxxxxxxxxxx
- Re: where exactly c++,c fail and Ada gets thru'
- From: Maciej Sobczak
- Re: where exactly c++,c fail and Ada gets thru'
- From: Martin Krischik
- Re: where exactly c++,c fail and Ada gets thru'
- From: Maciej Sobczak
- Re: where exactly c++,c fail and Ada gets thru'
- From: Martin Krischik
- Re: where exactly c++,c fail and Ada gets thru'
- From: Maciej Sobczak
- where exactly c++,c fail and Ada gets thru'
- Prev by Date: Re: where exactly c++,c fail and Ada gets thru'
- Next by Date: Re: where exactly c++,c fail and Ada gets thru'
- Previous by thread: Re: where exactly c++,c fail and Ada gets thru'
- Next by thread: Re: where exactly c++,c fail and Ada gets thru'
- Index(es):