Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 05, 2009 How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
I'm currently using a lot of pointers to perform heavy computation Has D the equivalent for C's restrict ? More generally, how does D cope with the aliasing of pointers ? I think it's crucial for the code optimizer. |
September 05, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | On Sat, Sep 5, 2009 at 3:49 AM, #ponce<aliloko@gmail.com> wrote: > I'm currently using a lot of pointers to perform heavy computation > > Has D the equivalent for C's restrict ? More generally, how does D cope with the aliasing of pointers ? I think it's crucial for the code optimizer. It doesn't. |
September 05, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | #ponce: > I'm currently using a lot of pointers to perform heavy computation Has D the equivalent for C's restrict ? More generally, how does D cope with the aliasing of pointers ? I think it's crucial for the code optimizer.< DMD probably just doesn't perform such optimizations. LLVM that's under LDC is probably able to perform such optimizations, but in the language there is no way to give such semantics to the compiler. My suggestion for you is to ask for such feature in the main D newsgroup, and/or in bugzilla. In the meantime you can also ask such feature to LDC developers, they may just add a small LDC-specific pragma that gives such semantics to the LLVM (in future, when D will add such annotation LDC developers will just change the syntax of this feature). (I'll ask to LDC developers to see what they think). Bye, bearophile |
September 05, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | #ponce wrote: > I'm currently using a lot of pointers to perform heavy computation > > Has D the equivalent for C's restrict ? More generally, how does D cope with the aliasing of pointers ? I think it's crucial for the code optimizer. My recollection of reading the spec is that a D compiler is allowed to optimise by assuming no pointer aliasing. But I can't remember at the moment where I read this. But in the absence of this, you can use contracts to guard against at least the simplest forms of aliasing. Stewart. |
September 07, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon Wrote:
> My recollection of reading the spec is that a D compiler is allowed to optimise by assuming no pointer aliasing. But I can't remember at the moment where I read this.
I don't know if this is neat or nasty for a compiler to do so.
OT : Is there a DMD switch to disable bound check exceptions ? This way I wouldn't have to rely on pointers so much.
|
September 07, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | #ponce Wrote: > Stewart Gordon Wrote: > > My recollection of reading the spec is that a D compiler is allowed to optimise by assuming no pointer aliasing. But I can't remember at the moment where I read this. > > I don't know if this is neat or nasty for a compiler to do so. > > OT : Is there a DMD switch to disable bound check exceptions ? This way I wouldn't have to rely on pointers so much. |
September 07, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | #ponce wrote: > Stewart Gordon Wrote: >> My recollection of reading the spec is that a D compiler is allowed to optimise by assuming no pointer aliasing. But I can't remember at the moment where I read this. > > I don't know if this is neat or nasty for a compiler to do so. > > OT : Is there a DMD switch to disable bound check exceptions ? This way I wouldn't have to rely on pointers so much. The -release switch turns off array bounds checking. However, it also disables contracts and asserts. -Lars |
September 07, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to #ponce | #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. |
September 08, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | 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++).
|
September 08, 2009 Re: How does D cope with aliasing | ||||
---|---|---|---|---|
| ||||
Posted in reply to ponce | ponce: >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.< With LDC you can fine-tune the "release", for example disabling just bound checkingbut keeping other asserts. See the LDC command line extended help. >This is why I use pointers over arrays.< In D using pointers instead of arrays is usually discouraged, arrays are for most purposes, pointers are for special purposes. And in release mode with DMD the pointer-based arrays are a bit slower than normal arrays (in LDC they have the same speed), I don't know why. >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.< Such problems aren't handled yet in D. Another person has told you the same thing. >I come from a background where pointer aliasing was considered important to efficient code generation.< D developers are designing large features of the D2 language, so I think they aren't interested in fine optimizations yet. That's why I have told you that in the short term your best hope is to have added a ldc-specific pragma in ldc that works as restrict. Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation