R
Rick C. Hodgin
Guest
I\'m not sure where to ask this question, so I pushed it out to several
groups. You need not reply to all of them if you don\'t think it is a
topical subject.
I included comp.compilers in a previous message, but it apparently holds
the message until it passes moderation. So, I\'ve not included it here.
A duplicate message may post if/when the comp.compilers moderator John
Levine approves it.
-----
Are there any algorithms which take a known-at-compile-time sequence
of bitwise operations on an 8-bit to 64-bit quantity, and optimize
them down to their minimal set of operations?
For example, if I have an 8-bit byte and I want to swizzle the bits
thusly:
Input: 07 06 05 04 03 02 01 00
Output: 05 04 07 02 01 03 00 06
I can easily swizzle the data using a brute force method:
v = get_value();
o = 0;
swizzle1(o, v, 0, 6);
swizzle1(o, v, 1, 0);
swizzle1(o, v, 2, 3);
swizzle1(o, v, 3, 1);
swizzle1(o, v, 4, 2);
swizzle1(o, v, 5, 7);
swizzle1(o, v, 6, 4);
swizzle1(o, v, 7, 5);
// Untested, off the top of my head
void swizzle(unsigned char& o, unsigned char v, int s, int d)
{
o |= (((v & (1 << s)) >> s) << d);
}
And, of course, that algorithm can be optimized based on relative
values of s and d, and if s is 0, etc.
However, there also exists a minimal set of steps to complete that
swizzling because in the operation above, bits 5 and 4 are used in
sequence. It could be done using a swizzle2() operation, for example
and handle 2 bits at a time.
Are there any existing algorithms which examine the operations that
must be conducted and the optimized / minimal sequence of steps to
conduct it?
Thank you in advance.
--
Rick C. Hodgin
groups. You need not reply to all of them if you don\'t think it is a
topical subject.
I included comp.compilers in a previous message, but it apparently holds
the message until it passes moderation. So, I\'ve not included it here.
A duplicate message may post if/when the comp.compilers moderator John
Levine approves it.
-----
Are there any algorithms which take a known-at-compile-time sequence
of bitwise operations on an 8-bit to 64-bit quantity, and optimize
them down to their minimal set of operations?
For example, if I have an 8-bit byte and I want to swizzle the bits
thusly:
Input: 07 06 05 04 03 02 01 00
Output: 05 04 07 02 01 03 00 06
I can easily swizzle the data using a brute force method:
v = get_value();
o = 0;
swizzle1(o, v, 0, 6);
swizzle1(o, v, 1, 0);
swizzle1(o, v, 2, 3);
swizzle1(o, v, 3, 1);
swizzle1(o, v, 4, 2);
swizzle1(o, v, 5, 7);
swizzle1(o, v, 6, 4);
swizzle1(o, v, 7, 5);
// Untested, off the top of my head
void swizzle(unsigned char& o, unsigned char v, int s, int d)
{
o |= (((v & (1 << s)) >> s) << d);
}
And, of course, that algorithm can be optimized based on relative
values of s and d, and if s is 0, etc.
However, there also exists a minimal set of steps to complete that
swizzling because in the operation above, bits 5 and 4 are used in
sequence. It could be done using a swizzle2() operation, for example
and handle 2 bits at a time.
Are there any existing algorithms which examine the operations that
must be conducted and the optimized / minimal sequence of steps to
conduct it?
Thank you in advance.
--
Rick C. Hodgin