Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to determine the relevent msb bit in a 32 bit stream

Status
Not open for further replies.

Ashish Agrawal

Member level 3
Joined
Mar 24, 2015
Messages
60
Helped
8
Reputation
16
Reaction score
8
Trophy points
8
Activity points
502
Hi
I have a 32 bit stream. However only some of the bits are used.
For example in 0000_0000_0000_0000_0000_0000_0000_1010 only last 4 bits are relevent. So relevent msb is 3.

I have to write a synthesizable verilog code to determine the relevent msb.

Thanks in advance.
 

Such a circuit is called a "priority encoder". If it is a school homework, try to solve it yourself before searching for the solution.
 

I have a 32 bit stream. However only some of the bits are used.
For example in 0000_0000_0000_0000_0000_0000_0000_1010 only last 4 bits are relevent. So relevent msb is 3.

Hint: log2(x)
 

Hint: log2(x)

A log2 function is normally used to determine the number of bits needed to represent a number, and it is often not suitable for synthesis.

The OP asks for synthesizable code. "Priority encoder" circuits are normally synthesizable.
 

A log2 function is normally used to determine the number of bits needed to represent a number, and it is often not suitable for synthesis.

The OP asks for synthesizable code. "Priority encoder" circuits are normally synthesizable.

log2 is synthesizable as well, and not just for computing constants. Maybe you should take another look at the code for log2 and re-evaluate your statement that log2 is 'often not suitable for synthesis'. In fact, look at it to say in what way log2 even differs from a priority encoder.

For a single clock cycle input to output delay, Quartus 14.0, targeting a Cyclone IV GX, registering the inputs and outputs surrounding the call to the log2 function (in order to produce a meaningful Fmax for comparison) produces the following results:
31 bits => 252 LE 32.86 MHz
30 bits => 247 LE 35.12 MHz
29 bits => 231 LE 365.65 MHz
16 bits => 38 LE 225.78 MHz
12 bits => 18 LE 550.36 MHz
8 bits => 11 LE 728.86 MHz

I suspect that 'priority encoder' should produce similar results but will leave that for you to produce.

Kevin Jennings
 
Last edited:

log2 is synthesizable as well, and not just for computing constants. Maybe you should take another look at the code for log2 and re-evaluate your statement that log2 is 'often not suitable for synthesis'. In fact, look at it to say in what way log2 even differs from a priority encoder.
I now see that the original request was for verilog code. I live in the VHDL world, and the only standardized log2 function is in the non-synthesizable math_real package.

I agree that a log2 function and a "priority encoder" have the same function.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top