Cleanup ffs/fls_32/64 functions

This just cleans up the code a bit. No functional change.

Signed-off-by: Michael Neuling <mikey@neuling.org>
pull/37/head
Michael Neuling 6 years ago
parent 5ae92a721f
commit 21cf70e2ef

@ -29,59 +29,47 @@ end package helpers;


package body helpers is package body helpers is
function fls_32 (val: std_ulogic_vector(31 downto 0)) return integer is function fls_32 (val: std_ulogic_vector(31 downto 0)) return integer is
variable ret: integer;
begin begin
ret := 32;
for i in val'range loop for i in val'range loop
if val(i) = '1' then if val(i) = '1' then
ret := 31 - i; return 31 - i;
exit;
end if; end if;
end loop; end loop;


return ret; return 32;
end; end;


function ffs_32 (val: std_ulogic_vector(31 downto 0)) return integer is function ffs_32 (val: std_ulogic_vector(31 downto 0)) return integer is
variable ret: integer;
begin begin
ret := 32;
for i in val'reverse_range loop for i in val'reverse_range loop
if val(i) = '1' then if val(i) = '1' then
ret := i; return i;
exit;
end if; end if;
end loop; end loop;


return ret; return 32;
end; end;


function fls_64 (val: std_ulogic_vector(63 downto 0)) return integer is function fls_64 (val: std_ulogic_vector(63 downto 0)) return integer is
variable ret: integer;
begin begin
ret := 64;
for i in val'range loop for i in val'range loop
if val(i) = '1' then if val(i) = '1' then
ret := 63 - i; return 63 - i;
exit;
end if; end if;
end loop; end loop;


return ret; return 64;
end; end;


function ffs_64 (val: std_ulogic_vector(63 downto 0)) return integer is function ffs_64 (val: std_ulogic_vector(63 downto 0)) return integer is
variable ret: integer;
begin begin
ret := 64;
for i in val'reverse_range loop for i in val'reverse_range loop
if val(i) = '1' then if val(i) = '1' then
ret := i; return i;
exit;
end if; end if;
end loop; end loop;


return ret; return 64;
end; end;


function popcnt8(val: std_ulogic_vector(7 downto 0)) return std_ulogic_vector is function popcnt8(val: std_ulogic_vector(7 downto 0)) return std_ulogic_vector is

Loading…
Cancel
Save