determining of the position of the MSB

  • Thread starter =?ISO-8859-1?Q?Johan_Bernsp=E5ng?=
  • Start date
J

Jonathan Bromley

Hi.

Jonathan Bromley wrote:
[...]
My delight in recursive
solutions is showing itself again :)

That's a nice solution, but probably the second best one. The problem is
that you'll have to get the thermometer code first. But you can also
process the original operand directly:

function findmsb (X : in std_ulogic_vector) return std_ulogic_vector is
constant N : natural := X'length; -- assume it's a power of two
constant xx : std_ulogic_vector(N-1 downto 0);
begin
xx := to_X01(X); -- convert to something more useful
if N = 2 then
return xx(1 downto 1);
elsif xx(N-1 downto N/2) = (N-1 downto N/2 => '0') then

I already posted essentially this solution in response to the
original poster on this thread. I agree that it's nice.
However, in Xilinx and Altera FPGAs I suspect that it may be
less attractive than the thermometer code version, because
you can very easily construct a thermometer code using the
carry chain (if you're prepared to instantiate the MUXCYs
by hand, as others have noted).
The only
drawback is that a zero operand and an operand with only the LSB set
will have the same result (others => '0'). But you can change that by
adding another MUX at the output:

Or by concatenating an extra redundant bit whose value is 1.

Fun stuff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top