1-- ----------------------------------------------------------------- 2-- 3-- Copyright 2019 IEEE P1076 WG Authors 4-- 5-- See the LICENSE file distributed with this work for copyright and 6-- licensing information and the AUTHORS file. 7-- 8-- This file to you under the Apache License, Version 2.0 (the "License"). 9-- You may obtain a copy of the License at 10-- 11-- http://www.apache.org/licenses/LICENSE-2.0 12-- 13-- Unless required by applicable law or agreed to in writing, software 14-- distributed under the License is distributed on an "AS IS" BASIS, 15-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 16-- implied. See the License for the specific language governing 17-- permissions and limitations under the License. 18-- 19-- Title : Fixed-point package (Generic package declaration) 20-- : 21-- Library : This package shall be compiled into a library 22-- : symbolically named IEEE. 23-- : 24-- Developers: Accellera VHDL-TC and IEEE P1076 Working Group 25-- : 26-- Purpose : This packages defines basic binary fixed point 27-- : arithmetic functions 28-- : 29-- Note : This package may be modified to include additional data 30-- : required by tools, but it must in no way change the 31-- : external interfaces or simulation behavior of the 32-- : description. It is permissible to add comments and/or 33-- : attributes to the package declarations, but not to change 34-- : or delete any original lines of the package declaration. 35-- : The package body may be changed only in accordance with 36-- : the terms of Clause 16 of this standard. 37-- : 38-- -------------------------------------------------------------------- 39-- $Revision: 1220 $ 40-- $Date: 2008-04-10 17:16:09 +0930 (Thu, 10 Apr 2008) $ 41-- -------------------------------------------------------------------- 42 43use STD.TEXTIO.all; 44library IEEE; 45use IEEE.STD_LOGIC_1164.all; 46use IEEE.NUMERIC_STD.all; 47use IEEE.fixed_float_types.all; 48 49package fixed_generic_pkg is 50 generic ( 51 -- Rounding routine to use in fixed point, fixed_round or fixed_truncate 52 fixed_round_style : fixed_round_style_type := fixed_round; 53 -- Overflow routine to use in fixed point, fixed_saturate or fixed_wrap 54 fixed_overflow_style : fixed_overflow_style_type := fixed_saturate; 55 -- Extra bits used in divide routines 56 fixed_guard_bits : NATURAL := 3; 57 -- If TRUE, then turn off warnings on "X" propagation 58 no_warning : BOOLEAN := false 59 ); 60 61 -- Author David Bishop (dbishop@vhdl.org) 62 constant CopyRightNotice : STRING := 63 "Copyright IEEE P1076 WG. Licensed Apache 2.0"; 64 65 -- base Unsigned fixed point type, downto direction assumed 66 type UNRESOLVED_ufixed is array (INTEGER range <>) of STD_ULOGIC; 67 -- base Signed fixed point type, downto direction assumed 68 type UNRESOLVED_sfixed is array (INTEGER range <>) of STD_ULOGIC; 69 70 alias U_ufixed is UNRESOLVED_ufixed; 71 alias U_sfixed is UNRESOLVED_sfixed; 72 73 subtype ufixed is (resolved) UNRESOLVED_ufixed; 74 subtype sfixed is (resolved) UNRESOLVED_sfixed; 75 76 --=========================================================================== 77 -- Arithmetic Operators: 78 --=========================================================================== 79 80 -- Absolute value, 2's complement 81 -- abs sfixed(a downto b) = sfixed(a+1 downto b) 82 function "abs" (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 83 84 -- Negation, 2's complement 85 -- - sfixed(a downto b) = sfixed(a+1 downto b) 86 function "-" (arg : UNRESOLVED_sfixed)return UNRESOLVED_sfixed; 87 88 -- Addition 89 -- ufixed(a downto b) + ufixed(c downto d) 90 -- = ufixed(maximum(a,c)+1 downto minimum(b,d)) 91 function "+" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 92 93 -- sfixed(a downto b) + sfixed(c downto d) 94 -- = sfixed(maximum(a,c)+1 downto minimum(b,d)) 95 function "+" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 96 97 -- Subtraction 98 -- ufixed(a downto b) - ufixed(c downto d) 99 -- = ufixed(maximum(a,c)+1 downto minimum(b,d)) 100 function "-" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 101 102 -- sfixed(a downto b) - sfixed(c downto d) 103 -- = sfixed(maximum(a,c)+1 downto minimum(b,d)) 104 function "-" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 105 106 -- Multiplication 107 -- ufixed(a downto b) * ufixed(c downto d) = ufixed(a+c+1 downto b+d) 108 function "*" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 109 110 -- sfixed(a downto b) * sfixed(c downto d) = sfixed(a+c+1 downto b+d) 111 function "*" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 112 113 -- Division 114 -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1) 115 function "/" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 116 117 -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c) 118 function "/" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 119 120 -- Remainder 121 -- ufixed (a downto b) rem ufixed (c downto d) 122 -- = ufixed (minimum(a,c) downto minimum(b,d)) 123 function "rem" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 124 125 -- sfixed (a downto b) rem sfixed (c downto d) 126 -- = sfixed (minimum(a,c) downto minimum(b,d)) 127 function "rem" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 128 129 -- Modulo 130 -- ufixed (a downto b) mod ufixed (c downto d) 131 -- = ufixed (minimum(a,c) downto minimum(b, d)) 132 function "mod" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 133 134 -- sfixed (a downto b) mod sfixed (c downto d) 135 -- = sfixed (c downto minimum(b, d)) 136 function "mod" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 137 138 ---------------------------------------------------------------------------- 139 -- In these routines the "real" or "natural" (integer) 140 -- are converted into a fixed point number and then the operation is 141 -- performed. It is assumed that the array will be large enough. 142 -- If the input is "real" then the real number is converted into a fixed of 143 -- the same size as the fixed point input. If the number is an "integer" 144 -- then it is converted into fixed with the range (l'high downto 0). 145 ---------------------------------------------------------------------------- 146 147 -- ufixed(a downto b) + ufixed(a downto b) = ufixed(a+1 downto b) 148 function "+" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 149 150 -- ufixed(c downto d) + ufixed(c downto d) = ufixed(c+1 downto d) 151 function "+" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 152 153 -- ufixed(a downto b) + ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b)) 154 function "+" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 155 156 -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d)) 157 function "+" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 158 159 -- ufixed(a downto b) - ufixed(a downto b) = ufixed(a+1 downto b) 160 function "-" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 161 162 -- ufixed(c downto d) - ufixed(c downto d) = ufixed(c+1 downto d) 163 function "-" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 164 165 -- ufixed(a downto b) - ufixed(a downto 0) = ufixed(a+1 downto minimum(0,b)) 166 function "-" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 167 168 -- ufixed(a downto 0) + ufixed(c downto d) = ufixed(c+1 downto minimum(0,d)) 169 function "-" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 170 171 -- ufixed(a downto b) * ufixed(a downto b) = ufixed(2a+1 downto 2b) 172 function "*" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 173 174 -- ufixed(c downto d) * ufixed(c downto d) = ufixed(2c+1 downto 2d) 175 function "*" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 176 177 -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b) 178 function "*" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 179 180 -- ufixed (a downto b) * ufixed (a downto 0) = ufixed (2a+1 downto b) 181 function "*" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 182 183 -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1) 184 function "/" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 185 186 -- ufixed(a downto b) / ufixed(a downto b) = ufixed(a-b downto b-a-1) 187 function "/" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 188 189 -- ufixed(a downto b) / ufixed(a downto 0) = ufixed(a downto b-a-1) 190 function "/" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 191 192 -- ufixed(c downto 0) / ufixed(c downto d) = ufixed(c-d downto -c-1) 193 function "/" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 194 195 -- ufixed (a downto b) rem ufixed (a downto b) = ufixed (a downto b) 196 function "rem" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 197 198 -- ufixed (c downto d) rem ufixed (c downto d) = ufixed (c downto d) 199 function "rem" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 200 201 -- ufixed (a downto b) rem ufixed (a downto 0) = ufixed (a downto minimum(b,0)) 202 function "rem" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 203 204 -- ufixed (c downto 0) rem ufixed (c downto d) = ufixed (c downto minimum(d,0)) 205 function "rem" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 206 207 -- ufixed (a downto b) mod ufixed (a downto b) = ufixed (a downto b) 208 function "mod" (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 209 210 -- ufixed (c downto d) mod ufixed (c downto d) = ufixed (c downto d) 211 function "mod" (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 212 213 -- ufixed (a downto b) mod ufixed (a downto 0) = ufixed (a downto minimum(b,0)) 214 function "mod" (l : UNRESOLVED_ufixed; r : NATURAL) return UNRESOLVED_ufixed; 215 216 -- ufixed (c downto 0) mod ufixed (c downto d) = ufixed (c downto minimum(d,0)) 217 function "mod" (l : NATURAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 218 219 -- sfixed(a downto b) + sfixed(a downto b) = sfixed(a+1 downto b) 220 function "+" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 221 222 -- sfixed(c downto d) + sfixed(c downto d) = sfixed(c+1 downto d) 223 function "+" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 224 225 -- sfixed(a downto b) + sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b)) 226 function "+" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 227 228 -- sfixed(c downto 0) + sfixed(c downto d) = sfixed(c+1 downto minimum(0,d)) 229 function "+" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 230 231 -- sfixed(a downto b) - sfixed(a downto b) = sfixed(a+1 downto b) 232 function "-" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 233 234 -- sfixed(c downto d) - sfixed(c downto d) = sfixed(c+1 downto d) 235 function "-" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 236 237 -- sfixed(a downto b) - sfixed(a downto 0) = sfixed(a+1 downto minimum(0,b)) 238 function "-" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 239 240 -- sfixed(c downto 0) - sfixed(c downto d) = sfixed(c+1 downto minimum(0,d)) 241 function "-" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 242 243 -- sfixed(a downto b) * sfixed(a downto b) = sfixed(2a+1 downto 2b) 244 function "*" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 245 246 -- sfixed(c downto d) * sfixed(c downto d) = sfixed(2c+1 downto 2d) 247 function "*" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 248 249 -- sfixed(a downto b) * sfixed(a downto 0) = sfixed(2a+1 downto b) 250 function "*" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 251 252 -- sfixed(c downto 0) * sfixed(c downto d) = sfixed(2c+1 downto d) 253 function "*" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 254 255 -- sfixed(a downto b) / sfixed(a downto b) = sfixed(a-b+1 downto b-a) 256 function "/" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 257 258 -- sfixed(c downto d) / sfixed(c downto d) = sfixed(c-d+1 downto d-c) 259 function "/" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 260 261 -- sfixed(a downto b) / sfixed(a downto 0) = sfixed(a+1 downto b-a) 262 function "/" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 263 264 -- sfixed(c downto 0) / sfixed(c downto d) = sfixed(c-d+1 downto -c) 265 function "/" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 266 267 -- sfixed (a downto b) rem sfixed (a downto b) = sfixed (a downto b) 268 function "rem" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 269 270 -- sfixed (c downto d) rem sfixed (c downto d) = sfixed (c downto d) 271 function "rem" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 272 273 -- sfixed (a downto b) rem sfixed (a downto 0) = sfixed (a downto minimum(b,0)) 274 function "rem" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 275 276 -- sfixed (c downto 0) rem sfixed (c downto d) = sfixed (c downto minimum(d,0)) 277 function "rem" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 278 279 -- sfixed (a downto b) mod sfixed (a downto b) = sfixed (a downto b) 280 function "mod" (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 281 282 -- sfixed (c downto d) mod sfixed (c downto d) = sfixed (c downto d) 283 function "mod" (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 284 285 -- sfixed (a downto b) mod sfixed (a downto 0) = sfixed (a downto minimum(b,0)) 286 function "mod" (l : UNRESOLVED_sfixed; r : INTEGER) return UNRESOLVED_sfixed; 287 288 -- sfixed (c downto 0) mod sfixed (c downto d) = sfixed (c downto minimum(d,0)) 289 function "mod" (l : INTEGER; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 290 291 -- This version of divide gives the user more control 292 -- ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1) 293 function divide ( 294 l, r : UNRESOLVED_ufixed; 295 constant round_style : fixed_round_style_type := fixed_round_style; 296 constant guard_bits : NATURAL := fixed_guard_bits) 297 return UNRESOLVED_ufixed; 298 299 -- This version of divide gives the user more control 300 -- sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c) 301 function divide ( 302 l, r : UNRESOLVED_sfixed; 303 constant round_style : fixed_round_style_type := fixed_round_style; 304 constant guard_bits : NATURAL := fixed_guard_bits) 305 return UNRESOLVED_sfixed; 306 307 -- These functions return 1/X 308 -- 1 / ufixed(a downto b) = ufixed(-b downto -a-1) 309 function reciprocal ( 310 arg : UNRESOLVED_ufixed; -- fixed point input 311 constant round_style : fixed_round_style_type := fixed_round_style; 312 constant guard_bits : NATURAL := fixed_guard_bits) 313 return UNRESOLVED_ufixed; 314 315 -- 1 / sfixed(a downto b) = sfixed(-b+1 downto -a) 316 function reciprocal ( 317 arg : UNRESOLVED_sfixed; -- fixed point input 318 constant round_style : fixed_round_style_type := fixed_round_style; 319 constant guard_bits : NATURAL := fixed_guard_bits) 320 return UNRESOLVED_sfixed; 321 322 -- REM function 323 -- ufixed (a downto b) rem ufixed (c downto d) 324 -- = ufixed (minimum(a,c) downto minimum(b,d)) 325 function remainder ( 326 l, r : UNRESOLVED_ufixed; 327 constant round_style : fixed_round_style_type := fixed_round_style; 328 constant guard_bits : NATURAL := fixed_guard_bits) 329 return UNRESOLVED_ufixed; 330 331 -- sfixed (a downto b) rem sfixed (c downto d) 332 -- = sfixed (minimum(a,c) downto minimum(b,d)) 333 function remainder ( 334 l, r : UNRESOLVED_sfixed; 335 constant round_style : fixed_round_style_type := fixed_round_style; 336 constant guard_bits : NATURAL := fixed_guard_bits) 337 return UNRESOLVED_sfixed; 338 339 -- mod function 340 -- ufixed (a downto b) mod ufixed (c downto d) 341 -- = ufixed (minimum(a,c) downto minimum(b, d)) 342 function modulo ( 343 l, r : UNRESOLVED_ufixed; 344 constant round_style : fixed_round_style_type := fixed_round_style; 345 constant guard_bits : NATURAL := fixed_guard_bits) 346 return UNRESOLVED_ufixed; 347 348 -- sfixed (a downto b) mod sfixed (c downto d) 349 -- = sfixed (c downto minimum(b, d)) 350 function modulo ( 351 l, r : UNRESOLVED_sfixed; 352 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 353 constant round_style : fixed_round_style_type := fixed_round_style; 354 constant guard_bits : NATURAL := fixed_guard_bits) 355 return UNRESOLVED_sfixed; 356 357 -- Procedure for those who need an "accumulator" function. 358 -- add_carry (ufixed(a downto b), ufixed (c downto d)) 359 -- = ufixed (maximum(a,c) downto minimum(b,d)) 360 procedure add_carry ( 361 L, R : in UNRESOLVED_ufixed; 362 c_in : in STD_ULOGIC; 363 result : out UNRESOLVED_ufixed; 364 c_out : out STD_ULOGIC); 365 366 -- add_carry (sfixed(a downto b), sfixed (c downto d)) 367 -- = sfixed (maximum(a,c) downto minimum(b,d)) 368 procedure add_carry ( 369 L, R : in UNRESOLVED_sfixed; 370 c_in : in STD_ULOGIC; 371 result : out UNRESOLVED_sfixed; 372 c_out : out STD_ULOGIC); 373 374 -- Scales the result by a power of 2. Width of input = width of output with 375 -- the binary point moved. 376 function scalb (y : UNRESOLVED_ufixed; N : INTEGER) return UNRESOLVED_ufixed; 377 function scalb (y : UNRESOLVED_ufixed; N : UNRESOLVED_SIGNED) return UNRESOLVED_ufixed; 378 function scalb (y : UNRESOLVED_sfixed; N : INTEGER) return UNRESOLVED_sfixed; 379 function scalb (y : UNRESOLVED_sfixed; N : UNRESOLVED_SIGNED) return UNRESOLVED_sfixed; 380 381 function Is_Negative (arg : UNRESOLVED_sfixed) return BOOLEAN; 382 383 --=========================================================================== 384 -- Comparison Operators 385 --=========================================================================== 386 387 function ">" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 388 function ">" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 389 function "<" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 390 function "<" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 391 function "<=" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 392 function "<=" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 393 function ">=" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 394 function ">=" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 395 function "=" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 396 function "=" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 397 function "/=" (l, r : UNRESOLVED_ufixed) return BOOLEAN; 398 function "/=" (l, r : UNRESOLVED_sfixed) return BOOLEAN; 399 400 function "?=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 401 function "?/=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 402 function "?>" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 403 function "?>=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 404 function "?<" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 405 function "?<=" (l, r : UNRESOLVED_ufixed) return STD_ULOGIC; 406 function "?=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 407 function "?/=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 408 function "?>" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 409 function "?>=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 410 function "?<" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 411 function "?<=" (l, r : UNRESOLVED_sfixed) return STD_ULOGIC; 412 413 function std_match (l, r : UNRESOLVED_ufixed) return BOOLEAN; 414 function std_match (l, r : UNRESOLVED_sfixed) return BOOLEAN; 415 416 -- Overloads the default "maximum" and "minimum" function 417 418 function maximum (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 419 function minimum (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 420 function maximum (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 421 function minimum (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 422 423 ---------------------------------------------------------------------------- 424 -- In these compare functions a natural is converted into a 425 -- fixed point number of the bounds "maximum(l'high,0) downto 0" 426 ---------------------------------------------------------------------------- 427 428 function "=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 429 function "/=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 430 function ">=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 431 function "<=" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 432 function ">" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 433 function "<" (l : UNRESOLVED_ufixed; r : NATURAL) return BOOLEAN; 434 435 function "=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 436 function "/=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 437 function ">=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 438 function "<=" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 439 function ">" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 440 function "<" (l : NATURAL; r : UNRESOLVED_ufixed) return BOOLEAN; 441 442 function "?=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 443 function "?/=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 444 function "?>=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 445 function "?<=" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 446 function "?>" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 447 function "?<" (l : UNRESOLVED_ufixed; r : NATURAL) return STD_ULOGIC; 448 449 function "?=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 450 function "?/=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 451 function "?>=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 452 function "?<=" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 453 function "?>" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 454 function "?<" (l : NATURAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 455 456 function maximum (l : UNRESOLVED_ufixed; r : NATURAL) 457 return UNRESOLVED_ufixed; 458 function minimum (l : UNRESOLVED_ufixed; r : NATURAL) 459 return UNRESOLVED_ufixed; 460 function maximum (l : NATURAL; r : UNRESOLVED_ufixed) 461 return UNRESOLVED_ufixed; 462 function minimum (l : NATURAL; r : UNRESOLVED_ufixed) 463 return UNRESOLVED_ufixed; 464 ---------------------------------------------------------------------------- 465 -- In these compare functions a real is converted into a 466 -- fixed point number of the bounds "l'high+1 downto l'low" 467 ---------------------------------------------------------------------------- 468 469 function "=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 470 function "/=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 471 function ">=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 472 function "<=" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 473 function ">" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 474 function "<" (l : UNRESOLVED_ufixed; r : REAL) return BOOLEAN; 475 476 function "=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 477 function "/=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 478 function ">=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 479 function "<=" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 480 function ">" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 481 function "<" (l : REAL; r : UNRESOLVED_ufixed) return BOOLEAN; 482 483 function "?=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 484 function "?/=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 485 function "?>=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 486 function "?<=" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 487 function "?>" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 488 function "?<" (l : UNRESOLVED_ufixed; r : REAL) return STD_ULOGIC; 489 490 function "?=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 491 function "?/=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 492 function "?>=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 493 function "?<=" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 494 function "?>" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 495 function "?<" (l : REAL; r : UNRESOLVED_ufixed) return STD_ULOGIC; 496 497 function maximum (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 498 function maximum (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 499 function minimum (l : UNRESOLVED_ufixed; r : REAL) return UNRESOLVED_ufixed; 500 function minimum (l : REAL; r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 501 ---------------------------------------------------------------------------- 502 -- In these compare functions an integer is converted into a 503 -- fixed point number of the bounds "maximum(l'high,1) downto 0" 504 ---------------------------------------------------------------------------- 505 506 function "=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 507 function "/=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 508 function ">=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 509 function "<=" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 510 function ">" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 511 function "<" (l : UNRESOLVED_sfixed; r : INTEGER) return BOOLEAN; 512 513 function "=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 514 function "/=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 515 function ">=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 516 function "<=" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 517 function ">" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 518 function "<" (l : INTEGER; r : UNRESOLVED_sfixed) return BOOLEAN; 519 520 function "?=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 521 function "?/=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 522 function "?>=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 523 function "?<=" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 524 function "?>" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 525 function "?<" (l : UNRESOLVED_sfixed; r : INTEGER) return STD_ULOGIC; 526 527 function "?=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 528 function "?/=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 529 function "?>=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 530 function "?<=" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 531 function "?>" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 532 function "?<" (l : INTEGER; r : UNRESOLVED_sfixed) return STD_ULOGIC; 533 534 function maximum (l : UNRESOLVED_sfixed; r : INTEGER) 535 return UNRESOLVED_sfixed; 536 function maximum (l : INTEGER; r : UNRESOLVED_sfixed) 537 return UNRESOLVED_sfixed; 538 function minimum (l : UNRESOLVED_sfixed; r : INTEGER) 539 return UNRESOLVED_sfixed; 540 function minimum (l : INTEGER; r : UNRESOLVED_sfixed) 541 return UNRESOLVED_sfixed; 542 ---------------------------------------------------------------------------- 543 -- In these compare functions a real is converted into a 544 -- fixed point number of the bounds "l'high+1 downto l'low" 545 ---------------------------------------------------------------------------- 546 547 function "=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 548 function "/=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 549 function ">=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 550 function "<=" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 551 function ">" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 552 function "<" (l : UNRESOLVED_sfixed; r : REAL) return BOOLEAN; 553 554 function "=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 555 function "/=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 556 function ">=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 557 function "<=" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 558 function ">" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 559 function "<" (l : REAL; r : UNRESOLVED_sfixed) return BOOLEAN; 560 561 function "?=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 562 function "?/=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 563 function "?>=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 564 function "?<=" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 565 function "?>" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 566 function "?<" (l : UNRESOLVED_sfixed; r : REAL) return STD_ULOGIC; 567 568 function "?=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 569 function "?/=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 570 function "?>=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 571 function "?<=" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 572 function "?>" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 573 function "?<" (l : REAL; r : UNRESOLVED_sfixed) return STD_ULOGIC; 574 575 function maximum (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 576 function maximum (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 577 function minimum (l : UNRESOLVED_sfixed; r : REAL) return UNRESOLVED_sfixed; 578 function minimum (l : REAL; r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 579 --=========================================================================== 580 -- Shift and Rotate Functions. 581 -- Note that sra and sla are not the same as the BIT_VECTOR version 582 --=========================================================================== 583 584 function "sll" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 585 return UNRESOLVED_ufixed; 586 function "srl" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 587 return UNRESOLVED_ufixed; 588 function "rol" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 589 return UNRESOLVED_ufixed; 590 function "ror" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 591 return UNRESOLVED_ufixed; 592 function "sla" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 593 return UNRESOLVED_ufixed; 594 function "sra" (ARG : UNRESOLVED_ufixed; COUNT : INTEGER) 595 return UNRESOLVED_ufixed; 596 function "sll" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 597 return UNRESOLVED_sfixed; 598 function "srl" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 599 return UNRESOLVED_sfixed; 600 function "rol" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 601 return UNRESOLVED_sfixed; 602 function "ror" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 603 return UNRESOLVED_sfixed; 604 function "sla" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 605 return UNRESOLVED_sfixed; 606 function "sra" (ARG : UNRESOLVED_sfixed; COUNT : INTEGER) 607 return UNRESOLVED_sfixed; 608 function SHIFT_LEFT (ARG : UNRESOLVED_ufixed; COUNT : NATURAL) 609 return UNRESOLVED_ufixed; 610 function SHIFT_RIGHT (ARG : UNRESOLVED_ufixed; COUNT : NATURAL) 611 return UNRESOLVED_ufixed; 612 function SHIFT_LEFT (ARG : UNRESOLVED_sfixed; COUNT : NATURAL) 613 return UNRESOLVED_sfixed; 614 function SHIFT_RIGHT (ARG : UNRESOLVED_sfixed; COUNT : NATURAL) 615 return UNRESOLVED_sfixed; 616 617 ---------------------------------------------------------------------------- 618 -- logical functions 619 ---------------------------------------------------------------------------- 620 621 function "not" (l : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 622 function "and" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 623 function "or" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 624 function "nand" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 625 function "nor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 626 function "xor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 627 function "xnor" (l, r : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 628 function "not" (l : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 629 function "and" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 630 function "or" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 631 function "nand" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 632 function "nor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 633 function "xor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 634 function "xnor" (l, r : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 635 636 -- Vector and std_ulogic functions, same as functions in numeric_std 637 function "and" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 638 return UNRESOLVED_ufixed; 639 function "and" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 640 return UNRESOLVED_ufixed; 641 function "or" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 642 return UNRESOLVED_ufixed; 643 function "or" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 644 return UNRESOLVED_ufixed; 645 function "nand" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 646 return UNRESOLVED_ufixed; 647 function "nand" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 648 return UNRESOLVED_ufixed; 649 function "nor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 650 return UNRESOLVED_ufixed; 651 function "nor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 652 return UNRESOLVED_ufixed; 653 function "xor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 654 return UNRESOLVED_ufixed; 655 function "xor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 656 return UNRESOLVED_ufixed; 657 function "xnor" (l : STD_ULOGIC; r : UNRESOLVED_ufixed) 658 return UNRESOLVED_ufixed; 659 function "xnor" (l : UNRESOLVED_ufixed; r : STD_ULOGIC) 660 return UNRESOLVED_ufixed; 661 function "and" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 662 return UNRESOLVED_sfixed; 663 function "and" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 664 return UNRESOLVED_sfixed; 665 function "or" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 666 return UNRESOLVED_sfixed; 667 function "or" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 668 return UNRESOLVED_sfixed; 669 function "nand" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 670 return UNRESOLVED_sfixed; 671 function "nand" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 672 return UNRESOLVED_sfixed; 673 function "nor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 674 return UNRESOLVED_sfixed; 675 function "nor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 676 return UNRESOLVED_sfixed; 677 function "xor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 678 return UNRESOLVED_sfixed; 679 function "xor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 680 return UNRESOLVED_sfixed; 681 function "xnor" (l : STD_ULOGIC; r : UNRESOLVED_sfixed) 682 return UNRESOLVED_sfixed; 683 function "xnor" (l : UNRESOLVED_sfixed; r : STD_ULOGIC) 684 return UNRESOLVED_sfixed; 685 686 -- Reduction operators, same as numeric_std functions 687 function "and" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 688 function "nand" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 689 function "or" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 690 function "nor" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 691 function "xor" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 692 function "xnor" (l : UNRESOLVED_ufixed) return STD_ULOGIC; 693 function "and" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 694 function "nand" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 695 function "or" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 696 function "nor" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 697 function "xor" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 698 function "xnor" (l : UNRESOLVED_sfixed) return STD_ULOGIC; 699 700 -- returns arg'low-1 if not found 701 function find_leftmost (arg : UNRESOLVED_ufixed; y : STD_ULOGIC) 702 return INTEGER; 703 function find_leftmost (arg : UNRESOLVED_sfixed; y : STD_ULOGIC) 704 return INTEGER; 705 706 -- returns arg'high+1 if not found 707 function find_rightmost (arg : UNRESOLVED_ufixed; y : STD_ULOGIC) 708 return INTEGER; 709 function find_rightmost (arg : UNRESOLVED_sfixed; y : STD_ULOGIC) 710 return INTEGER; 711 712 --=========================================================================== 713 -- RESIZE Functions 714 --=========================================================================== 715 -- resizes the number (larger or smaller) 716 -- The returned result will be ufixed (left_index downto right_index) 717 -- If "round_style" is fixed_round, then the result will be rounded. 718 -- If the MSB of the remainder is a "1" AND the LSB of the unrounded result 719 -- is a '1' or the lower bits of the remainder include a '1' then the result 720 -- will be increased by the smallest representable number for that type. 721 -- "overflow_style" can be fixed_saturate or fixed_wrap. 722 -- In saturate mode, if the number overflows then the largest possible 723 -- representable number is returned. If wrap mode, then the upper bits 724 -- of the number are truncated. 725 726 function resize ( 727 arg : UNRESOLVED_ufixed; -- input 728 constant left_index : INTEGER; -- integer portion 729 constant right_index : INTEGER; -- size of fraction 730 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 731 constant round_style : fixed_round_style_type := fixed_round_style) 732 return UNRESOLVED_ufixed; 733 734 -- "size_res" functions create the size of the output from the indices 735 -- of the "size_res" input. The actual value of "size_res" is not used. 736 function resize ( 737 arg : UNRESOLVED_ufixed; -- input 738 size_res : UNRESOLVED_ufixed; -- for size only 739 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 740 constant round_style : fixed_round_style_type := fixed_round_style) 741 return UNRESOLVED_ufixed; 742 743 -- Note that in "wrap" mode the sign bit is not replicated. Thus the 744 -- resize of a negative number can have a positive result in wrap mode. 745 function resize ( 746 arg : UNRESOLVED_sfixed; -- input 747 constant left_index : INTEGER; -- integer portion 748 constant right_index : INTEGER; -- size of fraction 749 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 750 constant round_style : fixed_round_style_type := fixed_round_style) 751 return UNRESOLVED_sfixed; 752 753 function resize ( 754 arg : UNRESOLVED_sfixed; -- input 755 size_res : UNRESOLVED_sfixed; -- for size only 756 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 757 constant round_style : fixed_round_style_type := fixed_round_style) 758 return UNRESOLVED_sfixed; 759 760 --=========================================================================== 761 -- Conversion Functions 762 --=========================================================================== 763 764 -- integer (natural) to unsigned fixed point. 765 -- arguments are the upper and lower bounds of the number, thus 766 -- ufixed (7 downto -3) <= to_ufixed (int, 7, -3); 767 function to_ufixed ( 768 arg : NATURAL; -- integer 769 constant left_index : INTEGER; -- left index (high index) 770 constant right_index : INTEGER := 0; -- right index 771 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 772 constant round_style : fixed_round_style_type := fixed_round_style) 773 return UNRESOLVED_ufixed; 774 775 function to_ufixed ( 776 arg : NATURAL; -- integer 777 size_res : UNRESOLVED_ufixed; -- for size only 778 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 779 constant round_style : fixed_round_style_type := fixed_round_style) 780 return UNRESOLVED_ufixed; 781 782 -- real to unsigned fixed point 783 function to_ufixed ( 784 arg : REAL; -- real 785 constant left_index : INTEGER; -- left index (high index) 786 constant right_index : INTEGER; -- right index 787 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 788 constant round_style : fixed_round_style_type := fixed_round_style; 789 constant guard_bits : NATURAL := fixed_guard_bits) 790 return UNRESOLVED_ufixed; 791 792 function to_ufixed ( 793 arg : REAL; -- real 794 size_res : UNRESOLVED_ufixed; -- for size only 795 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 796 constant round_style : fixed_round_style_type := fixed_round_style; 797 constant guard_bits : NATURAL := fixed_guard_bits) 798 return UNRESOLVED_ufixed; 799 800 -- unsigned to unsigned fixed point 801 function to_ufixed ( 802 arg : UNRESOLVED_UNSIGNED; -- unsigned 803 constant left_index : INTEGER; -- left index (high index) 804 constant right_index : INTEGER := 0; -- right index 805 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 806 constant round_style : fixed_round_style_type := fixed_round_style) 807 return UNRESOLVED_ufixed; 808 809 function to_ufixed ( 810 arg : UNRESOLVED_UNSIGNED; -- unsigned 811 size_res : UNRESOLVED_ufixed; -- for size only 812 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 813 constant round_style : fixed_round_style_type := fixed_round_style) 814 return UNRESOLVED_ufixed; 815 816 -- Performs a conversion. ufixed (arg'range) is returned 817 function to_ufixed ( 818 arg : UNRESOLVED_UNSIGNED) -- unsigned 819 return UNRESOLVED_ufixed; 820 821 -- unsigned fixed point to unsigned 822 function to_unsigned ( 823 arg : UNRESOLVED_ufixed; -- fixed point input 824 constant size : NATURAL; -- length of output 825 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 826 constant round_style : fixed_round_style_type := fixed_round_style) 827 return UNRESOLVED_UNSIGNED; 828 829 -- unsigned fixed point to unsigned 830 function to_unsigned ( 831 arg : UNRESOLVED_ufixed; -- fixed point input 832 size_res : UNRESOLVED_UNSIGNED; -- used for length of output 833 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 834 constant round_style : fixed_round_style_type := fixed_round_style) 835 return UNRESOLVED_UNSIGNED; 836 837 -- unsigned fixed point to real 838 function to_real ( 839 arg : UNRESOLVED_ufixed) -- fixed point input 840 return REAL; 841 842 -- unsigned fixed point to integer 843 function to_integer ( 844 arg : UNRESOLVED_ufixed; -- fixed point input 845 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 846 constant round_style : fixed_round_style_type := fixed_round_style) 847 return NATURAL; 848 849 -- Integer to UNRESOLVED_sfixed 850 function to_sfixed ( 851 arg : INTEGER; -- integer 852 constant left_index : INTEGER; -- left index (high index) 853 constant right_index : INTEGER := 0; -- right index 854 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 855 constant round_style : fixed_round_style_type := fixed_round_style) 856 return UNRESOLVED_sfixed; 857 858 function to_sfixed ( 859 arg : INTEGER; -- integer 860 size_res : UNRESOLVED_sfixed; -- for size only 861 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 862 constant round_style : fixed_round_style_type := fixed_round_style) 863 return UNRESOLVED_sfixed; 864 865 -- Real to sfixed 866 function to_sfixed ( 867 arg : REAL; -- real 868 constant left_index : INTEGER; -- left index (high index) 869 constant right_index : INTEGER; -- right index 870 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 871 constant round_style : fixed_round_style_type := fixed_round_style; 872 constant guard_bits : NATURAL := fixed_guard_bits) 873 return UNRESOLVED_sfixed; 874 875 function to_sfixed ( 876 arg : REAL; -- real 877 size_res : UNRESOLVED_sfixed; -- for size only 878 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 879 constant round_style : fixed_round_style_type := fixed_round_style; 880 constant guard_bits : NATURAL := fixed_guard_bits) 881 return UNRESOLVED_sfixed; 882 883 -- signed to sfixed 884 function to_sfixed ( 885 arg : UNRESOLVED_SIGNED; -- signed 886 constant left_index : INTEGER; -- left index (high index) 887 constant right_index : INTEGER := 0; -- right index 888 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 889 constant round_style : fixed_round_style_type := fixed_round_style) 890 return UNRESOLVED_sfixed; 891 892 function to_sfixed ( 893 arg : UNRESOLVED_SIGNED; -- signed 894 size_res : UNRESOLVED_sfixed; -- for size only 895 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 896 constant round_style : fixed_round_style_type := fixed_round_style) 897 return UNRESOLVED_sfixed; 898 899 -- signed to sfixed (output assumed to be size of signed input) 900 function to_sfixed ( 901 arg : UNRESOLVED_SIGNED) -- signed 902 return UNRESOLVED_sfixed; 903 904 -- Conversion from ufixed to sfixed 905 function to_sfixed ( 906 arg : UNRESOLVED_ufixed) 907 return UNRESOLVED_sfixed; 908 909 -- signed fixed point to signed 910 function to_signed ( 911 arg : UNRESOLVED_sfixed; -- fixed point input 912 constant size : NATURAL; -- length of output 913 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 914 constant round_style : fixed_round_style_type := fixed_round_style) 915 return UNRESOLVED_SIGNED; 916 917 -- signed fixed point to signed 918 function to_signed ( 919 arg : UNRESOLVED_sfixed; -- fixed point input 920 size_res : UNRESOLVED_SIGNED; -- used for length of output 921 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 922 constant round_style : fixed_round_style_type := fixed_round_style) 923 return UNRESOLVED_SIGNED; 924 925 -- signed fixed point to real 926 function to_real ( 927 arg : UNRESOLVED_sfixed) -- fixed point input 928 return REAL; 929 930 -- signed fixed point to integer 931 function to_integer ( 932 arg : UNRESOLVED_sfixed; -- fixed point input 933 constant overflow_style : fixed_overflow_style_type := fixed_overflow_style; 934 constant round_style : fixed_round_style_type := fixed_round_style) 935 return INTEGER; 936 937 -- Because of the fairly complicated sizing rules in the fixed point 938 -- packages these functions are provided to compute the result ranges 939 -- Example: 940 -- signal uf1 : ufixed (3 downto -3); 941 -- signal uf2 : ufixed (4 downto -2); 942 -- signal uf1multuf2 : ufixed (ufixed_high (3, -3, '*', 4, -2) downto 943 -- ufixed_low (3, -3, '*', 4, -2)); 944 -- uf1multuf2 <= uf1 * uf2; 945 -- Valid characters: '+', '-', '*', '/', 'r' or 'R' (rem), 'm' or 'M' (mod), 946 -- '1' (reciprocal), 'a' or 'A' (abs), 'n' or 'N' (unary -) 947 function ufixed_high (left_index, right_index : INTEGER; 948 operation : CHARACTER := 'X'; 949 left_index2, right_index2 : INTEGER := 0) 950 return INTEGER; 951 952 function ufixed_low (left_index, right_index : INTEGER; 953 operation : CHARACTER := 'X'; 954 left_index2, right_index2 : INTEGER := 0) 955 return INTEGER; 956 957 function sfixed_high (left_index, right_index : INTEGER; 958 operation : CHARACTER := 'X'; 959 left_index2, right_index2 : INTEGER := 0) 960 return INTEGER; 961 962 function sfixed_low (left_index, right_index : INTEGER; 963 operation : CHARACTER := 'X'; 964 left_index2, right_index2 : INTEGER := 0) 965 return INTEGER; 966 967 -- Same as above, but using the "size_res" input only for their ranges: 968 -- signal uf1multuf2 : ufixed (ufixed_high (uf1, '*', uf2) downto 969 -- ufixed_low (uf1, '*', uf2)); 970 -- uf1multuf2 <= uf1 * uf2; 971 -- 972 function ufixed_high (size_res : UNRESOLVED_ufixed; 973 operation : CHARACTER := 'X'; 974 size_res2 : UNRESOLVED_ufixed) 975 return INTEGER; 976 977 function ufixed_low (size_res : UNRESOLVED_ufixed; 978 operation : CHARACTER := 'X'; 979 size_res2 : UNRESOLVED_ufixed) 980 return INTEGER; 981 982 function sfixed_high (size_res : UNRESOLVED_sfixed; 983 operation : CHARACTER := 'X'; 984 size_res2 : UNRESOLVED_sfixed) 985 return INTEGER; 986 987 function sfixed_low (size_res : UNRESOLVED_sfixed; 988 operation : CHARACTER := 'X'; 989 size_res2 : UNRESOLVED_sfixed) 990 return INTEGER; 991 992 -- purpose: returns a saturated number 993 function saturate ( 994 constant left_index : INTEGER; 995 constant right_index : INTEGER) 996 return UNRESOLVED_ufixed; 997 998 -- purpose: returns a saturated number 999 function saturate ( 1000 constant left_index : INTEGER; 1001 constant right_index : INTEGER) 1002 return UNRESOLVED_sfixed; 1003 1004 function saturate ( 1005 size_res : UNRESOLVED_ufixed) -- only the size of this is used 1006 return UNRESOLVED_ufixed; 1007 1008 function saturate ( 1009 size_res : UNRESOLVED_sfixed) -- only the size of this is used 1010 return UNRESOLVED_sfixed; 1011 1012 --=========================================================================== 1013 -- Translation Functions 1014 --=========================================================================== 1015 1016 -- maps meta-logical values 1017 function to_01 ( 1018 s : UNRESOLVED_ufixed; -- fixed point input 1019 constant XMAP : STD_ULOGIC := '0') -- Map x to 1020 return UNRESOLVED_ufixed; 1021 1022 -- maps meta-logical values 1023 function to_01 ( 1024 s : UNRESOLVED_sfixed; -- fixed point input 1025 constant XMAP : STD_ULOGIC := '0') -- Map x to 1026 return UNRESOLVED_sfixed; 1027 1028 function Is_X (arg : UNRESOLVED_ufixed) return BOOLEAN; 1029 function Is_X (arg : UNRESOLVED_sfixed) return BOOLEAN; 1030 function to_X01 (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 1031 function to_X01 (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 1032 function to_X01Z (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 1033 function to_X01Z (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 1034 function to_UX01 (arg : UNRESOLVED_ufixed) return UNRESOLVED_ufixed; 1035 function to_UX01 (arg : UNRESOLVED_sfixed) return UNRESOLVED_sfixed; 1036 1037 -- straight vector conversion routines, needed for synthesis. 1038 -- These functions are here so that a std_logic_vector can be 1039 -- converted to and from sfixed and ufixed. Note that you can 1040 -- not convert these vectors because of their negative index. 1041 1042 function to_slv ( 1043 arg : UNRESOLVED_ufixed) -- fixed point vector 1044 return STD_LOGIC_VECTOR; 1045 alias to_StdLogicVector is to_slv [UNRESOLVED_ufixed 1046 return STD_LOGIC_VECTOR]; 1047 alias to_Std_Logic_Vector is to_slv [UNRESOLVED_ufixed 1048 return STD_LOGIC_VECTOR]; 1049 1050 function to_slv ( 1051 arg : UNRESOLVED_sfixed) -- fixed point vector 1052 return STD_LOGIC_VECTOR; 1053 alias to_StdLogicVector is to_slv [UNRESOLVED_sfixed 1054 return STD_LOGIC_VECTOR]; 1055 alias to_Std_Logic_Vector is to_slv [UNRESOLVED_sfixed 1056 return STD_LOGIC_VECTOR]; 1057 1058 function to_sulv ( 1059 arg : UNRESOLVED_ufixed) -- fixed point vector 1060 return STD_ULOGIC_VECTOR; 1061 alias to_StdULogicVector is to_sulv [UNRESOLVED_ufixed 1062 return STD_ULOGIC_VECTOR]; 1063 alias to_Std_ULogic_Vector is to_sulv [UNRESOLVED_ufixed 1064 return STD_ULOGIC_VECTOR]; 1065 1066 function to_sulv ( 1067 arg : UNRESOLVED_sfixed) -- fixed point vector 1068 return STD_ULOGIC_VECTOR; 1069 alias to_StdULogicVector is to_sulv [UNRESOLVED_sfixed 1070 return STD_ULOGIC_VECTOR]; 1071 alias to_Std_ULogic_Vector is to_sulv [UNRESOLVED_sfixed 1072 return STD_ULOGIC_VECTOR]; 1073 1074 function to_ufixed ( 1075 arg : STD_ULOGIC_VECTOR; -- shifted vector 1076 constant left_index : INTEGER; 1077 constant right_index : INTEGER) 1078 return UNRESOLVED_ufixed; 1079 1080 function to_ufixed ( 1081 arg : STD_ULOGIC_VECTOR; -- shifted vector 1082 size_res : UNRESOLVED_ufixed) -- for size only 1083 return UNRESOLVED_ufixed; 1084 1085 function to_sfixed ( 1086 arg : STD_ULOGIC_VECTOR; -- shifted vector 1087 constant left_index : INTEGER; 1088 constant right_index : INTEGER) 1089 return UNRESOLVED_sfixed; 1090 1091 function to_sfixed ( 1092 arg : STD_ULOGIC_VECTOR; -- shifted vector 1093 size_res : UNRESOLVED_sfixed) -- for size only 1094 return UNRESOLVED_sfixed; 1095 1096 -- As a concession to those who use a graphical DSP environment, 1097 -- these functions take parameters in those tools format and create 1098 -- fixed point numbers. These functions are designed to convert from 1099 -- a std_logic_vector to the VHDL fixed point format using the conventions 1100 -- of these packages. In a pure VHDL environment you should use the 1101 -- "to_ufixed" and "to_sfixed" routines. 1102 1103 -- unsigned fixed point 1104 function to_UFix ( 1105 arg : STD_ULOGIC_VECTOR; 1106 width : NATURAL; -- width of vector 1107 fraction : NATURAL) -- width of fraction 1108 return UNRESOLVED_ufixed; 1109 1110 -- signed fixed point 1111 function to_SFix ( 1112 arg : STD_ULOGIC_VECTOR; 1113 width : NATURAL; -- width of vector 1114 fraction : NATURAL) -- width of fraction 1115 return UNRESOLVED_sfixed; 1116 1117 -- finding the bounds of a number. These functions can be used like this: 1118 -- signal xxx : ufixed (7 downto -3); 1119 -- -- Which is the same as "ufixed (UFix_high (11,3) downto UFix_low(11,3))" 1120 -- signal yyy : ufixed (UFix_high (11, 3, "+", 11, 3) 1121 -- downto UFix_low(11, 3, "+", 11, 3)); 1122 -- Where "11" is the width of xxx (xxx'length), 1123 -- and 3 is the lower bound (abs (xxx'low)) 1124 -- In a pure VHDL environment use "ufixed_high" and "ufixed_low" 1125 1126 function UFix_high (width, fraction : NATURAL; 1127 operation : CHARACTER := 'X'; 1128 width2, fraction2 : NATURAL := 0) 1129 return INTEGER; 1130 1131 function UFix_low (width, fraction : NATURAL; 1132 operation : CHARACTER := 'X'; 1133 width2, fraction2 : NATURAL := 0) 1134 return INTEGER; 1135 1136 -- Same as above but for signed fixed point. Note that the width 1137 -- of a signed fixed point number ignores the sign bit, thus 1138 -- width = sxxx'length-1 1139 1140 function SFix_high (width, fraction : NATURAL; 1141 operation : CHARACTER := 'X'; 1142 width2, fraction2 : NATURAL := 0) 1143 return INTEGER; 1144 1145 function SFix_low (width, fraction : NATURAL; 1146 operation : CHARACTER := 'X'; 1147 width2, fraction2 : NATURAL := 0) 1148 return INTEGER; 1149 1150 --=========================================================================== 1151 -- string and textio Functions 1152 --=========================================================================== 1153 1154 -- purpose: writes fixed point into a line 1155 procedure WRITE ( 1156 L : inout LINE; -- input line 1157 VALUE : in UNRESOLVED_ufixed; -- fixed point input 1158 JUSTIFIED : in SIDE := right; 1159 FIELD : in WIDTH := 0); 1160 1161 -- purpose: writes fixed point into a line 1162 procedure WRITE ( 1163 L : inout LINE; -- input line 1164 VALUE : in UNRESOLVED_sfixed; -- fixed point input 1165 JUSTIFIED : in SIDE := right; 1166 FIELD : in WIDTH := 0); 1167 1168 procedure READ(L : inout LINE; 1169 VALUE : out UNRESOLVED_ufixed); 1170 1171 procedure READ(L : inout LINE; 1172 VALUE : out UNRESOLVED_ufixed; 1173 GOOD : out BOOLEAN); 1174 1175 procedure READ(L : inout LINE; 1176 VALUE : out UNRESOLVED_sfixed); 1177 1178 procedure READ(L : inout LINE; 1179 VALUE : out UNRESOLVED_sfixed; 1180 GOOD : out BOOLEAN); 1181 1182 alias bwrite is WRITE [LINE, UNRESOLVED_ufixed, SIDE, width]; 1183 alias bwrite is WRITE [LINE, UNRESOLVED_sfixed, SIDE, width]; 1184 alias bread is READ [LINE, UNRESOLVED_ufixed]; 1185 alias bread is READ [LINE, UNRESOLVED_ufixed, BOOLEAN]; 1186 alias bread is READ [LINE, UNRESOLVED_sfixed]; 1187 alias bread is READ [LINE, UNRESOLVED_sfixed, BOOLEAN]; 1188 alias BINARY_WRITE is WRITE [LINE, UNRESOLVED_ufixed, SIDE, width]; 1189 alias BINARY_WRITE is WRITE [LINE, UNRESOLVED_sfixed, SIDE, width]; 1190 alias BINARY_READ is READ [LINE, UNRESOLVED_ufixed, BOOLEAN]; 1191 alias BINARY_READ is READ [LINE, UNRESOLVED_ufixed]; 1192 alias BINARY_READ is READ [LINE, UNRESOLVED_sfixed, BOOLEAN]; 1193 alias BINARY_READ is READ [LINE, UNRESOLVED_sfixed]; 1194 1195 -- octal read and write 1196 procedure OWRITE ( 1197 L : inout LINE; -- input line 1198 VALUE : in UNRESOLVED_ufixed; -- fixed point input 1199 JUSTIFIED : in SIDE := right; 1200 FIELD : in WIDTH := 0); 1201 1202 procedure OWRITE ( 1203 L : inout LINE; -- input line 1204 VALUE : in UNRESOLVED_sfixed; -- fixed point input 1205 JUSTIFIED : in SIDE := right; 1206 FIELD : in WIDTH := 0); 1207 1208 procedure OREAD(L : inout LINE; 1209 VALUE : out UNRESOLVED_ufixed); 1210 1211 procedure OREAD(L : inout LINE; 1212 VALUE : out UNRESOLVED_ufixed; 1213 GOOD : out BOOLEAN); 1214 1215 procedure OREAD(L : inout LINE; 1216 VALUE : out UNRESOLVED_sfixed); 1217 1218 procedure OREAD(L : inout LINE; 1219 VALUE : out UNRESOLVED_sfixed; 1220 GOOD : out BOOLEAN); 1221 alias OCTAL_READ is OREAD [LINE, UNRESOLVED_ufixed, BOOLEAN]; 1222 alias OCTAL_READ is OREAD [LINE, UNRESOLVED_ufixed]; 1223 alias OCTAL_READ is OREAD [LINE, UNRESOLVED_sfixed, BOOLEAN]; 1224 alias OCTAL_READ is OREAD [LINE, UNRESOLVED_sfixed]; 1225 alias OCTAL_WRITE is OWRITE [LINE, UNRESOLVED_ufixed, SIDE, WIDTH]; 1226 alias OCTAL_WRITE is OWRITE [LINE, UNRESOLVED_sfixed, SIDE, WIDTH]; 1227 1228 -- hex read and write 1229 procedure HWRITE ( 1230 L : inout LINE; -- input line 1231 VALUE : in UNRESOLVED_ufixed; -- fixed point input 1232 JUSTIFIED : in SIDE := right; 1233 FIELD : in WIDTH := 0); 1234 1235 -- purpose: writes fixed point into a line 1236 procedure HWRITE ( 1237 L : inout LINE; -- input line 1238 VALUE : in UNRESOLVED_sfixed; -- fixed point input 1239 JUSTIFIED : in SIDE := right; 1240 FIELD : in WIDTH := 0); 1241 1242 procedure HREAD(L : inout LINE; 1243 VALUE : out UNRESOLVED_ufixed); 1244 1245 procedure HREAD(L : inout LINE; 1246 VALUE : out UNRESOLVED_ufixed; 1247 GOOD : out BOOLEAN); 1248 1249 procedure HREAD(L : inout LINE; 1250 VALUE : out UNRESOLVED_sfixed); 1251 1252 procedure HREAD(L : inout LINE; 1253 VALUE : out UNRESOLVED_sfixed; 1254 GOOD : out BOOLEAN); 1255 alias HEX_READ is HREAD [LINE, UNRESOLVED_ufixed, BOOLEAN]; 1256 alias HEX_READ is HREAD [LINE, UNRESOLVED_sfixed, BOOLEAN]; 1257 alias HEX_READ is HREAD [LINE, UNRESOLVED_ufixed]; 1258 alias HEX_READ is HREAD [LINE, UNRESOLVED_sfixed]; 1259 alias HEX_WRITE is HWRITE [LINE, UNRESOLVED_ufixed, SIDE, WIDTH]; 1260 alias HEX_WRITE is HWRITE [LINE, UNRESOLVED_sfixed, SIDE, WIDTH]; 1261 1262 -- returns a string, useful for: 1263 -- assert (x = y) report "error found " & TO_STRING(x) severity error; 1264 function TO_STRING (value : UNRESOLVED_ufixed) return STRING; 1265 1266 alias TO_BSTRING is TO_STRING [UNRESOLVED_ufixed return STRING]; 1267 alias TO_BINARY_STRING is TO_STRING [UNRESOLVED_ufixed return STRING]; 1268 1269 function TO_OSTRING (value : UNRESOLVED_ufixed) return STRING; 1270 alias TO_OCTAL_STRING is TO_OSTRING [UNRESOLVED_ufixed return STRING]; 1271 1272 function TO_HSTRING (value : UNRESOLVED_ufixed) return STRING; 1273 alias TO_HEX_STRING is TO_HSTRING [UNRESOLVED_ufixed return STRING]; 1274 1275 function TO_STRING (value : UNRESOLVED_sfixed) return STRING; 1276 alias TO_BSTRING is TO_STRING [UNRESOLVED_sfixed return STRING]; 1277 alias TO_BINARY_STRING is TO_STRING [UNRESOLVED_sfixed return STRING]; 1278 1279 function TO_OSTRING (value : UNRESOLVED_sfixed) return STRING; 1280 alias TO_OCTAL_STRING is TO_OSTRING [UNRESOLVED_sfixed return STRING]; 1281 1282 function TO_HSTRING (value : UNRESOLVED_sfixed) return STRING; 1283 alias TO_HEX_STRING is TO_HSTRING [UNRESOLVED_sfixed return STRING]; 1284 1285 -- From string functions allow you to convert a string into a fixed 1286 -- point number. Example: 1287 -- signal uf1 : ufixed (3 downto -3); 1288 -- uf1 <= from_string ("0110.100", uf1'high, uf1'low); -- 6.5 1289 -- The "." is optional in this syntax, however it exist and is 1290 -- in the wrong location an error is produced. Overflow will 1291 -- result in saturation. 1292 1293 function from_string ( 1294 bstring : STRING; -- binary string 1295 constant left_index : INTEGER; 1296 constant right_index : INTEGER) 1297 return UNRESOLVED_ufixed; 1298 alias from_bstring is from_string [STRING, INTEGER, INTEGER 1299 return UNRESOLVED_ufixed]; 1300 alias from_binary_string is from_string [STRING, INTEGER, INTEGER 1301 return UNRESOLVED_ufixed]; 1302 1303 -- Octal and hex conversions work as follows: 1304 -- uf1 <= from_hstring ("6.8", 3, -3); -- 6.5 (bottom zeros dropped) 1305 -- uf1 <= from_ostring ("06.4", 3, -3); -- 6.5 (top zeros dropped) 1306 1307 function from_ostring ( 1308 ostring : STRING; -- Octal string 1309 constant left_index : INTEGER; 1310 constant right_index : INTEGER) 1311 return UNRESOLVED_ufixed; 1312 alias from_octal_string is from_ostring [STRING, INTEGER, INTEGER 1313 return UNRESOLVED_ufixed]; 1314 1315 function from_hstring ( 1316 hstring : STRING; -- hex string 1317 constant left_index : INTEGER; 1318 constant right_index : INTEGER) 1319 return UNRESOLVED_ufixed; 1320 alias from_hex_string is from_hstring [STRING, INTEGER, INTEGER 1321 return UNRESOLVED_ufixed]; 1322 1323 function from_string ( 1324 bstring : STRING; -- binary string 1325 constant left_index : INTEGER; 1326 constant right_index : INTEGER) 1327 return UNRESOLVED_sfixed; 1328 alias from_bstring is from_string [STRING, INTEGER, INTEGER 1329 return UNRESOLVED_sfixed]; 1330 alias from_binary_string is from_string [STRING, INTEGER, INTEGER 1331 return UNRESOLVED_sfixed]; 1332 1333 function from_ostring ( 1334 ostring : STRING; -- Octal string 1335 constant left_index : INTEGER; 1336 constant right_index : INTEGER) 1337 return UNRESOLVED_sfixed; 1338 alias from_octal_string is from_ostring [STRING, INTEGER, INTEGER 1339 return UNRESOLVED_sfixed]; 1340 1341 function from_hstring ( 1342 hstring : STRING; -- hex string 1343 constant left_index : INTEGER; 1344 constant right_index : INTEGER) 1345 return UNRESOLVED_sfixed; 1346 alias from_hex_string is from_hstring [STRING, INTEGER, INTEGER 1347 return UNRESOLVED_sfixed]; 1348 1349 -- Same as above, "size_res" is used for it's range only. 1350 function from_string ( 1351 bstring : STRING; -- binary string 1352 size_res : UNRESOLVED_ufixed) 1353 return UNRESOLVED_ufixed; 1354 alias from_bstring is from_string [STRING, UNRESOLVED_ufixed 1355 return UNRESOLVED_ufixed]; 1356 alias from_binary_string is from_string [STRING, UNRESOLVED_ufixed 1357 return UNRESOLVED_ufixed]; 1358 1359 function from_ostring ( 1360 ostring : STRING; -- Octal string 1361 size_res : UNRESOLVED_ufixed) 1362 return UNRESOLVED_ufixed; 1363 alias from_octal_string is from_ostring [STRING, UNRESOLVED_ufixed 1364 return UNRESOLVED_ufixed]; 1365 1366 function from_hstring ( 1367 hstring : STRING; -- hex string 1368 size_res : UNRESOLVED_ufixed) 1369 return UNRESOLVED_ufixed; 1370 alias from_hex_string is from_hstring [STRING, UNRESOLVED_ufixed 1371 return UNRESOLVED_ufixed]; 1372 1373 function from_string ( 1374 bstring : STRING; -- binary string 1375 size_res : UNRESOLVED_sfixed) 1376 return UNRESOLVED_sfixed; 1377 alias from_bstring is from_string [STRING, UNRESOLVED_sfixed 1378 return UNRESOLVED_sfixed]; 1379 alias from_binary_string is from_string [STRING, UNRESOLVED_sfixed 1380 return UNRESOLVED_sfixed]; 1381 1382 function from_ostring ( 1383 ostring : STRING; -- Octal string 1384 size_res : UNRESOLVED_sfixed) 1385 return UNRESOLVED_sfixed; 1386 alias from_octal_string is from_ostring [STRING, UNRESOLVED_sfixed 1387 return UNRESOLVED_sfixed]; 1388 1389 function from_hstring ( 1390 hstring : STRING; -- hex string 1391 size_res : UNRESOLVED_sfixed) 1392 return UNRESOLVED_sfixed; 1393 alias from_hex_string is from_hstring [STRING, UNRESOLVED_sfixed 1394 return UNRESOLVED_sfixed]; 1395 1396 -- Direct conversion functions. Example: 1397 -- signal uf1 : ufixed (3 downto -3); 1398 -- uf1 <= from_string ("0110.100"); -- 6.5 1399 -- In this case the "." is not optional, and the size of 1400 -- the output must match exactly. 1401 1402 function from_string ( 1403 bstring : STRING) -- binary string 1404 return UNRESOLVED_ufixed; 1405 alias from_bstring is from_string [STRING return UNRESOLVED_ufixed]; 1406 alias from_binary_string is from_string [STRING return UNRESOLVED_ufixed]; 1407 1408 -- Direct octal and hex conversion functions. In this case 1409 -- the string lengths must match. Example: 1410 -- signal sf1 := sfixed (5 downto -3); 1411 -- sf1 <= from_ostring ("71.4") -- -6.5 1412 1413 function from_ostring ( 1414 ostring : STRING) -- Octal string 1415 return UNRESOLVED_ufixed; 1416 alias from_octal_string is from_ostring [STRING return UNRESOLVED_ufixed]; 1417 1418 function from_hstring ( 1419 hstring : STRING) -- hex string 1420 return UNRESOLVED_ufixed; 1421 alias from_hex_string is from_hstring [STRING return UNRESOLVED_ufixed]; 1422 1423 function from_string ( 1424 bstring : STRING) -- binary string 1425 return UNRESOLVED_sfixed; 1426 alias from_bstring is from_string [STRING return UNRESOLVED_sfixed]; 1427 alias from_binary_string is from_string [STRING return UNRESOLVED_sfixed]; 1428 1429 function from_ostring ( 1430 ostring : STRING) -- Octal string 1431 return UNRESOLVED_sfixed; 1432 alias from_octal_string is from_ostring [STRING return UNRESOLVED_sfixed]; 1433 1434 function from_hstring ( 1435 hstring : STRING) -- hex string 1436 return UNRESOLVED_sfixed; 1437 alias from_hex_string is from_hstring [STRING return UNRESOLVED_sfixed]; 1438 1439end package fixed_generic_pkg; 1440