• Create Account

### #ActualMisery

Posted 16 October 2012 - 06:03 AM

Hello,

I am using integers as bit containers representing bool values.
How do I make a fast instruction that reads some bit from one integer and sets its value to another.
Lets say: there are two 64 bit integers. One of them x has some bits set.
I want to rewrite every second bit from x to y (from beginning). How do I make that avoiding code similar to that:
y=0; //clear y
t=0;
for (int i=0;i<64;i+=2)
if (x & (CONTAINER_INT(1) << (i%ContainerSize)))
{
y |= CONTAINER_INT(1) << (t%ContainerSize);
t++;
}


I mean I want to avoid if instruction.

Regards.

### #1Misery

Posted 16 October 2012 - 05:52 AM

Hello,

I am using integers as bit containers representing bool values.
How do I make a fast instruction that reads some bit from one integer and sets its value to another.
Lets say: there are two 64 bit integers. One of them x has some bits set.
I want to rewrite every second bit from x to y (from beginning). How do I make that avoiding code similar to that:
y=0; //clear y
t=0;
for (int i=0;i<64;i+=2)
if (x[i/ContainerSize] & (CONTAINER_INT(1) << (i%ContainerSize)))
{
y[t/ContainerSize]|= CONTAINER_INT(1) << (t%ContainerSize);
t++;
}


I mean I want to avoid if instruction.

Regards.

PARTNERS