1-- This -*- vhdl -*- file is part of GHDL. 2-- IEEE 1076.3 compliant numeric std package. 3-- Copyright (C) 2015 Tristan Gingold 4-- 5-- This program is free software: you can redistribute it and/or modify 6-- it under the terms of the GNU General Public License as published by 7-- the Free Software Foundation, either version 2 of the License, or 8-- (at your option) any later version. 9-- 10-- This program is distributed in the hope that it will be useful, 11-- but WITHOUT ANY WARRANTY; without even the implied warranty of 12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13-- GNU General Public License for more details. 14-- 15-- You should have received a copy of the GNU General Public License 16-- along with this program. If not, see <gnu.org/licenses>. 17 18library IEEE; 19use IEEE.STD_LOGIC_1164.all; 20 21package NUMERIC_STD is 22 type UNSIGNED is array (natural range <>) of STD_LOGIC; 23 type SIGNED is array (natural range <>) of STD_LOGIC; 24 25 function TO_01 (S : SIGNED; XMAP : STD_LOGIC := '0') return SIGNED; 26 function TO_01 (S : UNSIGNED; XMAP : STD_LOGIC := '0') return UNSIGNED; 27 -- Convert 'H' and '1' to '1', 'L' and '0' to '0'. 28 -- If any other value is present, return (others => XMAP) 29 -- Issue a warning in that case, and if S is a null array. 30 -- Result index range is S'Length - 1 downto 0. 31 32 function std_match (l, r : std_ulogic) return boolean; 33 function std_match (l, r : std_ulogic_vector) return boolean; 34 function std_match (l, r : std_logic_vector) return boolean; 35 function std_match (l, r : UNSIGNED) return boolean; 36 function std_match (l, r : SIGNED) return boolean; 37 -- Return True iff L and R matches. 38 39 40 function TO_INTEGER (ARG : UNSIGNED) return NATURAL; 41 function TO_INTEGER (ARG : SIGNED) return INTEGER; 42 -- Convert ARG to an integer. 43 -- Simulation is aborted in case of overflow. 44 -- Issue a warning in case of non-logical value. 45 46 function TO_UNSIGNED (ARG, SIZE : NATURAL) return UNSIGNED; 47 -- Convert ARG to unsigned. 48 -- Result index range is SIZE - 1 downto 0. 49 -- Issue a warning if value is truncated. 50 51 function TO_SIGNED (ARG : INTEGER; SIZE : NATURAL) return SIGNED; 52 -- Convert ARG to signed. 53 -- Result index range is SIZE - 1 downto 0. 54 -- Issue a warning if value is truncated. 55 56 function resize (ARG : UNSIGNED; NEW_SIZE: natural) return UNSIGNED; 57 function resize (ARG : SIGNED; NEW_SIZE: natural) return SIGNED; 58 -- Result index range is NEW_SIZE - 1 downto 0 (unless null array). 59 -- For SIGNED, the sign of the result is the sign of ARG. 60 61 function "=" (L, R : UNSIGNED) return BOOLEAN; 62 function "=" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 63 function "=" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 64 function "/=" (L, R : UNSIGNED) return BOOLEAN; 65 function "/=" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 66 function "/=" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 67 function "<" (L, R : UNSIGNED) return BOOLEAN; 68 function "<" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 69 function "<" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 70 function "<=" (L, R : UNSIGNED) return BOOLEAN; 71 function "<=" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 72 function "<=" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 73 function ">" (L, R : UNSIGNED) return BOOLEAN; 74 function ">" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 75 function ">" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 76 function ">=" (L, R : UNSIGNED) return BOOLEAN; 77 function ">=" (L : UNSIGNED; R : NATURAL) return BOOLEAN; 78 function ">=" (L : NATURAL; R : UNSIGNED) return BOOLEAN; 79 80 function "=" (L, R : SIGNED) return BOOLEAN; 81 function "=" (L : SIGNED; R : INTEGER) return BOOLEAN; 82 function "=" (L : INTEGER; R : SIGNED) return BOOLEAN; 83 function "/=" (L, R : SIGNED) return BOOLEAN; 84 function "/=" (L : SIGNED; R : INTEGER) return BOOLEAN; 85 function "/=" (L : INTEGER; R : SIGNED) return BOOLEAN; 86 function "<" (L, R : SIGNED) return BOOLEAN; 87 function "<" (L : SIGNED; R : INTEGER) return BOOLEAN; 88 function "<" (L : INTEGER; R : SIGNED) return BOOLEAN; 89 function "<=" (L, R : SIGNED) return BOOLEAN; 90 function "<=" (L : SIGNED; R : INTEGER) return BOOLEAN; 91 function "<=" (L : INTEGER; R : SIGNED) return BOOLEAN; 92 function ">" (L, R : SIGNED) return BOOLEAN; 93 function ">" (L : SIGNED; R : INTEGER) return BOOLEAN; 94 function ">" (L : INTEGER; R : SIGNED) return BOOLEAN; 95 function ">=" (L, R : SIGNED) return BOOLEAN; 96 function ">=" (L : SIGNED; R : INTEGER) return BOOLEAN; 97 function ">=" (L : INTEGER; R : SIGNED) return BOOLEAN; 98 -- Issue a warning in case of non-logical value. 99 100 function "-" (ARG : SIGNED) return SIGNED; 101 -- Compute -ARG. 102 -- Result index range is Arg'length - 1 downto 0. 103 104 function "abs" (ARG : SIGNED) return SIGNED; 105 -- Compute abs ARG. 106 -- Result index range is Arg'length - 1 downto 0. 107 108 function "+" (L, R : UNSIGNED) return UNSIGNED; 109 function "+" (L, R : SIGNED) return SIGNED; 110 function "-" (L, R : UNSIGNED) return UNSIGNED; 111 function "-" (L, R : SIGNED) return SIGNED; 112 -- Compute L +/- R. 113 -- Result index range is max (L'Length, R'Length) - 1 downto 0. 114 -- Issue a warning in case of non-logical value. 115 116 function "+" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 117 function "+" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 118 function "+" (L : SIGNED; R : INTEGER) return SIGNED; 119 function "+" (L : INTEGER; R : SIGNED) return SIGNED; 120 function "-" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 121 function "-" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 122 function "-" (L : SIGNED; R : INTEGER) return SIGNED; 123 function "-" (L : INTEGER; R : SIGNED) return SIGNED; 124 -- Compute L +/- R. 125 -- Result index range is V'Length - 1 downto 0, where V is the vector 126 -- parameter. 127 -- Issue a warning in case of non-logical value. 128 -- Issue a warning if value is truncated. 129 130 function "*" (L, R : UNSIGNED) return UNSIGNED; 131 function "*" (L, R : SIGNED) return SIGNED; 132 -- Compute L * R 133 -- Result index range is L'Length + R'Length - 1 downto 0. 134 135 function "*" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 136 function "*" (L : SIGNED; R : INTEGER) return SIGNED; 137 -- Compute L * R 138 -- R is converted to a vector of length L'length 139 140 function "*" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 141 function "*" (L : INTEGER; R : SIGNED) return SIGNED; 142 -- Compute L * R 143 -- L is converted to a vector of length R'length 144 145 function "/" (L, R : UNSIGNED) return UNSIGNED; 146 function "/" (L, R : SIGNED) return SIGNED; 147 function "rem" (L, R : UNSIGNED) return UNSIGNED; 148 function "rem" (L, R : SIGNED) return SIGNED; 149 function "mod" (L, R : UNSIGNED) return UNSIGNED; 150 function "mod" (L, R : SIGNED) return SIGNED; 151 -- Compute L op R 152 -- Result index range is L'Length - 1 downto 0. 153 -- Issue a warning in case of non-logical value. 154 -- Issue an error if R is 0. 155 156 function "/" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 157 function "/" (L : SIGNED; R : INTEGER) return SIGNED; 158 function "rem" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 159 function "rem" (L : SIGNED; R : INTEGER) return SIGNED; 160 function "mod" (L : UNSIGNED; R : NATURAL) return UNSIGNED; 161 function "mod" (L : SIGNED; R : INTEGER) return SIGNED; 162 -- Compute L op R. 163 -- Result index range is L'Length - 1 downto 0. 164 -- Issue a warning in case of non-logical value. 165 -- Issue an error if R is 0. 166 167 function "/" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 168 function "/" (L : INTEGER; R : SIGNED) return SIGNED; 169 function "rem" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 170 function "rem" (L : INTEGER; R : SIGNED) return SIGNED; 171 function "mod" (L : NATURAL; R : UNSIGNED) return UNSIGNED; 172 function "mod" (L : INTEGER; R : SIGNED) return SIGNED; 173 -- Compute L op R. 174 -- Result index range is R'Length - 1 downto 0. 175 -- Issue a warning in case of non-logical value. 176 -- Issue an error if R is 0. 177 -- Result may be truncated. 178 179 function "not" (l : UNSIGNED) return UNSIGNED; 180 function "not" (l : SIGNED) return SIGNED; 181 function "and" (l, r : UNSIGNED) return UNSIGNED; 182 function "and" (l, r : SIGNED) return SIGNED; 183 function "nand" (l, r : UNSIGNED) return UNSIGNED; 184 function "nand" (l, r : SIGNED) return SIGNED; 185 function "or" (l, r : UNSIGNED) return UNSIGNED; 186 function "or" (l, r : SIGNED) return SIGNED; 187 function "nor" (l, r : UNSIGNED) return UNSIGNED; 188 function "nor" (l, r : SIGNED) return SIGNED; 189 function "xor" (l, r : UNSIGNED) return UNSIGNED; 190 function "xor" (l, r : SIGNED) return SIGNED; 191 function "xnor" (l, r : UNSIGNED) return UNSIGNED; 192 function "xnor" (l, r : SIGNED) return SIGNED; 193 -- Compute L OP R. 194 -- Result index range is L'Length - 1 downto 0. 195 -- No specific handling of null array: the index range of the result 196 -- would be -1 downto 0 (without warning). This it not what is specified 197 -- in 1076.3, but corresponds to the standard implementation. 198 -- No specific handling of non-logical values. Behaviour is compatible 199 -- with std_logic_1164. 200 201 function shift_left (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED; 202 function shift_left (ARG : SIGNED; COUNT: NATURAL) return SIGNED; 203 function shift_right (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED; 204 function shift_right (ARG : SIGNED; COUNT: NATURAL) return SIGNED; 205 -- Result index range is ARG'Length - 1 downto 0. 206 207 function rotate_left (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED; 208 function rotate_left (ARG : SIGNED; COUNT: NATURAL) return SIGNED; 209 function rotate_right (ARG : UNSIGNED; COUNT: NATURAL) return UNSIGNED; 210 function rotate_right (ARG : SIGNED; COUNT: NATURAL) return SIGNED; 211 -- Result index range is ARG'Length - 1 downto 0. 212 213 function "sll" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED; 214 function "sll" (ARG : SIGNED; COUNT: INTEGER) return SIGNED; 215 function "srl" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED; 216 function "srl" (ARG : SIGNED; COUNT: INTEGER) return SIGNED; 217 -- Result index range is ARG'Length - 1 downto 0. 218 219 function "rol" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED; 220 function "rol" (ARG : SIGNED; COUNT: INTEGER) return SIGNED; 221 function "ror" (ARG : UNSIGNED; COUNT: INTEGER) return UNSIGNED; 222 function "ror" (ARG : SIGNED; COUNT: INTEGER) return SIGNED; 223 -- Result index range is ARG'Length - 1 downto 0. 224end NUMERIC_STD; 225