Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Francisco Almeida
== Quote from Walter Bright (newshou...@digitalmars.com)'s article > True, but dynamic arrays offer no inherent protection against overlap, though > you can add a runtime check for that. Another reason why we should have memory pool support in Phobos.

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Walter Bright
On 4/28/2011 9:10 PM, Don wrote: D reduces the use of pointers. You can do much more with arrays. True, but dynamic arrays offer no inherent protection against overlap, though you can add a runtime check for that.

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Don
Jens Mueller wrote: Andrei Alexandrescu wrote: On 4/28/11 12:57 PM, Jens Mueller wrote: Walter Bright wrote: On 4/28/2011 9:19 AM, Daniel Gibson wrote: But there's no need for a D compiler to optimize loops that just copy parts of an array into another array (and similar stuff), because in D

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Andrei Alexandrescu
On 4/28/11 7:53 PM, bearophile wrote: Andrei: C's restricts sets a poor example. There are infinite things that a compiler can't prove about the code. Restrict is particularly bad. See http://www.lysator.liu.se/c/dmr-on-noalias.html (noalias was the initial name of restrict). Andrei

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread bearophile
Andrei: > C's restricts sets a poor example. There are infinite things that a compiler can't prove about the code. Example: the type system can't prove that @system code that uses pointer arithmetic contains no bugs, pointers that go past arrays, etc. C99 restrict is just another example where

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Andrei Alexandrescu
On 4/28/11 4:14 PM, Jens Mueller wrote: Walter Bright wrote: On 4/28/2011 11:44 AM, Jens Mueller wrote: Thanks. So if a compiler can assume that pointers do not alias it can generate much better code. What's D's standpoint on that matter then? C99 has restrict. I never came across something sim

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread bearophile
Moritz Warning: > When the contents are both const, then there won't be any writing > to it, of course. In that case the same optimizations can be applied as > when they point to different memory. > > both arrays point to different memory. I see, thank you. Bye, bearophile

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Moritz Warning
On Thu, 28 Apr 2011 17:44:35 -0400, bearophile wrote: > Walter: > >> On 4/28/2011 11:44 AM, Jens Mueller wrote: >> > Thanks. So if a compiler can assume that pointers do not alias it can >> > generate much better code. What's D's standpoint on that matter then? >> > C99 has restrict. I never came

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread bearophile
Jens Mueller: > That allows specifying that the memory pointed to is only readable which > enables doing the optimizations. But what if the memory is writable but > I can my sure that the pointers pointing to it will never alias? How do > I pass that information to the compiler? Here's my answer.

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread bearophile
> "restrict" means "this pointer has no alias". Jens Mueller is right, it's not just pointers, a.ptr and b.ptr are distinct but they refer to memory zones that are not distinct: auto a = [1, 2, 3, 4, 5]; auto b = [1 .. 3]; Bye, bearophile

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread bearophile
Walter: > On 4/28/2011 11:44 AM, Jens Mueller wrote: > > Thanks. So if a compiler can assume that pointers do not alias it can > > generate much better code. What's D's standpoint on that matter then? > > C99 has restrict. I never came across something similar in D. > > Const and immutable. I do

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Jens Mueller
Timon Gehr wrote: > > That allows specifying that the memory pointed to is only readable which > > enables doing the optimizations. But what if the memory is writable but > > I can my sure that the pointers pointing to it will never alias? How do > > I pass that information to the compiler? > > > >

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Timon Gehr
> That allows specifying that the memory pointed to is only readable which > enables doing the optimizations. But what if the memory is writable but > I can my sure that the pointers pointing to it will never alias? How do > I pass that information to the compiler? > > Jens assert(p1 != p2); (or a

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Jens Mueller
Walter Bright wrote: > On 4/28/2011 11:44 AM, Jens Mueller wrote: > >Thanks. So if a compiler can assume that pointers do not alias it can > >generate much better code. What's D's standpoint on that matter then? > >C99 has restrict. I never came across something similar in D. > > Const and immutab

Re: Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Walter Bright
On 4/28/2011 11:44 AM, Jens Mueller wrote: Thanks. So if a compiler can assume that pointers do not alias it can generate much better code. What's D's standpoint on that matter then? C99 has restrict. I never came across something similar in D. Const and immutable.

Pointer aliasing in D (Was: Programming language benchmarks)

2011-04-28 Thread Jens Mueller
Andrei Alexandrescu wrote: > On 4/28/11 12:57 PM, Jens Mueller wrote: > >Walter Bright wrote: > >>On 4/28/2011 9:19 AM, Daniel Gibson wrote: > >>>But there's no need for a D compiler to optimize loops that just copy > >>>parts of an array into another array (and similar stuff), because in D > >>>yo