How does D cope with aliasing

ponce aliloko at gmail.com
Tue Sep 8 11:21:51 PDT 2009


Stewart Gordon Wrote:

> #ponce wrote:
> <snip>
> > OT : Is there a DMD switch to disable bound check exceptions ? This way I wouldn't have to rely on pointers so much.
> 
> Why do you want to do that?  Sounds like a case of trying to fix the 
> wrong problem.
> 
> Stewart.

The problem is that I need my audio routines to go at full-speed even in debug mode (with asserts and DbC on). Bound checking make it quite slow since there is so much array access. 

This is why I use pointers over arrays. But the semantics of pointers and how the compiler consider these as aliased or not is quite unclear. Of course I may have a false view of how D handle these problems.

In C/C++ you have many ways to help the compiler to reduce aliasing :
- pointers to const
- restrict
- various pragmas
...
I come from a background where pointer aliasing was considered important to efficient code generation.


>From the compiler point of view, there is a safe approach considering that pointers can always alias, but this prevent some optimizations (loop unrolling, parallelization).

In the other hand, considering that no pointer ever alias allow these optimizations but could break correct code (at least in C/C++).


More information about the Digitalmars-d-announce mailing list