What is the most efficient way to shuffle huge bit vectors using GCC

I have two very large bit vectors (about 1 GB each) and I want to shuffle them like this:

first bit vector: a[0], a[1], a[n]
second bit:b[0], b[1], b[n]

This should lead to something like:

c[0] = a[0]
c[1] = b[0] 
c[2] = a[1]
c[3] = b[1]

What is the most efficient way to do this in C ++ using vector operations of new Intel processors? I want to do this with GCC.

+4
source share
1 answer

you can try flipping your own loop -

int ch1, ch2;
while ((ch1 = fgetc(fp1)) != EOF && (ch2 = fgetc(fp2)) != EOF) {
    int i, dst = 0;
    // assuming msb goes first
    for (i=7; i>=0; i--) {
        dst |= (ch1 & (1<<i)) << (2*i + 1);
        dst |= (ch2 & (1<<i)) << (2*i + 0);
    }
    putc(dst >> 8);
    putc(dst & 0xFF);
}

, , , 16 , 4 (-O3 ).

, 150 3GHz, 40 /, 2x20 /, 50 2x1000 . .

0

All Articles