FPGA Groups (http://www.fpgacentral.com/group/index.php)
-   FPGA (http://www.fpgacentral.com/group/forumdisplay.php?f=14)
-   -   How to get first bit '0' position in certain register? (http://www.fpgacentral.com/group/showthread.php?t=51026)

 Newhand 12-25-2003 04:15 PM

How to get first bit '0' position in certain register?

Dear all,

For certain register, say stream = 16'b1111010011111111;
the position of first bit '0' is: 8 (from LSB);
if stream = 16'b1111000100010011, then the position is 2;

what I need is to get the position.

Since it should be done in one clock cycle, combination logic in
Verilog might be a better choice.

Could anybody give me some pieces of suggestion? Thanks in advance.

Newhand

 Robert Sefton 12-25-2003 04:58 PM

Re: How to get first bit '0' position in certain register?

This function is called "find first one" and is fairly common. You could
use a for loop or if-else construct in Verilog. Try Googling on "find
first one" - you may find something you can use.

Robert

"Newhand" <[email protected]> wrote in message
news:[email protected] om...
> Dear all,
>
> For certain register, say stream = 16'b1111010011111111;
> the position of first bit '0' is: 8 (from LSB);
> if stream = 16'b1111000100010011, then the position is 2;
>
> what I need is to get the position.
>
> Since it should be done in one clock cycle, combination logic in
> Verilog might be a better choice.
>
> Could anybody give me some pieces of suggestion? Thanks in advance.
>
> Newhand

 Hal Murray 12-25-2003 07:59 PM

Re: How to get first bit '0' position in certain register?

>This function is called "find first one" and is fairly common. You could
>use a for loop or if-else construct in Verilog. Try Googling on "find
>first one" - you may find something you can use.

Another term to search on is priority encoder.

--
The suespammers.org mail server is located in California. So are all my
other mailboxes. Please do not send unsolicited bulk e-mail or unsolicited
commercial e-mail to my suespammers.org address or any of my other addresses.
These are my opinions, not necessarily my employer's. I hate spam.

 Peter Alfke 12-26-2003 06:48 AM

Re: How to get first bit '0' position in certain register?

[email protected] (Hal Murray) wrote in message news:<[email protected]>...
> >This function is called "find first one" and is fairly common. You could
> >use a for loop or if-else construct in Verilog. Try Googling on "find
> >first one" - you may find something you can use.

>
> Another term to search on is priority encoder.

If you can restrict your search to the first 24 bits, and if you have
a Virtex-II BlockRAM available, you can feed the upper 12 bits as
address to one port, and the lower 12 bits as address to the other
port, and make the BlockRAM give you the 4-bit position information
within the 12 address bits. You then have to combine the two port
outputs. You can get the answer in one clock cycle (faster than all
the suggested software solutions) at well over 100 MHz,
ocnservatively.

Peter Alfke, Xilinx Applications (answering from home)
Merry Christmas to everybody on this newsgroup, and an interesting and
interactive 2004!

 All times are GMT +1. The time now is 05:08 AM.