LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA - What is the most efficient way to set a bit...

Hello,
 
I'm working w/ Labview 8.5 and FPGA.  Lets say I have a U32 passing into a Single-cycle timed loop via a shift register.  What is the most efficient way to set a bit in the U32?
 
Let's say I wanted to set the LSB.  I could check if it is odd or even, then add 1 (wasteful).  Or I could AND it with 1.  If I AND it, would I have to AND it with another U32?  Still kind of wasteful, since I generate the hardware to AND all the other bits? If it is an arbitrary bit (ie which bit I want changes at execution time) then this probably would be the way to go.
 
If my "register" was made from flipflops and I was doing VHDL, I would use the set / clear of the required FF.  What if I use the number to bool array, set the bit, then convert back?
 
Any suggestions?
Thanks!
0 Kudos
Message 1 of 2
(3,786 Views)

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.

0 Kudos
Message 2 of 2
(3,780 Views)