On Feb 3, 2005, at 4:46 PM, Gabriel Sechan wrote:

When did I ever say that all languages ran with equal efficiency? I didn't, I know I can write assembly that runs faster than my C, and I know any compiled language is faster than an interpreted one. We're talking programmer efficiency here.

If execution time is part of the problem, then programmer efficiency is measured by how quickly a programmer can fix the execution time problem.


You cannot just exclude some class of problems because *you* do not consider it relevant.

There is a fundamental language difference that conforming compilers cannot ignore. C/C++ compilers *must* assume that arrays/pointers can alias with one another. Fortran compiles can assume that arrays/pointers cannot alias with one another.

On a tangent, why does that slow C down? I'm misunderstanding or missing something here. An array and a pointer in assembly are the same thing in any language- an address of the first element, with all elements coming one after another (possibly with some packing).

int a[5], *b, i;

b = a;
a[0] = 0;

for(i=0; i<4; ++i) {
        b[i+1] = a[i];
}

is guaranteed to initialize array a to all zeros. This means that the following sequence must occur (rN is a machine register):

r0=a[0]; b[1]=r0<wait>; r1=a[1]; b[2]=r1<wait>; r2=a[2]; b[3]=r2<wait>; r3=a[3]; b[4]=r3<wait>

Each assignment must actually get pushed back to memory before the next assignment will then fetch the new result from memory because a and b overlap (in this case, they are the same).

If, however, aliasing is assumed not to occur, the compiler is allowed to generate the following sequence instead:

r0=a[0]; r1=a[1]; r2=a[2]; r3=a[3]; b[1]=r0; b[2]=r1; b[3]=r2; b[4]=r3

There are no waits between the memory assignments. Of course, the aliasing causes an incorrect assignment in this case.

However, C compilers cannot a priori distinguish whether b points into a or not. Thus they must always generate the sequence which waits rather than the sequence which doesn't.

This transform comes up in a compiler optimization called "Loop unrolling".

-a

--

KPLUG-List mailing list
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to