aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/exit01/exit02.vhdl
blob: 17895dce9182e245d1701ad0564d4e96a0f13116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library ieee;
use ieee.std_logic_1164.all;

entity exit02 is
  port (val : std_logic_vector (3 downto 0);
        res : out integer);
end exit02;

architecture behav of exit02 is
  function ffs (v : std_logic_vector (3 downto 0)) return natural
  is
    variable r : natural;
  begin
    r := 4;
    for i in v'reverse_range loop
      if v (i) = '1' then
        r := i;
        exit;
      end if;
    end loop;
    return r;
  end ffs;
begin
  res <= ffs (val);
end behav;