On 17/01/12 11:34 PM, Walter Bright wrote:
On 1/17/2012 3:23 PM, Peter Alexander wrote:
On 17/01/12 10:55 PM, Walter Bright wrote:
On 1/17/2012 1:47 PM, Peter Alexander wrote:
On 17/01/12 9:24 PM, Walter Bright wrote:
On 1/17/2012 1:20 PM, Peter Alexander wrote:
As Manu said, you need something like __restrict (or a linear type
system) to
solve this problem.
No, you don't. It can be done with a runtime check, like array bounds
checking is done.
So you'd change it to this, even in release builds?
No. Like array bounds, if they overlap, an exception is thrown.
Remember, the D spec says that overlapping arrays are illegal.
The D spec says that overlapping arrays are illegal for vector ops. The
foo(int[], int[], int[]) function does not use vector ops.
Or am I missing something really major?
For example, is this legal code?
int[100] a;
int[] b = a[0..100];
int[] c = a[10..90]; // Illegal? b and c overlap...
No, not illegal.
foreach (i; 0..80)
c[i] = b[i]; // Illegal?
No, not illegal.
I know that b[] = c[] would be illegal, but that has nothing to do
with the
prior discussion.
Yes, b[]=c[] is illegal.
So, my original point still stands, you can't vectorise this function:
void foo(int[] a, int[] b, int[] c)
{
foreach (i; 0..256)
a[i] = b[i] + c[i];
}
Those slices are allowed to overlap, so this cannot be automatically
vectorised (without inlining to get better context about those arrays).
Without inlining, you need something along the lines of __restrict or
uniqueness typing.