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)