I am experimenting to make a Inverse Multiplexer, which could split one bitstream into many according to some masks.
Here's the idea example
This is a 24 bit stream, each letter represents 1 bit:
abcdefgh ijklmnop qrstuvwx
Given three masks, every mask has no bit in common, if & together they are [1,1,1,1,1,1,1,1]
[1, 1, 0, 0, 1, 0, 0, 0]
[0, 0, 1, 0, 0, 0, 1, 1]
[0, 0, 0, 1, 0, 1, 0, 0]
apply these masks to the stream like this
stream1 = ab__e___ ij__m___ qr__u___
stream2 = __c___gh __k___op __s___wx
stream3 = ___d_f__ ___l_n__ ___t_v__
So the original bitstream is splitted into three bitstreams like this:
stream1 = abeijmqru
stream2 = cghkopswx
stream3 = dflntv
The above is just an example, I need to apply arbitrary number of masks to a given bitstream. The masks are guranteed, between every each other, has OR
result of ZEROs. Aply AND
to all the masks has the result of ONEs. All masks are the same length.
I wrote a dumb version to brute force the idea which is basically shifting bits one by one in a loop. Thought it's certainly not efficient.
I looked into this http://graphics.stanford.edu/~seander/bithacks.html
No clue. Anyone has better idea how to improve this? (On x86 machines)