diff options
Diffstat (limited to 'libraries/openieee/numeric_bit-body.v93')
-rw-r--r-- | libraries/openieee/numeric_bit-body.v93 | 202 |
1 files changed, 172 insertions, 30 deletions
diff --git a/libraries/openieee/numeric_bit-body.v93 b/libraries/openieee/numeric_bit-body.v93 index ae4d453..869b0d2 100644 --- a/libraries/openieee/numeric_bit-body.v93 +++ b/libraries/openieee/numeric_bit-body.v93 @@ -176,7 +176,7 @@ package body NUMERIC_BIT is end TO_SIGNED; - function "+" (l : UNSIGNED; r : UNSIGNED) return UNSIGNED + function "+" (l, r : UNSIGNED) return UNSIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is UNSIGNED (lft downto 0); @@ -206,7 +206,7 @@ package body NUMERIC_BIT is return res; end "+"; - function "+" (l : SIGNED; r : SIGNED) return SIGNED + function "+" (l, r : SIGNED) return SIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is SIGNED (lft downto 0); @@ -376,7 +376,7 @@ package body NUMERIC_BIT is return res; end "+"; - function "-" (l : UNSIGNED; r : UNSIGNED) return UNSIGNED + function "-" (l, r : UNSIGNED) return UNSIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is UNSIGNED (lft downto 0); @@ -407,7 +407,7 @@ package body NUMERIC_BIT is return res; end "-"; - function "-" (l : SIGNED; r : SIGNED) return SIGNED + function "-" (l, r : SIGNED) return SIGNED is constant lft : integer := MAX (l'length, r'length) - 1; subtype res_type is SIGNED (lft downto 0); @@ -582,7 +582,7 @@ package body NUMERIC_BIT is return res; end "-"; - function "*" (L : UNSIGNED; R : UNSIGNED) return UNSIGNED + function "*" (L, R : UNSIGNED) return UNSIGNED is alias la : UNSIGNED (L'Length - 1 downto 0) is l; alias ra : UNSIGNED (R'Length - 1 downto 0) is r; @@ -616,7 +616,7 @@ package body NUMERIC_BIT is return res; end "*"; - function "*" (L : SIGNED; R : SIGNED) return SIGNED + function "*" (L, R : SIGNED) return SIGNED is alias la : SIGNED (L'Length - 1 downto 0) is l; alias ra : SIGNED (R'Length - 1 downto 0) is r; @@ -781,7 +781,7 @@ package body NUMERIC_BIT is return res; end size_signed; - function "/" (L : UNSIGNED; R : UNSIGNED) return UNSIGNED + function "/" (L, R : UNSIGNED) return UNSIGNED is subtype l_type is UNSIGNED (L'length - 1 downto 0); subtype r_type is UNSIGNED (R'length - 1 downto 0); @@ -821,7 +821,7 @@ package body NUMERIC_BIT is return resize (to_unsigned (l, l_size) / r, r'length); end "/"; - function "rem" (L : UNSIGNED; R : UNSIGNED) return UNSIGNED + function "rem" (L, R : UNSIGNED) return UNSIGNED is subtype l_type is UNSIGNED (L'length - 1 downto 0); subtype r_type is UNSIGNED (R'length - 1 downto 0); @@ -861,7 +861,7 @@ package body NUMERIC_BIT is return to_unsigned (l, l_size) rem r; end "rem"; - function "mod" (L : UNSIGNED; R : UNSIGNED) return UNSIGNED + function "mod" (L, R : UNSIGNED) return UNSIGNED is subtype l_type is UNSIGNED (L'length - 1 downto 0); subtype r_type is UNSIGNED (R'length - 1 downto 0); @@ -952,7 +952,7 @@ package body NUMERIC_BIT is return res; end "abs"; - function "/" (L : SIGNED; R : SIGNED) return SIGNED + function "/" (L, R : SIGNED) return SIGNED is subtype l_type is SIGNED (L'length - 1 downto 0); subtype r_type is SIGNED (R'length - 1 downto 0); @@ -1010,7 +1010,7 @@ package body NUMERIC_BIT is return resize (to_signed (l, max (l_size, r'length)) / r, r'length); end "/"; - function "rem" (L : SIGNED; R : SIGNED) return SIGNED + function "rem" (L, R : SIGNED) return SIGNED is subtype l_type is SIGNED (L'length - 1 downto 0); subtype r_type is SIGNED (R'length - 1 downto 0); @@ -1069,7 +1069,7 @@ package body NUMERIC_BIT is return to_signed (l, l_size) rem r; end "rem"; - function "mod" (L : SIGNED; R : SIGNED) return SIGNED + function "mod" (L, R : SIGNED) return SIGNED is subtype l_type is SIGNED (L'length - 1 downto 0); subtype r_type is SIGNED (R'length - 1 downto 0); @@ -1450,7 +1450,7 @@ package body NUMERIC_BIT is return res; end "xnor"; - function ucompare (l : UNSIGNED; r : UNSIGNED) return compare_type + function ucompare (l, r : UNSIGNED) return compare_type is constant sz : integer := MAX (l'length, r'length) - 1; alias la : UNSIGNED (l'length - 1 downto 0) is l; @@ -1480,7 +1480,7 @@ package body NUMERIC_BIT is return res; end ucompare; - function scompare (l : SIGNED; r : SIGNED) return compare_type + function scompare (l, r : SIGNED) return compare_type is constant sz : integer := MAX (l'length, r'length) - 1; alias la : SIGNED (l'length - 1 downto 0) is l; @@ -1589,7 +1589,7 @@ package body NUMERIC_BIT is return res; end scompare; - function "=" (l : UNSIGNED; r : UNSIGNED) return boolean + function "=" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -1604,7 +1604,7 @@ package body NUMERIC_BIT is return res = compare_eq; end "="; - function "=" (l : SIGNED; r : SIGNED) return boolean + function "=" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -1697,7 +1697,7 @@ package body NUMERIC_BIT is return compare_eq = res; end "="; - function "/=" (l : UNSIGNED; r : UNSIGNED) return boolean + function "/=" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -1712,7 +1712,7 @@ package body NUMERIC_BIT is return res /= compare_eq; end "/="; - function "/=" (l : SIGNED; r : SIGNED) return boolean + function "/=" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -1805,7 +1805,7 @@ package body NUMERIC_BIT is return compare_eq /= res; end "/="; - function ">" (l : UNSIGNED; r : UNSIGNED) return boolean + function ">" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -1820,7 +1820,7 @@ package body NUMERIC_BIT is return res > compare_eq; end ">"; - function ">" (l : SIGNED; r : SIGNED) return boolean + function ">" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -1913,7 +1913,7 @@ package body NUMERIC_BIT is return compare_eq > res; end ">"; - function ">=" (l : UNSIGNED; r : UNSIGNED) return boolean + function ">=" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -1928,7 +1928,7 @@ package body NUMERIC_BIT is return res >= compare_eq; end ">="; - function ">=" (l : SIGNED; r : SIGNED) return boolean + function ">=" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -2021,7 +2021,7 @@ package body NUMERIC_BIT is return compare_eq >= res; end ">="; - function "<" (l : UNSIGNED; r : UNSIGNED) return boolean + function "<" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -2036,7 +2036,7 @@ package body NUMERIC_BIT is return res < compare_eq; end "<"; - function "<" (l : SIGNED; r : SIGNED) return boolean + function "<" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -2129,7 +2129,7 @@ package body NUMERIC_BIT is return compare_eq < res; end "<"; - function "<=" (l : UNSIGNED; r : UNSIGNED) return boolean + function "<=" (l, r : UNSIGNED) return boolean is variable res : compare_type; begin @@ -2144,7 +2144,7 @@ package body NUMERIC_BIT is return res <= compare_eq; end "<="; - function "<=" (l : SIGNED; r : SIGNED) return boolean + function "<=" (l, r : SIGNED) return boolean is variable res : compare_type; begin @@ -2267,7 +2267,7 @@ package body NUMERIC_BIT is return res; end shift_right; - function rotate_left (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED + function rotate_left (ARG : UNSIGNED; COUNT: natural) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; @@ -2283,7 +2283,7 @@ package body NUMERIC_BIT is return res; end rotate_left; - function rotate_right (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED + function rotate_right (ARG : UNSIGNED; COUNT: natural) return UNSIGNED is subtype res_type is UNSIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; @@ -2299,6 +2299,72 @@ package body NUMERIC_BIT is return res; end rotate_right; + function "sll" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED + is + subtype res_type is UNSIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + begin + if res'length = 0 then + return null_UNSIGNED; + end if; + if count >= 0 and count <= arg1'left then + res (res'left downto count) := arg1 (arg1'left - count downto 0); + elsif count < 0 and count >= -arg1'left then + res (res'left + count downto 0) := arg1 (arg1'left downto -count); + end if; + return res; + end "sll"; + + function "srl" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED + is + subtype res_type is UNSIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + begin + if res'length = 0 then + return null_UNSIGNED; + end if; + if count >= 0 and count <= arg1'left then + res (res'left - count downto 0) := arg1 (arg1'left downto count); + elsif count < 0 and count >= -arg1'left then + res (res'left downto -count) := arg1 (arg1'left + count downto 0); + end if; + return res; + end "srl"; + + function "rol" (ARG : UNSIGNED; COUNT: integer) return UNSIGNED + is + subtype res_type is UNSIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + variable cnt : natural; + begin + if res'length = 0 then + return null_UNSIGNED; + end if; + cnt := count mod res'length; + res (res'left downto cnt) := arg1 (res'left - cnt downto 0); + res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); + return res; + end "rol"; + + function "ror" (ARG : UNSIGNED; COUNT: integer) return UNSIGNED + is + subtype res_type is UNSIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + variable cnt : natural; + begin + if res'length = 0 then + return null_UNSIGNED; + end if; + cnt := count mod res'length; + res (res'left - cnt downto 0) := arg1 (res'left downto cnt); + res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); + return res; + end "ror"; + function shift_left (ARG : SIGNED; COUNT: NATURAL) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); @@ -2329,7 +2395,7 @@ package body NUMERIC_BIT is return res; end shift_right; - function rotate_left (ARG : SIGNED; COUNT: NATURAL) return SIGNED + function rotate_left (ARG : SIGNED; COUNT: natural) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; @@ -2345,7 +2411,7 @@ package body NUMERIC_BIT is return res; end rotate_left; - function rotate_right (ARG : SIGNED; COUNT: NATURAL) return SIGNED + function rotate_right (ARG : SIGNED; COUNT: natural) return SIGNED is subtype res_type is SIGNED (ARG'length - 1 downto 0); alias arg1 : res_type is arg; @@ -2360,4 +2426,80 @@ package body NUMERIC_BIT is res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); return res; end rotate_right; + + function "sll" (ARG : SIGNED; COUNT: INTEGER) return SIGNED + is + subtype res_type is SIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + begin + if res'length = 0 then + return null_SIGNED; + end if; + if count >= 0 and count <= arg1'left then + res (res'left downto count) := arg1 (arg1'left - count downto 0); + elsif count < 0 and count >= -arg1'left then + res (res'left + count downto 0) := arg1 (arg1'left downto -count); + end if; + return res; + end "sll"; + + function "srl" (ARG : SIGNED; COUNT: INTEGER) return SIGNED + is + subtype res_type is SIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + begin + if res'length = 0 then + return null_SIGNED; + end if; + if count >= 0 and count <= arg1'left then + res (res'left - count downto 0) := arg1 (arg1'left downto count); + elsif count < 0 and count >= -arg1'left then + res (res'left downto -count) := arg1 (arg1'left + count downto 0); + end if; + return res; + end "srl"; + + function "rol" (ARG : SIGNED; COUNT: integer) return SIGNED + is + subtype res_type is SIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + variable cnt : natural; + begin + if res'length = 0 then + return null_SIGNED; + end if; + cnt := count mod res'length; + res (res'left downto cnt) := arg1 (res'left - cnt downto 0); + res (cnt - 1 downto 0) := arg1 (res'left downto res'left - cnt + 1); + return res; + end "rol"; + + function "ror" (ARG : SIGNED; COUNT: integer) return SIGNED + is + subtype res_type is SIGNED (ARG'length - 1 downto 0); + alias arg1 : res_type is arg; + variable res : res_type := (others => '0'); + variable cnt : natural; + begin + if res'length = 0 then + return null_SIGNED; + end if; + cnt := count mod res'length; + res (res'left - cnt downto 0) := arg1 (res'left downto cnt); + res (res'left downto res'left - cnt + 1) := arg1 (cnt - 1 downto 0); + return res; + end "ror"; + + function rising_edge (signal s : bit) return boolean is + begin + return s'event and s = '1'; + end rising_edge; + + function falling_edge (signal s : bit) return boolean is + begin + return s'event and s = '0'; + end falling_edge; end NUMERIC_BIT; |