# How best to implement search function in Verilog? - verilog

This is a discussion on How best to implement search function in Verilog? - verilog ; An irregular array contains a[32] = {0, 3, 10, 17, 33, ..., 1000}, find the location my data is. For example, if data is between 0~3, result = 1, between 3~10, result = 2, etc. Do I write 64 comparators ...

1. ## How best to implement search function in Verilog?

An irregular array contains a[32] = {0, 3, 10, 17, 33, ..., 1000}, find the
location my data is.
For example, if data is between 0~3, result = 1, between 3~10, result = 2,
etc.

Do I write 64 comparators to find out the result (assuming single cycle
operation).

Thanks.

2. ## Re: How best to implement search function in Verilog?

Mr. Ken wrote:
> An irregular array contains a[32] = {0, 3, 10, 17, 33, ..., 1000}, find the
> location my data is.
> For example, if data is between 0~3, result = 1, between 3~10, result = 2,
> etc.
>
> Do I write 64 comparators to find out the result (assuming single cycle
> operation).
>
> Thanks.

Nobody will do your homework, but I will give you a small tip:

Your array has members which are ordered.
Each search iteration can be done in one cycle.

If yes, then you don't need 64 comparators (why 64?).
Instead, you will need just ....
The rest of exercise goes to your assignment.

Have you ever heard "binary search"?

Utku.

3. ## Re: How best to implement search function in Verilog?

Sorry I haven't read the sentence with "one cycle".
One cycle search is technically an overkill.

You must increase the number of clock cycles to pay less for silicon.

Utku.

utku.ozcan@gmail.com wrote:
> Mr. Ken wrote:
> > An irregular array contains a[32] = {0, 3, 10, 17, 33, ..., 1000}, find the
> > location my data is.
> > For example, if data is between 0~3, result = 1, between 3~10, result = 2,
> > etc.
> >
> > Do I write 64 comparators to find out the result (assuming single cycle
> > operation).
> >
> > Thanks.

>
> Nobody will do your homework, but I will give you a small tip:
>
> Your array has members which are ordered.
> Each search iteration can be done in one cycle.
>
> If yes, then you don't need 64 comparators (why 64?).
> Instead, you will need just ....
> The rest of exercise goes to your assignment.
>
> Have you ever heard "binary search"?
>
> Utku.

4. ## Re: How best to implement search function in Verilog?

<utku.ozcan@gmail.com> wrote in message
>
> Sorry I haven't read the sentence with "one cycle".
> One cycle search is technically an overkill.
>
> You must increase the number of clock cycles to pay less for silicon.
>
> Utku.
>

Yeah Utku.
If I am not wrong, binary search takes 5 stages of comparator right? I bet
that could well fit into
one clock cycle since my clock speed is a slow 20MHz, but maybe i will use 5
cycles anyhow.

5. ## Re: How best to implement search function in Verilog?

> Yeah Utku.
> If I am not wrong, binary search takes 5 stages of comparator right? I bet
> that could well fit into
> one clock cycle since my clock speed is a slow 20MHz, but maybe i will use 5
> cycles anyhow.

To find what you searching in one clock cycle, you have to compare
everything in one clock. That means you must access ALL the address in
the table. This is not a very good design practice I think, even though
you run the thing in 20 MHz.

Utku.

6. ## Re: How best to implement search function in Verilog?

Massive parallel comparison of data in single cycle is possible through
CAM design.
You could possible look at this option.

--josh

Mr. Ken wrote:
> An irregular array contains a[32] = {0, 3, 10, 17, 33, ..., 1000}, find the
> location my data is.
> For example, if data is between 0~3, result = 1, between 3~10, result = 2,
> etc.
>
> Do I write 64 comparators to find out the result (assuming single cycle
> operation).
>
> Thanks.