Skip to content
Snippets Groups Projects
Commit 4f088081 authored by Daniel van der Schuur's avatar Daniel van der Schuur
Browse files

-Added function vector_one_hot.

parent 9375a951
No related branches found
No related tags found
No related merge requests found
...@@ -188,6 +188,7 @@ PACKAGE common_pkg IS ...@@ -188,6 +188,7 @@ PACKAGE common_pkg IS
FUNCTION vector_and(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '1' when all slv bits are '1' else '0' FUNCTION vector_and(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '1' when all slv bits are '1' else '0'
FUNCTION vector_or( slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '0' when all slv bits are '0' else '1' FUNCTION vector_or( slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '0' when all slv bits are '0' else '1'
FUNCTION vector_xor(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '1' when the slv has an odd number of '1' bits else '0' FUNCTION vector_xor(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- '1' when the slv has an odd number of '1' bits else '0'
FUNCTION vector_one_hot(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR; -- Returns slv when it contains one hot bit, else returns 0.
FUNCTION andv(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- alias of vector_and FUNCTION andv(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- alias of vector_and
FUNCTION orv( slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- alias of vector_or FUNCTION orv( slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC; -- alias of vector_or
...@@ -666,6 +667,25 @@ PACKAGE BODY common_pkg IS ...@@ -666,6 +667,25 @@ PACKAGE BODY common_pkg IS
BEGIN BEGIN
RETURN vector_tree(slv, "XOR"); RETURN vector_tree(slv, "XOR");
END; END;
FUNCTION vector_one_hot(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
VARIABLE v_one_hot : BOOLEAN := FALSE;
VARIABLE v_zeros : STD_LOGIC_VECTOR(slv'RANGE) := (OTHERS=>'0');
BEGIN
FOR i IN slv'RANGE LOOP
IF slv(i) = '1' THEN
IF NOT(v_one_hot) THEN
-- No hot bits found so far
v_one_hot := TRUE;
ELSE
-- This is the second hot bit found; return zeros.
RETURN v_zeros;
END IF;
END IF;
END LOOP;
-- No or a single hot bit found in slv; return slv.
RETURN slv;
END;
FUNCTION andv(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC IS FUNCTION andv(slv : STD_LOGIC_VECTOR) RETURN STD_LOGIC IS
BEGIN BEGIN
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment