1-- ----------------------------------------------------------------------------- 2-- 3-- Copyright 1995 by IEEE. All rights reserved. 4-- 5-- This source file is considered by the IEEE to be an essential part of the use 6-- of the standard 1076.3 and as such may be distributed without change, except 7-- as permitted by the standard. This source file may not be sold or distributed 8-- for profit. This package may be modified to include additional data required 9-- by tools, but must in no way change the external interfaces or simulation 10-- behaviour of the description. It is permissible to add comments and/or 11-- attributes to the package declarations, but not to change or delete any 12-- original lines of the approved package declaration. The package body may be 13-- changed only in accordance with the terms of clauses 7.1 and 7.2 of the 14-- standard. 15-- 16-- Title : Standard VHDL Synthesis Package (1076.3, NUMERIC_BIT) 17-- 18-- Library : This package shall be compiled into a library symbolically 19-- : named IEEE. 20-- 21-- Developers : IEEE DASC Synthesis Working Group, PAR 1076.3 22-- 23-- Purpose : This package defines numeric types and arithmetic functions 24-- : for use with synthesis tools. Two numeric types are defined: 25-- : -- > UNSIGNED: represents an UNSIGNED number in vector form 26-- : -- > SIGNED: represents a SIGNED number in vector form 27-- : The base element type is type BIT. 28-- : The leftmost bit is treated as the most significant bit. 29-- : Signed vectors are represented in two's complement form. 30-- : This package contains overloaded arithmetic operators on 31-- : the SIGNED and UNSIGNED types. The package also contains 32-- : useful type conversions functions, clock detection 33-- : functions, and other utility functions. 34-- : 35-- : If any argument to a function is a null array, a null array is 36-- : returned (exceptions, if any, are noted individually). 37-- 38-- Limitation : 39-- 40-- Note : No declarations or definitions shall be included in, 41-- : or excluded from this package. The "package declaration" 42-- : defines the types, subtypes and declarations of 43-- : NUMERIC_BIT. The NUMERIC_BIT package body shall be 44-- : considered the formal definition of the semantics of 45-- : this package. Tool developers may choose to implement 46-- : the package body in the most efficient manner available 47-- : to them. 48-- : 49-- ----------------------------------------------------------------------------- 50-- Version : 2.4 51-- Date : 12 April 1995 52-- ----------------------------------------------------------------------------- 53 54package NUMERIC_BIT is 55 constant CopyRightNotice: STRING 56 := "Copyright 1995 IEEE. All rights reserved."; 57 58 --============================================================================ 59 -- Numeric array type definitions 60 --============================================================================ 61 62 type UNSIGNED is array (NATURAL range <> ) of BIT; 63 type SIGNED is array (NATURAL range <> ) of BIT; 64 65 --============================================================================ 66 -- Arithmetic Operators: 67 --============================================================================ 68 69 -- Id: A.1 70 function "abs" (ARG: SIGNED) return SIGNED; 71 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0). 72 -- Result: Returns the absolute value of a SIGNED vector ARG. 73 74 -- Id: A.2 75 function "-" (ARG: SIGNED) return SIGNED; 76 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0). 77 -- Result: Returns the value of the unary minus operation on a 78 -- SIGNED vector ARG. 79 80 --============================================================================ 81 82 -- Id: A.3 83 function "+" (L, R: UNSIGNED) return UNSIGNED; 84 -- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0). 85 -- Result: Adds two UNSIGNED vectors that may be of different lengths. 86 87 -- Id: A.4 88 function "+" (L, R: SIGNED) return SIGNED; 89 -- Result subtype: SIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0). 90 -- Result: Adds two SIGNED vectors that may be of different lengths. 91 92 -- Id: A.5 93 function "+" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 94 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0). 95 -- Result: Adds an UNSIGNED vector, L, with a non-negative INTEGER, R. 96 97 -- Id: A.6 98 function "+" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 99 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0). 100 -- Result: Adds a non-negative INTEGER, L, with an UNSIGNED vector, R. 101 102 -- Id: A.7 103 function "+" (L: INTEGER; R: SIGNED) return SIGNED; 104 -- Result subtype: SIGNED(R'LENGTH-1 downto 0). 105 -- Result: Adds an INTEGER, L(may be positive or negative), to a SIGNED 106 -- vector, R. 107 108 -- Id: A.8 109 function "+" (L: SIGNED; R: INTEGER) return SIGNED; 110 -- Result subtype: SIGNED(L'LENGTH-1 downto 0). 111 -- Result: Adds a SIGNED vector, L, to an INTEGER, R. 112 113 --============================================================================ 114 115 -- Id: A.9 116 function "-" (L, R: UNSIGNED) return UNSIGNED; 117 -- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0). 118 -- Result: Subtracts two UNSIGNED vectors that may be of different lengths. 119 120 -- Id: A.10 121 function "-" (L, R: SIGNED) return SIGNED; 122 -- Result subtype: SIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0). 123 -- Result: Subtracts a SIGNED vector, R, from another SIGNED vector, L, 124 -- that may possibly be of different lengths. 125 126 -- Id: A.11 127 function "-" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 128 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0). 129 -- Result: Subtracts a non-negative INTEGER, R, from an UNSIGNED vector, L. 130 131 -- Id: A.12 132 function "-" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 133 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0). 134 -- Result: Subtracts an UNSIGNED vector, R, from a non-negative INTEGER, L. 135 136 -- Id: A.13 137 function "-" (L: SIGNED; R: INTEGER) return SIGNED; 138 -- Result subtype: SIGNED(L'LENGTH-1 downto 0). 139 -- Result: Subtracts an INTEGER, R, from a SIGNED vector, L. 140 141 -- Id: A.14 142 function "-" (L: INTEGER; R: SIGNED) return SIGNED; 143 -- Result subtype: SIGNED(R'LENGTH-1 downto 0). 144 -- Result: Subtracts a SIGNED vector, R, from an INTEGER, L. 145 146 --============================================================================ 147 148 -- Id: A.15 149 function "*" (L, R: UNSIGNED) return UNSIGNED; 150 -- Result subtype: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0). 151 -- Result: Performs the multiplication operation on two UNSIGNED vectors 152 -- that may possibly be of different lengths. 153 154 -- Id: A.16 155 function "*" (L, R: SIGNED) return SIGNED; 156 -- Result subtype: SIGNED((L'LENGTH+R'LENGTH-1) downto 0) 157 -- Result: Multiplies two SIGNED vectors that may possibly be of 158 -- different lengths. 159 160 -- Id: A.17 161 function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 162 -- Result subtype: UNSIGNED((L'LENGTH+L'LENGTH-1) downto 0). 163 -- Result: Multiplies an UNSIGNED vector, L, with a non-negative 164 -- INTEGER, R. R is converted to an UNSIGNED vector of 165 -- size L'LENGTH before multiplication. 166 167 -- Id: A.18 168 function "*" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 169 -- Result subtype: UNSIGNED((R'LENGTH+R'LENGTH-1) downto 0). 170 -- Result: Multiplies an UNSIGNED vector, R, with a non-negative 171 -- INTEGER, L. L is converted to an UNSIGNED vector of 172 -- size R'LENGTH before multiplication. 173 174 -- Id: A.19 175 function "*" (L: SIGNED; R: INTEGER) return SIGNED; 176 -- Result subtype: SIGNED((L'LENGTH+L'LENGTH-1) downto 0) 177 -- Result: Multiplies a SIGNED vector, L, with an INTEGER, R. R is 178 -- converted to a SIGNED vector of size L'LENGTH before 179 -- multiplication. 180 181 -- Id: A.20 182 function "*" (L: INTEGER; R: SIGNED) return SIGNED; 183 -- Result subtype: SIGNED((R'LENGTH+R'LENGTH-1) downto 0) 184 -- Result: Multiplies a SIGNED vector, R, with an INTEGER, L. L is 185 -- converted to a SIGNED vector of size R'LENGTH before 186 -- multiplication. 187 188 --============================================================================ 189 -- 190 -- NOTE: If second argument is zero for "/" operator, a severity level 191 -- of ERROR is issued. 192 193 -- Id: A.21 194 function "/" (L, R: UNSIGNED) return UNSIGNED; 195 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 196 -- Result: Divides an UNSIGNED vector, L, by another UNSIGNED vector, R. 197 198 -- Id: A.22 199 function "/" (L, R: SIGNED) return SIGNED; 200 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 201 -- Result: Divides an SIGNED vector, L, by another SIGNED vector, R. 202 203 -- Id: A.23 204 function "/" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 205 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 206 -- Result: Divides an UNSIGNED vector, L, by a non-negative INTEGER, R. 207 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 208 209 -- Id: A.24 210 function "/" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 211 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0) 212 -- Result: Divides a non-negative INTEGER, L, by an UNSIGNED vector, R. 213 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 214 215 -- Id: A.25 216 function "/" (L: SIGNED; R: INTEGER) return SIGNED; 217 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 218 -- Result: Divides a SIGNED vector, L, by an INTEGER, R. 219 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 220 221 -- Id: A.26 222 function "/" (L: INTEGER; R: SIGNED) return SIGNED; 223 -- Result subtype: SIGNED(R'LENGTH-1 downto 0) 224 -- Result: Divides an INTEGER, L, by a SIGNED vector, R. 225 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 226 227 --============================================================================ 228 -- 229 -- NOTE: If second argument is zero for "rem" operator, a severity level 230 -- of ERROR is issued. 231 232 -- Id: A.27 233 function "rem" (L, R: UNSIGNED) return UNSIGNED; 234 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0) 235 -- Result: Computes "L rem R" where L and R are UNSIGNED vectors. 236 237 -- Id: A.28 238 function "rem" (L, R: SIGNED) return SIGNED; 239 -- Result subtype: SIGNED(R'LENGTH-1 downto 0) 240 -- Result: Computes "L rem R" where L and R are SIGNED vectors. 241 242 -- Id: A.29 243 function "rem" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 244 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 245 -- Result: Computes "L rem R" where L is an UNSIGNED vector and R is a 246 -- non-negative INTEGER. 247 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 248 249 -- Id: A.30 250 function "rem" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 251 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0) 252 -- Result: Computes "L rem R" where R is an UNSIGNED vector and L is a 253 -- non-negative INTEGER. 254 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 255 256 -- Id: A.31 257 function "rem" (L: SIGNED; R: INTEGER) return SIGNED; 258 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 259 -- Result: Computes "L rem R" where L is SIGNED vector and R is an INTEGER. 260 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 261 262 -- Id: A.32 263 function "rem" (L: INTEGER; R: SIGNED) return SIGNED; 264 -- Result subtype: SIGNED(R'LENGTH-1 downto 0) 265 -- Result: Computes "L rem R" where R is SIGNED vector and L is an INTEGER. 266 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 267 268 --============================================================================ 269 -- 270 -- NOTE: If second argument is zero for "mod" operator, a severity level 271 -- of ERROR is issued. 272 273 -- Id: A.33 274 function "mod" (L, R: UNSIGNED) return UNSIGNED; 275 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0) 276 -- Result: Computes "L mod R" where L and R are UNSIGNED vectors. 277 278 -- Id: A.34 279 function "mod" (L, R: SIGNED) return SIGNED; 280 -- Result subtype: SIGNED(R'LENGTH-1 downto 0) 281 -- Result: Computes "L mod R" where L and R are SIGNED vectors. 282 283 -- Id: A.35 284 function "mod" (L: UNSIGNED; R: NATURAL) return UNSIGNED; 285 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 286 -- Result: Computes "L mod R" where L is an UNSIGNED vector and R 287 -- is a non-negative INTEGER. 288 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 289 290 -- Id: A.36 291 function "mod" (L: NATURAL; R: UNSIGNED) return UNSIGNED; 292 -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0) 293 -- Result: Computes "L mod R" where R is an UNSIGNED vector and L 294 -- is a non-negative INTEGER. 295 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 296 297 -- Id: A.37 298 function "mod" (L: SIGNED; R: INTEGER) return SIGNED; 299 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 300 -- Result: Computes "L mod R" where L is a SIGNED vector and 301 -- R is an INTEGER. 302 -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH. 303 304 -- Id: A.38 305 function "mod" (L: INTEGER; R: SIGNED) return SIGNED; 306 -- Result subtype: SIGNED(R'LENGTH-1 downto 0) 307 -- Result: Computes "L mod R" where L is an INTEGER and 308 -- R is a SIGNED vector. 309 -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH. 310 311 --============================================================================ 312 -- Comparison Operators 313 --============================================================================ 314 315 -- Id: C.1 316 function ">" (L, R: UNSIGNED) return BOOLEAN; 317 -- Result subtype: BOOLEAN 318 -- Result: Computes "L > R" where L and R are UNSIGNED vectors possibly 319 -- of different lengths. 320 321 -- Id: C.2 322 function ">" (L, R: SIGNED) return BOOLEAN; 323 -- Result subtype: BOOLEAN 324 -- Result: Computes "L > R" where L and R are SIGNED vectors possibly 325 -- of different lengths. 326 327 -- Id: C.3 328 function ">" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 329 -- Result subtype: BOOLEAN 330 -- Result: Computes "L > R" where L is a non-negative INTEGER and 331 -- R is an UNSIGNED vector. 332 333 -- Id: C.4 334 function ">" (L: INTEGER; R: SIGNED) return BOOLEAN; 335 -- Result subtype: BOOLEAN 336 -- Result: Computes "L > R" where L is a INTEGER and 337 -- R is a SIGNED vector. 338 339 -- Id: C.5 340 function ">" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 341 -- Result subtype: BOOLEAN 342 -- Result: Computes "L > R" where L is an UNSIGNED vector and 343 -- R is a non-negative INTEGER. 344 345 -- Id: C.6 346 function ">" (L: SIGNED; R: INTEGER) return BOOLEAN; 347 -- Result subtype: BOOLEAN 348 -- Result: Computes "L > R" where L is a SIGNED vector and 349 -- R is a INTEGER. 350 351 --============================================================================ 352 353 -- Id: C.7 354 function "<" (L, R: UNSIGNED) return BOOLEAN; 355 -- Result subtype: BOOLEAN 356 -- Result: Computes "L < R" where L and R are UNSIGNED vectors possibly 357 -- of different lengths. 358 359 -- Id: C.8 360 function "<" (L, R: SIGNED) return BOOLEAN; 361 -- Result subtype: BOOLEAN 362 -- Result: Computes "L < R" where L and R are SIGNED vectors possibly 363 -- of different lengths. 364 365 -- Id: C.9 366 function "<" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 367 -- Result subtype: BOOLEAN 368 -- Result: Computes "L < R" where L is a non-negative INTEGER and 369 -- R is an UNSIGNED vector. 370 371 -- Id: C.10 372 function "<" (L: INTEGER; R: SIGNED) return BOOLEAN; 373 -- Result subtype: BOOLEAN 374 -- Result: Computes "L < R" where L is an INTEGER and 375 -- R is a SIGNED vector. 376 377 -- Id: C.11 378 function "<" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 379 -- Result subtype: BOOLEAN 380 -- Result: Computes "L < R" where L is an UNSIGNED vector and 381 -- R is a non-negative INTEGER. 382 383 -- Id: C.12 384 function "<" (L: SIGNED; R: INTEGER) return BOOLEAN; 385 -- Result subtype: BOOLEAN 386 -- Result: Computes "L < R" where L is a SIGNED vector and 387 -- R is an INTEGER. 388 389 --============================================================================ 390 391 -- Id: C.13 392 function "<=" (L, R: UNSIGNED) return BOOLEAN; 393 -- Result subtype: BOOLEAN 394 -- Result: Computes "L <= R" where L and R are UNSIGNED vectors possibly 395 -- of different lengths. 396 397 -- Id: C.14 398 function "<=" (L, R: SIGNED) return BOOLEAN; 399 -- Result subtype: BOOLEAN 400 -- Result: Computes "L <= R" where L and R are SIGNED vectors possibly 401 -- of different lengths. 402 403 -- Id: C.15 404 function "<=" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 405 -- Result subtype: BOOLEAN 406 -- Result: Computes "L <= R" where L is a non-negative INTEGER and 407 -- R is an UNSIGNED vector. 408 409 -- Id: C.16 410 function "<=" (L: INTEGER; R: SIGNED) return BOOLEAN; 411 -- Result subtype: BOOLEAN 412 -- Result: Computes "L <= R" where L is an INTEGER and 413 -- R is a SIGNED vector. 414 415 -- Id: C.17 416 function "<=" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 417 -- Result subtype: BOOLEAN 418 -- Result: Computes "L <= R" where L is an UNSIGNED vector and 419 -- R is a non-negative INTEGER. 420 421 -- Id: C.18 422 function "<=" (L: SIGNED; R: INTEGER) return BOOLEAN; 423 -- Result subtype: BOOLEAN 424 -- Result: Computes "L <= R" where L is a SIGNED vector and 425 -- R is an INTEGER. 426 427 --============================================================================ 428 429 -- Id: C.19 430 function ">=" (L, R: UNSIGNED) return BOOLEAN; 431 -- Result subtype: BOOLEAN 432 -- Result: Computes "L >= R" where L and R are UNSIGNED vectors possibly 433 -- of different lengths. 434 435 -- Id: C.20 436 function ">=" (L, R: SIGNED) return BOOLEAN; 437 -- Result subtype: BOOLEAN 438 -- Result: Computes "L >= R" where L and R are SIGNED vectors possibly 439 -- of different lengths. 440 441 -- Id: C.21 442 function ">=" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 443 -- Result subtype: BOOLEAN 444 -- Result: Computes "L >= R" where L is a non-negative INTEGER and 445 -- R is an UNSIGNED vector. 446 447 -- Id: C.22 448 function ">=" (L: INTEGER; R: SIGNED) return BOOLEAN; 449 -- Result subtype: BOOLEAN 450 -- Result: Computes "L >= R" where L is an INTEGER and 451 -- R is a SIGNED vector. 452 453 -- Id: C.23 454 function ">=" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 455 -- Result subtype: BOOLEAN 456 -- Result: Computes "L >= R" where L is an UNSIGNED vector and 457 -- R is a non-negative INTEGER. 458 459 -- Id: C.24 460 function ">=" (L: SIGNED; R: INTEGER) return BOOLEAN; 461 -- Result subtype: BOOLEAN 462 -- Result: Computes "L >= R" where L is a SIGNED vector and 463 -- R is an INTEGER. 464 465 --============================================================================ 466 467 -- Id: C.25 468 function "=" (L, R: UNSIGNED) return BOOLEAN; 469 -- Result subtype: BOOLEAN 470 -- Result: Computes "L = R" where L and R are UNSIGNED vectors possibly 471 -- of different lengths. 472 473 -- Id: C.26 474 function "=" (L, R: SIGNED) return BOOLEAN; 475 -- Result subtype: BOOLEAN 476 -- Result: Computes "L = R" where L and R are SIGNED vectors possibly 477 -- of different lengths. 478 479 -- Id: C.27 480 function "=" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 481 -- Result subtype: BOOLEAN 482 -- Result: Computes "L = R" where L is a non-negative INTEGER and 483 -- R is an UNSIGNED vector. 484 485 -- Id: C.28 486 function "=" (L: INTEGER; R: SIGNED) return BOOLEAN; 487 -- Result subtype: BOOLEAN 488 -- Result: Computes "L = R" where L is an INTEGER and 489 -- R is a SIGNED vector. 490 491 -- Id: C.29 492 function "=" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 493 -- Result subtype: BOOLEAN 494 -- Result: Computes "L = R" where L is an UNSIGNED vector and 495 -- R is a non-negative INTEGER. 496 497 -- Id: C.30 498 function "=" (L: SIGNED; R: INTEGER) return BOOLEAN; 499 -- Result subtype: BOOLEAN 500 -- Result: Computes "L = R" where L is a SIGNED vector and 501 -- R is an INTEGER. 502 503 --============================================================================ 504 505 -- Id: C.31 506 function "/=" (L, R: UNSIGNED) return BOOLEAN; 507 -- Result subtype: BOOLEAN 508 -- Result: Computes "L /= R" where L and R are UNSIGNED vectors possibly 509 -- of different lengths. 510 511 -- Id: C.32 512 function "/=" (L, R: SIGNED) return BOOLEAN; 513 -- Result subtype: BOOLEAN 514 -- Result: Computes "L /= R" where L and R are SIGNED vectors possibly 515 -- of different lengths. 516 517 -- Id: C.33 518 function "/=" (L: NATURAL; R: UNSIGNED) return BOOLEAN; 519 -- Result subtype: BOOLEAN 520 -- Result: Computes "L /= R" where L is a non-negative INTEGER and 521 -- R is an UNSIGNED vector. 522 523 -- Id: C.34 524 function "/=" (L: INTEGER; R: SIGNED) return BOOLEAN; 525 -- Result subtype: BOOLEAN 526 -- Result: Computes "L /= R" where L is an INTEGER and 527 -- R is a SIGNED vector. 528 529 -- Id: C.35 530 function "/=" (L: UNSIGNED; R: NATURAL) return BOOLEAN; 531 -- Result subtype: BOOLEAN 532 -- Result: Computes "L /= R" where L is an UNSIGNED vector and 533 -- R is a non-negative INTEGER. 534 535 -- Id: C.36 536 function "/=" (L: SIGNED; R: INTEGER) return BOOLEAN; 537 -- Result subtype: BOOLEAN 538 -- Result: Computes "L /= R" where L is a SIGNED vector and 539 -- R is an INTEGER. 540 541 --============================================================================ 542 -- Shift and Rotate Functions 543 --============================================================================ 544 545 -- Id: S.1 546 function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 547 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 548 -- Result: Performs a shift-left on an UNSIGNED vector COUNT times. 549 -- The vacated positions are filled with Bit '0'. 550 -- The COUNT leftmost bits are lost. 551 552 -- Id: S.2 553 function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 554 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 555 -- Result: Performs a shift-right on an UNSIGNED vector COUNT times. 556 -- The vacated positions are filled with Bit '0'. 557 -- The COUNT rightmost bits are lost. 558 559 -- Id: S.3 560 function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 561 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 562 -- Result: Performs a shift-left on a SIGNED vector COUNT times. 563 -- The vacated positions are filled with Bit '0'. 564 -- The COUNT leftmost bits, except ARG'LEFT, are lost. 565 566 -- Id: S.4 567 function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 568 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 569 -- Result: Performs a shift-right on a SIGNED vector COUNT times. 570 -- The vacated positions are filled with the leftmost bit, ARG'LEFT. 571 -- The COUNT rightmost bits are lost. 572 573 --============================================================================ 574 575 -- Id: S.5 576 function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 577 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 578 -- Result: Performs a rotate-left of an UNSIGNED vector COUNT times. 579 580 -- Id: S.6 581 function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 582 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 583 -- Result: Performs a rotate-right of an UNSIGNED vector COUNT times. 584 585 -- Id: S.7 586 function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 587 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 588 -- Result: Performs a logical rotate-left of a SIGNED vector COUNT times. 589 590 -- Id: S.8 591 function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 592 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 593 -- Result: Performs a logical rotate-right of a SIGNED vector COUNT times. 594 595 --============================================================================ 596 597 ------------------------------------------------------------------------------ 598 -- Note : Function S.9 is not compatible with VHDL 1076-1987. Comment 599 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 600 ------------------------------------------------------------------------------ 601 -- Id: S.9 602 function "sll" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED; 603 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 604 -- Result: SHIFT_LEFT(ARG, COUNT) 605 606 ------------------------------------------------------------------------------ 607 -- Note : Function S.10 is not compatible with VHDL 1076-1987. Comment 608 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 609 ------------------------------------------------------------------------------ 610 -- Id: S.10 611 function "sll" (ARG: SIGNED; COUNT: INTEGER) return SIGNED; 612 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 613 -- Result: SHIFT_LEFT(ARG, COUNT) 614 615 ------------------------------------------------------------------------------ 616 -- Note : Function S.11 is not compatible with VHDL 1076-1987. Comment 617 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 618 ------------------------------------------------------------------------------ 619 -- Id: S.11 620 function "srl" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED; 621 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 622 -- Result: SHIFT_RIGHT(ARG, COUNT) 623 624 ------------------------------------------------------------------------------ 625 -- Note : Function S.12 is not compatible with VHDL 1076-1987. Comment 626 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 627 ------------------------------------------------------------------------------ 628 -- Id: S.12 629 function "srl" (ARG: SIGNED; COUNT: INTEGER) return SIGNED; 630 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 631 -- Result: SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), COUNT)) 632 633 ------------------------------------------------------------------------------ 634 -- Note : Function S.13 is not compatible with VHDL 1076-1987. Comment 635 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 636 ------------------------------------------------------------------------------ 637 -- Id: S.13 638 function "rol" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED; 639 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 640 -- Result: ROTATE_LEFT(ARG, COUNT) 641 642 ------------------------------------------------------------------------------ 643 -- Note : Function S.14 is not compatible with VHDL 1076-1987. Comment 644 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 645 ------------------------------------------------------------------------------ 646 -- Id: S.14 647 function "rol" (ARG: SIGNED; COUNT: INTEGER) return SIGNED; 648 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 649 -- Result: ROTATE_LEFT(ARG, COUNT) 650 651 ------------------------------------------------------------------------------ 652 -- Note : Function S.15 is not compatible with VHDL 1076-1987. Comment 653 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 654 ------------------------------------------------------------------------------ 655 -- Id: S.15 656 function "ror" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED; 657 -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 658 -- Result: ROTATE_RIGHT(ARG, COUNT) 659 660 ------------------------------------------------------------------------------ 661 -- Note : Function S.16 is not compatible with VHDL 1076-1987. Comment 662 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 663 ------------------------------------------------------------------------------ 664 -- Id: S.16 665 function "ror" (ARG: SIGNED; COUNT: INTEGER) return SIGNED; 666 -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 667 -- Result: ROTATE_RIGHT(ARG, COUNT) 668 669 --============================================================================ 670 -- RESIZE Functions 671 --============================================================================ 672 673 -- Id: R.1 674 function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED; 675 -- Result subtype: SIGNED(NEW_SIZE-1 downto 0) 676 -- Result: Resizes the SIGNED vector ARG to the specified size. 677 -- To create a larger vector, the new [leftmost] bit positions 678 -- are filled with the sign bit (ARG'LEFT). When truncating, 679 -- the sign bit is retained along with the rightmost part. 680 681 -- Id: R.2 682 function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED; 683 -- Result subtype: UNSIGNED(NEW_SIZE-1 downto 0) 684 -- Result: Resizes the UNSIGNED vector ARG to the specified size. 685 -- To create a larger vector, the new [leftmost] bit positions 686 -- are filled with '0'. When truncating, the leftmost bits 687 -- are dropped. 688 689 --============================================================================ 690 -- Conversion Functions 691 --============================================================================ 692 693 -- Id: D.1 694 function TO_INTEGER (ARG: UNSIGNED) return NATURAL; 695 -- Result subtype: NATURAL. Value cannot be negative since parameter is an 696 -- UNSIGNED vector. 697 -- Result: Converts the UNSIGNED vector to an INTEGER. 698 699 -- Id: D.2 700 function TO_INTEGER (ARG: SIGNED) return INTEGER; 701 -- Result subtype: INTEGER 702 -- Result: Converts a SIGNED vector to an INTEGER. 703 704 -- Id: D.3 705 function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED; 706 -- Result subtype: UNSIGNED(SIZE-1 downto 0) 707 -- Result: Converts a non-negative INTEGER to an UNSIGNED vector with 708 -- the specified size. 709 710 -- Id: D.4 711 function TO_SIGNED (ARG: INTEGER; SIZE: NATURAL) return SIGNED; 712 -- Result subtype: SIGNED(SIZE-1 downto 0) 713 -- Result: Converts an INTEGER to a SIGNED vector of the specified size. 714 715 --============================================================================ 716 -- Logical Operators 717 --============================================================================ 718 719 -- Id: L.1 720 function "not" (L: UNSIGNED) return UNSIGNED; 721 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 722 -- Result: Termwise inversion 723 724 -- Id: L.2 725 function "and" (L, R: UNSIGNED) return UNSIGNED; 726 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 727 -- Result: Vector AND operation 728 729 -- Id: L.3 730 function "or" (L, R: UNSIGNED) return UNSIGNED; 731 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 732 -- Result: Vector OR operation 733 734 -- Id: L.4 735 function "nand" (L, R: UNSIGNED) return UNSIGNED; 736 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 737 -- Result: Vector NAND operation 738 739 -- Id: L.5 740 function "nor" (L, R: UNSIGNED) return UNSIGNED; 741 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 742 -- Result: Vector NOR operation 743 744 -- Id: L.6 745 function "xor" (L, R: UNSIGNED) return UNSIGNED; 746 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 747 -- Result: Vector XOR operation 748 749 ------------------------------------------------------------------------------ 750 -- Note : Function L.7 is not compatible with VHDL 1076-1987. Comment 751 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 752 ------------------------------------------------------------------------------ 753 -- Id: L.7 754 function "xnor" (L, R: UNSIGNED) return UNSIGNED; 755 -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0) 756 -- Result: Vector XNOR operation 757 758 -- Id: L.8 759 function "not" (L: SIGNED) return SIGNED; 760 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 761 -- Result: Termwise inversion 762 763 -- Id: L.9 764 function "and" (L, R: SIGNED) return SIGNED; 765 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 766 -- Result: Vector AND operation 767 768 -- Id: L.10 769 function "or" (L, R: SIGNED) return SIGNED; 770 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 771 -- Result: Vector OR operation 772 773 -- Id: L.11 774 function "nand" (L, R: SIGNED) return SIGNED; 775 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 776 -- Result: Vector NAND operation 777 778 -- Id: L.12 779 function "nor" (L, R: SIGNED) return SIGNED; 780 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 781 -- Result: Vector NOR operation 782 783 -- Id: L.13 784 function "xor" (L, R: SIGNED) return SIGNED; 785 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 786 -- Result: Vector XOR operation 787 788 ------------------------------------------------------------------------------ 789 -- Note : Function L.14 is not compatible with VHDL 1076-1987. Comment 790 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 791 ------------------------------------------------------------------------------ 792 -- Id: L.14 793 function "xnor" (L, R: SIGNED) return SIGNED; 794 -- Result subtype: SIGNED(L'LENGTH-1 downto 0) 795 -- Result: Vector XNOR operation 796 797 --============================================================================ 798 -- Edge Detection Functions 799 --============================================================================ 800 801 -- Id: E.1 802 function RISING_EDGE (signal S: BIT) return BOOLEAN; 803 -- Result subtype: BOOLEAN 804 -- Result: Returns TRUE if an event is detected on signal S and the 805 -- value changed from a '0' to a '1'. 806 807 -- Id: E.2 808 function FALLING_EDGE (signal S: BIT) return BOOLEAN; 809 -- Result subtype: BOOLEAN 810 -- Result: Returns TRUE if an event is detected on signal S and the 811 -- value changed from a '1' to a '0'. 812 813end NUMERIC_BIT; 814 815--============================================================================== 816--======================= Package Body ========================================= 817--============================================================================== 818 819package body NUMERIC_BIT is 820 821 -- null range array constants 822 823 constant NAU: UNSIGNED(0 downto 1) := (others => '0'); 824 constant NAS: SIGNED(0 downto 1) := (others => '0'); 825 826 -- implementation controls 827 828 constant NO_WARNING: BOOLEAN := FALSE; -- default to emit warnings 829 830 --=========================Local Subprograms ================================= 831 832 function MAX (LEFT, RIGHT: INTEGER) return INTEGER is 833 begin 834 if LEFT > RIGHT then return LEFT; 835 else return RIGHT; 836 end if; 837 end MAX; 838 839 function MIN (LEFT, RIGHT: INTEGER) return INTEGER is 840 begin 841 if LEFT < RIGHT then return LEFT; 842 else return RIGHT; 843 end if; 844 end MIN; 845 846 function SIGNED_NUM_BITS (ARG: INTEGER) return NATURAL is 847 variable NBITS: NATURAL; 848 variable N: NATURAL; 849 begin 850 if ARG >= 0 then 851 N := ARG; 852 else 853 N := -(ARG+1); 854 end if; 855 NBITS := 1; 856 while N > 0 loop 857 NBITS := NBITS+1; 858 N := N / 2; 859 end loop; 860 return NBITS; 861 end SIGNED_NUM_BITS; 862 863 function UNSIGNED_NUM_BITS (ARG: NATURAL) return NATURAL is 864 variable NBITS: NATURAL; 865 variable N: NATURAL; 866 begin 867 N := ARG; 868 NBITS := 1; 869 while N > 1 loop 870 NBITS := NBITS+1; 871 N := N / 2; 872 end loop; 873 return NBITS; 874 end UNSIGNED_NUM_BITS; 875 876 ------------------------------------------------------------------------------ 877 -- this internal function computes the addition of two UNSIGNED 878 -- with input carry 879 -- * the two arguments are of the same length 880 881 function ADD_UNSIGNED (L, R: UNSIGNED; C: BIT) return UNSIGNED is 882 constant L_LEFT: INTEGER := L'LENGTH-1; 883 alias XL: UNSIGNED(L_LEFT downto 0) is L; 884 alias XR: UNSIGNED(L_LEFT downto 0) is R; 885 variable RESULT: UNSIGNED(L_LEFT downto 0); 886 variable CBIT: BIT := C; 887 begin 888 for I in 0 to L_LEFT loop 889 RESULT(I) := CBIT xor XL(I) xor XR(I); 890 CBIT := (CBIT and XL(I)) or (CBIT and XR(I)) or (XL(I) and XR(I)); 891 end loop; 892 return RESULT; 893 end ADD_UNSIGNED; 894 895 -- this internal function computes the addition of two SIGNED 896 -- with input carry 897 -- * the two arguments are of the same length 898 899 function ADD_SIGNED (L, R: SIGNED; C: BIT) return SIGNED is 900 constant L_LEFT: INTEGER := L'LENGTH-1; 901 alias XL: SIGNED(L_LEFT downto 0) is L; 902 alias XR: SIGNED(L_LEFT downto 0) is R; 903 variable RESULT: SIGNED(L_LEFT downto 0); 904 variable CBIT: BIT := C; 905 begin 906 for I in 0 to L_LEFT loop 907 RESULT(I) := CBIT xor XL(I) xor XR(I); 908 CBIT := (CBIT and XL(I)) or (CBIT and XR(I)) or (XL(I) and XR(I)); 909 end loop; 910 return RESULT; 911 end ADD_SIGNED; 912 913 ------------------------------------------------------------------------------ 914 915 -- this internal procedure computes UNSIGNED division 916 -- giving the quotient and remainder. 917 procedure DIVMOD (NUM, XDENOM: UNSIGNED; XQUOT, XREMAIN: out UNSIGNED) is 918 variable TEMP: UNSIGNED(NUM'LENGTH downto 0); 919 variable QUOT: UNSIGNED(MAX(NUM'LENGTH, XDENOM'LENGTH)-1 downto 0); 920 alias DENOM: UNSIGNED(XDENOM'LENGTH-1 downto 0) is XDENOM; 921 variable TOPBIT: INTEGER; 922 begin 923 TEMP := "0"&NUM; 924 QUOT := (others => '0'); 925 TOPBIT := -1; 926 for J in DENOM'RANGE loop 927 if DENOM(J)='1' then 928 TOPBIT := J; 929 exit; 930 end if; 931 end loop; 932 assert TOPBIT >= 0 report "DIV, MOD, or REM by zero" severity ERROR; 933 934 for J in NUM'LENGTH-(TOPBIT+1) downto 0 loop 935 if TEMP(TOPBIT+J+1 downto J) >= "0"&DENOM(TOPBIT downto 0) then 936 TEMP(TOPBIT+J+1 downto J) := (TEMP(TOPBIT+J+1 downto J)) 937 -("0"&DENOM(TOPBIT downto 0)); 938 QUOT(J) := '1'; 939 end if; 940 assert TEMP(TOPBIT+J+1)='0' 941 report "internal error in the division algorithm" 942 severity ERROR; 943 end loop; 944 XQUOT := RESIZE(QUOT, XQUOT'LENGTH); 945 XREMAIN := RESIZE(TEMP, XREMAIN'LENGTH); 946 end DIVMOD; 947 948 -----------------Local Subprograms - shift/rotate ops------------------------- 949 950 function XSLL (ARG: BIT_VECTOR; COUNT: NATURAL) return BIT_VECTOR is 951 constant ARG_L: INTEGER := ARG'LENGTH-1; 952 alias XARG: BIT_VECTOR(ARG_L downto 0) is ARG; 953 variable RESULT: BIT_VECTOR(ARG_L downto 0) := (others => '0'); 954 begin 955 if COUNT <= ARG_L then 956 RESULT(ARG_L downto COUNT) := XARG(ARG_L-COUNT downto 0); 957 end if; 958 return RESULT; 959 end XSLL; 960 961 function XSRL (ARG: BIT_VECTOR; COUNT: NATURAL) return BIT_VECTOR is 962 constant ARG_L: INTEGER := ARG'LENGTH-1; 963 alias XARG: BIT_VECTOR(ARG_L downto 0) is ARG; 964 variable RESULT: BIT_VECTOR(ARG_L downto 0) := (others => '0'); 965 begin 966 if COUNT <= ARG_L then 967 RESULT(ARG_L-COUNT downto 0) := XARG(ARG_L downto COUNT); 968 end if; 969 return RESULT; 970 end XSRL; 971 972 function XSRA (ARG: BIT_VECTOR; COUNT: NATURAL) return BIT_VECTOR is 973 constant ARG_L: INTEGER := ARG'LENGTH-1; 974 alias XARG: BIT_VECTOR(ARG_L downto 0) is ARG; 975 variable RESULT: BIT_VECTOR(ARG_L downto 0); 976 variable XCOUNT: NATURAL := COUNT; 977 begin 978 if ((ARG'LENGTH <= 1) or (XCOUNT = 0)) then return ARG; 979 else 980 if (XCOUNT > ARG_L) then XCOUNT := ARG_L; 981 end if; 982 RESULT(ARG_L-XCOUNT downto 0) := XARG(ARG_L downto XCOUNT); 983 RESULT(ARG_L downto (ARG_L - XCOUNT + 1)) := (others => XARG(ARG_L)); 984 end if; 985 return RESULT; 986 end XSRA; 987 988 function XROL (ARG: BIT_VECTOR; COUNT: NATURAL) return BIT_VECTOR is 989 constant ARG_L: INTEGER := ARG'LENGTH-1; 990 alias XARG: BIT_VECTOR(ARG_L downto 0) is ARG; 991 variable RESULT: BIT_VECTOR(ARG_L downto 0) := XARG; 992 variable COUNTM: INTEGER; 993 begin 994 COUNTM := COUNT mod (ARG_L + 1); 995 if COUNTM /= 0 then 996 RESULT(ARG_L downto COUNTM) := XARG(ARG_L-COUNTM downto 0); 997 RESULT(COUNTM-1 downto 0) := XARG(ARG_L downto ARG_L-COUNTM+1); 998 end if; 999 return RESULT; 1000 end XROL; 1001 1002 function XROR (ARG: BIT_VECTOR; COUNT: NATURAL) return BIT_VECTOR is 1003 constant ARG_L: INTEGER := ARG'LENGTH-1; 1004 alias XARG: BIT_VECTOR(ARG_L downto 0) is ARG; 1005 variable RESULT: BIT_VECTOR(ARG_L downto 0) := XARG; 1006 variable COUNTM: INTEGER; 1007 begin 1008 COUNTM := COUNT mod (ARG_L + 1); 1009 if COUNTM /= 0 then 1010 RESULT(ARG_L-COUNTM downto 0) := XARG(ARG_L downto COUNTM); 1011 RESULT(ARG_L downto ARG_L-COUNTM+1) := XARG(COUNTM-1 downto 0); 1012 end if; 1013 return RESULT; 1014 end XROR; 1015 1016 ---------------- Local Subprograms - Relational Operators -------------------- 1017 1018 -- General "=" for UNSIGNED vectors, same length 1019 -- 1020 function UNSIGNED_EQUAL (L, R: UNSIGNED) return BOOLEAN is 1021 begin 1022 return BIT_VECTOR(L) = BIT_VECTOR(R); 1023 end UNSIGNED_EQUAL; 1024 1025 -- 1026 -- General "=" for SIGNED vectors, same length 1027 -- 1028 function SIGNED_EQUAL (L, R: SIGNED) return BOOLEAN is 1029 begin 1030 return BIT_VECTOR(L) = BIT_VECTOR(R); 1031 end SIGNED_EQUAL; 1032 1033 -- 1034 -- General "<" for UNSIGNED vectors, same length 1035 -- 1036 function UNSIGNED_LESS (L, R: UNSIGNED) return BOOLEAN is 1037 begin 1038 return BIT_VECTOR(L) < BIT_VECTOR(R); 1039 end UNSIGNED_LESS; 1040 1041 -- 1042 -- General "<" function for SIGNED vectors, same length 1043 -- 1044 function SIGNED_LESS (L, R: SIGNED) return BOOLEAN is 1045 -- Need aliases to assure index direction 1046 variable INTERN_L: SIGNED(0 to L'LENGTH-1); 1047 variable INTERN_R: SIGNED(0 to R'LENGTH-1); 1048 begin 1049 INTERN_L := L; 1050 INTERN_R := R; 1051 INTERN_L(0) := not INTERN_L(0); 1052 INTERN_R(0) := not INTERN_R(0); 1053 return BIT_VECTOR(INTERN_L) < BIT_VECTOR(INTERN_R); 1054 end SIGNED_LESS; 1055 1056 -- 1057 -- General "<=" function for UNSIGNED vectors, same length 1058 -- 1059 function UNSIGNED_LESS_OR_EQUAL (L, R: UNSIGNED) return BOOLEAN is 1060 begin 1061 return BIT_VECTOR(L) <= BIT_VECTOR(R); 1062 end UNSIGNED_LESS_OR_EQUAL; 1063 1064 -- 1065 -- General "<=" function for SIGNED vectors, same length 1066 -- 1067 function SIGNED_LESS_OR_EQUAL (L, R: SIGNED) return BOOLEAN is 1068 -- Need aliases to assure index direction 1069 variable INTERN_L: SIGNED(0 to L'LENGTH-1); 1070 variable INTERN_R: SIGNED(0 to R'LENGTH-1); 1071 begin 1072 INTERN_L := L; 1073 INTERN_R := R; 1074 INTERN_L(0) := not INTERN_L(0); 1075 INTERN_R(0) := not INTERN_R(0); 1076 return BIT_VECTOR(INTERN_L) <= BIT_VECTOR(INTERN_R); 1077 end SIGNED_LESS_OR_EQUAL; 1078 1079 --====================== Exported Functions ================================== 1080 1081 -- Id: A.1 1082 function "abs" (ARG: SIGNED) return SIGNED is 1083 constant ARG_LEFT: INTEGER := ARG'LENGTH-1; 1084 variable RESULT: SIGNED(ARG_LEFT downto 0); 1085 begin 1086 if ARG'LENGTH < 1 then return NAS; 1087 end if; 1088 RESULT := ARG; 1089 if RESULT(RESULT'LEFT) = '1' then 1090 RESULT := -RESULT; 1091 end if; 1092 return RESULT; 1093 end "abs"; 1094 1095 -- Id: A.2 1096 function "-" (ARG: SIGNED) return SIGNED is 1097 constant ARG_LEFT: INTEGER := ARG'LENGTH-1; 1098 alias XARG: SIGNED(ARG_LEFT downto 0) is ARG; 1099 variable RESULT: SIGNED(ARG_LEFT downto 0); 1100 variable CBIT: BIT := '1'; 1101 begin 1102 if ARG'LENGTH < 1 then return NAS; 1103 end if; 1104 for I in 0 to RESULT'LEFT loop 1105 RESULT(I) := not(XARG(I)) xor CBIT; 1106 CBIT := CBIT and not(XARG(I)); 1107 end loop; 1108 return RESULT; 1109 end "-"; 1110 1111 --============================================================================ 1112 1113 -- Id: A.3 1114 function "+" (L, R: UNSIGNED) return UNSIGNED is 1115 constant L_LEFT: INTEGER := L'LENGTH-1; 1116 constant R_LEFT: INTEGER := R'LENGTH-1; 1117 constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1118 begin 1119 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1120 end if; 1121 return ADD_UNSIGNED(RESIZE(L, SIZE), RESIZE(R, SIZE), '0'); 1122 end "+"; 1123 1124 -- Id: A.4 1125 function "+" (L, R: SIGNED) return SIGNED is 1126 constant L_LEFT: INTEGER := L'LENGTH-1; 1127 constant R_LEFT: INTEGER := R'LENGTH-1; 1128 constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1129 begin 1130 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS; 1131 end if; 1132 return ADD_SIGNED(RESIZE(L, SIZE), RESIZE(R, SIZE), '0'); 1133 end "+"; 1134 1135 -- Id: A.5 1136 function "+" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1137 begin 1138 return L + TO_UNSIGNED(R, L'LENGTH); 1139 end "+"; 1140 1141 -- Id: A.6 1142 function "+" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1143 begin 1144 return TO_UNSIGNED(L, R'LENGTH) + R; 1145 end "+"; 1146 1147 -- Id: A.7 1148 function "+" (L: SIGNED; R: INTEGER) return SIGNED is 1149 begin 1150 return L + TO_SIGNED(R, L'LENGTH); 1151 end "+"; 1152 1153 -- Id: A.8 1154 function "+" (L: INTEGER; R: SIGNED) return SIGNED is 1155 begin 1156 return TO_SIGNED(L, R'LENGTH) + R; 1157 end "+"; 1158 1159 --============================================================================ 1160 1161 -- Id: A.9 1162 function "-" (L, R: UNSIGNED) return UNSIGNED is 1163 constant L_LEFT: INTEGER := L'LENGTH-1; 1164 constant R_LEFT: INTEGER := R'LENGTH-1; 1165 constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1166 begin 1167 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1168 end if; 1169 return ADD_UNSIGNED(RESIZE(L, SIZE), 1170 not(RESIZE(R, SIZE)), 1171 '1'); 1172 end "-"; 1173 1174 -- Id: A.10 1175 function "-" (L, R: SIGNED) return SIGNED is 1176 constant L_LEFT: INTEGER := L'LENGTH-1; 1177 constant R_LEFT: INTEGER := R'LENGTH-1; 1178 constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1179 begin 1180 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS; 1181 end if; 1182 return ADD_SIGNED(RESIZE(L, SIZE), 1183 not(RESIZE(R, SIZE)), 1184 '1'); 1185 end "-"; 1186 1187 -- Id: A.11 1188 function "-" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1189 begin 1190 return L - TO_UNSIGNED(R, L'LENGTH); 1191 end "-"; 1192 1193 -- Id: A.12 1194 function "-" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1195 begin 1196 return TO_UNSIGNED(L, R'LENGTH) - R; 1197 end "-"; 1198 1199 -- Id: A.13 1200 function "-" (L: SIGNED; R: INTEGER) return SIGNED is 1201 begin 1202 return L - TO_SIGNED(R, L'LENGTH); 1203 end "-"; 1204 1205 -- Id: A.14 1206 function "-" (L: INTEGER; R: SIGNED) return SIGNED is 1207 begin 1208 return TO_SIGNED(L, R'LENGTH) - R; 1209 end "-"; 1210 1211 --============================================================================ 1212 1213 -- Id: A.15 1214 function "*" (L, R: UNSIGNED) return UNSIGNED is 1215 constant L_LEFT: INTEGER := L'LENGTH-1; 1216 constant R_LEFT: INTEGER := R'LENGTH-1; 1217 alias XL: UNSIGNED(L_LEFT downto 0) is L; 1218 alias XR: UNSIGNED(R_LEFT downto 0) is R; 1219 variable RESULT: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0) := (others => '0'); 1220 variable ADVAL: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0); 1221 begin 1222 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1223 end if; 1224 ADVAL := RESIZE(XR, RESULT'LENGTH); 1225 for I in 0 to L_LEFT loop 1226 if XL(I)='1' then RESULT := RESULT + ADVAL; 1227 end if; 1228 ADVAL := SHIFT_LEFT(ADVAL, 1); 1229 end loop; 1230 return RESULT; 1231 end "*"; 1232 1233 -- Id: A.16 1234 function "*" (L, R: SIGNED) return SIGNED is 1235 constant L_LEFT: INTEGER := L'LENGTH-1; 1236 constant R_LEFT: INTEGER := R'LENGTH-1; 1237 variable XL: SIGNED(L_LEFT downto 0); 1238 variable XR: SIGNED(R_LEFT downto 0); 1239 variable RESULT: SIGNED((L_LEFT+R_LEFT+1) downto 0) := (others => '0'); 1240 variable ADVAL: SIGNED((L_LEFT+R_LEFT+1) downto 0); 1241 begin 1242 if ((L_LEFT < 0) or (R_LEFT < 0)) then return NAS; 1243 end if; 1244 XL := L; 1245 XR := R; 1246 ADVAL := RESIZE(XR, RESULT'LENGTH); 1247 for I in 0 to L_LEFT-1 loop 1248 if XL(I)='1' then RESULT := RESULT + ADVAL; 1249 end if; 1250 ADVAL := SHIFT_LEFT(ADVAL, 1); 1251 end loop; 1252 if XL(L_LEFT)='1' then 1253 RESULT := RESULT - ADVAL; 1254 end if; 1255 return RESULT; 1256 end "*"; 1257 1258 -- Id: A.17 1259 function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1260 begin 1261 return L * TO_UNSIGNED(R, L'LENGTH); 1262 end "*"; 1263 1264 -- Id: A.18 1265 function "*" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1266 begin 1267 return TO_UNSIGNED(L, R'LENGTH) * R; 1268 end "*"; 1269 1270 -- Id: A.19 1271 function "*" (L: SIGNED; R: INTEGER) return SIGNED is 1272 begin 1273 return L * TO_SIGNED(R, L'LENGTH); 1274 end "*"; 1275 1276 -- Id: A.20 1277 function "*" (L: INTEGER; R: SIGNED) return SIGNED is 1278 begin 1279 return TO_SIGNED(L, R'LENGTH) * R; 1280 end "*"; 1281 1282 --============================================================================ 1283 1284 -- Id: A.21 1285 function "/" (L, R: UNSIGNED) return UNSIGNED is 1286 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1287 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1288 begin 1289 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1290 end if; 1291 DIVMOD(L, R, FQUOT, FREMAIN); 1292 return FQUOT; 1293 end "/"; 1294 1295 -- Id: A.22 1296 function "/" (L, R: SIGNED) return SIGNED is 1297 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1298 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1299 variable XNUM: UNSIGNED(L'LENGTH-1 downto 0); 1300 variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0); 1301 variable QNEG: BOOLEAN := FALSE; 1302 begin 1303 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS; 1304 end if; 1305 if L(L'LEFT)='1' then 1306 XNUM := UNSIGNED(-L); 1307 QNEG := TRUE; 1308 else 1309 XNUM := UNSIGNED(L); 1310 end if; 1311 if R(R'LEFT)='1' then 1312 XDENOM := UNSIGNED(-R); 1313 QNEG := not QNEG; 1314 else 1315 XDENOM := UNSIGNED(R); 1316 end if; 1317 DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN); 1318 if QNEG then FQUOT := "0"-FQUOT; 1319 end if; 1320 return SIGNED(FQUOT); 1321 end "/"; 1322 1323 -- Id: A.23 1324 function "/" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1325 constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R)); 1326 variable XR, QUOT: UNSIGNED(R_LENGTH-1 downto 0); 1327 begin 1328 if (L'LENGTH < 1) then return NAU; 1329 end if; 1330 if (R_LENGTH > L'LENGTH) then 1331 QUOT := (others => '0'); 1332 return RESIZE(QUOT, L'LENGTH); 1333 end if; 1334 XR := TO_UNSIGNED(R, R_LENGTH); 1335 QUOT := RESIZE((L / XR), QUOT'LENGTH); 1336 return RESIZE(QUOT, L'LENGTH); 1337 end "/"; 1338 1339 -- Id: A.24 1340 function "/" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1341 constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH); 1342 variable XL, QUOT: UNSIGNED(L_LENGTH-1 downto 0); 1343 begin 1344 if (R'LENGTH < 1) then return NAU; 1345 end if; 1346 XL := TO_UNSIGNED(L, L_LENGTH); 1347 QUOT := RESIZE((XL / R), QUOT'LENGTH); 1348 if L_LENGTH > R'LENGTH 1349 and QUOT(L_LENGTH-1 downto R'LENGTH) 1350 /= (L_LENGTH-1 downto R'LENGTH => '0') 1351 then 1352 assert NO_WARNING report "NUMERIC_BIT.""/"": Quotient Truncated" 1353 severity WARNING; 1354 end if; 1355 return RESIZE(QUOT, R'LENGTH); 1356 end "/"; 1357 1358 -- Id: A.25 1359 function "/" (L: SIGNED; R: INTEGER) return SIGNED is 1360 constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R)); 1361 variable XR, QUOT: SIGNED(R_LENGTH-1 downto 0); 1362 begin 1363 if (L'LENGTH < 1) then return NAS; 1364 end if; 1365 if (R_LENGTH > L'LENGTH) then 1366 QUOT := (others => '0'); 1367 return RESIZE(QUOT, L'LENGTH); 1368 end if; 1369 XR := TO_SIGNED(R, R_LENGTH); 1370 QUOT := RESIZE((L / XR), QUOT'LENGTH); 1371 return RESIZE(QUOT, L'LENGTH); 1372 end "/"; 1373 1374 -- Id: A.26 1375 function "/" (L: INTEGER; R: SIGNED) return SIGNED is 1376 constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH); 1377 variable XL, QUOT: SIGNED(L_LENGTH-1 downto 0); 1378 begin 1379 if (R'LENGTH < 1) then return NAS; 1380 end if; 1381 XL := TO_SIGNED(L, L_LENGTH); 1382 QUOT := RESIZE((XL / R), QUOT'LENGTH); 1383 if L_LENGTH > R'LENGTH and QUOT(L_LENGTH-1 downto R'LENGTH) 1384 /= (L_LENGTH-1 downto R'LENGTH => QUOT(R'LENGTH-1)) 1385 then 1386 assert NO_WARNING report "NUMERIC_BIT.""/"": Quotient Truncated" 1387 severity WARNING; 1388 end if; 1389 return RESIZE(QUOT, R'LENGTH); 1390 end "/"; 1391 1392 --============================================================================ 1393 1394 -- Id: A.27 1395 function "rem" (L, R: UNSIGNED) return UNSIGNED is 1396 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1397 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1398 begin 1399 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1400 end if; 1401 DIVMOD(L, R, FQUOT, FREMAIN); 1402 return FREMAIN; 1403 end "rem"; 1404 1405 -- Id: A.28 1406 function "rem" (L, R: SIGNED) return SIGNED is 1407 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1408 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1409 variable XNUM: UNSIGNED(L'LENGTH-1 downto 0); 1410 variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0); 1411 variable RNEG: BOOLEAN := FALSE; 1412 begin 1413 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS; 1414 end if; 1415 if L(L'LEFT)='1' then 1416 XNUM := UNSIGNED(-L); 1417 RNEG := TRUE; 1418 else 1419 XNUM := UNSIGNED(L); 1420 end if; 1421 if R(R'LEFT)='1' then 1422 XDENOM := UNSIGNED(-R); 1423 else 1424 XDENOM := UNSIGNED(R); 1425 end if; 1426 DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN); 1427 if RNEG then 1428 FREMAIN := "0"-FREMAIN; 1429 end if; 1430 return SIGNED(FREMAIN); 1431 end "rem"; 1432 1433 -- Id: A.29 1434 function "rem" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1435 constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R)); 1436 variable XR, XREM: UNSIGNED(R_LENGTH-1 downto 0); 1437 begin 1438 if (L'LENGTH < 1) then return NAU; 1439 end if; 1440 XR := TO_UNSIGNED(R, R_LENGTH); 1441 XREM := RESIZE((L rem XR), XREM'LENGTH); 1442 if R_LENGTH > L'LENGTH and XREM(R_LENGTH-1 downto L'LENGTH) 1443 /= (R_LENGTH-1 downto L'LENGTH => '0') 1444 then 1445 assert NO_WARNING report "NUMERIC_BIT.""rem"": Remainder Truncated" 1446 severity WARNING; 1447 end if; 1448 return RESIZE(XREM, L'LENGTH); 1449 end "rem"; 1450 1451 -- Id: A.30 1452 function "rem" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1453 constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH); 1454 variable XL, XREM: UNSIGNED(L_LENGTH-1 downto 0); 1455 begin 1456 if (R'LENGTH < 1) then return NAU; 1457 end if; 1458 XL := TO_UNSIGNED(L, L_LENGTH); 1459 XREM := RESIZE((XL rem R), XREM'LENGTH); 1460 if L_LENGTH > R'LENGTH and XREM(L_LENGTH-1 downto R'LENGTH) 1461 /= (L_LENGTH-1 downto R'LENGTH => '0') 1462 then 1463 assert NO_WARNING report "NUMERIC_BIT.""rem"": Remainder Truncated" 1464 severity WARNING; 1465 end if; 1466 return RESIZE(XREM, R'LENGTH); 1467 end "rem"; 1468 1469 -- Id: A.31 1470 function "rem" (L: SIGNED; R: INTEGER) return SIGNED is 1471 constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R)); 1472 variable XR, XREM: SIGNED(R_LENGTH-1 downto 0); 1473 begin 1474 if (L'LENGTH < 1) then return NAS; 1475 end if; 1476 XR := TO_SIGNED(R, R_LENGTH); 1477 XREM := RESIZE((L rem XR), XREM'LENGTH); 1478 if R_LENGTH > L'LENGTH and XREM(R_LENGTH-1 downto L'LENGTH) 1479 /= (R_LENGTH-1 downto L'LENGTH => XREM(L'LENGTH-1)) 1480 then 1481 assert NO_WARNING report "NUMERIC_BIT.""rem"": Remainder Truncated" 1482 severity WARNING; 1483 end if; 1484 return RESIZE(XREM, L'LENGTH); 1485 end "rem"; 1486 1487 -- Id: A.32 1488 function "rem" (L: INTEGER; R: SIGNED) return SIGNED is 1489 constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH); 1490 variable XL, XREM: SIGNED(L_LENGTH-1 downto 0); 1491 begin 1492 if (R'LENGTH < 1) then return NAS; 1493 end if; 1494 XL := TO_SIGNED(L, L_LENGTH); 1495 XREM := RESIZE((XL rem R), XREM'LENGTH); 1496 if L_LENGTH > R'LENGTH and XREM(L_LENGTH-1 downto R'LENGTH) 1497 /= (L_LENGTH-1 downto R'LENGTH => XREM(R'LENGTH-1)) 1498 then 1499 assert NO_WARNING report "NUMERIC_BIT.""rem"": Remainder Truncated" 1500 severity WARNING; 1501 end if; 1502 return RESIZE(XREM, R'LENGTH); 1503 end "rem"; 1504 1505 --============================================================================ 1506 1507 -- Id: A.33 1508 function "mod" (L, R: UNSIGNED) return UNSIGNED is 1509 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1510 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1511 begin 1512 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU; 1513 end if; 1514 DIVMOD(L, R, FQUOT, FREMAIN); 1515 return FREMAIN; 1516 end "mod"; 1517 1518 -- Id: A.34 1519 function "mod" (L, R: SIGNED) return SIGNED is 1520 variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0); 1521 variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0); 1522 variable XNUM: UNSIGNED(L'LENGTH-1 downto 0); 1523 variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0); 1524 variable RNEG: BOOLEAN := FALSE; 1525 begin 1526 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS; 1527 end if; 1528 if L(L'LEFT)='1' then 1529 XNUM := UNSIGNED(-L); 1530 else 1531 XNUM := UNSIGNED(L); 1532 end if; 1533 if R(R'LEFT)='1' then 1534 XDENOM := UNSIGNED(-R); 1535 RNEG := TRUE; 1536 else 1537 XDENOM := UNSIGNED(R); 1538 end if; 1539 DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN); 1540 if RNEG and L(L'LEFT)='1' then 1541 FREMAIN := "0"-FREMAIN; 1542 elsif RNEG and FREMAIN/="0" then 1543 FREMAIN := FREMAIN-XDENOM; 1544 elsif L(L'LEFT)='1' and FREMAIN/="0" then 1545 FREMAIN := XDENOM-FREMAIN; 1546 end if; 1547 return SIGNED(FREMAIN); 1548 end "mod"; 1549 1550 -- Id: A.35 1551 function "mod" (L: UNSIGNED; R: NATURAL) return UNSIGNED is 1552 constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R)); 1553 variable XR, XREM: UNSIGNED(R_LENGTH-1 downto 0); 1554 begin 1555 if (L'LENGTH < 1) then return NAU; 1556 end if; 1557 XR := TO_UNSIGNED(R, R_LENGTH); 1558 XREM := RESIZE((L mod XR), XREM'LENGTH); 1559 if R_LENGTH > L'LENGTH and XREM(R_LENGTH-1 downto L'LENGTH) 1560 /= (R_LENGTH-1 downto L'LENGTH => '0') 1561 then 1562 assert NO_WARNING report "NUMERIC_BIT.""mod"": modulus Truncated" 1563 severity WARNING; 1564 end if; 1565 return RESIZE(XREM, L'LENGTH); 1566 end "mod"; 1567 1568 -- Id: A.36 1569 function "mod" (L: NATURAL; R: UNSIGNED) return UNSIGNED is 1570 constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH); 1571 variable XL, XREM: UNSIGNED(L_LENGTH-1 downto 0); 1572 begin 1573 if (R'LENGTH < 1) then return NAU; 1574 end if; 1575 XL := TO_UNSIGNED(L, L_LENGTH); 1576 XREM := RESIZE((XL mod R), XREM'LENGTH); 1577 if L_LENGTH > R'LENGTH and XREM(L_LENGTH-1 downto R'LENGTH) 1578 /= (L_LENGTH-1 downto R'LENGTH => '0') 1579 then 1580 assert NO_WARNING report "NUMERIC_BIT.""mod"": modulus Truncated" 1581 severity WARNING; 1582 end if; 1583 return RESIZE(XREM, R'LENGTH); 1584 end "mod"; 1585 1586 -- Id: A.37 1587 function "mod" (L: SIGNED; R: INTEGER) return SIGNED is 1588 constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R)); 1589 variable XR, XREM: SIGNED(R_LENGTH-1 downto 0); 1590 begin 1591 if (L'LENGTH < 1) then return NAS; 1592 end if; 1593 XR := TO_SIGNED(R, R_LENGTH); 1594 XREM := RESIZE((L mod XR), XREM'LENGTH); 1595 if R_LENGTH > L'LENGTH and XREM(R_LENGTH-1 downto L'LENGTH) 1596 /= (R_LENGTH-1 downto L'LENGTH => XREM(L'LENGTH-1)) 1597 then 1598 assert NO_WARNING report "NUMERIC_BIT.""mod"": modulus Truncated" 1599 severity WARNING; 1600 end if; 1601 return RESIZE(XREM, L'LENGTH); 1602 end "mod"; 1603 1604 -- Id: A.38 1605 function "mod" (L: INTEGER; R: SIGNED) return SIGNED is 1606 constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH); 1607 variable XL, XREM: SIGNED(L_LENGTH-1 downto 0); 1608 begin 1609 if (R'LENGTH < 1) then return NAS; 1610 end if; 1611 XL := TO_SIGNED(L, L_LENGTH); 1612 XREM := RESIZE((XL mod R), XREM'LENGTH); 1613 if L_LENGTH > R'LENGTH and XREM(L_LENGTH-1 downto R'LENGTH) 1614 /= (L_LENGTH-1 downto R'LENGTH => XREM(R'LENGTH-1)) 1615 then 1616 assert NO_WARNING report "NUMERIC_BIT.""mod"": modulus Truncated" 1617 severity WARNING; 1618 end if; 1619 return RESIZE(XREM, R'LENGTH); 1620 end "mod"; 1621 1622 --============================================================================ 1623 1624 -- Id: C.1 1625 function ">" (L, R: UNSIGNED) return BOOLEAN is 1626 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1627 begin 1628 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1629 assert NO_WARNING 1630 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1631 severity WARNING; 1632 return FALSE; 1633 end if; 1634 return not UNSIGNED_LESS_OR_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1635 end ">"; 1636 1637 -- Id: C.2 1638 function ">" (L, R: SIGNED) return BOOLEAN is 1639 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1640 begin 1641 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1642 assert NO_WARNING 1643 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1644 severity WARNING; 1645 return FALSE; 1646 end if; 1647 return not SIGNED_LESS_OR_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1648 end ">"; 1649 1650 -- Id: C.3 1651 function ">" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 1652 begin 1653 if (R'LENGTH < 1) then 1654 assert NO_WARNING 1655 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1656 severity WARNING; 1657 return FALSE; 1658 end if; 1659 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return TRUE; 1660 end if; 1661 return not UNSIGNED_LESS_OR_EQUAL(TO_UNSIGNED(L, R'LENGTH), R); 1662 end ">"; 1663 1664 -- Id: C.4 1665 function ">" (L: INTEGER; R: SIGNED) return BOOLEAN is 1666 begin 1667 if (R'LENGTH < 1) then 1668 assert NO_WARNING 1669 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1670 severity WARNING; 1671 return FALSE; 1672 end if; 1673 if SIGNED_NUM_BITS(L) > R'LENGTH then return L > 0; 1674 end if; 1675 return not SIGNED_LESS_OR_EQUAL(TO_SIGNED(L, R'LENGTH), R); 1676 end ">"; 1677 1678 -- Id: C.5 1679 function ">" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 1680 begin 1681 if (L'LENGTH < 1) then 1682 assert NO_WARNING 1683 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1684 severity WARNING; 1685 return FALSE; 1686 end if; 1687 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return FALSE; 1688 end if; 1689 return not UNSIGNED_LESS_OR_EQUAL(L, TO_UNSIGNED(R, L'LENGTH)); 1690 end ">"; 1691 1692 -- Id: C.6 1693 function ">" (L: SIGNED; R: INTEGER) return BOOLEAN is 1694 begin 1695 if (L'LENGTH < 1) then 1696 assert NO_WARNING 1697 report "NUMERIC_BIT."">"": null argument detected, returning FALSE" 1698 severity WARNING; 1699 return FALSE; 1700 end if; 1701 if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R; 1702 end if; 1703 return not SIGNED_LESS_OR_EQUAL(L, TO_SIGNED(R, L'LENGTH)); 1704 end ">"; 1705 1706 --============================================================================ 1707 1708 -- Id: C.7 1709 function "<" (L, R: UNSIGNED) return BOOLEAN is 1710 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1711 begin 1712 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1713 assert NO_WARNING 1714 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1715 severity WARNING; 1716 return FALSE; 1717 end if; 1718 return UNSIGNED_LESS(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1719 end "<"; 1720 1721 -- Id: C.8 1722 function "<" (L, R: SIGNED) return BOOLEAN is 1723 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1724 begin 1725 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1726 assert NO_WARNING 1727 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1728 severity WARNING; 1729 return FALSE; 1730 end if; 1731 return SIGNED_LESS(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1732 end "<"; 1733 1734 -- Id: C.9 1735 function "<" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 1736 begin 1737 if (R'LENGTH < 1) then 1738 assert NO_WARNING 1739 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1740 severity WARNING; 1741 return FALSE; 1742 end if; 1743 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L < 0; 1744 end if; 1745 return UNSIGNED_LESS(TO_UNSIGNED(L, R'LENGTH), R); 1746 end "<"; 1747 1748 -- Id: C.10 1749 function "<" (L: INTEGER; R: SIGNED) return BOOLEAN is 1750 begin 1751 if (R'LENGTH < 1) then 1752 assert NO_WARNING 1753 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1754 severity WARNING; 1755 return FALSE; 1756 end if; 1757 if SIGNED_NUM_BITS(L) > R'LENGTH then return L < 0; 1758 end if; 1759 return SIGNED_LESS(TO_SIGNED(L, R'LENGTH), R); 1760 end "<"; 1761 1762 -- Id: C.11 1763 function "<" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 1764 begin 1765 if (L'LENGTH < 1) then 1766 assert NO_WARNING 1767 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1768 severity WARNING; 1769 return FALSE; 1770 end if; 1771 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R; 1772 end if; 1773 return UNSIGNED_LESS(L, TO_UNSIGNED(R, L'LENGTH)); 1774 end "<"; 1775 1776 -- Id: C.12 1777 function "<" (L: SIGNED; R: INTEGER) return BOOLEAN is 1778 begin 1779 if (L'LENGTH < 1) then 1780 assert NO_WARNING 1781 report "NUMERIC_BIT.""<"": null argument detected, returning FALSE" 1782 severity WARNING; 1783 return FALSE; 1784 end if; 1785 if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R; 1786 end if; 1787 return SIGNED_LESS(L, TO_SIGNED(R, L'LENGTH)); 1788 end "<"; 1789 1790 --============================================================================ 1791 1792 -- Id: C.13 1793 function "<=" (L, R: UNSIGNED) return BOOLEAN is 1794 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1795 begin 1796 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1797 assert NO_WARNING 1798 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1799 severity WARNING; 1800 return FALSE; 1801 end if; 1802 return UNSIGNED_LESS_OR_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1803 end "<="; 1804 1805 -- Id: C.14 1806 function "<=" (L, R: SIGNED) return BOOLEAN is 1807 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1808 begin 1809 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1810 assert NO_WARNING 1811 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1812 severity WARNING; 1813 return FALSE; 1814 end if; 1815 return SIGNED_LESS_OR_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1816 end "<="; 1817 1818 -- Id: C.15 1819 function "<=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 1820 begin 1821 if (R'LENGTH < 1) then 1822 assert NO_WARNING 1823 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1824 severity WARNING; 1825 return FALSE; 1826 end if; 1827 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L < 0; 1828 end if; 1829 return UNSIGNED_LESS_OR_EQUAL(TO_UNSIGNED(L, R'LENGTH), R); 1830 end "<="; 1831 1832 -- Id: C.16 1833 function "<=" (L: INTEGER; R: SIGNED) return BOOLEAN is 1834 begin 1835 if (R'LENGTH < 1) then 1836 assert NO_WARNING 1837 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1838 severity WARNING; 1839 return FALSE; 1840 end if; 1841 if SIGNED_NUM_BITS(L) > R'LENGTH then return L < 0; 1842 end if; 1843 return SIGNED_LESS_OR_EQUAL(TO_SIGNED(L, R'LENGTH), R); 1844 end "<="; 1845 1846 -- Id: C.17 1847 function "<=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 1848 begin 1849 if (L'LENGTH < 1) then 1850 assert NO_WARNING 1851 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1852 severity WARNING; 1853 return FALSE; 1854 end if; 1855 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R; 1856 end if; 1857 return UNSIGNED_LESS_OR_EQUAL(L, TO_UNSIGNED(R, L'LENGTH)); 1858 end "<="; 1859 1860 -- Id: C.18 1861 function "<=" (L: SIGNED; R: INTEGER) return BOOLEAN is 1862 begin 1863 if (L'LENGTH < 1) then 1864 assert NO_WARNING 1865 report "NUMERIC_BIT.""<="": null argument detected, returning FALSE" 1866 severity WARNING; 1867 return FALSE; 1868 end if; 1869 if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R; 1870 end if; 1871 return SIGNED_LESS_OR_EQUAL(L, TO_SIGNED(R, L'LENGTH)); 1872 end "<="; 1873 1874 --============================================================================ 1875 1876 -- Id: C.19 1877 function ">=" (L, R: UNSIGNED) return BOOLEAN is 1878 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1879 begin 1880 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1881 assert NO_WARNING 1882 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1883 severity WARNING; 1884 return FALSE; 1885 end if; 1886 return not UNSIGNED_LESS(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1887 end ">="; 1888 1889 -- Id: C.20 1890 function ">=" (L, R: SIGNED) return BOOLEAN is 1891 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1892 begin 1893 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1894 assert NO_WARNING 1895 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1896 severity WARNING; 1897 return FALSE; 1898 end if; 1899 return not SIGNED_LESS(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1900 end ">="; 1901 1902 -- Id: C.21 1903 function ">=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 1904 begin 1905 if (R'LENGTH < 1) then 1906 assert NO_WARNING 1907 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1908 severity WARNING; 1909 return FALSE; 1910 end if; 1911 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L > 0; 1912 end if; 1913 return not UNSIGNED_LESS(TO_UNSIGNED(L, R'LENGTH), R); 1914 end ">="; 1915 1916 -- Id: C.22 1917 function ">=" (L: INTEGER; R: SIGNED) return BOOLEAN is 1918 begin 1919 if (R'LENGTH < 1) then 1920 assert NO_WARNING 1921 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1922 severity WARNING; 1923 return FALSE; 1924 end if; 1925 if SIGNED_NUM_BITS(L) > R'LENGTH then return L > 0; 1926 end if; 1927 return not SIGNED_LESS(TO_SIGNED(L, R'LENGTH), R); 1928 end ">="; 1929 1930 -- Id: C.23 1931 function ">=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 1932 begin 1933 if (L'LENGTH < 1) then 1934 assert NO_WARNING 1935 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1936 severity WARNING; 1937 return FALSE; 1938 end if; 1939 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R; 1940 end if; 1941 return not UNSIGNED_LESS(L, TO_UNSIGNED(R, L'LENGTH)); 1942 end ">="; 1943 1944 -- Id: C.24 1945 function ">=" (L: SIGNED; R: INTEGER) return BOOLEAN is 1946 begin 1947 if (L'LENGTH < 1) then 1948 assert NO_WARNING 1949 report "NUMERIC_BIT."">="": null argument detected, returning FALSE" 1950 severity WARNING; 1951 return FALSE; 1952 end if; 1953 if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R; 1954 end if; 1955 return not SIGNED_LESS(L, TO_SIGNED(R, L'LENGTH)); 1956 end ">="; 1957 1958 --============================================================================ 1959 1960 -- Id: C.25 1961 function "=" (L, R: UNSIGNED) return BOOLEAN is 1962 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1963 begin 1964 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1965 assert NO_WARNING 1966 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 1967 severity WARNING; 1968 return FALSE; 1969 end if; 1970 return UNSIGNED_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1971 end "="; 1972 1973 -- Id: C.26 1974 function "=" (L, R: SIGNED) return BOOLEAN is 1975 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 1976 begin 1977 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 1978 assert NO_WARNING 1979 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 1980 severity WARNING; 1981 return FALSE; 1982 end if; 1983 return SIGNED_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE)); 1984 end "="; 1985 1986 -- Id: C.27 1987 function "=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 1988 begin 1989 if (R'LENGTH < 1) then 1990 assert NO_WARNING 1991 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 1992 severity WARNING; 1993 return FALSE; 1994 end if; 1995 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return FALSE; 1996 end if; 1997 return UNSIGNED_EQUAL(TO_UNSIGNED(L, R'LENGTH), R); 1998 end "="; 1999 2000 -- Id: C.28 2001 function "=" (L: INTEGER; R: SIGNED) return BOOLEAN is 2002 begin 2003 if (R'LENGTH < 1) then 2004 assert NO_WARNING 2005 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 2006 severity WARNING; 2007 return FALSE; 2008 end if; 2009 if SIGNED_NUM_BITS(L) > R'LENGTH then return FALSE; 2010 end if; 2011 return SIGNED_EQUAL(TO_SIGNED(L, R'LENGTH), R); 2012 end "="; 2013 2014 -- Id: C.29 2015 function "=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 2016 begin 2017 if (L'LENGTH < 1) then 2018 assert NO_WARNING 2019 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 2020 severity WARNING; 2021 return FALSE; 2022 end if; 2023 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return FALSE; 2024 end if; 2025 return UNSIGNED_EQUAL(L, TO_UNSIGNED(R, L'LENGTH)); 2026 end "="; 2027 2028 -- Id: C.30 2029 function "=" (L: SIGNED; R: INTEGER) return BOOLEAN is 2030 begin 2031 if (L'LENGTH < 1) then 2032 assert NO_WARNING 2033 report "NUMERIC_BIT.""="": null argument detected, returning FALSE" 2034 severity WARNING; 2035 return FALSE; 2036 end if; 2037 if SIGNED_NUM_BITS(R) > L'LENGTH then return FALSE; 2038 end if; 2039 return SIGNED_EQUAL(L, TO_SIGNED(R, L'LENGTH)); 2040 end "="; 2041 2042 --============================================================================ 2043 2044 -- Id: C.31 2045 function "/=" (L, R: UNSIGNED) return BOOLEAN is 2046 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 2047 begin 2048 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 2049 assert NO_WARNING 2050 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2051 severity WARNING; 2052 return TRUE; 2053 end if; 2054 return not(UNSIGNED_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE))); 2055 end "/="; 2056 2057 -- Id: C.32 2058 function "/=" (L, R: SIGNED) return BOOLEAN is 2059 variable SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH); 2060 begin 2061 if ((L'LENGTH < 1) or (R'LENGTH < 1)) then 2062 assert NO_WARNING 2063 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2064 severity WARNING; 2065 return TRUE; 2066 end if; 2067 return not(SIGNED_EQUAL(RESIZE(L, SIZE), RESIZE(R, SIZE))); 2068 end "/="; 2069 2070 -- Id: C.33 2071 function "/=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is 2072 begin 2073 if (R'LENGTH < 1) then 2074 assert NO_WARNING 2075 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2076 severity WARNING; 2077 return TRUE; 2078 end if; 2079 if UNSIGNED_NUM_BITS(L) > R'LENGTH then return TRUE; 2080 end if; 2081 return not(UNSIGNED_EQUAL(TO_UNSIGNED(L, R'LENGTH), R)); 2082 end "/="; 2083 2084 -- Id: C.34 2085 function "/=" (L: INTEGER; R: SIGNED) return BOOLEAN is 2086 begin 2087 if (R'LENGTH < 1) then 2088 assert NO_WARNING 2089 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2090 severity WARNING; 2091 return TRUE; 2092 end if; 2093 if SIGNED_NUM_BITS(L) > R'LENGTH then return TRUE; 2094 end if; 2095 return not(SIGNED_EQUAL(TO_SIGNED(L, R'LENGTH), R)); 2096 end "/="; 2097 2098 -- Id: C.35 2099 function "/=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is 2100 begin 2101 if (L'LENGTH < 1) then 2102 assert NO_WARNING 2103 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2104 severity WARNING; 2105 return TRUE; 2106 end if; 2107 if UNSIGNED_NUM_BITS(R) > L'LENGTH then return TRUE; 2108 end if; 2109 return not(UNSIGNED_EQUAL(L, TO_UNSIGNED(R, L'LENGTH))); 2110 end "/="; 2111 2112 -- Id: C.36 2113 function "/=" (L: SIGNED; R: INTEGER) return BOOLEAN is 2114 begin 2115 if (L'LENGTH < 1) then 2116 assert NO_WARNING 2117 report "NUMERIC_BIT.""/="": null argument detected, returning TRUE" 2118 severity WARNING; 2119 return TRUE; 2120 end if; 2121 if SIGNED_NUM_BITS(R) > L'LENGTH then return TRUE; 2122 end if; 2123 return not(SIGNED_EQUAL(L, TO_SIGNED(R, L'LENGTH))); 2124 end "/="; 2125 2126 --============================================================================ 2127 2128 -- Id: S.1 2129 function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is 2130 begin 2131 if (ARG'LENGTH < 1) then return NAU; 2132 end if; 2133 return UNSIGNED(XSLL(BIT_VECTOR(ARG), COUNT)); 2134 end SHIFT_LEFT; 2135 2136 -- Id: S.2 2137 function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is 2138 begin 2139 if (ARG'LENGTH < 1) then return NAU; 2140 end if; 2141 return UNSIGNED(XSRL(BIT_VECTOR(ARG), COUNT)); 2142 end SHIFT_RIGHT; 2143 2144 -- Id: S.3 2145 function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is 2146 begin 2147 if (ARG'LENGTH < 1) then return NAS; 2148 end if; 2149 return SIGNED(XSLL(BIT_VECTOR(ARG), COUNT)); 2150 end SHIFT_LEFT; 2151 2152 -- Id: S.4 2153 function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is 2154 begin 2155 if (ARG'LENGTH < 1) then return NAS; 2156 end if; 2157 return SIGNED(XSRA(BIT_VECTOR(ARG), COUNT)); 2158 end SHIFT_RIGHT; 2159 2160 --============================================================================ 2161 2162 -- Id: S.5 2163 function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is 2164 begin 2165 if (ARG'LENGTH < 1) then return NAU; 2166 end if; 2167 return UNSIGNED(XROL(BIT_VECTOR(ARG), COUNT)); 2168 end ROTATE_LEFT; 2169 2170 -- Id: S.6 2171 function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is 2172 begin 2173 if (ARG'LENGTH < 1) then return NAU; 2174 end if; 2175 return UNSIGNED(XROR(BIT_VECTOR(ARG), COUNT)); 2176 end ROTATE_RIGHT; 2177 2178 -- Id: S.7 2179 function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is 2180 begin 2181 if (ARG'LENGTH < 1) then return NAS; 2182 end if; 2183 return SIGNED(XROL(BIT_VECTOR(ARG), COUNT)); 2184 end ROTATE_LEFT; 2185 2186 -- Id: S.8 2187 function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is 2188 begin 2189 if (ARG'LENGTH < 1) then return NAS; 2190 end if; 2191 return SIGNED(XROR(BIT_VECTOR(ARG), COUNT)); 2192 end ROTATE_RIGHT; 2193 2194 --============================================================================ 2195 2196 ------------------------------------------------------------------------------ 2197 -- Note : Function S.9 is not compatible with VHDL 1076-1987. Comment 2198 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2199 ------------------------------------------------------------------------------ 2200 -- Id: S.9 2201 function "sll" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is 2202 begin 2203 if (COUNT >= 0) then 2204 return SHIFT_LEFT(ARG, COUNT); 2205 else 2206 return SHIFT_RIGHT(ARG, -COUNT); 2207 end if; 2208 end "sll"; 2209 2210 ------------------------------------------------------------------------------ 2211 -- Note : Function S.10 is not compatible with VHDL 1076-1987. Comment 2212 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2213 ------------------------------------------------------------------------------ 2214 -- Id: S.10 2215 function "sll" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is 2216 begin 2217 if (COUNT >= 0) then 2218 return SHIFT_LEFT(ARG, COUNT); 2219 else 2220 return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), -COUNT)); 2221 end if; 2222 end "sll"; 2223 2224 ------------------------------------------------------------------------------ 2225 -- Note : Function S.11 is not compatible with VHDL 1076-1987. Comment 2226 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2227 ------------------------------------------------------------------------------ 2228 -- Id: S.11 2229 function "srl" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is 2230 begin 2231 if (COUNT >= 0) then 2232 return SHIFT_RIGHT(ARG, COUNT); 2233 else 2234 return SHIFT_LEFT(ARG, -COUNT); 2235 end if; 2236 end "srl"; 2237 2238 ------------------------------------------------------------------------------ 2239 -- Note : Function S.12 is not compatible with VHDL 1076-1987. Comment 2240 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2241 ------------------------------------------------------------------------------ 2242 -- Id: S.12 2243 function "srl" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is 2244 begin 2245 if (COUNT >= 0) then 2246 return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), COUNT)); 2247 else 2248 return SHIFT_LEFT(ARG, -COUNT); 2249 end if; 2250 end "srl"; 2251 2252 ------------------------------------------------------------------------------ 2253 -- Note : Function S.13 is not compatible with VHDL 1076-1987. Comment 2254 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2255 ------------------------------------------------------------------------------ 2256 -- Id: S.13 2257 function "rol" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is 2258 begin 2259 if (COUNT >= 0) then 2260 return ROTATE_LEFT(ARG, COUNT); 2261 else 2262 return ROTATE_RIGHT(ARG, -COUNT); 2263 end if; 2264 end "rol"; 2265 2266 ------------------------------------------------------------------------------ 2267 -- Note : Function S.14 is not compatible with VHDL 1076-1987. Comment 2268 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2269 ------------------------------------------------------------------------------ 2270 -- Id: S.14 2271 function "rol" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is 2272 begin 2273 if (COUNT >= 0) then 2274 return ROTATE_LEFT(ARG, COUNT); 2275 else 2276 return ROTATE_RIGHT(ARG, -COUNT); 2277 end if; 2278 end "rol"; 2279 2280 ------------------------------------------------------------------------------ 2281 -- Note : Function S.15 is not compatible with VHDL 1076-1987. Comment 2282 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2283 ------------------------------------------------------------------------------ 2284 -- Id: S.15 2285 function "ror" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is 2286 begin 2287 if (COUNT >= 0) then 2288 return ROTATE_RIGHT(ARG, COUNT); 2289 else 2290 return ROTATE_LEFT(ARG, -COUNT); 2291 end if; 2292 end "ror"; 2293 2294 ------------------------------------------------------------------------------ 2295 -- Note : Function S.16 is not compatible with VHDL 1076-1987. Comment 2296 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2297 ------------------------------------------------------------------------------ 2298 -- Id: S.16 2299 function "ror" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is 2300 begin 2301 if (COUNT >= 0) then 2302 return ROTATE_RIGHT(ARG, COUNT); 2303 else 2304 return ROTATE_LEFT(ARG, -COUNT); 2305 end if; 2306 end "ror"; 2307 2308 --============================================================================ 2309 2310 -- Id: D.1 2311 function TO_INTEGER (ARG: UNSIGNED) return NATURAL is 2312 constant ARG_LEFT: INTEGER := ARG'LENGTH-1; 2313 alias XARG: UNSIGNED(ARG_LEFT downto 0) is ARG; 2314 variable RESULT: NATURAL := 0; 2315 begin 2316 if (ARG'LENGTH < 1) then 2317 assert NO_WARNING 2318 report "NUMERIC_BIT.TO_INTEGER: null detected, returning 0" 2319 severity WARNING; 2320 return 0; 2321 end if; 2322 for I in XARG'RANGE loop 2323 RESULT := RESULT+RESULT; 2324 if XARG(I) = '1' then 2325 RESULT := RESULT + 1; 2326 end if; 2327 end loop; 2328 return RESULT; 2329 end TO_INTEGER; 2330 2331 -- Id: D.2 2332 function TO_INTEGER (ARG: SIGNED) return INTEGER is 2333 begin 2334 if (ARG'LENGTH < 1) then 2335 assert NO_WARNING 2336 report "NUMERIC_BIT.TO_INTEGER: null detected, returning 0" 2337 severity WARNING; 2338 return 0; 2339 end if; 2340 if ARG(ARG'LEFT) = '0' then 2341 return TO_INTEGER(UNSIGNED(ARG)); 2342 else 2343 return (- (TO_INTEGER(UNSIGNED(- (ARG + 1)))) -1); 2344 end if; 2345 end TO_INTEGER; 2346 2347 -- Id: D.3 2348 function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED is 2349 variable RESULT: UNSIGNED(SIZE-1 downto 0); 2350 variable I_VAL: NATURAL := ARG; 2351 begin 2352 if (SIZE < 1) then return NAU; 2353 end if; 2354 for I in 0 to RESULT'LEFT loop 2355 if (I_VAL mod 2) = 0 then 2356 RESULT(I) := '0'; 2357 else RESULT(I) := '1'; 2358 end if; 2359 I_VAL := I_VAL/2; 2360 end loop; 2361 if not(I_VAL =0) then 2362 assert NO_WARNING 2363 report "NUMERIC_BIT.TO_UNSIGNED: vector truncated" 2364 severity WARNING; 2365 end if; 2366 return RESULT; 2367 end TO_UNSIGNED; 2368 2369 -- Id: D.4 2370 function TO_SIGNED (ARG: INTEGER; 2371 SIZE: NATURAL) return SIGNED is 2372 variable RESULT: SIGNED(SIZE-1 downto 0); 2373 variable B_VAL: BIT := '0'; 2374 variable I_VAL: INTEGER := ARG; 2375 begin 2376 if (SIZE < 1) then return NAS; 2377 end if; 2378 if (ARG < 0) then 2379 B_VAL := '1'; 2380 I_VAL := -(ARG+1); 2381 end if; 2382 for I in 0 to RESULT'LEFT loop 2383 if (I_VAL mod 2) = 0 then 2384 RESULT(I) := B_VAL; 2385 else 2386 RESULT(I) := not B_VAL; 2387 end if; 2388 I_VAL := I_VAL/2; 2389 end loop; 2390 if ((I_VAL/=0) or (B_VAL/=RESULT(RESULT'LEFT))) then 2391 assert NO_WARNING 2392 report "NUMERIC_BIT.TO_SIGNED: vector truncated" 2393 severity WARNING; 2394 end if; 2395 return RESULT; 2396 end TO_SIGNED; 2397 2398 --============================================================================ 2399 2400 -- Id: R.1 2401 function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED is 2402 alias INVEC: SIGNED(ARG'LENGTH-1 downto 0) is ARG; 2403 variable RESULT: SIGNED(NEW_SIZE-1 downto 0) := (others => '0'); 2404 constant BOUND: INTEGER := MIN(ARG'LENGTH, RESULT'LENGTH)-2; 2405 begin 2406 if (NEW_SIZE < 1) then return NAS; 2407 end if; 2408 if (ARG'LENGTH = 0) then return RESULT; 2409 end if; 2410 RESULT := (others => ARG(ARG'LEFT)); 2411 if BOUND >= 0 then 2412 RESULT(BOUND downto 0) := INVEC(BOUND downto 0); 2413 end if; 2414 return RESULT; 2415 end RESIZE; 2416 2417 -- Id: R.2 2418 function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED is 2419 constant ARG_LEFT: INTEGER := ARG'LENGTH-1; 2420 alias XARG: UNSIGNED(ARG_LEFT downto 0) is ARG; 2421 variable RESULT: UNSIGNED(NEW_SIZE-1 downto 0) := (others => '0'); 2422 begin 2423 if (NEW_SIZE < 1) then return NAU; 2424 end if; 2425 if XARG'LENGTH =0 then return RESULT; 2426 end if; 2427 if (RESULT'LENGTH < ARG'LENGTH) then 2428 RESULT(RESULT'LEFT downto 0) := XARG(RESULT'LEFT downto 0); 2429 else 2430 RESULT(RESULT'LEFT downto XARG'LEFT+1) := (others => '0'); 2431 RESULT(XARG'LEFT downto 0) := XARG; 2432 end if; 2433 return RESULT; 2434 end RESIZE; 2435 2436 --============================================================================ 2437 2438 -- Id: L.1 2439 function "not" (L: UNSIGNED) return UNSIGNED is 2440 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2441 begin 2442 RESULT := UNSIGNED(not(BIT_VECTOR(L))); 2443 return RESULT; 2444 end "not"; 2445 2446 -- Id: L.2 2447 function "and" (L, R: UNSIGNED) return UNSIGNED is 2448 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2449 begin 2450 RESULT := UNSIGNED(BIT_VECTOR(L) and BIT_VECTOR(R)); 2451 return RESULT; 2452 end "and"; 2453 2454 -- Id: L.3 2455 function "or" (L, R: UNSIGNED) return UNSIGNED is 2456 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2457 begin 2458 RESULT := UNSIGNED(BIT_VECTOR(L) or BIT_VECTOR(R)); 2459 return RESULT; 2460 end "or"; 2461 2462 -- Id: L.4 2463 function "nand" (L, R: UNSIGNED) return UNSIGNED is 2464 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2465 begin 2466 RESULT := UNSIGNED(BIT_VECTOR(L) nand BIT_VECTOR(R)); 2467 return RESULT; 2468 end "nand"; 2469 2470 -- Id: L.5 2471 function "nor" (L, R: UNSIGNED) return UNSIGNED is 2472 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2473 begin 2474 RESULT := UNSIGNED(BIT_VECTOR(L) nor BIT_VECTOR(R)); 2475 return RESULT; 2476 end "nor"; 2477 2478 -- Id: L.6 2479 function "xor" (L, R: UNSIGNED) return UNSIGNED is 2480 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2481 begin 2482 RESULT := UNSIGNED(BIT_VECTOR(L) xor BIT_VECTOR(R)); 2483 return RESULT; 2484 end "xor"; 2485 2486 ------------------------------------------------------------------------------ 2487 -- Note : Function L.7 is not compatible with VHDL 1076-1987. Comment 2488 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2489 ------------------------------------------------------------------------------ 2490 -- Id: L.7 2491 function "xnor" (L, R: UNSIGNED) return UNSIGNED is 2492 variable RESULT: UNSIGNED(L'LENGTH-1 downto 0); 2493 begin 2494 RESULT := UNSIGNED(BIT_VECTOR(L) xnor BIT_VECTOR(R)); 2495 return RESULT; 2496 end "xnor"; 2497 2498 -- Id: L.8 2499 function "not" (L: SIGNED) return SIGNED is 2500 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2501 begin 2502 RESULT := SIGNED(not(BIT_VECTOR(L))); 2503 return RESULT; 2504 end "not"; 2505 2506 -- Id: L.9 2507 function "and" (L, R: SIGNED) return SIGNED is 2508 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2509 begin 2510 RESULT := SIGNED(BIT_VECTOR(L) and BIT_VECTOR(R)); 2511 return RESULT; 2512 end "and"; 2513 2514 -- Id: L.10 2515 function "or" (L, R: SIGNED) return SIGNED is 2516 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2517 begin 2518 RESULT := SIGNED(BIT_VECTOR(L) or BIT_VECTOR(R)); 2519 return RESULT; 2520 end "or"; 2521 2522 -- Id: L.11 2523 function "nand" (L, R: SIGNED) return SIGNED is 2524 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2525 begin 2526 RESULT := SIGNED(BIT_VECTOR(L) nand BIT_VECTOR(R)); 2527 return RESULT; 2528 end "nand"; 2529 2530 -- Id: L.12 2531 function "nor" (L, R: SIGNED) return SIGNED is 2532 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2533 begin 2534 RESULT := SIGNED(BIT_VECTOR(L) nor BIT_VECTOR(R)); 2535 return RESULT; 2536 end "nor"; 2537 2538 -- Id: L.13 2539 function "xor" (L, R: SIGNED) return SIGNED is 2540 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2541 begin 2542 RESULT := SIGNED(BIT_VECTOR(L) xor BIT_VECTOR(R)); 2543 return RESULT; 2544 end "xor"; 2545 2546 ------------------------------------------------------------------------------ 2547 -- Note : Function L.14 is not compatible with VHDL 1076-1987. Comment 2548 -- out the function (declaration and body) for VHDL 1076-1987 compatibility. 2549 ------------------------------------------------------------------------------ 2550 -- Id: L.14 2551 function "xnor" (L, R: SIGNED) return SIGNED is 2552 variable RESULT: SIGNED(L'LENGTH-1 downto 0); 2553 begin 2554 RESULT := SIGNED(BIT_VECTOR(L) xnor BIT_VECTOR(R)); 2555 return RESULT; 2556 end "xnor"; 2557 2558 --============================================================================ 2559 2560 -- Id: E.1 2561 function RISING_EDGE (signal S: BIT) return BOOLEAN is 2562 begin 2563 return S'EVENT and S = '1'; 2564 end RISING_EDGE; 2565 2566 -- Id: E.2 2567 function FALLING_EDGE (signal S: BIT) return BOOLEAN is 2568 begin 2569 return S'EVENT and S = '0'; 2570 end FALLING_EDGE; 2571 2572 --============================================================================ 2573end NUMERIC_BIT; 2574