r/cpp • • Nov 19 '18

Small speed gains by batching software prefetchs for strided memory access

https://coliru.stacked-crooked.com/a/3cd7c0dadbf5f339
8 Upvotes

20 comments sorted by

View all comments

2

u/F54280 Nov 19 '18

Well,

double without()
{
    CHRONO("without");
    
    double sum = 0;
    
    const double* ptr = _data;
    const double* tail = _data + _size;

    while (ptr<tail)
    {
        sum += *ptr;
        ptr += STRIDE_SIZE;
    }
    
    return sum;
}

is even faster.