Path: utzoo!mnetor!uunet!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.lang.c Subject: Re: noalias and vectors Message-ID: <7492@boring.cwi.nl> Date: 22 Jan 88 10:10:05 GMT References: <2942@hall.cray.com> <531@cresswell.quintus.UUCP> <7088@brl-smoke.ARPA> <3419@ihlpf.ATT.COM> <7142@brl-smoke.ARPA> <3458@ihlpf.ATT.COM> Organization: CWI, Amsterdam Lines: 46 Keywords: noalias, auto-vectorizing In article <3458@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704A-Liber,N.) writes: > In article <7142@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: > >In article <3419@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704A-Liber,N.) writes: > >-Actually, from what I understand, all that noalias would mean here is that s1 > >-and s2 don't point to EXACTLY the same place ... Overlap would still > >-be allowed. > > > >Not the way I understand it. > > Are you telling me that noaliasing a pointer to char means that I cannot have > overlap anywhere past the character that I am pointing to? Do you think > that noalias believes that all uses of pointers to char are for null-terminated > strings (which is not the only way to define strings)? Since string operations What I think is meant is: if in a routine pointer p1 is declared noalias, there will be no instance during the execution of the routine that p1 will point to anything else accessible by the routine. This is very useful to vectorize statements like p1++ = p2++ + p3++; It ensures that during a calculation of the array element that p1 points to, no previous calculated element of the array is used. Without this assurance the statement cannot be vectorized. We can have even more complicated situations like: void vector_scatter(float *v1, *v2, int *index, int n) { noalias float *p1; while(n--) { /* instead of v1[*index++] = *v2++ */ p1 = &v1[*index++]; *p1 = *v2++; } } Note the kludge with p1 to ensure proper information to the compiler; noaliasing v1 does not work I think. Without noalias this will not vectorize, with noalias it will. Note also there is no easy way to check the validity of the noalias, and it is also not possible to do the same using assertions (as has been suggested). This is one of the most common operations in vectorized programs, available as a single instruction (for the loop) on most vector machines. (If I erred about the semantics of noalias it is all my fault.) -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax