Browse Source

Add functions count_ones() & xor_reduce

New functions added:

  * count_ones(): returns number of 1 in a given std_logic_vector
  * xor_reduce(): returns the xor of all bits in a std_logic_vector

Functions even_parity() & odd_parity() now use the xor_reduce function
to calc the parity.
pull/1/head
T. Meissner 9 years ago
parent
commit
7b1f2f071f
1 changed files with 21 additions and 6 deletions
  1. +21
    -6
      common/UtilsP.vhd

+ 21
- 6
common/UtilsP.vhd View File

@ -13,9 +13,13 @@ package UtilsP is
function or_reduce (data : in std_logic_vector) return std_logic;
function or_reduce (data : in boolean_vector) return boolean;
function xor_reduce (data : in std_logic_vector) return std_logic;
function even_parity (data : in std_logic_vector) return std_logic;
function odd_parity (data : in std_logic_vector) return std_logic;
function count_ones (data : in std_logic_vector) return natural;
end package UtilsP;
@ -66,23 +70,34 @@ package body UtilsP is
end function or_reduce;
function even_parity (data : in std_logic_vector) return std_logic is
function xor_reduce (data : in std_logic_vector) return std_logic is
variable v_return : std_logic := '0';
begin
for i in data'range loop
for i in data'range loop
v_return := v_return xor data(i);
end loop;
return v_return;
end function xor_reduce;
function even_parity (data : in std_logic_vector) return std_logic is
begin
return xor_reduce(data);
end function even_parity;
function odd_parity (data : in std_logic_vector) return std_logic is
variable v_return : std_logic := '1';
begin
return not(xor_reduce(data));
end function odd_parity;
function count_ones (data : in std_logic_vector) return natural is
variable v_return : natural := 0;
begin
for i in data'range loop
v_return := v_return xor data(i);
v_return := v_return + 1;
end loop;
return v_return;
end function odd_parity;
end function count_ones;
end package body UtilsP;

Loading…
Cancel
Save