g6k icon indicating copy to clipboard operation
g6k copied to clipboard

Factoring signed-accumulate for vectors

Open lducas opened this issue 5 years ago • 0 comments

The following snippet (and most likely many variation thereoff) appears repeatedly.

    if(sign == 1)
    {
        for(unsigned int i=0; i < n; ++i)
        {
            x[l+i] += db[i2].x[i];
        }
        for(unsigned int i=0; i < OTF_LIFT_HELPER_DIM; ++i)
        {
            otf_helper[i] += db[i2].otf_helper[i];
        }
    }
    else
    {
        for(unsigned int i=0; i < n; ++i)
        {
            x[l+i] -= db[i2].x[i];
        }
        for(unsigned int i=0; i < OTF_LIFT_HELPER_DIM; ++i)
        {
            otf_helper[i] -= db[i2].otf_helper[i];
        }
    }

It seems like good practice to replace it by calls to an inlined function:

vector_signed_accumulate(&x+l, db[i2].x, n, sign);
vector_signed_accumulate(&otf_helper, db[i2].otf_helper, OTF_LIFT_HELPER_DIM, sign);

Not sure yet whether we want to pass pointers, references, or iterators.

lducas avatar Nov 23 '20 15:11 lducas