digitalmars.D.learn - How does D cope with aliasing
- #ponce <aliloko gmail.com> Sep 05 2009
- Jarrett Billingsley <jarrett.billingsley gmail.com> Sep 05 2009
- bearophile <bearophileHUGS lycos.com> Sep 05 2009
- Stewart Gordon <smjg_1998 yahoo.com> Sep 05 2009
- #ponce <aliloko gmail.com> Sep 07 2009
- #ponce <aliloko gmail.com> Sep 07 2009
- "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> Sep 07 2009
- Stewart Gordon <smjg_1998 yahoo.com> Sep 07 2009
- grauzone <none example.net> Sep 09 2009
- #ponce <aliloko gmail.com> Sep 09 2009
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: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
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: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.
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.
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









Jarrett Billingsley <jarrett.billingsley gmail.com> 