10-05-2007 11:26 AM
10-05-2007 11:54 AM
I've occasionally done some benchmark tests on operations of this nature, and in my experience the various methods end up being equivalent. I usually choose based on what is cleanest on the diagram.
The bit-masking method would involve an OR operation to set bits, an AND operation to clear them. Although LV FPGA generates code for a 32-bit operation, Xilinx is pretty good at recognizing and optimizing constant operations (in this case, it would not be difficult to recognized that 31 of the OR operations will not have any effect, as long as the bitmask is a constant).
Converting to a boolean array and setting the bit is equivalent. It has the advantage of showing explicitly that you're only operating on one bit, but tends to be a bit on the ugly side.
For LSB or MSB operations, you could also use two Rotate Left/Right With Carry functions--shift out the bit of interest and then shift the other way, setting or clearing the carry bit as desired.