digitalmars.D.learn - How does D cope with aliasing
- #ponce (2/2) Sep 05 2009 I'm currently using a lot of pointers to perform heavy computation
- Jarrett Billingsley (2/4) Sep 05 2009 It doesn't.
- bearophile (5/6) Sep 05 2009 DMD probably just doesn't perform such optimizations. LLVM that's under ...
- Stewart Gordon (7/12) Sep 05 2009 My recollection of reading the spec is that a D compiler is allowed to
- #ponce (3/6) Sep 07 2009 I don't know if this is neat or nasty for a compiler to do so.
- #ponce (1/9) Sep 07 2009
- Lars T. Kyllingstad (4/12) Sep 07 2009 The -release switch turns off array bounds checking. However, it also
- Stewart Gordon (5/6) Sep 07 2009 Why do you want to do that? Sounds like a case of trying to fix the
- grauzone (7/15) Sep 09 2009 If you always want DMD never to bounds check for specific code, you just...
- #ponce (1/7) Sep 09 2009 Interesting tip, thanks !
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.
Sep 05 2009
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.
Sep 05 2009
#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
Sep 05 2009
#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.
Sep 05 2009
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.
Sep 07 2009
#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.
Sep 07 2009
#ponce wrote:Stewart Gordon Wrote:The -release switch turns off array bounds checking. However, it also disables contracts and asserts. -LarsMy 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.
Sep 07 2009
#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.
Sep 07 2009
#ponce wrote:Stewart Gordon Wrote:If you always want DMD never to bounds check for specific code, you just can write "a.ptr[index]" instead of "a[index]" (when a is an array). That's because array.ptr returns a pointer to the first element, and using [] on a pointer works exactly like C pointer math. The good thing about this is that you still can use array slices and the .length field, so the code most likely is less messy than the C version would be.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.
Sep 09 2009
If you always want DMD never to bounds check for specific code, you just can write "a.ptr[index]" instead of "a[index]" (when a is an array). That's because array.ptr returns a pointer to the first element, and using [] on a pointer works exactly like C pointer math. The good thing about this is that you still can use array slices and the .length field, so the code most likely is less messy than the C version would be.Interesting tip, thanks !
Sep 09 2009