www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Partial array bounds checks removal

reply bearophile <bearophileHUGS lycos.com> writes:
This article shows a way to remove lot of array bounds checks, it's not the
first of this kind, but this method seems simple enough.
"Array Bounds Check Elimination for the Java HotSpot Client Compiler"
By Thomas Würthinger, Christian Wimmer and Hanspeter Mössenböck:

http://www.ssw.uni-linz.ac.at/Research/Papers/Wuerthinger07/Wuerthinger07.pdf

With some heuristics it's often able to move the array bounds checks before the
loop. It also uses some complex tricks to produce the array bound exception
where it belongs, and not before the loop.

I think a similar strategy may be used by safeD to remove most of its array
bounds checks, to produce code that is almost as fast as normal D code compiled
with -release.
(Probably the tricks shown in the article can't be used by a static compiler,
array bounds checks will be probably thrown before the loops in such safeD.).
(Other heuristics can be used to avoid lot of the checks done to catch integer
overflow errors).

Bye,
bearophile
Dec 16 2008
parent reply "Tim M" <a b.com> writes:
I haven't tried safeD and i'm guessing that is extra secure version of D  
but what would be the point in removing those secuirty checks?

On Wed, 17 Dec 2008 08:34:17 +1300, bearophile <bearophileHUGS lycos.com>  
wrote:

 This article shows a way to remove lot of array bounds checks, it's not  
 the first of this kind, but this method seems simple enough.
 "Array Bounds Check Elimination for the Java HotSpot Client Compiler"
 By Thomas Würthinger, Christian Wimmer and Hanspeter Mössenböck:

 http://www.ssw.uni-linz.ac.at/Research/Papers/Wuerthinger07/Wuerthinger07.pdf

 With some heuristics it's often able to move the array bounds checks  
 before the loop. It also uses some complex tricks to produce the array  
 bound exception where it belongs, and not before the loop.

 I think a similar strategy may be used by safeD to remove most of its  
 array bounds checks, to produce code that is almost as fast as normal D  
 code compiled with -release.
 (Probably the tricks shown in the article can't be used by a static  
 compiler, array bounds checks will be probably thrown before the loops  
 in such safeD.).
 (Other heuristics can be used to avoid lot of the checks done to catch  
 integer overflow errors).

 Bye,
 bearophile

Dec 16 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to tim,

 I haven't tried safeD and i'm guessing that is extra secure version of
 D  but what would be the point in removing those secuirty checks?
 

I think it implication is that some checks can be removed if you can show that they will never fail.
Dec 16 2008
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Tim M:
Oh now this will never fail but you can never be too sure.<

In the last thousand years humans have invented a thing named "mathematics". In certain circumstances it allows you to be certain of some things. In some part of the programs you can use this (simple) mathematics and be actually certain a certain bound will not be exceeded. Trust me, mathematics can be marvelous :-) Bye, bearophile
Dec 16 2008
prev sibling parent Brad Roberts <braddr puremagic.com> writes:
bearophile wrote:
 Tim M:
 Oh now this will never fail but you can never be too sure.<

In the last thousand years humans have invented a thing named "mathematics". In certain circumstances it allows you to be certain of some things. In some part of the programs you can use this (simple) mathematics and be actually certain a certain bound will not be exceeded. Trust me, mathematics can be marvelous :-) Bye, bearophile

And in the last 30 years, compiler writers have invented optimizers. Nearly every bit of that is in the realm of exactly what the optimization phases of a compiler do. So, yes, dmd, llvm, gcc.. they all do this by design. No need to be condescending, bearophile. Later, Brad
Dec 16 2008
prev sibling parent "Tim M" <a b.com> writes:
But that's the main problem. Oh now this will never fail but you can never  
be too sure. Also 640K should be enough for anyone. :)

On Wed, 17 Dec 2008 14:26:37 +1300, BCS <ao pathlink.com> wrote:

 Reply to tim,

 I haven't tried safeD and i'm guessing that is extra secure version of
 D  but what would be the point in removing those secuirty checks?

I think it implication is that some checks can be removed if you can show that they will never fail.

Dec 16 2008