On 8/15/2016 6:28 PM, Ali Çehreli wrote:
void main() {
    auto p = arr.ptr;

    foreach (j; 0 .. 100) {
        foreach (i; 0..arr.length) {
            version (POINTER) {
                p[i] += cast(ubyte)i;
            }
            else {
                arr[i] += cast(ubyte)i;
            }
        }
    }
}

When accessing global arrays like this, cache the address of the data in a local variable. This will enable the compiler to enregister it. Putting global data in registers is problematic because any assignment through a pointer could change it, so the compiler takes a pessimistic view of it.

Your POINTER version does cache the pointer, but arr.length needs to be cached as well.

Reply via email to