Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 130.44 KB | None | 0 0
  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_STD)
  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 UNSIGNED number in vector form
  26. -- : -- > SIGNED: represents a SIGNED number in vector form
  27. -- : The base element type is type STD_LOGIC.
  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.
  33. -- :
  34. -- : If any argument to a function is a null array, a null array is
  35. -- : returned (exceptions, if any, are noted individually).
  36. --
  37. -- Limitation :
  38. --
  39. -- Note : No declarations or definitions shall be included in,
  40. -- : or excluded from this package. The "package declaration"
  41. -- : defines the types, subtypes and declarations of
  42. -- : NUMERIC_STD. The NUMERIC_STD package body shall be
  43. -- : considered the formal definition of the semantics of
  44. -- : this package. Tool developers may choose to implement
  45. -- : the package body in the most efficient manner available
  46. -- : to them.
  47. --
  48. -- --------------------------------------------------------------------
  49. -- modification history :
  50. -- --------------------------------------------------------------------
  51. -- Version: 2.4
  52. -- Date : 12 April 1995
  53. -- -----------------------------------------------------------------------------
  54. library IEEE;
  55. use IEEE.STD_LOGIC_1164.all;
  56.  
  57. package NUMERIC_STD is
  58. constant CopyRightNotice: STRING
  59. := "Copyright 1995 IEEE. All rights reserved.";
  60.  
  61. --============================================================================
  62. -- Numeric array type definitions
  63. --============================================================================
  64.  
  65. type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;
  66. type SIGNED is array (NATURAL range <>) of STD_LOGIC;
  67.  
  68. --============================================================================
  69. -- Arithmetic Operators:
  70. --===========================================================================
  71.  
  72. -- Id: A.1
  73. function "abs" (ARG: SIGNED) return SIGNED;
  74. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0).
  75. -- Result: Returns the absolute value of a SIGNED vector ARG.
  76.  
  77. -- Id: A.2
  78. function "-" (ARG: SIGNED) return SIGNED;
  79. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0).
  80. -- Result: Returns the value of the unary minus operation on a
  81. -- SIGNED vector ARG.
  82.  
  83. --============================================================================
  84.  
  85. -- Id: A.3
  86. function "+" (L, R: UNSIGNED) return UNSIGNED;
  87. -- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0).
  88. -- Result: Adds two UNSIGNED vectors that may be of different lengths.
  89.  
  90. -- Id: A.4
  91. function "+" (L, R: SIGNED) return SIGNED;
  92. -- Result subtype: SIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0).
  93. -- Result: Adds two SIGNED vectors that may be of different lengths.
  94.  
  95. -- Id: A.5
  96. function "+" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  97. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0).
  98. -- Result: Adds an UNSIGNED vector, L, with a non-negative INTEGER, R.
  99.  
  100. -- Id: A.6
  101. function "+" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  102. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0).
  103. -- Result: Adds a non-negative INTEGER, L, with an UNSIGNED vector, R.
  104.  
  105. -- Id: A.7
  106. function "+" (L: INTEGER; R: SIGNED) return SIGNED;
  107. -- Result subtype: SIGNED(R'LENGTH-1 downto 0).
  108. -- Result: Adds an INTEGER, L(may be positive or negative), to a SIGNED
  109. -- vector, R.
  110.  
  111. -- Id: A.8
  112. function "+" (L: SIGNED; R: INTEGER) return SIGNED;
  113. -- Result subtype: SIGNED(L'LENGTH-1 downto 0).
  114. -- Result: Adds a SIGNED vector, L, to an INTEGER, R.
  115.  
  116. --============================================================================
  117.  
  118. -- Id: A.9
  119. function "-" (L, R: UNSIGNED) return UNSIGNED;
  120. -- Result subtype: UNSIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0).
  121. -- Result: Subtracts two UNSIGNED vectors that may be of different lengths.
  122.  
  123. -- Id: A.10
  124. function "-" (L, R: SIGNED) return SIGNED;
  125. -- Result subtype: SIGNED(MAX(L'LENGTH, R'LENGTH)-1 downto 0).
  126. -- Result: Subtracts a SIGNED vector, R, from another SIGNED vector, L,
  127. -- that may possibly be of different lengths.
  128.  
  129. -- Id: A.11
  130. function "-" (L: UNSIGNED;R: NATURAL) return UNSIGNED;
  131. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0).
  132. -- Result: Subtracts a non-negative INTEGER, R, from an UNSIGNED vector, L.
  133.  
  134. -- Id: A.12
  135. function "-" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  136. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0).
  137. -- Result: Subtracts an UNSIGNED vector, R, from a non-negative INTEGER, L.
  138.  
  139. -- Id: A.13
  140. function "-" (L: SIGNED; R: INTEGER) return SIGNED;
  141. -- Result subtype: SIGNED(L'LENGTH-1 downto 0).
  142. -- Result: Subtracts an INTEGER, R, from a SIGNED vector, L.
  143.  
  144. -- Id: A.14
  145. function "-" (L: INTEGER; R: SIGNED) return SIGNED;
  146. -- Result subtype: SIGNED(R'LENGTH-1 downto 0).
  147. -- Result: Subtracts a SIGNED vector, R, from an INTEGER, L.
  148.  
  149. --============================================================================
  150.  
  151. -- Id: A.15
  152. function "*" (L, R: UNSIGNED) return UNSIGNED;
  153. -- Result subtype: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0).
  154. -- Result: Performs the multiplication operation on two UNSIGNED vectors
  155. -- that may possibly be of different lengths.
  156.  
  157. -- Id: A.16
  158. function "*" (L, R: SIGNED) return SIGNED;
  159. -- Result subtype: SIGNED((L'LENGTH+R'LENGTH-1) downto 0)
  160. -- Result: Multiplies two SIGNED vectors that may possibly be of
  161. -- different lengths.
  162.  
  163. -- Id: A.17
  164. function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  165. -- Result subtype: UNSIGNED((L'LENGTH+L'LENGTH-1) downto 0).
  166. -- Result: Multiplies an UNSIGNED vector, L, with a non-negative
  167. -- INTEGER, R. R is converted to an UNSIGNED vector of
  168. -- SIZE L'LENGTH before multiplication.
  169.  
  170. -- Id: A.18
  171. function "*" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  172. -- Result subtype: UNSIGNED((R'LENGTH+R'LENGTH-1) downto 0).
  173. -- Result: Multiplies an UNSIGNED vector, R, with a non-negative
  174. -- INTEGER, L. L is converted to an UNSIGNED vector of
  175. -- SIZE R'LENGTH before multiplication.
  176.  
  177. -- Id: A.19
  178. function "*" (L: SIGNED; R: INTEGER) return SIGNED;
  179. -- Result subtype: SIGNED((L'LENGTH+L'LENGTH-1) downto 0)
  180. -- Result: Multiplies a SIGNED vector, L, with an INTEGER, R. R is
  181. -- converted to a SIGNED vector of SIZE L'LENGTH before
  182. -- multiplication.
  183.  
  184. -- Id: A.20
  185. function "*" (L: INTEGER; R: SIGNED) return SIGNED;
  186. -- Result subtype: SIGNED((R'LENGTH+R'LENGTH-1) downto 0)
  187. -- Result: Multiplies a SIGNED vector, R, with an INTEGER, L. L is
  188. -- converted to a SIGNED vector of SIZE R'LENGTH before
  189. -- multiplication.
  190.  
  191. --============================================================================
  192. --
  193. -- NOTE: If second argument is zero for "/" operator, a severity level
  194. -- of ERROR is issued.
  195.  
  196. -- Id: A.21
  197. function "/" (L, R: UNSIGNED) return UNSIGNED;
  198. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  199. -- Result: Divides an UNSIGNED vector, L, by another UNSIGNED vector, R.
  200.  
  201. -- Id: A.22
  202. function "/" (L, R: SIGNED) return SIGNED;
  203. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  204. -- Result: Divides an SIGNED vector, L, by another SIGNED vector, R.
  205.  
  206. -- Id: A.23
  207. function "/" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  208. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  209. -- Result: Divides an UNSIGNED vector, L, by a non-negative INTEGER, R.
  210. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  211.  
  212. -- Id: A.24
  213. function "/" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  214. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0)
  215. -- Result: Divides a non-negative INTEGER, L, by an UNSIGNED vector, R.
  216. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  217.  
  218. -- Id: A.25
  219. function "/" (L: SIGNED; R: INTEGER) return SIGNED;
  220. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  221. -- Result: Divides a SIGNED vector, L, by an INTEGER, R.
  222. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  223.  
  224. -- Id: A.26
  225. function "/" (L: INTEGER; R: SIGNED) return SIGNED;
  226. -- Result subtype: SIGNED(R'LENGTH-1 downto 0)
  227. -- Result: Divides an INTEGER, L, by a SIGNED vector, R.
  228. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  229.  
  230. --============================================================================
  231. --
  232. -- NOTE: If second argument is zero for "rem" operator, a severity level
  233. -- of ERROR is issued.
  234.  
  235. -- Id: A.27
  236. function "rem" (L, R: UNSIGNED) return UNSIGNED;
  237. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0)
  238. -- Result: Computes "L rem R" where L and R are UNSIGNED vectors.
  239.  
  240. -- Id: A.28
  241. function "rem" (L, R: SIGNED) return SIGNED;
  242. -- Result subtype: SIGNED(R'LENGTH-1 downto 0)
  243. -- Result: Computes "L rem R" where L and R are SIGNED vectors.
  244.  
  245. -- Id: A.29
  246. function "rem" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  247. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  248. -- Result: Computes "L rem R" where L is an UNSIGNED vector and R is a
  249. -- non-negative INTEGER.
  250. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  251.  
  252. -- Id: A.30
  253. function "rem" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  254. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0)
  255. -- Result: Computes "L rem R" where R is an UNSIGNED vector and L is a
  256. -- non-negative INTEGER.
  257. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  258.  
  259. -- Id: A.31
  260. function "rem" (L: SIGNED; R: INTEGER) return SIGNED;
  261. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  262. -- Result: Computes "L rem R" where L is SIGNED vector and R is an INTEGER.
  263. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  264.  
  265. -- Id: A.32
  266. function "rem" (L: INTEGER; R: SIGNED) return SIGNED;
  267. -- Result subtype: SIGNED(R'LENGTH-1 downto 0)
  268. -- Result: Computes "L rem R" where R is SIGNED vector and L is an INTEGER.
  269. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  270.  
  271. --============================================================================
  272. --
  273. -- NOTE: If second argument is zero for "mod" operator, a severity level
  274. -- of ERROR is issued.
  275.  
  276. -- Id: A.33
  277. function "mod" (L, R: UNSIGNED) return UNSIGNED;
  278. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0)
  279. -- Result: Computes "L mod R" where L and R are UNSIGNED vectors.
  280.  
  281. -- Id: A.34
  282. function "mod" (L, R: SIGNED) return SIGNED;
  283. -- Result subtype: SIGNED(R'LENGTH-1 downto 0)
  284. -- Result: Computes "L mod R" where L and R are SIGNED vectors.
  285.  
  286. -- Id: A.35
  287. function "mod" (L: UNSIGNED; R: NATURAL) return UNSIGNED;
  288. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  289. -- Result: Computes "L mod R" where L is an UNSIGNED vector and R
  290. -- is a non-negative INTEGER.
  291. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  292.  
  293. -- Id: A.36
  294. function "mod" (L: NATURAL; R: UNSIGNED) return UNSIGNED;
  295. -- Result subtype: UNSIGNED(R'LENGTH-1 downto 0)
  296. -- Result: Computes "L mod R" where R is an UNSIGNED vector and L
  297. -- is a non-negative INTEGER.
  298. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  299.  
  300. -- Id: A.37
  301. function "mod" (L: SIGNED; R: INTEGER) return SIGNED;
  302. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  303. -- Result: Computes "L mod R" where L is a SIGNED vector and
  304. -- R is an INTEGER.
  305. -- If NO_OF_BITS(R) > L'LENGTH, result is truncated to L'LENGTH.
  306.  
  307. -- Id: A.38
  308. function "mod" (L: INTEGER; R: SIGNED) return SIGNED;
  309. -- Result subtype: SIGNED(R'LENGTH-1 downto 0)
  310. -- Result: Computes "L mod R" where L is an INTEGER and
  311. -- R is a SIGNED vector.
  312. -- If NO_OF_BITS(L) > R'LENGTH, result is truncated to R'LENGTH.
  313.  
  314. --============================================================================
  315. -- Comparison Operators
  316. --============================================================================
  317.  
  318. -- Id: C.1
  319. function ">" (L, R: UNSIGNED) return BOOLEAN;
  320. -- Result subtype: BOOLEAN
  321. -- Result: Computes "L > R" where L and R are UNSIGNED vectors possibly
  322. -- of different lengths.
  323.  
  324. -- Id: C.2
  325. function ">" (L, R: SIGNED) return BOOLEAN;
  326. -- Result subtype: BOOLEAN
  327. -- Result: Computes "L > R" where L and R are SIGNED vectors possibly
  328. -- of different lengths.
  329.  
  330. -- Id: C.3
  331. function ">" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  332. -- Result subtype: BOOLEAN
  333. -- Result: Computes "L > R" where L is a non-negative INTEGER and
  334. -- R is an UNSIGNED vector.
  335.  
  336. -- Id: C.4
  337. function ">" (L: INTEGER; R: SIGNED) return BOOLEAN;
  338. -- Result subtype: BOOLEAN
  339. -- Result: Computes "L > R" where L is a INTEGER and
  340. -- R is a SIGNED vector.
  341.  
  342. -- Id: C.5
  343. function ">" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  344. -- Result subtype: BOOLEAN
  345. -- Result: Computes "L > R" where L is an UNSIGNED vector and
  346. -- R is a non-negative INTEGER.
  347.  
  348. -- Id: C.6
  349. function ">" (L: SIGNED; R: INTEGER) return BOOLEAN;
  350. -- Result subtype: BOOLEAN
  351. -- Result: Computes "L > R" where L is a SIGNED vector and
  352. -- R is a INTEGER.
  353.  
  354. --============================================================================
  355.  
  356. -- Id: C.7
  357. function "<" (L, R: UNSIGNED) return BOOLEAN;
  358. -- Result subtype: BOOLEAN
  359. -- Result: Computes "L < R" where L and R are UNSIGNED vectors possibly
  360. -- of different lengths.
  361.  
  362. -- Id: C.8
  363. function "<" (L, R: SIGNED) return BOOLEAN;
  364. -- Result subtype: BOOLEAN
  365. -- Result: Computes "L < R" where L and R are SIGNED vectors possibly
  366. -- of different lengths.
  367.  
  368. -- Id: C.9
  369. function "<" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  370. -- Result subtype: BOOLEAN
  371. -- Result: Computes "L < R" where L is a non-negative INTEGER and
  372. -- R is an UNSIGNED vector.
  373.  
  374. -- Id: C.10
  375. function "<" (L: INTEGER; R: SIGNED) return BOOLEAN;
  376. -- Result subtype: BOOLEAN
  377. -- Result: Computes "L < R" where L is an INTEGER and
  378. -- R is a SIGNED vector.
  379.  
  380. -- Id: C.11
  381. function "<" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  382. -- Result subtype: BOOLEAN
  383. -- Result: Computes "L < R" where L is an UNSIGNED vector and
  384. -- R is a non-negative INTEGER.
  385.  
  386. -- Id: C.12
  387. function "<" (L: SIGNED; R: INTEGER) return BOOLEAN;
  388. -- Result subtype: BOOLEAN
  389. -- Result: Computes "L < R" where L is a SIGNED vector and
  390. -- R is an INTEGER.
  391.  
  392. --============================================================================
  393.  
  394. -- Id: C.13
  395. function "<=" (L, R: UNSIGNED) return BOOLEAN;
  396. -- Result subtype: BOOLEAN
  397. -- Result: Computes "L <= R" where L and R are UNSIGNED vectors possibly
  398. -- of different lengths.
  399.  
  400. -- Id: C.14
  401. function "<=" (L, R: SIGNED) return BOOLEAN;
  402. -- Result subtype: BOOLEAN
  403. -- Result: Computes "L <= R" where L and R are SIGNED vectors possibly
  404. -- of different lengths.
  405.  
  406. -- Id: C.15
  407. function "<=" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  408. -- Result subtype: BOOLEAN
  409. -- Result: Computes "L <= R" where L is a non-negative INTEGER and
  410. -- R is an UNSIGNED vector.
  411.  
  412. -- Id: C.16
  413. function "<=" (L: INTEGER; R: SIGNED) return BOOLEAN;
  414. -- Result subtype: BOOLEAN
  415. -- Result: Computes "L <= R" where L is an INTEGER and
  416. -- R is a SIGNED vector.
  417.  
  418. -- Id: C.17
  419. function "<=" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  420. -- Result subtype: BOOLEAN
  421. -- Result: Computes "L <= R" where L is an UNSIGNED vector and
  422. -- R is a non-negative INTEGER.
  423.  
  424. -- Id: C.18
  425. function "<=" (L: SIGNED; R: INTEGER) return BOOLEAN;
  426. -- Result subtype: BOOLEAN
  427. -- Result: Computes "L <= R" where L is a SIGNED vector and
  428. -- R is an INTEGER.
  429.  
  430. --============================================================================
  431.  
  432. -- Id: C.19
  433. function ">=" (L, R: UNSIGNED) return BOOLEAN;
  434. -- Result subtype: BOOLEAN
  435. -- Result: Computes "L >= R" where L and R are UNSIGNED vectors possibly
  436. -- of different lengths.
  437.  
  438. -- Id: C.20
  439. function ">=" (L, R: SIGNED) return BOOLEAN;
  440. -- Result subtype: BOOLEAN
  441. -- Result: Computes "L >= R" where L and R are SIGNED vectors possibly
  442. -- of different lengths.
  443.  
  444. -- Id: C.21
  445. function ">=" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  446. -- Result subtype: BOOLEAN
  447. -- Result: Computes "L >= R" where L is a non-negative INTEGER and
  448. -- R is an UNSIGNED vector.
  449.  
  450. -- Id: C.22
  451. function ">=" (L: INTEGER; R: SIGNED) return BOOLEAN;
  452. -- Result subtype: BOOLEAN
  453. -- Result: Computes "L >= R" where L is an INTEGER and
  454. -- R is a SIGNED vector.
  455.  
  456. -- Id: C.23
  457. function ">=" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  458. -- Result subtype: BOOLEAN
  459. -- Result: Computes "L >= R" where L is an UNSIGNED vector and
  460. -- R is a non-negative INTEGER.
  461.  
  462. -- Id: C.24
  463. function ">=" (L: SIGNED; R: INTEGER) return BOOLEAN;
  464. -- Result subtype: BOOLEAN
  465. -- Result: Computes "L >= R" where L is a SIGNED vector and
  466. -- R is an INTEGER.
  467.  
  468. --============================================================================
  469.  
  470. -- Id: C.25
  471. function "=" (L, R: UNSIGNED) return BOOLEAN;
  472. -- Result subtype: BOOLEAN
  473. -- Result: Computes "L = R" where L and R are UNSIGNED vectors possibly
  474. -- of different lengths.
  475.  
  476. -- Id: C.26
  477. function "=" (L, R: SIGNED) return BOOLEAN;
  478. -- Result subtype: BOOLEAN
  479. -- Result: Computes "L = R" where L and R are SIGNED vectors possibly
  480. -- of different lengths.
  481.  
  482. -- Id: C.27
  483. function "=" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  484. -- Result subtype: BOOLEAN
  485. -- Result: Computes "L = R" where L is a non-negative INTEGER and
  486. -- R is an UNSIGNED vector.
  487.  
  488. -- Id: C.28
  489. function "=" (L: INTEGER; R: SIGNED) return BOOLEAN;
  490. -- Result subtype: BOOLEAN
  491. -- Result: Computes "L = R" where L is an INTEGER and
  492. -- R is a SIGNED vector.
  493.  
  494. -- Id: C.29
  495. function "=" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  496. -- Result subtype: BOOLEAN
  497. -- Result: Computes "L = R" where L is an UNSIGNED vector and
  498. -- R is a non-negative INTEGER.
  499.  
  500. -- Id: C.30
  501. function "=" (L: SIGNED; R: INTEGER) return BOOLEAN;
  502. -- Result subtype: BOOLEAN
  503. -- Result: Computes "L = R" where L is a SIGNED vector and
  504. -- R is an INTEGER.
  505.  
  506. --============================================================================
  507.  
  508. -- Id: C.31
  509. function "/=" (L, R: UNSIGNED) return BOOLEAN;
  510. -- Result subtype: BOOLEAN
  511. -- Result: Computes "L /= R" where L and R are UNSIGNED vectors possibly
  512. -- of different lengths.
  513.  
  514. -- Id: C.32
  515. function "/=" (L, R: SIGNED) return BOOLEAN;
  516. -- Result subtype: BOOLEAN
  517. -- Result: Computes "L /= R" where L and R are SIGNED vectors possibly
  518. -- of different lengths.
  519.  
  520. -- Id: C.33
  521. function "/=" (L: NATURAL; R: UNSIGNED) return BOOLEAN;
  522. -- Result subtype: BOOLEAN
  523. -- Result: Computes "L /= R" where L is a non-negative INTEGER and
  524. -- R is an UNSIGNED vector.
  525.  
  526. -- Id: C.34
  527. function "/=" (L: INTEGER; R: SIGNED) return BOOLEAN;
  528. -- Result subtype: BOOLEAN
  529. -- Result: Computes "L /= R" where L is an INTEGER and
  530. -- R is a SIGNED vector.
  531.  
  532. -- Id: C.35
  533. function "/=" (L: UNSIGNED; R: NATURAL) return BOOLEAN;
  534. -- Result subtype: BOOLEAN
  535. -- Result: Computes "L /= R" where L is an UNSIGNED vector and
  536. -- R is a non-negative INTEGER.
  537.  
  538. -- Id: C.36
  539. function "/=" (L: SIGNED; R: INTEGER) return BOOLEAN;
  540. -- Result subtype: BOOLEAN
  541. -- Result: Computes "L /= R" where L is a SIGNED vector and
  542. -- R is an INTEGER.
  543.  
  544. --============================================================================
  545. -- Shift and Rotate Functions
  546. --============================================================================
  547.  
  548. -- Id: S.1
  549. function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
  550. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  551. -- Result: Performs a shift-left on an UNSIGNED vector COUNT times.
  552. -- The vacated positions are filled with '0'.
  553. -- The COUNT leftmost elements are lost.
  554.  
  555. -- Id: S.2
  556. function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
  557. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  558. -- Result: Performs a shift-right on an UNSIGNED vector COUNT times.
  559. -- The vacated positions are filled with '0'.
  560. -- The COUNT rightmost elements are lost.
  561.  
  562. -- Id: S.3
  563. function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED;
  564. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  565. -- Result: Performs a shift-left on a SIGNED vector COUNT times.
  566. -- The vacated positions are filled with '0'.
  567. -- The COUNT leftmost elements are lost.
  568.  
  569. -- Id: S.4
  570. function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED;
  571. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  572. -- Result: Performs a shift-right on a SIGNED vector COUNT times.
  573. -- The vacated positions are filled with the leftmost
  574. -- element, ARG'LEFT. The COUNT rightmost elements are lost.
  575.  
  576. --============================================================================
  577.  
  578. -- Id: S.5
  579. function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
  580. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  581. -- Result: Performs a rotate-left of an UNSIGNED vector COUNT times.
  582.  
  583. -- Id: S.6
  584. function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
  585. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  586. -- Result: Performs a rotate-right of an UNSIGNED vector COUNT times.
  587.  
  588. -- Id: S.7
  589. function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED;
  590. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  591. -- Result: Performs a logical rotate-left of a SIGNED
  592. -- vector COUNT times.
  593.  
  594. -- Id: S.8
  595. function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED;
  596. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  597. -- Result: Performs a logical rotate-right of a SIGNED
  598. -- vector COUNT times.
  599.  
  600. --============================================================================
  601.  
  602. --============================================================================
  603.  
  604. ------------------------------------------------------------------------------
  605. -- Note : Function S.9 is not compatible with VHDL 1076-1987. Comment
  606. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  607. ------------------------------------------------------------------------------
  608. -- Id: S.9
  609. function "sll" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED;
  610. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  611. -- Result: SHIFT_LEFT(ARG, COUNT)
  612.  
  613. ------------------------------------------------------------------------------
  614. -- Note : Function S.10 is not compatible with VHDL 1076-1987. Comment
  615. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  616. ------------------------------------------------------------------------------
  617. -- Id: S.10
  618. function "sll" (ARG: SIGNED; COUNT: INTEGER) return SIGNED;
  619. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  620. -- Result: SHIFT_LEFT(ARG, COUNT)
  621.  
  622. ------------------------------------------------------------------------------
  623. -- Note : Function S.11 is not compatible with VHDL 1076-1987. Comment
  624. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  625. ------------------------------------------------------------------------------
  626. -- Id: S.11
  627. function "srl" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED;
  628. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  629. -- Result: SHIFT_RIGHT(ARG, COUNT)
  630.  
  631. ------------------------------------------------------------------------------
  632. -- Note : Function S.12 is not compatible with VHDL 1076-1987. Comment
  633. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  634. ------------------------------------------------------------------------------
  635. -- Id: S.12
  636. function "srl" (ARG: SIGNED; COUNT: INTEGER) return SIGNED;
  637. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  638. -- Result: SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), COUNT))
  639.  
  640. ------------------------------------------------------------------------------
  641. -- Note : Function S.13 is not compatible with VHDL 1076-1987. Comment
  642. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  643. ------------------------------------------------------------------------------
  644. -- Id: S.13
  645. function "rol" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED;
  646. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  647. -- Result: ROTATE_LEFT(ARG, COUNT)
  648.  
  649. ------------------------------------------------------------------------------
  650. -- Note : Function S.14 is not compatible with VHDL 1076-1987. Comment
  651. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  652. ------------------------------------------------------------------------------
  653. -- Id: S.14
  654. function "rol" (ARG: SIGNED; COUNT: INTEGER) return SIGNED;
  655. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  656. -- Result: ROTATE_LEFT(ARG, COUNT)
  657.  
  658. ------------------------------------------------------------------------------
  659. -- Note : Function S.15 is not compatible with VHDL 1076-1987. Comment
  660. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  661. ------------------------------------------------------------------------------
  662. -- Id: S.15
  663. function "ror" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED;
  664. -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
  665. -- Result: ROTATE_RIGHT(ARG, COUNT)
  666.  
  667. ------------------------------------------------------------------------------
  668. -- Note : Function S.16 is not compatible with VHDL 1076-1987. Comment
  669. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  670. ------------------------------------------------------------------------------
  671. -- Id: S.16
  672. function "ror" (ARG: SIGNED; COUNT: INTEGER) return SIGNED;
  673. -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)
  674. -- Result: ROTATE_RIGHT(ARG, COUNT)
  675.  
  676. --============================================================================
  677. -- RESIZE Functions
  678. --============================================================================
  679.  
  680. -- Id: R.1
  681. function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED;
  682. -- Result subtype: SIGNED(NEW_SIZE-1 downto 0)
  683. -- Result: Resizes the SIGNED vector ARG to the specified size.
  684. -- To create a larger vector, the new [leftmost] bit positions
  685. -- are filled with the sign bit (ARG'LEFT). When truncating,
  686. -- the sign bit is retained along with the rightmost part.
  687.  
  688. -- Id: R.2
  689. function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED;
  690. -- Result subtype: UNSIGNED(NEW_SIZE-1 downto 0)
  691. -- Result: Resizes the SIGNED vector ARG to the specified size.
  692. -- To create a larger vector, the new [leftmost] bit positions
  693. -- are filled with '0'. When truncating, the leftmost bits
  694. -- are dropped.
  695.  
  696. --============================================================================
  697. -- Conversion Functions
  698. --============================================================================
  699.  
  700. -- Id: D.1
  701. function TO_INTEGER (ARG: UNSIGNED) return NATURAL;
  702. -- Result subtype: NATURAL. Value cannot be negative since parameter is an
  703. -- UNSIGNED vector.
  704. -- Result: Converts the UNSIGNED vector to an INTEGER.
  705.  
  706. -- Id: D.2
  707. function TO_INTEGER (ARG: SIGNED) return INTEGER;
  708. -- Result subtype: INTEGER
  709. -- Result: Converts a SIGNED vector to an INTEGER.
  710.  
  711. -- Id: D.3
  712. function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED;
  713. -- Result subtype: UNSIGNED(SIZE-1 downto 0)
  714. -- Result: Converts a non-negative INTEGER to an UNSIGNED vector with
  715. -- the specified SIZE.
  716.  
  717. -- Id: D.4
  718. function TO_SIGNED (ARG: INTEGER; SIZE: NATURAL) return SIGNED;
  719. -- Result subtype: SIGNED(SIZE-1 downto 0)
  720. -- Result: Converts an INTEGER to a SIGNED vector of the specified SIZE.
  721.  
  722. --============================================================================
  723. -- Logical Operators
  724. --============================================================================
  725.  
  726. -- Id: L.1
  727. function "not" (L: UNSIGNED) return UNSIGNED;
  728. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  729. -- Result: Termwise inversion
  730.  
  731. -- Id: L.2
  732. function "and" (L, R: UNSIGNED) return UNSIGNED;
  733. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  734. -- Result: Vector AND operation
  735.  
  736. -- Id: L.3
  737. function "or" (L, R: UNSIGNED) return UNSIGNED;
  738. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  739. -- Result: Vector OR operation
  740.  
  741. -- Id: L.4
  742. function "nand" (L, R: UNSIGNED) return UNSIGNED;
  743. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  744. -- Result: Vector NAND operation
  745.  
  746. -- Id: L.5
  747. function "nor" (L, R: UNSIGNED) return UNSIGNED;
  748. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  749. -- Result: Vector NOR operation
  750.  
  751. -- Id: L.6
  752. function "xor" (L, R: UNSIGNED) return UNSIGNED;
  753. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  754. -- Result: Vector XOR operation
  755.  
  756. -- ---------------------------------------------------------------------------
  757. -- Note : Function L.7 is not compatible with VHDL 1076-1987. Comment
  758. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  759. -- ---------------------------------------------------------------------------
  760. -- Id: L.7
  761. function "xnor" (L, R: UNSIGNED) return UNSIGNED;
  762. -- Result subtype: UNSIGNED(L'LENGTH-1 downto 0)
  763. -- Result: Vector XNOR operation
  764.  
  765. -- Id: L.8
  766. function "not" (L: SIGNED) return SIGNED;
  767. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  768. -- Result: Termwise inversion
  769.  
  770. -- Id: L.9
  771. function "and" (L, R: SIGNED) return SIGNED;
  772. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  773. -- Result: Vector AND operation
  774.  
  775. -- Id: L.10
  776. function "or" (L, R: SIGNED) return SIGNED;
  777. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  778. -- Result: Vector OR operation
  779.  
  780. -- Id: L.11
  781. function "nand" (L, R: SIGNED) return SIGNED;
  782. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  783. -- Result: Vector NAND operation
  784.  
  785. -- Id: L.12
  786. function "nor" (L, R: SIGNED) return SIGNED;
  787. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  788. -- Result: Vector NOR operation
  789.  
  790. -- Id: L.13
  791. function "xor" (L, R: SIGNED) return SIGNED;
  792. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  793. -- Result: Vector XOR operation
  794.  
  795. -- ---------------------------------------------------------------------------
  796. -- Note : Function L.14 is not compatible with VHDL 1076-1987. Comment
  797. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  798. -- ---------------------------------------------------------------------------
  799. -- Id: L.14
  800. function "xnor" (L, R: SIGNED) return SIGNED;
  801. -- Result subtype: SIGNED(L'LENGTH-1 downto 0)
  802. -- Result: Vector XNOR operation
  803.  
  804. --============================================================================
  805. -- Match Functions
  806. --============================================================================
  807.  
  808. -- Id: M.1
  809. function STD_MATCH (L, R: STD_ULOGIC) return BOOLEAN;
  810. -- Result subtype: BOOLEAN
  811. -- Result: terms compared per STD_LOGIC_1164 intent
  812.  
  813. -- Id: M.2
  814. function STD_MATCH (L, R: UNSIGNED) return BOOLEAN;
  815. -- Result subtype: BOOLEAN
  816. -- Result: terms compared per STD_LOGIC_1164 intent
  817.  
  818. -- Id: M.3
  819. function STD_MATCH (L, R: SIGNED) return BOOLEAN;
  820. -- Result subtype: BOOLEAN
  821. -- Result: terms compared per STD_LOGIC_1164 intent
  822.  
  823. -- Id: M.4
  824. function STD_MATCH (L, R: STD_LOGIC_VECTOR) return BOOLEAN;
  825. -- Result subtype: BOOLEAN
  826. -- Result: terms compared per STD_LOGIC_1164 intent
  827.  
  828. -- Id: M.5
  829. function STD_MATCH (L, R: STD_ULOGIC_VECTOR) return BOOLEAN;
  830. -- Result subtype: BOOLEAN
  831. -- Result: terms compared per STD_LOGIC_1164 intent
  832.  
  833. --============================================================================
  834. -- Translation Functions
  835. --============================================================================
  836.  
  837. -- Id: T.1
  838. function TO_01 (S: UNSIGNED; XMAP: STD_LOGIC := '0') return UNSIGNED;
  839. -- Result subtype: UNSIGNED(S'RANGE)
  840. -- Result: Termwise, 'H' is translated to '1', and 'L' is translated
  841. -- to '0'. If a value other than '0'|'1'|'H'|'L' is found,
  842. -- the array is set to (others => XMAP), and a warning is
  843. -- issued.
  844.  
  845. -- Id: T.2
  846. function TO_01 (S: SIGNED; XMAP: STD_LOGIC := '0') return SIGNED;
  847. -- Result subtype: SIGNED(S'RANGE)
  848. -- Result: Termwise, 'H' is translated to '1', and 'L' is translated
  849. -- to '0'. If a value other than '0'|'1'|'H'|'L' is found,
  850. -- the array is set to (others => XMAP), and a warning is
  851. -- issued.
  852.  
  853. end NUMERIC_STD;
  854.  
  855. --==============================================================================
  856. --============================= Package Body ===================================
  857. --==============================================================================
  858.  
  859. -- Synthesis Directives
  860. -- Directives are in the form of the following two attributes :
  861. -- attribute SYNTHESIS_RETURN : STRING ;
  862. -- attribute IS_SIGNED : BOOLEAN ;
  863.  
  864. -- The SYNTHESIS_RETURN attribute is set on a return variable inside a function.
  865. -- Quartus will recognize the attribute and replace the function body by a
  866. -- built-in definition for synthesis.
  867. -- The variable on which the attribute is set defines the return (index) range
  868. -- of the function.
  869. -- The IS_SIGNED attribute is set on array parameters of the function that
  870. -- should be interpreted as 2-complement values.
  871. -- MSB is always the left most bit in an array (both for parameters and for
  872. -- return values).
  873.  
  874. library altera;
  875. use altera.altera_internal_syn.all;
  876.  
  877. package body NUMERIC_STD is
  878.  
  879. -- null range array constants
  880.  
  881. constant NAU: UNSIGNED(0 downto 1) := (others => '0');
  882. constant NAS: SIGNED(0 downto 1) := (others => '0');
  883.  
  884. -- implementation controls
  885.  
  886. constant NO_WARNING: BOOLEAN := FALSE; -- default to emit warnings
  887.  
  888. --=========================Local Subprograms =================================
  889.  
  890. function MAX (LEFT, RIGHT: INTEGER) return INTEGER is
  891. begin
  892. if LEFT > RIGHT then return LEFT;
  893. else return RIGHT;
  894. end if;
  895. end MAX;
  896.  
  897. function MIN (LEFT, RIGHT: INTEGER) return INTEGER is
  898. begin
  899. if LEFT < RIGHT then return LEFT;
  900. else return RIGHT;
  901. end if;
  902. end MIN;
  903.  
  904. function SIGNED_NUM_BITS (ARG: INTEGER) return NATURAL is
  905. variable NBITS: NATURAL;
  906. variable N: NATURAL;
  907. begin
  908. if ARG >= 0 then
  909. N := ARG;
  910. else
  911. N := -(ARG+1);
  912. end if;
  913. NBITS := 1;
  914. while N > 0 loop
  915. NBITS := NBITS+1;
  916. N := N / 2;
  917. end loop;
  918. return NBITS;
  919. end SIGNED_NUM_BITS;
  920.  
  921. function UNSIGNED_NUM_BITS (ARG: NATURAL) return NATURAL is
  922. variable NBITS: NATURAL;
  923. variable N: NATURAL;
  924. begin
  925. N := ARG;
  926. NBITS := 1;
  927. while N > 1 loop
  928. NBITS := NBITS+1;
  929. N := N / 2;
  930. end loop;
  931. return NBITS;
  932. end UNSIGNED_NUM_BITS;
  933.  
  934. ------------------------------------------------------------------------
  935.  
  936. -- this internal function computes the addition of two UNSIGNED
  937. -- with input CARRY
  938. -- * the two arguments are of the same length
  939.  
  940. function ADD_UNSIGNED (L, R: UNSIGNED; C: STD_LOGIC) return UNSIGNED is
  941. constant L_LEFT: INTEGER := L'LENGTH-1;
  942. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  943. alias XR: UNSIGNED(L_LEFT downto 0) is R;
  944. variable RESULT: UNSIGNED(L_LEFT downto 0);
  945. variable CBIT: STD_LOGIC := C;
  946. begin
  947. for I in 0 to L_LEFT loop
  948. RESULT(I) := CBIT xor XL(I) xor XR(I);
  949. CBIT := (CBIT and XL(I)) or (CBIT and XR(I)) or (XL(I) and XR(I));
  950. end loop;
  951. return RESULT;
  952. end ADD_UNSIGNED;
  953.  
  954. -- this internal function computes the addition of two SIGNED
  955. -- with input CARRY
  956. -- * the two arguments are of the same length
  957.  
  958. function ADD_SIGNED (L, R: SIGNED; C: STD_LOGIC) return SIGNED is
  959. constant L_LEFT: INTEGER := L'LENGTH-1;
  960. alias XL: SIGNED(L_LEFT downto 0) is L;
  961. alias XR: SIGNED(L_LEFT downto 0) is R;
  962. variable RESULT: SIGNED(L_LEFT downto 0);
  963. variable CBIT: STD_LOGIC := C;
  964. begin
  965. for I in 0 to L_LEFT loop
  966. RESULT(I) := CBIT xor XL(I) xor XR(I);
  967. CBIT := (CBIT and XL(I)) or (CBIT and XR(I)) or (XL(I) and XR(I));
  968. end loop;
  969. return RESULT;
  970. end ADD_SIGNED;
  971.  
  972. -----------------------------------------------------------------------------
  973.  
  974. -- this internal procedure computes UNSIGNED division
  975. -- giving the quotient and remainder.
  976. procedure DIVMOD (NUM, XDENOM: UNSIGNED; XQUOT, XREMAIN: out UNSIGNED) is
  977. variable TEMP: UNSIGNED(NUM'LENGTH downto 0);
  978. variable QUOT: UNSIGNED(MAX(NUM'LENGTH, XDENOM'LENGTH)-1 downto 0);
  979. alias DENOM: UNSIGNED(XDENOM'LENGTH-1 downto 0) is XDENOM;
  980. variable TOPBIT: INTEGER;
  981. begin
  982. TEMP := "0"&NUM;
  983. QUOT := (others => '0');
  984. TOPBIT := -1;
  985. for J in DENOM'RANGE loop
  986. if DENOM(J)='1' then
  987. TOPBIT := J;
  988. exit;
  989. end if;
  990. end loop;
  991. assert TOPBIT >= 0 report "DIV, MOD, or REM by zero" severity ERROR;
  992.  
  993. for J in NUM'LENGTH-(TOPBIT+1) downto 0 loop
  994. if TEMP(TOPBIT+J+1 downto J) >= "0"&DENOM(TOPBIT downto 0) then
  995. TEMP(TOPBIT+J+1 downto J) := (TEMP(TOPBIT+J+1 downto J))
  996. -("0"&DENOM(TOPBIT downto 0));
  997. QUOT(J) := '1';
  998. end if;
  999. assert TEMP(TOPBIT+J+1)='0'
  1000. report "internal error in the division algorithm"
  1001. severity ERROR;
  1002. end loop;
  1003. XQUOT := RESIZE(QUOT, XQUOT'LENGTH);
  1004. XREMAIN := RESIZE(TEMP, XREMAIN'LENGTH);
  1005. end DIVMOD;
  1006.  
  1007. -----------------Local Subprograms - shift/rotate ops-------------------------
  1008.  
  1009. function XSLL (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
  1010. is
  1011. constant ARG_L: INTEGER := ARG'LENGTH-1;
  1012. alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
  1013. variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0) := (others => '0');
  1014. -- Synthesis directives :
  1015. attribute SYNTHESIS_RETURN of RESULT:variable is "SLL" ;
  1016. begin
  1017. if COUNT <= ARG_L then
  1018. RESULT(ARG_L downto COUNT) := XARG(ARG_L-COUNT downto 0);
  1019. end if;
  1020. return RESULT;
  1021. end XSLL;
  1022.  
  1023. function XSRL (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
  1024. is
  1025. constant ARG_L: INTEGER := ARG'LENGTH-1;
  1026. alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
  1027. variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0) := (others => '0');
  1028. -- Synthesis directives :
  1029. attribute SYNTHESIS_RETURN of RESULT:variable is "SRL" ;
  1030. begin
  1031. if COUNT <= ARG_L then
  1032. RESULT(ARG_L-COUNT downto 0) := XARG(ARG_L downto COUNT);
  1033. end if;
  1034. return RESULT;
  1035. end XSRL;
  1036.  
  1037. function XSRA (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
  1038. is
  1039. constant ARG_L: INTEGER := ARG'LENGTH-1;
  1040. alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
  1041. variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0);
  1042. variable XCOUNT: NATURAL := COUNT;
  1043. -- Synthesis directives :
  1044. attribute SYNTHESIS_RETURN of RESULT:variable is "SRA" ;
  1045. begin
  1046. if ((ARG'LENGTH <= 1) or (XCOUNT = 0)) then return ARG;
  1047. else
  1048. if (XCOUNT > ARG_L) then XCOUNT := ARG_L;
  1049. end if;
  1050. RESULT(ARG_L-XCOUNT downto 0) := XARG(ARG_L downto XCOUNT);
  1051. RESULT(ARG_L downto (ARG_L - XCOUNT + 1)) := (others => XARG(ARG_L));
  1052. end if;
  1053. return RESULT;
  1054. end XSRA;
  1055.  
  1056. function XROL (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
  1057. is
  1058. constant ARG_L: INTEGER := ARG'LENGTH-1;
  1059. alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
  1060. variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0) := XARG;
  1061. variable COUNTM: INTEGER;
  1062. -- Synthesis directives :
  1063. attribute SYNTHESIS_RETURN of RESULT:variable is "ROL" ;
  1064. begin
  1065. COUNTM := COUNT mod (ARG_L + 1);
  1066. if COUNTM /= 0 then
  1067. RESULT(ARG_L downto COUNTM) := XARG(ARG_L-COUNTM downto 0);
  1068. RESULT(COUNTM-1 downto 0) := XARG(ARG_L downto ARG_L-COUNTM+1);
  1069. end if;
  1070. return RESULT;
  1071. end XROL;
  1072.  
  1073. function XROR (ARG: STD_LOGIC_VECTOR; COUNT: NATURAL) return STD_LOGIC_VECTOR
  1074. is
  1075. constant ARG_L: INTEGER := ARG'LENGTH-1;
  1076. alias XARG: STD_LOGIC_VECTOR(ARG_L downto 0) is ARG;
  1077. variable RESULT: STD_LOGIC_VECTOR(ARG_L downto 0) := XARG;
  1078. variable COUNTM: INTEGER;
  1079. -- Synthesis directives :
  1080. attribute SYNTHESIS_RETURN of RESULT:variable is "ROR" ;
  1081. begin
  1082. COUNTM := COUNT mod (ARG_L + 1);
  1083. if COUNTM /= 0 then
  1084. RESULT(ARG_L-COUNTM downto 0) := XARG(ARG_L downto COUNTM);
  1085. RESULT(ARG_L downto ARG_L-COUNTM+1) := XARG(COUNTM-1 downto 0);
  1086. end if;
  1087. return RESULT;
  1088. end XROR;
  1089.  
  1090. -----------------Local Subprograms - Relational ops---------------------------
  1091.  
  1092. --
  1093. -- General "=" for UNSIGNED vectors, same length
  1094. --
  1095. function UNSIGNED_EQUAL (L, R: UNSIGNED) return BOOLEAN is
  1096. begin
  1097. return STD_LOGIC_VECTOR(L) = STD_LOGIC_VECTOR(R);
  1098. end UNSIGNED_EQUAL;
  1099.  
  1100. --
  1101. -- General "=" for SIGNED vectors, same length
  1102. --
  1103. function SIGNED_EQUAL (L, R: SIGNED) return BOOLEAN is
  1104. begin
  1105. return STD_LOGIC_VECTOR(L) = STD_LOGIC_VECTOR(R);
  1106. end SIGNED_EQUAL;
  1107.  
  1108. --
  1109. -- General "<" for UNSIGNED vectors, same length
  1110. --
  1111. function UNSIGNED_LESS (L, R: UNSIGNED) return BOOLEAN is
  1112. begin
  1113. return STD_LOGIC_VECTOR(L) < STD_LOGIC_VECTOR(R);
  1114. end UNSIGNED_LESS;
  1115.  
  1116. --
  1117. -- General "<" function for SIGNED vectors, same length
  1118. --
  1119. function SIGNED_LESS (L, R: SIGNED) return BOOLEAN is
  1120. variable INTERN_L: SIGNED(0 to L'LENGTH-1);
  1121. variable INTERN_R: SIGNED(0 to R'LENGTH-1);
  1122. begin
  1123. INTERN_L := L;
  1124. INTERN_R := R;
  1125. INTERN_L(0) := not INTERN_L(0);
  1126. INTERN_R(0) := not INTERN_R(0);
  1127. return STD_LOGIC_VECTOR(INTERN_L) < STD_LOGIC_VECTOR(INTERN_R);
  1128. end SIGNED_LESS;
  1129.  
  1130. --
  1131. -- General "<=" function for UNSIGNED vectors, same length
  1132. --
  1133. function UNSIGNED_LESS_OR_EQUAL (L, R: UNSIGNED) return BOOLEAN is
  1134. begin
  1135. return STD_LOGIC_VECTOR(L) <= STD_LOGIC_VECTOR(R);
  1136. end UNSIGNED_LESS_OR_EQUAL;
  1137.  
  1138. --
  1139. -- General "<=" function for SIGNED vectors, same length
  1140. --
  1141. function SIGNED_LESS_OR_EQUAL (L, R: SIGNED) return BOOLEAN is
  1142. -- Need aliases to assure index direction
  1143. variable INTERN_L: SIGNED(0 to L'LENGTH-1);
  1144. variable INTERN_R: SIGNED(0 to R'LENGTH-1);
  1145. begin
  1146. INTERN_L := L;
  1147. INTERN_R := R;
  1148. INTERN_L(0) := not INTERN_L(0);
  1149. INTERN_R(0) := not INTERN_R(0);
  1150. return STD_LOGIC_VECTOR(INTERN_L) <= STD_LOGIC_VECTOR(INTERN_R);
  1151. end SIGNED_LESS_OR_EQUAL;
  1152.  
  1153. --=========================Exported Functions ==========================
  1154.  
  1155. -- Id: A.1
  1156. function "abs" (ARG: SIGNED) return SIGNED is
  1157. constant ARG_LEFT: INTEGER := ARG'LENGTH-1;
  1158. alias XARG: SIGNED(ARG_LEFT downto 0) is ARG;
  1159. variable RESULT: SIGNED(ARG_LEFT downto 0);
  1160. -- Synthesis directives :
  1161. attribute IS_SIGNED of ARG:constant is TRUE ;
  1162. attribute SYNTHESIS_RETURN of RESULT:variable is "ABS" ;
  1163. begin
  1164. if ARG'LENGTH < 1 then return NAS;
  1165. end if;
  1166. RESULT := TO_01(XARG, 'X');
  1167. if (RESULT(RESULT'LEFT)='X') then return RESULT;
  1168. end if;
  1169. if RESULT(RESULT'LEFT) = '1' then
  1170. RESULT := -RESULT;
  1171. end if;
  1172. return RESULT;
  1173. end "abs";
  1174.  
  1175. -- Id: A.2
  1176. function "-" (ARG: SIGNED) return SIGNED is
  1177. constant ARG_LEFT: INTEGER := ARG'LENGTH-1;
  1178. alias XARG: SIGNED(ARG_LEFT downto 0) is ARG;
  1179. variable RESULT, XARG01 : SIGNED(ARG_LEFT downto 0);
  1180. variable CBIT: STD_LOGIC := '1';
  1181. -- Synthesis directives :
  1182. attribute IS_SIGNED of ARG:constant is TRUE ;
  1183. attribute IS_SIGNED of RESULT:variable is TRUE ;
  1184. attribute SYNTHESIS_RETURN of RESULT:variable is "UMINUS" ;
  1185. begin
  1186. if ARG'LENGTH < 1 then return NAS;
  1187. end if;
  1188. XARG01 := TO_01(ARG, 'X');
  1189. if (XARG01(XARG01'LEFT)='X') then return XARG01;
  1190. end if;
  1191. for I in 0 to RESULT'LEFT loop
  1192. RESULT(I) := not(XARG01(I)) xor CBIT;
  1193. CBIT := CBIT and not(XARG01(I));
  1194. end loop;
  1195. return RESULT;
  1196. end "-";
  1197.  
  1198. --============================================================================
  1199.  
  1200. -- Id: A.3
  1201. function "+" (L, R: UNSIGNED) return UNSIGNED is
  1202. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1203. variable L01 : UNSIGNED(SIZE-1 downto 0);
  1204. variable R01 : UNSIGNED(SIZE-1 downto 0);
  1205. -- Synthesis directives :
  1206. attribute SYNTHESIS_RETURN of L01:variable is "ADD" ;
  1207. begin
  1208. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1209. end if;
  1210. L01 := TO_01(RESIZE(L, SIZE), 'X');
  1211. if (L01(L01'LEFT)='X') then return L01;
  1212. end if;
  1213. R01 := TO_01(RESIZE(R, SIZE), 'X');
  1214. if (R01(R01'LEFT)='X') then return R01;
  1215. end if;
  1216. return ADD_UNSIGNED(L01, R01, '0');
  1217. end "+";
  1218.  
  1219. -- Id: A.4
  1220. function "+" (L, R: SIGNED) return SIGNED is
  1221. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1222. variable L01 : SIGNED(SIZE-1 downto 0);
  1223. variable R01 : SIGNED(SIZE-1 downto 0);
  1224. -- Synthesis directives :
  1225. attribute IS_SIGNED of L:constant is TRUE ;
  1226. attribute IS_SIGNED of R:constant is TRUE ;
  1227. attribute IS_SIGNED of L01:variable is TRUE ;
  1228. attribute SYNTHESIS_RETURN of L01:variable is "ADD" ;
  1229. begin
  1230. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS;
  1231. end if;
  1232. L01 := TO_01(RESIZE(L, SIZE), 'X');
  1233. if (L01(L01'LEFT)='X') then return L01;
  1234. end if;
  1235. R01 := TO_01(RESIZE(R, SIZE), 'X');
  1236. if (R01(R01'LEFT)='X') then return R01;
  1237. end if;
  1238. return ADD_SIGNED(L01, R01, '0');
  1239. end "+";
  1240.  
  1241. -- Id: A.5
  1242. function "+" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1243. begin
  1244. return L + TO_UNSIGNED(R, L'LENGTH);
  1245. end "+";
  1246.  
  1247. -- Id: A.6
  1248. function "+" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1249. begin
  1250. return TO_UNSIGNED(L, R'LENGTH) + R;
  1251. end "+";
  1252.  
  1253. -- Id: A.7
  1254. function "+" (L: SIGNED; R: INTEGER) return SIGNED is
  1255. begin
  1256. return L + TO_SIGNED(R, L'LENGTH);
  1257. end "+";
  1258.  
  1259. -- Id: A.8
  1260. function "+" (L: INTEGER; R: SIGNED) return SIGNED is
  1261. begin
  1262. return TO_SIGNED(L, R'LENGTH) + R;
  1263. end "+";
  1264.  
  1265. --============================================================================
  1266.  
  1267. -- Id: A.9
  1268. function "-" (L, R: UNSIGNED) return UNSIGNED is
  1269. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1270. variable L01 : UNSIGNED(SIZE-1 downto 0);
  1271. variable R01 : UNSIGNED(SIZE-1 downto 0);
  1272. -- Synthesis directives :
  1273. attribute SYNTHESIS_RETURN of L01:variable is "SUB" ;
  1274. begin
  1275. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1276. end if;
  1277. L01 := TO_01(RESIZE(L, SIZE), 'X');
  1278. if (L01(L01'LEFT)='X') then return L01;
  1279. end if;
  1280. R01 := TO_01(RESIZE(R, SIZE), 'X');
  1281. if (R01(R01'LEFT)='X') then return R01;
  1282. end if;
  1283. return ADD_UNSIGNED(L01, not(R01), '1');
  1284. end "-";
  1285.  
  1286. -- Id: A.10
  1287. function "-" (L, R: SIGNED) return SIGNED is
  1288. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1289. variable L01 : SIGNED(SIZE-1 downto 0);
  1290. variable R01 : SIGNED(SIZE-1 downto 0);
  1291. -- Synthesis directives :
  1292. attribute IS_SIGNED of L:constant is TRUE ;
  1293. attribute IS_SIGNED of R:constant is TRUE ;
  1294. attribute IS_SIGNED of L01:variable is TRUE ;
  1295. attribute SYNTHESIS_RETURN of L01:variable is "SUB" ;
  1296. begin
  1297. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS;
  1298. end if;
  1299. L01 := TO_01(RESIZE(L, SIZE), 'X');
  1300. if (L01(L01'LEFT)='X') then return L01;
  1301. end if;
  1302. R01 := TO_01(RESIZE(R, SIZE), 'X');
  1303. if (R01(R01'LEFT)='X') then return R01;
  1304. end if;
  1305. return ADD_SIGNED(L01, not(R01), '1');
  1306. end "-";
  1307.  
  1308. -- Id: A.11
  1309. function "-" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1310. begin
  1311. return L - TO_UNSIGNED(R, L'LENGTH);
  1312. end "-";
  1313.  
  1314. -- Id: A.12
  1315. function "-" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1316. begin
  1317. return TO_UNSIGNED(L, R'LENGTH) - R;
  1318. end "-";
  1319.  
  1320. -- Id: A.13
  1321. function "-" (L: SIGNED; R: INTEGER) return SIGNED is
  1322. begin
  1323. return L - TO_SIGNED(R, L'LENGTH);
  1324. end "-";
  1325.  
  1326. -- Id: A.14
  1327. function "-" (L: INTEGER; R: SIGNED) return SIGNED is
  1328. begin
  1329. return TO_SIGNED(L, R'LENGTH) - R;
  1330. end "-";
  1331.  
  1332. --============================================================================
  1333.  
  1334. -- Id: A.15
  1335. function "*" (L, R: UNSIGNED) return UNSIGNED is
  1336. constant L_LEFT: INTEGER := L'LENGTH-1;
  1337. constant R_LEFT: INTEGER := R'LENGTH-1;
  1338. alias XXL: UNSIGNED(L_LEFT downto 0) is L;
  1339. alias XXR: UNSIGNED(R_LEFT downto 0) is R;
  1340. variable XL: UNSIGNED(L_LEFT downto 0);
  1341. variable XR: UNSIGNED(R_LEFT downto 0);
  1342. variable RESULT: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0) :=
  1343. (others => '0');
  1344. variable ADVAL: UNSIGNED((L'LENGTH+R'LENGTH-1) downto 0);
  1345. -- Synthesis directives :
  1346. attribute SYNTHESIS_RETURN of RESULT:variable is "MULT" ;
  1347. begin
  1348. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1349. end if;
  1350. XL := TO_01(XXL, 'X');
  1351. XR := TO_01(XXR, 'X');
  1352. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1353. RESULT := (others => 'X');
  1354. return RESULT;
  1355. end if;
  1356. ADVAL := RESIZE(XR, RESULT'LENGTH);
  1357. for I in 0 to L_LEFT loop
  1358. if XL(I)='1' then RESULT := RESULT + ADVAL;
  1359. end if;
  1360. ADVAL := SHIFT_LEFT(ADVAL, 1);
  1361. end loop;
  1362. return RESULT;
  1363. end "*";
  1364.  
  1365. -- Id: A.16
  1366. function "*" (L, R: SIGNED) return SIGNED is
  1367. constant L_LEFT: INTEGER := L'LENGTH-1;
  1368. constant R_LEFT: INTEGER := R'LENGTH-1;
  1369. variable XL: SIGNED(L_LEFT downto 0);
  1370. variable XR: SIGNED(R_LEFT downto 0);
  1371. variable RESULT: SIGNED((L_LEFT+R_LEFT+1) downto 0) := (others => '0');
  1372. variable ADVAL: SIGNED((L_LEFT+R_LEFT+1) downto 0);
  1373. -- Synthesis directives :
  1374. attribute IS_SIGNED of L:constant is TRUE ;
  1375. attribute IS_SIGNED of R:constant is TRUE ;
  1376. attribute IS_SIGNED of result:variable is TRUE ;
  1377. attribute SYNTHESIS_RETURN of RESULT:variable is "MULT" ;
  1378. begin
  1379. if ((L_LEFT < 0) or (R_LEFT < 0)) then return NAS;
  1380. end if;
  1381. XL := TO_01(L, 'X');
  1382. XR := TO_01(R, 'X');
  1383. if ((XL(L_LEFT)='X') or (XR(R_LEFT)='X')) then
  1384. RESULT := (others => 'X');
  1385. return RESULT;
  1386. end if;
  1387. ADVAL := RESIZE(XR, RESULT'LENGTH);
  1388. for I in 0 to L_LEFT-1 loop
  1389. if XL(I)='1' then RESULT := RESULT + ADVAL;
  1390. end if;
  1391. ADVAL := SHIFT_LEFT(ADVAL, 1);
  1392. end loop;
  1393. if XL(L_LEFT)='1' then
  1394. RESULT := RESULT - ADVAL;
  1395. end if;
  1396. return RESULT;
  1397. end "*";
  1398.  
  1399. -- Id: A.17
  1400. function "*" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1401. begin
  1402. return L * TO_UNSIGNED(R, L'LENGTH);
  1403. end "*";
  1404.  
  1405. -- Id: A.18
  1406. function "*" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1407. begin
  1408. return TO_UNSIGNED(L, R'LENGTH) * R;
  1409. end "*";
  1410.  
  1411. -- Id: A.19
  1412. function "*" (L: SIGNED; R: INTEGER) return SIGNED is
  1413. begin
  1414. return L * TO_SIGNED(R, L'LENGTH);
  1415. end "*";
  1416.  
  1417. -- Id: A.20
  1418. function "*" (L: INTEGER; R: SIGNED) return SIGNED is
  1419. begin
  1420. return TO_SIGNED(L, R'LENGTH) * R;
  1421. end "*";
  1422.  
  1423. --============================================================================
  1424.  
  1425. -- Id: A.21
  1426. function "/" (L, R: UNSIGNED) return UNSIGNED is
  1427. constant L_LEFT: INTEGER := L'LENGTH-1;
  1428. constant R_LEFT: INTEGER := R'LENGTH-1;
  1429. alias XXL: UNSIGNED(L_LEFT downto 0) is L;
  1430. alias XXR: UNSIGNED(R_LEFT downto 0) is R;
  1431. variable XL: UNSIGNED(L_LEFT downto 0);
  1432. variable XR: UNSIGNED(R_LEFT downto 0);
  1433. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1434. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1435. -- Synthesis directives :
  1436. attribute SYNTHESIS_RETURN of FQUOT:variable is "DIV" ;
  1437. attribute SYNTHESIS_RESULT_SIZE of FQUOT : variable is "LEFT";
  1438. begin
  1439. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1440. end if;
  1441. XL := TO_01(XXL, 'X');
  1442. XR := TO_01(XXR, 'X');
  1443. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1444. FQUOT := (others => 'X');
  1445. return FQUOT;
  1446. end if;
  1447. DIVMOD(XL, XR, FQUOT, FREMAIN);
  1448. return FQUOT;
  1449. end "/";
  1450.  
  1451. -- Id: A.22
  1452. function "/" (L, R: SIGNED) return SIGNED is
  1453. constant L_LEFT: INTEGER := L'LENGTH-1;
  1454. constant R_LEFT: INTEGER := R'LENGTH-1;
  1455. alias XXL: SIGNED(L_LEFT downto 0) is L;
  1456. alias XXR: SIGNED(R_LEFT downto 0) is R;
  1457. variable XL: SIGNED(L_LEFT downto 0);
  1458. variable XR: SIGNED(R_LEFT downto 0);
  1459. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1460. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1461. variable XNUM: UNSIGNED(L'LENGTH-1 downto 0);
  1462. variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0);
  1463. variable QNEG: BOOLEAN := FALSE;
  1464. -- Synthesis directives :
  1465. attribute IS_SIGNED of L:constant is TRUE ;
  1466. attribute IS_SIGNED of R:constant is TRUE ;
  1467. attribute IS_SIGNED of FQUOT:variable is TRUE ;
  1468. attribute SYNTHESIS_RETURN of FQUOT:variable is "DIV" ;
  1469. attribute SYNTHESIS_RESULT_SIZE of FQUOT : variable is "LEFT";
  1470. begin
  1471. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS;
  1472. end if;
  1473. XL := TO_01(XXL, 'X');
  1474. XR := TO_01(XXR, 'X');
  1475. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1476. FQUOT := (others => 'X');
  1477. return SIGNED(FQUOT);
  1478. end if;
  1479. if XL(XL'LEFT)='1' then
  1480. XNUM := UNSIGNED(-XL);
  1481. QNEG := TRUE;
  1482. else
  1483. XNUM := UNSIGNED(XL);
  1484. end if;
  1485. if XR(XR'LEFT)='1' then
  1486. XDENOM := UNSIGNED(-XR);
  1487. QNEG := not QNEG;
  1488. else
  1489. XDENOM := UNSIGNED(XR);
  1490. end if;
  1491. DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN);
  1492. if QNEG then FQUOT := "0"-FQUOT;
  1493. end if;
  1494. return SIGNED(FQUOT);
  1495. end "/";
  1496.  
  1497. -- Id: A.23
  1498. function "/" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1499. constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R));
  1500. variable XR, QUOT: UNSIGNED(R_LENGTH-1 downto 0);
  1501. -- Synthesis directives :
  1502. variable RESULT : UNSIGNED (L'LENGTH-1 downto 0) ;
  1503. attribute SYNTHESIS_RETURN of RESULT:variable is "DIV" ;
  1504. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "LEFT";
  1505. begin
  1506. if (L'LENGTH < 1) then return NAU;
  1507. end if;
  1508. if (R_LENGTH > L'LENGTH) then
  1509. QUOT := (others => '0');
  1510. return RESIZE(QUOT, L'LENGTH);
  1511. end if;
  1512. XR := TO_UNSIGNED(R, R_LENGTH);
  1513. QUOT := RESIZE((L / XR), QUOT'LENGTH);
  1514. return RESIZE(QUOT, L'LENGTH);
  1515. end "/";
  1516.  
  1517. -- Id: A.24
  1518. function "/" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1519. constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH);
  1520. variable XL, QUOT: UNSIGNED(L_LENGTH-1 downto 0);
  1521. -- Synthesis directives :
  1522. variable RESULT : UNSIGNED (R'LENGTH-1 downto 0) ;
  1523. attribute SYNTHESIS_RETURN of RESULT:variable is "DIV" ;
  1524. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "RIGHT";
  1525. begin
  1526. if (R'LENGTH < 1) then return NAU;
  1527. end if;
  1528. XL := TO_UNSIGNED(L, L_LENGTH);
  1529. QUOT := RESIZE((XL / R), QUOT'LENGTH);
  1530. if L_LENGTH > R'LENGTH and QUOT(0)/='X'
  1531. and QUOT(L_LENGTH-1 downto R'LENGTH)
  1532. /= (L_LENGTH-1 downto R'LENGTH => '0')
  1533. then
  1534. assert NO_WARNING report "NUMERIC_STD.""/"": Quotient Truncated"
  1535. severity WARNING;
  1536. end if;
  1537. return RESIZE(QUOT, R'LENGTH);
  1538. end "/";
  1539.  
  1540. -- Id: A.25
  1541. function "/" (L: SIGNED; R: INTEGER) return SIGNED is
  1542. constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R));
  1543. variable XR, QUOT: SIGNED(R_LENGTH-1 downto 0);
  1544. -- Synthesis directives :
  1545. variable RESULT : SIGNED (L'LENGTH-1 downto 0) ;
  1546. attribute IS_SIGNED of L:constant is TRUE ;
  1547. attribute IS_SIGNED of result:variable is TRUE ;
  1548. attribute SYNTHESIS_RETURN of RESULT:variable is "DIV" ;
  1549. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "LEFT";
  1550. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1551. begin
  1552. if (L'LENGTH < 1) then return NAS;
  1553. end if;
  1554. if (R_LENGTH > L'LENGTH) then
  1555. QUOT := (others => '0');
  1556. return RESIZE(QUOT, L'LENGTH);
  1557. end if;
  1558. XR := TO_SIGNED(R, R_LENGTH);
  1559. QUOT := RESIZE((L / XR), QUOT'LENGTH);
  1560. return RESIZE(QUOT, L'LENGTH);
  1561. end "/";
  1562.  
  1563. -- Id: A.26
  1564. function "/" (L: INTEGER; R: SIGNED) return SIGNED is
  1565. constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH);
  1566. variable XL, QUOT: SIGNED(L_LENGTH-1 downto 0);
  1567. -- Synthesis directives :
  1568. variable RESULT : SIGNED (R'LENGTH-1 downto 0) ;
  1569. attribute IS_SIGNED of R:constant is TRUE ;
  1570. attribute IS_SIGNED of result:variable is TRUE ;
  1571. attribute SYNTHESIS_RETURN of RESULT:variable is "DIV" ;
  1572. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "RIGHT";
  1573. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1574. begin
  1575. if (R'LENGTH < 1) then return NAS;
  1576. end if;
  1577. XL := TO_SIGNED(L, L_LENGTH);
  1578. QUOT := RESIZE((XL / R), QUOT'LENGTH);
  1579. if L_LENGTH > R'LENGTH and QUOT(0)/='X'
  1580. and QUOT(L_LENGTH-1 downto R'LENGTH)
  1581. /= (L_LENGTH-1 downto R'LENGTH => QUOT(R'LENGTH-1))
  1582. then
  1583. assert NO_WARNING report "NUMERIC_STD.""/"": Quotient Truncated"
  1584. severity WARNING;
  1585. end if;
  1586. return RESIZE(QUOT, R'LENGTH);
  1587. end "/";
  1588.  
  1589. --============================================================================
  1590.  
  1591. -- Id: A.27
  1592. function "rem" (L, R: UNSIGNED) return UNSIGNED is
  1593. constant L_LEFT: INTEGER := L'LENGTH-1;
  1594. constant R_LEFT: INTEGER := R'LENGTH-1;
  1595. alias XXL: UNSIGNED(L_LEFT downto 0) is L;
  1596. alias XXR: UNSIGNED(R_LEFT downto 0) is R;
  1597. variable XL: UNSIGNED(L_LEFT downto 0);
  1598. variable XR: UNSIGNED(R_LEFT downto 0);
  1599. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1600. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1601. -- Synthesis directives :
  1602. attribute SYNTHESIS_RETURN of FREMAIN:variable is "REM" ;
  1603. attribute SYNTHESIS_RESULT_SIZE of FREMAIN : variable is "RIGHT";
  1604. begin
  1605. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1606. end if;
  1607. XL := TO_01(XXL, 'X');
  1608. XR := TO_01(XXR, 'X');
  1609. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1610. FREMAIN := (others => 'X');
  1611. return FREMAIN;
  1612. end if;
  1613. DIVMOD(XL, XR, FQUOT, FREMAIN);
  1614. return FREMAIN;
  1615. end "rem";
  1616.  
  1617. -- Id: A.28
  1618. function "rem" (L, R: SIGNED) return SIGNED is
  1619. constant L_LEFT: INTEGER := L'LENGTH-1;
  1620. constant R_LEFT: INTEGER := R'LENGTH-1;
  1621. alias XXL: SIGNED(L_LEFT downto 0) is L;
  1622. alias XXR: SIGNED(R_LEFT downto 0) is R;
  1623. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1624. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1625. variable XNUM: UNSIGNED(L'LENGTH-1 downto 0);
  1626. variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0);
  1627. variable RNEG: BOOLEAN := FALSE;
  1628. -- Synthesis directives :
  1629. attribute IS_SIGNED of L:constant is TRUE ;
  1630. attribute IS_SIGNED of R:constant is TRUE ;
  1631. attribute SYNTHESIS_RETURN of FREMAIN:variable is "REM" ;
  1632. attribute SYNTHESIS_RESULT_SIZE of FREMAIN : variable is "RIGHT";
  1633. begin
  1634. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS;
  1635. end if;
  1636. XNUM := UNSIGNED(TO_01(XXL, 'X'));
  1637. XDENOM := UNSIGNED(TO_01(XXR, 'X'));
  1638. if ((XNUM(XNUM'LEFT)='X') or (XDENOM(XDENOM'LEFT)='X')) then
  1639. FREMAIN := (others => 'X');
  1640. return SIGNED(FREMAIN);
  1641. end if;
  1642. if XNUM(XNUM'LEFT)='1' then
  1643. XNUM := UNSIGNED(-SIGNED(XNUM));
  1644. RNEG := TRUE;
  1645. else
  1646. XNUM := UNSIGNED(XNUM);
  1647. end if;
  1648. if XDENOM(XDENOM'LEFT)='1' then
  1649. XDENOM := UNSIGNED(-SIGNED(XDENOM));
  1650. else
  1651. XDENOM := UNSIGNED(XDENOM);
  1652. end if;
  1653. DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN);
  1654. if RNEG then
  1655. FREMAIN := "0"-FREMAIN;
  1656. end if;
  1657. return SIGNED(FREMAIN);
  1658. end "rem";
  1659.  
  1660. -- Id: A.29
  1661. function "rem" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1662. constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R));
  1663. variable XR, XREM: UNSIGNED(R_LENGTH-1 downto 0);
  1664. -- Synthesis directives :
  1665. variable RESULT : UNSIGNED (L'LENGTH-1 downto 0) ;
  1666. attribute SYNTHESIS_RETURN of RESULT:variable is "REM" ;
  1667. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "LEFT";
  1668. begin
  1669. if (L'LENGTH < 1) then return NAU;
  1670. end if;
  1671. XR := TO_UNSIGNED(R, R_LENGTH);
  1672. XREM := L rem XR;
  1673. if R_LENGTH > L'LENGTH and XREM(0)/='X'
  1674. and XREM(R_LENGTH-1 downto L'LENGTH)
  1675. /= (R_LENGTH-1 downto L'LENGTH => '0')
  1676. then
  1677. assert NO_WARNING report "NUMERIC_STD.""rem"": Remainder Truncated"
  1678. severity WARNING;
  1679. end if;
  1680. return RESIZE(XREM, L'LENGTH);
  1681. end "rem";
  1682.  
  1683. -- Id: A.30
  1684. function "rem" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1685. constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH);
  1686. variable XL, XREM: UNSIGNED(L_LENGTH-1 downto 0);
  1687. -- Synthesis directives :
  1688. variable RESULT : UNSIGNED (R'LENGTH-1 downto 0) ;
  1689. attribute SYNTHESIS_RETURN of RESULT:variable is "REM" ;
  1690. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "RIGHT";
  1691. begin
  1692. XL := TO_UNSIGNED(L, L_LENGTH);
  1693. XREM := XL rem R;
  1694. if L_LENGTH > R'LENGTH and XREM(0)/='X'
  1695. and XREM(L_LENGTH-1 downto R'LENGTH)
  1696. /= (L_LENGTH-1 downto R'LENGTH => '0')
  1697. then
  1698. assert NO_WARNING report "NUMERIC_STD.""rem"": Remainder Truncated"
  1699. severity WARNING;
  1700. end if;
  1701. return RESIZE(XREM, R'LENGTH);
  1702. end "rem";
  1703.  
  1704. -- Id: A.31
  1705. function "rem" (L: SIGNED; R: INTEGER) return SIGNED is
  1706. constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R));
  1707. variable XR, XREM: SIGNED(R_LENGTH-1 downto 0);
  1708. -- Synthesis directives :
  1709. variable RESULT : SIGNED (L'LENGTH-1 downto 0) ;
  1710. attribute IS_SIGNED of L:constant is TRUE ;
  1711. attribute SYNTHESIS_RETURN of RESULT:variable is "REM" ;
  1712. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "LEFT";
  1713. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1714. begin
  1715. if (L'LENGTH < 1) then return NAS;
  1716. end if;
  1717. XR := TO_SIGNED(R, R_LENGTH);
  1718. XREM := RESIZE((L rem XR), XREM'LENGTH);
  1719. if R_LENGTH > L'LENGTH and XREM(0)/='X'
  1720. and XREM(R_LENGTH-1 downto L'LENGTH)
  1721. /= (R_LENGTH-1 downto L'LENGTH => XREM(L'LENGTH-1))
  1722. then
  1723. assert NO_WARNING report "NUMERIC_STD.""rem"": Remainder Truncated"
  1724. severity WARNING;
  1725. end if;
  1726. return RESIZE(XREM, L'LENGTH);
  1727. end "rem";
  1728.  
  1729. -- Id: A.32
  1730. function "rem" (L: INTEGER; R: SIGNED) return SIGNED is
  1731. constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH);
  1732. variable XL, XREM: SIGNED(L_LENGTH-1 downto 0);
  1733. -- Synthesis directives :
  1734. variable RESULT : SIGNED (R'LENGTH-1 downto 0) ;
  1735. attribute IS_SIGNED of R:constant is TRUE ;
  1736. attribute SYNTHESIS_RETURN of RESULT:variable is "REM" ;
  1737. attribute SYNTHESIS_RESULT_SIZE of RESULT : variable is "RIGHT";
  1738. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1739. begin
  1740. if (R'LENGTH < 1) then return NAS;
  1741. end if;
  1742. XL := TO_SIGNED(L, L_LENGTH);
  1743. XREM := RESIZE((XL rem R), XREM'LENGTH);
  1744. if L_LENGTH > R'LENGTH and XREM(0)/='X'
  1745. and XREM(L_LENGTH-1 downto R'LENGTH)
  1746. /= (L_LENGTH-1 downto R'LENGTH => XREM(R'LENGTH-1))
  1747. then
  1748. assert NO_WARNING report "NUMERIC_STD.""rem"": Remainder Truncated"
  1749. severity WARNING;
  1750. end if;
  1751. return RESIZE(XREM, R'LENGTH);
  1752. end "rem";
  1753.  
  1754. --============================================================================
  1755.  
  1756. -- Id: A.33
  1757. function "mod" (L, R: UNSIGNED) return UNSIGNED is
  1758. constant L_LEFT: INTEGER := L'LENGTH-1;
  1759. constant R_LEFT: INTEGER := R'LENGTH-1;
  1760. alias XXL: UNSIGNED(L_LEFT downto 0) is L;
  1761. alias XXR: UNSIGNED(R_LEFT downto 0) is R;
  1762. variable XL: UNSIGNED(L_LEFT downto 0);
  1763. variable XR: UNSIGNED(R_LEFT downto 0);
  1764. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1765. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1766. -- Synthesis directives :
  1767. attribute SYNTHESIS_RETURN of FREMAIN:variable is "MOD" ;
  1768. attribute SYNTHESIS_RESULT_SIZE of FREMAIN : variable is "RIGHT";
  1769. begin
  1770. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAU;
  1771. end if;
  1772. XL := TO_01(XXL, 'X');
  1773. XR := TO_01(XXR, 'X');
  1774. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1775. FREMAIN := (others => 'X');
  1776. return FREMAIN;
  1777. end if;
  1778. DIVMOD(XL, XR, FQUOT, FREMAIN);
  1779. return FREMAIN;
  1780. end "mod";
  1781.  
  1782. -- Id: A.34
  1783. function "mod" (L, R: SIGNED) return SIGNED is
  1784. constant L_LEFT: INTEGER := L'LENGTH-1;
  1785. constant R_LEFT: INTEGER := R'LENGTH-1;
  1786. alias XXL: SIGNED(L_LEFT downto 0) is L;
  1787. alias XXR: SIGNED(R_LEFT downto 0) is R;
  1788. variable XL: SIGNED(L_LEFT downto 0);
  1789. variable XR: SIGNED(R_LEFT downto 0);
  1790. variable FQUOT: UNSIGNED(L'LENGTH-1 downto 0);
  1791. variable FREMAIN: UNSIGNED(R'LENGTH-1 downto 0);
  1792. variable XNUM: UNSIGNED(L'LENGTH-1 downto 0);
  1793. variable XDENOM: UNSIGNED(R'LENGTH-1 downto 0);
  1794. variable RNEG: BOOLEAN := FALSE;
  1795. -- Synthesis directives :
  1796. attribute IS_SIGNED of L:constant is TRUE ;
  1797. attribute IS_SIGNED of R:constant is TRUE ;
  1798. attribute IS_SIGNED of FREMAIN:variable is TRUE ;
  1799. attribute SYNTHESIS_RETURN of FREMAIN:variable is "MOD" ;
  1800. attribute SYNTHESIS_RESULT_SIZE of FREMAIN : variable is "RIGHT";
  1801. begin
  1802. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then return NAS;
  1803. end if;
  1804. XL := TO_01(XXL, 'X');
  1805. XR := TO_01(XXR, 'X');
  1806. if ((XL(XL'LEFT)='X') or (XR(XR'LEFT)='X')) then
  1807. FREMAIN := (others => 'X');
  1808. return SIGNED(FREMAIN);
  1809. end if;
  1810. if XL(XL'LEFT)='1' then
  1811. XNUM := UNSIGNED(-XL);
  1812. else
  1813. XNUM := UNSIGNED(XL);
  1814. end if;
  1815. if XR(XR'LEFT)='1' then
  1816. XDENOM := UNSIGNED(-XR);
  1817. RNEG := TRUE;
  1818. else
  1819. XDENOM := UNSIGNED(XR);
  1820. end if;
  1821. DIVMOD(XNUM, XDENOM, FQUOT, FREMAIN);
  1822. if RNEG and L(L'LEFT)='1' then
  1823. FREMAIN := "0"-FREMAIN;
  1824. elsif RNEG and FREMAIN/="0" then
  1825. FREMAIN := FREMAIN-XDENOM;
  1826. elsif L(L'LEFT)='1' and FREMAIN/="0" then
  1827. FREMAIN := XDENOM-FREMAIN;
  1828. end if;
  1829. return SIGNED(FREMAIN);
  1830. end "mod";
  1831.  
  1832. -- Id: A.35
  1833. function "mod" (L: UNSIGNED; R: NATURAL) return UNSIGNED is
  1834. constant R_LENGTH: NATURAL := MAX(L'LENGTH, UNSIGNED_NUM_BITS(R));
  1835. variable XR, XREM: UNSIGNED(R_LENGTH-1 downto 0);
  1836. -- Synthesis directives :
  1837. variable RESULT : UNSIGNED (L'LENGTH-1 downto 0) ;
  1838. attribute SYNTHESIS_RETURN of RESULT:variable is "MOD" ;
  1839. attribute SYNTHESIS_RESULT_SIZE of RESULT:variable is "LEFT" ;
  1840. begin
  1841. if (L'LENGTH < 1) then return NAU;
  1842. end if;
  1843. XR := TO_UNSIGNED(R, R_LENGTH);
  1844. XREM := RESIZE((L mod XR), XREM'LENGTH);
  1845. if R_LENGTH > L'LENGTH and XREM(0)/='X'
  1846. and XREM(R_LENGTH-1 downto L'LENGTH)
  1847. /= (R_LENGTH-1 downto L'LENGTH => '0')
  1848. then
  1849. assert NO_WARNING report "NUMERIC_STD.""mod"": Modulus Truncated"
  1850. severity WARNING;
  1851. end if;
  1852. return RESIZE(XREM, L'LENGTH);
  1853. end "mod";
  1854.  
  1855. -- Id: A.36
  1856. function "mod" (L: NATURAL; R: UNSIGNED) return UNSIGNED is
  1857. constant L_LENGTH: NATURAL := MAX(UNSIGNED_NUM_BITS(L), R'LENGTH);
  1858. variable XL, XREM: UNSIGNED(L_LENGTH-1 downto 0);
  1859. -- Synthesis directives :
  1860. variable RESULT : UNSIGNED (R'LENGTH-1 downto 0) ;
  1861. attribute SYNTHESIS_RETURN of RESULT:variable is "MOD" ;
  1862. attribute SYNTHESIS_RESULT_SIZE of RESULT:variable is "RIGHT" ;
  1863. begin
  1864. if (R'LENGTH < 1) then return NAU;
  1865. end if;
  1866. XL := TO_UNSIGNED(L, L_LENGTH);
  1867. XREM := RESIZE((XL mod R), XREM'LENGTH);
  1868. if L_LENGTH > R'LENGTH and XREM(0)/='X'
  1869. and XREM(L_LENGTH-1 downto R'LENGTH)
  1870. /= (L_LENGTH-1 downto R'LENGTH => '0')
  1871. then
  1872. assert NO_WARNING report "NUMERIC_STD.""mod"": Modulus Truncated"
  1873. severity WARNING;
  1874. end if;
  1875. return RESIZE(XREM, R'LENGTH);
  1876. end "mod";
  1877.  
  1878. -- Id: A.37
  1879. function "mod" (L: SIGNED; R: INTEGER) return SIGNED is
  1880. constant R_LENGTH: NATURAL := MAX(L'LENGTH, SIGNED_NUM_BITS(R));
  1881. variable XR, XREM: SIGNED(R_LENGTH-1 downto 0);
  1882. -- Synthesis directives :
  1883. variable RESULT : SIGNED (L'LENGTH-1 downto 0) ;
  1884. attribute IS_SIGNED of L:constant is TRUE ;
  1885. attribute IS_SIGNED of result:variable is TRUE ;
  1886. attribute SYNTHESIS_RETURN of RESULT:variable is "MOD" ;
  1887. attribute SYNTHESIS_RESULT_SIZE of RESULT:variable is "LEFT" ;
  1888. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1889. begin
  1890. if (L'LENGTH < 1) then return NAS;
  1891. end if;
  1892. XR := TO_SIGNED(R, R_LENGTH);
  1893. XREM := RESIZE((L mod XR), XREM'LENGTH);
  1894. if R_LENGTH > L'LENGTH and XREM(0)/='X'
  1895. and XREM(R_LENGTH-1 downto L'LENGTH)
  1896. /= (R_LENGTH-1 downto L'LENGTH => XREM(L'LENGTH-1))
  1897. then
  1898. assert NO_WARNING report "NUMERIC_STD.""mod"": Modulus Truncated"
  1899. severity WARNING;
  1900. end if;
  1901. return RESIZE(XREM, L'LENGTH);
  1902. end "mod";
  1903.  
  1904. -- Id: A.38
  1905. function "mod" (L: INTEGER; R: SIGNED) return SIGNED is
  1906. constant L_LENGTH: NATURAL := MAX(SIGNED_NUM_BITS(L), R'LENGTH);
  1907. variable XL, XREM: SIGNED(L_LENGTH-1 downto 0);
  1908. -- Synthesis directives :
  1909. variable RESULT : SIGNED (R'LENGTH-1 downto 0) ;
  1910. attribute IS_SIGNED of R:constant is TRUE ;
  1911. attribute IS_SIGNED of result:variable is TRUE ;
  1912. attribute SYNTHESIS_RETURN of RESULT:variable is "MOD" ;
  1913. attribute SYNTHESIS_RESULT_SIZE of RESULT:variable is "RIGHT" ;
  1914. attribute SIGNED_TRUNCATION of RESULT : variable is true;
  1915. begin
  1916. if (R'LENGTH < 1) then return NAS;
  1917. end if;
  1918. XL := TO_SIGNED(L, L_LENGTH);
  1919. XREM := RESIZE((XL mod R), XREM'LENGTH);
  1920. if L_LENGTH > R'LENGTH and XREM(0)/='X'
  1921. and XREM(L_LENGTH-1 downto R'LENGTH)
  1922. /= (L_LENGTH-1 downto R'LENGTH => XREM(R'LENGTH-1))
  1923. then
  1924. assert NO_WARNING report "NUMERIC_STD.""mod"": Modulus Truncated"
  1925. severity WARNING;
  1926. end if;
  1927. return RESIZE(XREM, R'LENGTH);
  1928. end "mod";
  1929.  
  1930. --============================================================================
  1931.  
  1932. -- Id: C.1
  1933. function ">" (L, R: UNSIGNED) return BOOLEAN is
  1934. constant L_LEFT: INTEGER := L'LENGTH-1;
  1935. constant R_LEFT: INTEGER := R'LENGTH-1;
  1936. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  1937. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  1938. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1939. variable L01 : UNSIGNED(L_LEFT downto 0);
  1940. variable R01 : UNSIGNED(R_LEFT downto 0);
  1941. -- Synthesis directives :
  1942. variable RESULT : BOOLEAN ;
  1943. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  1944. begin
  1945. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  1946. assert NO_WARNING
  1947. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  1948. severity WARNING;
  1949. return FALSE;
  1950. end if;
  1951. L01 := TO_01(XL, 'X');
  1952. R01 := TO_01(XR, 'X');
  1953. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  1954. assert NO_WARNING
  1955. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  1956. severity WARNING;
  1957. return FALSE;
  1958. end if;
  1959. return not UNSIGNED_LESS_OR_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  1960. end ">";
  1961.  
  1962. -- Id: C.2
  1963. function ">" (L, R: SIGNED) return BOOLEAN is
  1964. constant L_LEFT: INTEGER := L'LENGTH-1;
  1965. constant R_LEFT: INTEGER := R'LENGTH-1;
  1966. alias XL: SIGNED(L_LEFT downto 0) is L;
  1967. alias XR: SIGNED(R_LEFT downto 0) is R;
  1968. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  1969. variable L01 : SIGNED(L_LEFT downto 0);
  1970. variable R01 : SIGNED(R_LEFT downto 0);
  1971. -- Synthesis directives :
  1972. variable RESULT : BOOLEAN ;
  1973. attribute IS_SIGNED of L:constant is TRUE ;
  1974. attribute IS_SIGNED of R:constant is TRUE ;
  1975. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  1976. begin
  1977. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  1978. assert NO_WARNING
  1979. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  1980. severity WARNING;
  1981. return FALSE;
  1982. end if;
  1983. L01 := TO_01(XL, 'X');
  1984. R01 := TO_01(XR, 'X');
  1985. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  1986. assert NO_WARNING
  1987. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  1988. severity WARNING;
  1989. return FALSE;
  1990. end if;
  1991. return not SIGNED_LESS_OR_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  1992. end ">";
  1993.  
  1994. -- Id: C.3
  1995. function ">" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  1996. constant R_LEFT: INTEGER := R'LENGTH-1;
  1997. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  1998. variable R01 : UNSIGNED(R_LEFT downto 0);
  1999. -- Synthesis directives :
  2000. variable RESULT : BOOLEAN ;
  2001. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  2002. begin
  2003. if (R'LENGTH < 1) then
  2004. assert NO_WARNING
  2005. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  2006. severity WARNING;
  2007. return FALSE;
  2008. end if;
  2009. R01 := TO_01(XR, 'X');
  2010. if (R01(R01'LEFT)='X') then
  2011. assert NO_WARNING
  2012. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  2013. severity WARNING;
  2014. return FALSE;
  2015. end if;
  2016. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return TRUE;
  2017. end if;
  2018. return not UNSIGNED_LESS_OR_EQUAL(TO_UNSIGNED(L, R01'LENGTH), R01);
  2019. end ">";
  2020.  
  2021. -- Id: C.4
  2022. function ">" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2023. constant R_LEFT: INTEGER := R'LENGTH-1;
  2024. alias XR: SIGNED(R_LEFT downto 0) is R;
  2025. variable R01 : SIGNED(R_LEFT downto 0);
  2026. -- Synthesis directives :
  2027. variable RESULT : BOOLEAN ;
  2028. attribute IS_SIGNED of R:constant is TRUE ;
  2029. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  2030. begin
  2031. if (R'LENGTH < 1) then
  2032. assert NO_WARNING
  2033. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  2034. severity WARNING;
  2035. return FALSE;
  2036. end if;
  2037. R01 := TO_01(XR, 'X');
  2038. if (R01(R01'LEFT)='X') then
  2039. assert NO_WARNING
  2040. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  2041. severity WARNING;
  2042. return FALSE;
  2043. end if;
  2044. if SIGNED_NUM_BITS(L) > R'LENGTH then return L > 0;
  2045. end if;
  2046. return not SIGNED_LESS_OR_EQUAL(TO_SIGNED(L, R01'LENGTH), R01);
  2047. end ">";
  2048.  
  2049. -- Id: C.5
  2050. function ">" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2051. constant L_LEFT: INTEGER := L'LENGTH-1;
  2052. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2053. variable L01 : UNSIGNED(L_LEFT downto 0);
  2054. -- Synthesis directives :
  2055. variable RESULT : BOOLEAN ;
  2056. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  2057. begin
  2058. if (L'LENGTH < 1) then
  2059. assert NO_WARNING
  2060. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  2061. severity WARNING;
  2062. return FALSE;
  2063. end if;
  2064. L01 := TO_01(XL, 'X');
  2065. if (L01(L01'LEFT)='X') then
  2066. assert NO_WARNING
  2067. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  2068. severity WARNING;
  2069. return FALSE;
  2070. end if;
  2071. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return FALSE;
  2072. end if;
  2073. return not UNSIGNED_LESS_OR_EQUAL(L01, TO_UNSIGNED(R, L01'LENGTH));
  2074. end ">";
  2075.  
  2076. -- Id: C.6
  2077. function ">" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2078. constant L_LEFT: INTEGER := L'LENGTH-1;
  2079. alias XL: SIGNED(L_LEFT downto 0) is L;
  2080. variable L01 : SIGNED(L_LEFT downto 0);
  2081. -- Synthesis directives :
  2082. variable RESULT : BOOLEAN ;
  2083. attribute IS_SIGNED of L:constant is TRUE ;
  2084. attribute SYNTHESIS_RETURN of RESULT:variable is "GT" ;
  2085. begin
  2086. if (L'LENGTH < 1) then
  2087. assert NO_WARNING
  2088. report "NUMERIC_STD."">"": null argument detected, returning FALSE"
  2089. severity WARNING;
  2090. return FALSE;
  2091. end if;
  2092. L01 := TO_01(XL, 'X');
  2093. if (L01(L01'LEFT)='X') then
  2094. assert NO_WARNING
  2095. report "NUMERIC_STD."">"": metavalue detected, returning FALSE"
  2096. severity WARNING;
  2097. return FALSE;
  2098. end if;
  2099. if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R;
  2100. end if;
  2101. return not SIGNED_LESS_OR_EQUAL(L01, TO_SIGNED(R, L01'LENGTH));
  2102. end ">";
  2103.  
  2104. --============================================================================
  2105.  
  2106. -- Id: C.7
  2107. function "<" (L, R: UNSIGNED) return BOOLEAN is
  2108. constant L_LEFT: INTEGER := L'LENGTH-1;
  2109. constant R_LEFT: INTEGER := R'LENGTH-1;
  2110. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2111. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2112. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2113. variable L01 : UNSIGNED(L_LEFT downto 0);
  2114. variable R01 : UNSIGNED(R_LEFT downto 0);
  2115. -- Synthesis directives :
  2116. variable RESULT : BOOLEAN ;
  2117. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2118. begin
  2119. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2120. assert NO_WARNING
  2121. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2122. severity WARNING;
  2123. return FALSE;
  2124. end if;
  2125. L01 := TO_01(XL, 'X');
  2126. R01 := TO_01(XR, 'X');
  2127. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2128. assert NO_WARNING
  2129. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2130. severity WARNING;
  2131. return FALSE;
  2132. end if;
  2133. return UNSIGNED_LESS(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2134. end "<";
  2135.  
  2136. -- Id: C.8
  2137. function "<" (L, R: SIGNED) return BOOLEAN is
  2138. constant L_LEFT: INTEGER := L'LENGTH-1;
  2139. constant R_LEFT: INTEGER := R'LENGTH-1;
  2140. alias XL: SIGNED(L_LEFT downto 0) is L;
  2141. alias XR: SIGNED(R_LEFT downto 0) is R;
  2142. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2143. variable L01 : SIGNED(L_LEFT downto 0);
  2144. variable R01 : SIGNED(R_LEFT downto 0);
  2145. -- Synthesis directives :
  2146. variable RESULT : BOOLEAN ;
  2147. attribute IS_SIGNED of L:constant is TRUE ;
  2148. attribute IS_SIGNED of R:constant is TRUE ;
  2149. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2150. begin
  2151. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2152. assert NO_WARNING
  2153. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2154. severity WARNING;
  2155. return FALSE;
  2156. end if;
  2157. L01 := TO_01(XL, 'X');
  2158. R01 := TO_01(XR, 'X');
  2159. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2160. assert NO_WARNING
  2161. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2162. severity WARNING;
  2163. return FALSE;
  2164. end if;
  2165. return SIGNED_LESS(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2166. end "<";
  2167.  
  2168. -- Id: C.9
  2169. function "<" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  2170. constant R_LEFT: INTEGER := R'LENGTH-1;
  2171. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2172. variable R01 : UNSIGNED(R_LEFT downto 0);
  2173. -- Synthesis directives :
  2174. variable RESULT : BOOLEAN ;
  2175. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2176. begin
  2177. if (R'LENGTH < 1) then
  2178. assert NO_WARNING
  2179. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2180. severity WARNING;
  2181. return FALSE;
  2182. end if;
  2183. R01 := TO_01(XR, 'X');
  2184. if (R01(R01'LEFT)='X') then
  2185. assert NO_WARNING
  2186. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2187. severity WARNING;
  2188. return FALSE;
  2189. end if;
  2190. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L < 0;
  2191. end if;
  2192. return UNSIGNED_LESS(TO_UNSIGNED(L, R01'LENGTH), R01);
  2193. end "<";
  2194.  
  2195. -- Id: C.10
  2196. function "<" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2197. constant R_LEFT: INTEGER := R'LENGTH-1;
  2198. alias XR: SIGNED(R_LEFT downto 0) is R;
  2199. variable R01 : SIGNED(R_LEFT downto 0);
  2200. -- Synthesis directives :
  2201. variable RESULT : BOOLEAN ;
  2202. attribute IS_SIGNED of R:constant is TRUE ;
  2203. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2204. begin
  2205. if (R'LENGTH < 1) then
  2206. assert NO_WARNING
  2207. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2208. severity WARNING;
  2209. return FALSE;
  2210. end if;
  2211. R01 := TO_01(XR, 'X');
  2212. if (R01(R01'LEFT)='X') then
  2213. assert NO_WARNING
  2214. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2215. severity WARNING;
  2216. return FALSE;
  2217. end if;
  2218. if SIGNED_NUM_BITS(L) > R'LENGTH then return L < 0;
  2219. end if;
  2220. return SIGNED_LESS(TO_SIGNED(L, R01'LENGTH), R01);
  2221. end "<";
  2222.  
  2223. -- Id: C.11
  2224. function "<" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2225. constant L_LEFT: INTEGER := L'LENGTH-1;
  2226. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2227. variable L01 : UNSIGNED(L_LEFT downto 0);
  2228. -- Synthesis directives :
  2229. variable RESULT : BOOLEAN ;
  2230. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2231. begin
  2232. if (L'LENGTH < 1) then
  2233. assert NO_WARNING
  2234. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2235. severity WARNING;
  2236. return FALSE;
  2237. end if;
  2238. L01 := TO_01(XL, 'X');
  2239. if (L01(L01'LEFT)='X') then
  2240. assert NO_WARNING
  2241. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2242. severity WARNING;
  2243. return FALSE;
  2244. end if;
  2245. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R;
  2246. end if;
  2247. return UNSIGNED_LESS(L01, TO_UNSIGNED(R, L01'LENGTH));
  2248. end "<";
  2249.  
  2250. -- Id: C.12
  2251. function "<" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2252. constant L_LEFT: INTEGER := L'LENGTH-1;
  2253. alias XL: SIGNED(L_LEFT downto 0) is L;
  2254. variable L01 : SIGNED(L_LEFT downto 0);
  2255. -- Synthesis directives :
  2256. variable RESULT : BOOLEAN ;
  2257. attribute IS_SIGNED of L:constant is TRUE ;
  2258. attribute SYNTHESIS_RETURN of RESULT:variable is "LT" ;
  2259. begin
  2260. if (L'LENGTH < 1) then
  2261. assert NO_WARNING
  2262. report "NUMERIC_STD.""<"": null argument detected, returning FALSE"
  2263. severity WARNING;
  2264. return FALSE;
  2265. end if;
  2266. L01 := TO_01(XL, 'X');
  2267. if (L01(L01'LEFT)='X') then
  2268. assert NO_WARNING
  2269. report "NUMERIC_STD.""<"": metavalue detected, returning FALSE"
  2270. severity WARNING;
  2271. return FALSE;
  2272. end if;
  2273. if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R;
  2274. end if;
  2275. return SIGNED_LESS(L01, TO_SIGNED(R, L01'LENGTH));
  2276. end "<";
  2277.  
  2278. --============================================================================
  2279.  
  2280. -- Id: C.13
  2281. function "<=" (L, R: UNSIGNED) return BOOLEAN is
  2282. constant L_LEFT: INTEGER := L'LENGTH-1;
  2283. constant R_LEFT: INTEGER := R'LENGTH-1;
  2284. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2285. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2286. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2287. variable L01 : UNSIGNED(L_LEFT downto 0);
  2288. variable R01 : UNSIGNED(R_LEFT downto 0);
  2289. -- Synthesis directives :
  2290. variable RESULT : BOOLEAN ;
  2291. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2292. begin
  2293. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2294. assert NO_WARNING
  2295. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2296. severity WARNING;
  2297. return FALSE;
  2298. end if;
  2299. L01 := TO_01(XL, 'X');
  2300. R01 := TO_01(XR, 'X');
  2301. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2302. assert NO_WARNING
  2303. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2304. severity WARNING;
  2305. return FALSE;
  2306. end if;
  2307. return UNSIGNED_LESS_OR_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2308. end "<=";
  2309.  
  2310. -- Id: C.14
  2311. function "<=" (L, R: SIGNED) return BOOLEAN is
  2312. constant L_LEFT: INTEGER := L'LENGTH-1;
  2313. constant R_LEFT: INTEGER := R'LENGTH-1;
  2314. alias XL: SIGNED(L_LEFT downto 0) is L;
  2315. alias XR: SIGNED(R_LEFT downto 0) is R;
  2316. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2317. variable L01 : SIGNED(L_LEFT downto 0);
  2318. variable R01 : SIGNED(R_LEFT downto 0);
  2319. -- Synthesis directives :
  2320. variable RESULT : BOOLEAN ;
  2321. attribute IS_SIGNED of L:constant is TRUE ;
  2322. attribute IS_SIGNED of R:constant is TRUE ;
  2323. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2324. begin
  2325. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2326. assert NO_WARNING
  2327. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2328. severity WARNING;
  2329. return FALSE;
  2330. end if;
  2331. L01 := TO_01(XL, 'X');
  2332. R01 := TO_01(XR, 'X');
  2333. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2334. assert NO_WARNING
  2335. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2336. severity WARNING;
  2337. return FALSE;
  2338. end if;
  2339. return SIGNED_LESS_OR_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2340. end "<=";
  2341.  
  2342. -- Id: C.15
  2343. function "<=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  2344. constant R_LEFT: INTEGER := R'LENGTH-1;
  2345. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2346. variable R01 : UNSIGNED(R_LEFT downto 0);
  2347. -- Synthesis directives :
  2348. variable RESULT : BOOLEAN ;
  2349. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2350. begin
  2351. if (R'LENGTH < 1) then
  2352. assert NO_WARNING
  2353. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2354. severity WARNING;
  2355. return FALSE;
  2356. end if;
  2357. R01 := TO_01(XR, 'X');
  2358. if (R01(R01'LEFT)='X') then
  2359. assert NO_WARNING
  2360. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2361. severity WARNING;
  2362. return FALSE;
  2363. end if;
  2364. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L < 0;
  2365. end if;
  2366. return UNSIGNED_LESS_OR_EQUAL(TO_UNSIGNED(L, R01'LENGTH), R01);
  2367. end "<=";
  2368.  
  2369. -- Id: C.16
  2370. function "<=" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2371. constant R_LEFT: INTEGER := R'LENGTH-1;
  2372. alias XR: SIGNED(R_LEFT downto 0) is R;
  2373. variable R01 : SIGNED(R_LEFT downto 0);
  2374. -- Synthesis directives :
  2375. variable RESULT : BOOLEAN ;
  2376. attribute IS_SIGNED of R:constant is TRUE ;
  2377. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2378. begin
  2379. if (R'LENGTH < 1) then
  2380. assert NO_WARNING
  2381. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2382. severity WARNING;
  2383. return FALSE;
  2384. end if;
  2385. R01 := TO_01(XR, 'X');
  2386. if (R01(R01'LEFT)='X') then
  2387. assert NO_WARNING
  2388. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2389. severity WARNING;
  2390. return FALSE;
  2391. end if;
  2392. if SIGNED_NUM_BITS(L) > R'LENGTH then return L < 0;
  2393. end if;
  2394. return SIGNED_LESS_OR_EQUAL(TO_SIGNED(L, R01'LENGTH), R01);
  2395. end "<=";
  2396.  
  2397. -- Id: C.17
  2398. function "<=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2399. constant L_LEFT: INTEGER := L'LENGTH-1;
  2400. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2401. variable L01 : UNSIGNED(L_LEFT downto 0);
  2402. -- Synthesis directives :
  2403. variable RESULT : BOOLEAN ;
  2404. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2405. begin
  2406. if (L_LEFT < 0) then
  2407. assert NO_WARNING
  2408. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2409. severity WARNING;
  2410. return FALSE;
  2411. end if;
  2412. L01 := TO_01(XL, 'X');
  2413. if (L01(L01'LEFT)='X') then
  2414. assert NO_WARNING
  2415. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2416. severity WARNING;
  2417. return FALSE;
  2418. end if;
  2419. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R;
  2420. end if;
  2421. return UNSIGNED_LESS_OR_EQUAL(L01, TO_UNSIGNED(R, L01'LENGTH));
  2422. end "<=";
  2423.  
  2424. -- Id: C.18
  2425. function "<=" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2426. constant L_LEFT: INTEGER := L'LENGTH-1;
  2427. alias XL: SIGNED(L_LEFT downto 0) is L;
  2428. variable L01 : SIGNED(L_LEFT downto 0);
  2429. -- Synthesis directives :
  2430. variable RESULT : BOOLEAN ;
  2431. attribute IS_SIGNED of L:constant is TRUE ;
  2432. attribute SYNTHESIS_RETURN of RESULT:variable is "LTE" ;
  2433. begin
  2434. if (L_LEFT < 0) then
  2435. assert NO_WARNING
  2436. report "NUMERIC_STD.""<="": null argument detected, returning FALSE"
  2437. severity WARNING;
  2438. return FALSE;
  2439. end if;
  2440. L01 := TO_01(XL, 'X');
  2441. if (L01(L01'LEFT)='X') then
  2442. assert NO_WARNING
  2443. report "NUMERIC_STD.""<="": metavalue detected, returning FALSE"
  2444. severity WARNING;
  2445. return FALSE;
  2446. end if;
  2447. if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 < R;
  2448. end if;
  2449. return SIGNED_LESS_OR_EQUAL(L01, TO_SIGNED(R, L01'LENGTH));
  2450. end "<=";
  2451.  
  2452. --============================================================================
  2453.  
  2454. -- Id: C.19
  2455. function ">=" (L, R: UNSIGNED) return BOOLEAN is
  2456. constant L_LEFT: INTEGER := L'LENGTH-1;
  2457. constant R_LEFT: INTEGER := R'LENGTH-1;
  2458. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2459. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2460. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2461. variable L01 : UNSIGNED(L_LEFT downto 0);
  2462. variable R01 : UNSIGNED(R_LEFT downto 0);
  2463. -- Synthesis directives :
  2464. variable RESULT : BOOLEAN ;
  2465. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2466. begin
  2467. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2468. assert NO_WARNING
  2469. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2470. severity WARNING;
  2471. return FALSE;
  2472. end if;
  2473. L01 := TO_01(XL, 'X');
  2474. R01 := TO_01(XR, 'X');
  2475. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2476. assert NO_WARNING
  2477. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2478. severity WARNING;
  2479. return FALSE;
  2480. end if;
  2481. return not UNSIGNED_LESS(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2482. end ">=";
  2483.  
  2484. -- Id: C.20
  2485. function ">=" (L, R: SIGNED) return BOOLEAN is
  2486. constant L_LEFT: INTEGER := L'LENGTH-1;
  2487. constant R_LEFT: INTEGER := R'LENGTH-1;
  2488. alias XL: SIGNED(L_LEFT downto 0) is L;
  2489. alias XR: SIGNED(R_LEFT downto 0) is R;
  2490. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2491. variable L01 : SIGNED(L_LEFT downto 0);
  2492. variable R01 : SIGNED(R_LEFT downto 0);
  2493. -- Synthesis directives :
  2494. variable RESULT : BOOLEAN ;
  2495. attribute IS_SIGNED of L:constant is TRUE ;
  2496. attribute IS_SIGNED of R:constant is TRUE ;
  2497. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2498. begin
  2499. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2500. assert NO_WARNING
  2501. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2502. severity WARNING;
  2503. return FALSE;
  2504. end if;
  2505. L01 := TO_01(XL, 'X');
  2506. R01 := TO_01(XR, 'X');
  2507. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2508. assert NO_WARNING
  2509. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2510. severity WARNING;
  2511. return FALSE;
  2512. end if;
  2513. return not SIGNED_LESS(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2514. end ">=";
  2515.  
  2516. -- Id: C.21
  2517. function ">=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  2518. constant R_LEFT: INTEGER := R'LENGTH-1;
  2519. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2520. variable R01 : UNSIGNED(R_LEFT downto 0);
  2521. -- Synthesis directives :
  2522. variable RESULT : BOOLEAN ;
  2523. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2524. begin
  2525. if (R'LENGTH < 1) then
  2526. assert NO_WARNING
  2527. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2528. severity WARNING;
  2529. return FALSE;
  2530. end if;
  2531. R01 := TO_01(XR, 'X');
  2532. if (R01(R01'LEFT)='X') then
  2533. assert NO_WARNING
  2534. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2535. severity WARNING;
  2536. return FALSE;
  2537. end if;
  2538. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return L > 0;
  2539. end if;
  2540. return not UNSIGNED_LESS(TO_UNSIGNED(L, R01'LENGTH), R01);
  2541. end ">=";
  2542.  
  2543. -- Id: C.22
  2544. function ">=" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2545. constant R_LEFT: INTEGER := R'LENGTH-1;
  2546. alias XR: SIGNED(R_LEFT downto 0) is R;
  2547. variable R01 : SIGNED(R_LEFT downto 0);
  2548. -- Synthesis directives :
  2549. variable RESULT : BOOLEAN ;
  2550. attribute IS_SIGNED of R:constant is TRUE ;
  2551. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2552. begin
  2553. if (R'LENGTH < 1) then
  2554. assert NO_WARNING
  2555. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2556. severity WARNING;
  2557. return FALSE;
  2558. end if;
  2559. R01 := TO_01(XR, 'X');
  2560. if (R01(R01'LEFT)='X') then
  2561. assert NO_WARNING
  2562. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2563. severity WARNING;
  2564. return FALSE;
  2565. end if;
  2566. if SIGNED_NUM_BITS(L) > R'LENGTH then return L > 0;
  2567. end if;
  2568. return not SIGNED_LESS(TO_SIGNED(L, R01'LENGTH), R01);
  2569. end ">=";
  2570.  
  2571. -- Id: C.23
  2572. function ">=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2573. constant L_LEFT: INTEGER := L'LENGTH-1;
  2574. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2575. variable L01 : UNSIGNED(L_LEFT downto 0);
  2576. -- Synthesis directives :
  2577. variable RESULT : BOOLEAN ;
  2578. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2579. begin
  2580. if (L'LENGTH < 1) then
  2581. assert NO_WARNING
  2582. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2583. severity WARNING;
  2584. return FALSE;
  2585. end if;
  2586. L01 := TO_01(XL, 'X');
  2587. if (L01(L01'LEFT)='X') then
  2588. assert NO_WARNING
  2589. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2590. severity WARNING;
  2591. return FALSE;
  2592. end if;
  2593. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R;
  2594. end if;
  2595. return not UNSIGNED_LESS(L01, TO_UNSIGNED(R, L01'LENGTH));
  2596. end ">=";
  2597.  
  2598. -- Id: C.24
  2599. function ">=" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2600. constant L_LEFT: INTEGER := L'LENGTH-1;
  2601. alias XL: SIGNED(L_LEFT downto 0) is L;
  2602. variable L01 : SIGNED(L_LEFT downto 0);
  2603. -- Synthesis directives :
  2604. variable RESULT : BOOLEAN ;
  2605. attribute IS_SIGNED of L:constant is TRUE ;
  2606. attribute SYNTHESIS_RETURN of RESULT:variable is "GTE" ;
  2607. begin
  2608. if (L'LENGTH < 1) then
  2609. assert NO_WARNING
  2610. report "NUMERIC_STD."">="": null argument detected, returning FALSE"
  2611. severity WARNING;
  2612. return FALSE;
  2613. end if;
  2614. L01 := TO_01(XL, 'X');
  2615. if (L01(L01'LEFT)='X') then
  2616. assert NO_WARNING
  2617. report "NUMERIC_STD."">="": metavalue detected, returning FALSE"
  2618. severity WARNING;
  2619. return FALSE;
  2620. end if;
  2621. if SIGNED_NUM_BITS(R) > L'LENGTH then return 0 > R;
  2622. end if;
  2623. return not SIGNED_LESS(L01, TO_SIGNED(R, L01'LENGTH));
  2624. end ">=";
  2625.  
  2626. --============================================================================
  2627.  
  2628. -- Id: C.25
  2629. function "=" (L, R: UNSIGNED) return BOOLEAN is
  2630. constant L_LEFT: INTEGER := L'LENGTH-1;
  2631. constant R_LEFT: INTEGER := R'LENGTH-1;
  2632. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2633. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2634. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2635. variable L01 : UNSIGNED(L_LEFT downto 0);
  2636. variable R01 : UNSIGNED(R_LEFT downto 0);
  2637. -- Synthesis directives :
  2638. variable RESULT : BOOLEAN ;
  2639. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2640. begin
  2641. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2642. assert NO_WARNING
  2643. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2644. severity WARNING;
  2645. return FALSE;
  2646. end if;
  2647. L01 := TO_01(XL, 'X');
  2648. R01 := TO_01(XR, 'X');
  2649. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2650. assert NO_WARNING
  2651. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2652. severity WARNING;
  2653. return FALSE;
  2654. end if;
  2655. return UNSIGNED_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2656. end "=";
  2657.  
  2658. -- Id: C.26
  2659. function "=" (L, R: SIGNED) return BOOLEAN is
  2660. constant L_LEFT: INTEGER := L'LENGTH-1;
  2661. constant R_LEFT: INTEGER := R'LENGTH-1;
  2662. alias XL: SIGNED(L_LEFT downto 0) is L;
  2663. alias XR: SIGNED(R_LEFT downto 0) is R;
  2664. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2665. variable L01 : SIGNED(L_LEFT downto 0);
  2666. variable R01 : SIGNED(R_LEFT downto 0);
  2667. -- Synthesis directives :
  2668. variable RESULT : BOOLEAN ;
  2669. attribute IS_SIGNED of L:constant is TRUE ;
  2670. attribute IS_SIGNED of R:constant is TRUE ;
  2671. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2672. begin
  2673. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2674. assert NO_WARNING
  2675. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2676. severity WARNING;
  2677. return FALSE;
  2678. end if;
  2679. L01 := TO_01(XL, 'X');
  2680. R01 := TO_01(XR, 'X');
  2681. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2682. assert NO_WARNING
  2683. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2684. severity WARNING;
  2685. return FALSE;
  2686. end if;
  2687. return SIGNED_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE));
  2688. end "=";
  2689.  
  2690. -- Id: C.27
  2691. function "=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  2692. constant R_LEFT: INTEGER := R'LENGTH-1;
  2693. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2694. variable R01 : UNSIGNED(R_LEFT downto 0);
  2695. -- Synthesis directives :
  2696. variable RESULT : BOOLEAN ;
  2697. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2698. begin
  2699. if (R'LENGTH < 1) then
  2700. assert NO_WARNING
  2701. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2702. severity WARNING;
  2703. return FALSE;
  2704. end if;
  2705. R01 := TO_01(XR, 'X');
  2706. if (R01(R01'LEFT)='X') then
  2707. assert NO_WARNING
  2708. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2709. severity WARNING;
  2710. return FALSE;
  2711. end if;
  2712. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return FALSE;
  2713. end if;
  2714. return UNSIGNED_EQUAL(TO_UNSIGNED(L, R01'LENGTH), R01);
  2715. end "=";
  2716.  
  2717. -- Id: C.28
  2718. function "=" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2719. constant R_LEFT: INTEGER := R'LENGTH-1;
  2720. alias XR: SIGNED(R_LEFT downto 0) is R;
  2721. variable R01 : SIGNED(R_LEFT downto 0);
  2722. -- Synthesis directives :
  2723. variable RESULT : BOOLEAN ;
  2724. attribute IS_SIGNED of R:constant is TRUE ;
  2725. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2726. begin
  2727. if (R'LENGTH < 1) then
  2728. assert NO_WARNING
  2729. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2730. severity WARNING;
  2731. return FALSE;
  2732. end if;
  2733. R01 := TO_01(XR, 'X');
  2734. if (R01(R01'LEFT)='X') then
  2735. assert NO_WARNING
  2736. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2737. severity WARNING;
  2738. return FALSE;
  2739. end if;
  2740. if SIGNED_NUM_BITS(L) > R'LENGTH then return FALSE;
  2741. end if;
  2742. return SIGNED_EQUAL(TO_SIGNED(L, R01'LENGTH), R01);
  2743. end "=";
  2744.  
  2745. -- Id: C.29
  2746. function "=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2747. constant L_LEFT: INTEGER := L'LENGTH-1;
  2748. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2749. variable L01 : UNSIGNED(L_LEFT downto 0);
  2750. -- Synthesis directives :
  2751. variable RESULT : BOOLEAN ;
  2752. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2753. begin
  2754. if (L'LENGTH < 1) then
  2755. assert NO_WARNING
  2756. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2757. severity WARNING;
  2758. return FALSE;
  2759. end if;
  2760. L01 := TO_01(XL, 'X');
  2761. if (L01(L01'LEFT)='X') then
  2762. assert NO_WARNING
  2763. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2764. severity WARNING;
  2765. return FALSE;
  2766. end if;
  2767. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return FALSE;
  2768. end if;
  2769. return UNSIGNED_EQUAL(L01, TO_UNSIGNED(R, L01'LENGTH));
  2770. end "=";
  2771.  
  2772. -- Id: C.30
  2773. function "=" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2774. constant L_LEFT: INTEGER := L'LENGTH-1;
  2775. alias XL: SIGNED(L_LEFT downto 0) is L;
  2776. variable L01 : SIGNED(L_LEFT downto 0);
  2777. -- Synthesis directives :
  2778. variable RESULT : BOOLEAN ;
  2779. attribute IS_SIGNED of L:constant is TRUE ;
  2780. attribute SYNTHESIS_RETURN of RESULT:variable is "EQ" ;
  2781. begin
  2782. if (L'LENGTH < 1) then
  2783. assert NO_WARNING
  2784. report "NUMERIC_STD.""="": null argument detected, returning FALSE"
  2785. severity WARNING;
  2786. return FALSE;
  2787. end if;
  2788. L01 := TO_01(XL, 'X');
  2789. if (L01(L01'LEFT)='X') then
  2790. assert NO_WARNING
  2791. report "NUMERIC_STD.""="": metavalue detected, returning FALSE"
  2792. severity WARNING;
  2793. return FALSE;
  2794. end if;
  2795. if SIGNED_NUM_BITS(R) > L'LENGTH then return FALSE;
  2796. end if;
  2797. return SIGNED_EQUAL(L01, TO_SIGNED(R, L01'LENGTH));
  2798. end "=";
  2799.  
  2800. --============================================================================
  2801.  
  2802. -- Id: C.31
  2803. function "/=" (L, R: UNSIGNED) return BOOLEAN is
  2804. constant L_LEFT: INTEGER := L'LENGTH-1;
  2805. constant R_LEFT: INTEGER := R'LENGTH-1;
  2806. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2807. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2808. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2809. variable L01 : UNSIGNED(L_LEFT downto 0);
  2810. variable R01 : UNSIGNED(R_LEFT downto 0);
  2811. -- Synthesis directives :
  2812. variable RESULT : BOOLEAN ;
  2813. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2814. begin
  2815. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2816. assert NO_WARNING
  2817. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2818. severity WARNING;
  2819. return TRUE;
  2820. end if;
  2821. L01 := TO_01(XL, 'X');
  2822. R01 := TO_01(XR, 'X');
  2823. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2824. assert NO_WARNING
  2825. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2826. severity WARNING;
  2827. return TRUE;
  2828. end if;
  2829. return not(UNSIGNED_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE)));
  2830. end "/=";
  2831.  
  2832. -- Id: C.32
  2833. function "/=" (L, R: SIGNED) return BOOLEAN is
  2834. constant L_LEFT: INTEGER := L'LENGTH-1;
  2835. constant R_LEFT: INTEGER := R'LENGTH-1;
  2836. alias XL: SIGNED(L_LEFT downto 0) is L;
  2837. alias XR: SIGNED(R_LEFT downto 0) is R;
  2838. constant SIZE: NATURAL := MAX(L'LENGTH, R'LENGTH);
  2839. variable L01 : SIGNED(L_LEFT downto 0);
  2840. variable R01 : SIGNED(R_LEFT downto 0);
  2841. -- Synthesis directives :
  2842. variable RESULT : BOOLEAN ;
  2843. attribute IS_SIGNED of L:constant is TRUE ;
  2844. attribute IS_SIGNED of R:constant is TRUE ;
  2845. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2846. begin
  2847. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  2848. assert NO_WARNING
  2849. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2850. severity WARNING;
  2851. return TRUE;
  2852. end if;
  2853. L01 := TO_01(XL, 'X');
  2854. R01 := TO_01(XR, 'X');
  2855. if ((L01(L01'LEFT)='X') or (R01(R01'LEFT)='X')) then
  2856. assert NO_WARNING
  2857. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2858. severity WARNING;
  2859. return TRUE;
  2860. end if;
  2861. return not(SIGNED_EQUAL(RESIZE(L01, SIZE), RESIZE(R01, SIZE)));
  2862. end "/=";
  2863.  
  2864. -- Id: C.33
  2865. function "/=" (L: NATURAL; R: UNSIGNED) return BOOLEAN is
  2866. constant R_LEFT: INTEGER := R'LENGTH-1;
  2867. alias XR: UNSIGNED(R_LEFT downto 0) is R;
  2868. variable R01 : UNSIGNED(R_LEFT downto 0);
  2869. -- Synthesis directives :
  2870. variable RESULT : BOOLEAN ;
  2871. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2872. begin
  2873. if (R'LENGTH < 1) then
  2874. assert NO_WARNING
  2875. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2876. severity WARNING;
  2877. return TRUE;
  2878. end if;
  2879. R01 := TO_01(XR, 'X');
  2880. if (R01(R01'LEFT)='X') then
  2881. assert NO_WARNING
  2882. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2883. severity WARNING;
  2884. return TRUE;
  2885. end if;
  2886. if UNSIGNED_NUM_BITS(L) > R'LENGTH then return TRUE;
  2887. end if;
  2888. return not(UNSIGNED_EQUAL(TO_UNSIGNED(L, R01'LENGTH), R01));
  2889. end "/=";
  2890.  
  2891. -- Id: C.34
  2892. function "/=" (L: INTEGER; R: SIGNED) return BOOLEAN is
  2893. constant R_LEFT: INTEGER := R'LENGTH-1;
  2894. alias XR: SIGNED(R_LEFT downto 0) is R;
  2895. variable R01 : SIGNED(R_LEFT downto 0);
  2896. -- Synthesis directives :
  2897. variable RESULT : BOOLEAN ;
  2898. attribute IS_SIGNED of R:constant is TRUE ;
  2899. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2900. begin
  2901. if (R'LENGTH < 1) then
  2902. assert NO_WARNING
  2903. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2904. severity WARNING;
  2905. return TRUE;
  2906. end if;
  2907. R01 := TO_01(XR, 'X');
  2908. if (R01(R01'LEFT)='X') then
  2909. assert NO_WARNING
  2910. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2911. severity WARNING;
  2912. return TRUE;
  2913. end if;
  2914. if SIGNED_NUM_BITS(L) > R'LENGTH then return TRUE;
  2915. end if;
  2916. return not(SIGNED_EQUAL(TO_SIGNED(L, R01'LENGTH), R01));
  2917. end "/=";
  2918.  
  2919. -- Id: C.35
  2920. function "/=" (L: UNSIGNED; R: NATURAL) return BOOLEAN is
  2921. constant L_LEFT: INTEGER := L'LENGTH-1;
  2922. alias XL: UNSIGNED(L_LEFT downto 0) is L;
  2923. variable L01 : UNSIGNED(L_LEFT downto 0);
  2924. -- Synthesis directives :
  2925. variable RESULT : BOOLEAN ;
  2926. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2927. begin
  2928. if (L'LENGTH < 1) then
  2929. assert NO_WARNING
  2930. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2931. severity WARNING;
  2932. return TRUE;
  2933. end if;
  2934. L01 := TO_01(XL, 'X');
  2935. if (L01(L01'LEFT)='X') then
  2936. assert NO_WARNING
  2937. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2938. severity WARNING;
  2939. return TRUE;
  2940. end if;
  2941. if UNSIGNED_NUM_BITS(R) > L'LENGTH then return TRUE;
  2942. end if;
  2943. return not(UNSIGNED_EQUAL(L01, TO_UNSIGNED(R, L01'LENGTH)));
  2944. end "/=";
  2945.  
  2946. -- Id: C.36
  2947. function "/=" (L: SIGNED; R: INTEGER) return BOOLEAN is
  2948. constant L_LEFT: INTEGER := L'LENGTH-1;
  2949. alias XL: SIGNED(L_LEFT downto 0) is L;
  2950. variable L01 : SIGNED(L_LEFT downto 0);
  2951. -- Synthesis directives :
  2952. variable RESULT : BOOLEAN ;
  2953. attribute IS_SIGNED of L:constant is TRUE ;
  2954. attribute SYNTHESIS_RETURN of RESULT:variable is "NEQ" ;
  2955. begin
  2956. if (L'LENGTH < 1) then
  2957. assert NO_WARNING
  2958. report "NUMERIC_STD.""/="": null argument detected, returning TRUE"
  2959. severity WARNING;
  2960. return TRUE;
  2961. end if;
  2962. L01 := TO_01(XL, 'X');
  2963. if (L01(L01'LEFT)='X') then
  2964. assert NO_WARNING
  2965. report "NUMERIC_STD.""/="": metavalue detected, returning TRUE"
  2966. severity WARNING;
  2967. return TRUE;
  2968. end if;
  2969. if SIGNED_NUM_BITS(R) > L'LENGTH then return TRUE;
  2970. end if;
  2971. return not(SIGNED_EQUAL(L01, TO_SIGNED(R, L01'LENGTH)));
  2972. end "/=";
  2973.  
  2974. --============================================================================
  2975.  
  2976. -- Id: S.1
  2977. function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is
  2978. -- Synthesis directives are in XSLL
  2979. begin
  2980. if (ARG'LENGTH < 1) then return NAU;
  2981. end if;
  2982. return UNSIGNED(XSLL(STD_LOGIC_VECTOR(ARG), COUNT));
  2983. end SHIFT_LEFT;
  2984.  
  2985. -- Id: S.2
  2986. function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is
  2987. -- Synthesis directives are in XSRL
  2988. begin
  2989. if (ARG'LENGTH < 1) then return NAU;
  2990. end if;
  2991. return UNSIGNED(XSRL(STD_LOGIC_VECTOR(ARG), COUNT));
  2992. end SHIFT_RIGHT;
  2993.  
  2994. -- Id: S.3
  2995. function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is
  2996. -- Synthesis directives are in XSLL
  2997. begin
  2998. if (ARG'LENGTH < 1) then return NAS;
  2999. end if;
  3000. return SIGNED(XSLL(STD_LOGIC_VECTOR(ARG), COUNT));
  3001. end SHIFT_LEFT;
  3002.  
  3003. -- Id: S.4
  3004. function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is
  3005. -- Synthesis directives are in XSRA
  3006. begin
  3007. if (ARG'LENGTH < 1) then return NAS;
  3008. end if;
  3009. return SIGNED(XSRA(STD_LOGIC_VECTOR(ARG), COUNT));
  3010. end SHIFT_RIGHT;
  3011.  
  3012. --============================================================================
  3013.  
  3014. -- Id: S.5
  3015. function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is
  3016. -- Synthesis directives are in XROL
  3017. begin
  3018. if (ARG'LENGTH < 1) then return NAU;
  3019. end if;
  3020. return UNSIGNED(XROL(STD_LOGIC_VECTOR(ARG), COUNT));
  3021. end ROTATE_LEFT;
  3022.  
  3023. -- Id: S.6
  3024. function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is
  3025. -- Synthesis directives are in XROR
  3026. begin
  3027. if (ARG'LENGTH < 1) then return NAU;
  3028. end if;
  3029. return UNSIGNED(XROR(STD_LOGIC_VECTOR(ARG), COUNT));
  3030. end ROTATE_RIGHT;
  3031.  
  3032.  
  3033. -- Id: S.7
  3034. function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is
  3035. -- Synthesis directives are in XROL
  3036. begin
  3037. if (ARG'LENGTH < 1) then return NAS;
  3038. end if;
  3039. return SIGNED(XROL(STD_LOGIC_VECTOR(ARG), COUNT));
  3040. end ROTATE_LEFT;
  3041.  
  3042. -- Id: S.8
  3043. function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is
  3044. -- Synthesis directives are in XROR
  3045. begin
  3046. if (ARG'LENGTH < 1) then return NAS;
  3047. end if;
  3048. return SIGNED(XROR(STD_LOGIC_VECTOR(ARG), COUNT));
  3049. end ROTATE_RIGHT;
  3050.  
  3051. --============================================================================
  3052.  
  3053. ------------------------------------------------------------------------------
  3054. -- Note : Function S.9 is not compatible with VHDL 1076-1987. Comment
  3055. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3056. ------------------------------------------------------------------------------
  3057. -- Id: S.9
  3058. function "sll" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is
  3059. -- Synthesis directives :
  3060. variable RESULT : UNSIGNED (ARG'LENGTH-1 downto 0) ;
  3061. attribute SYNTHESIS_RETURN of RESULT:variable is "SLL" ;
  3062. begin
  3063. if (COUNT >= 0) then
  3064. return SHIFT_LEFT(ARG, COUNT);
  3065. else
  3066. return SHIFT_RIGHT(ARG, -COUNT);
  3067. end if;
  3068. end "sll";
  3069.  
  3070. ------------------------------------------------------------------------------
  3071. -- Note : Function S.10 is not compatible with VHDL 1076-1987. Comment
  3072. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3073. ------------------------------------------------------------------------------
  3074. -- Id: S.10
  3075. function "sll" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is
  3076. -- Synthesis directives :
  3077. variable RESULT : SIGNED (ARG'LENGTH-1 downto 0) ;
  3078. attribute SYNTHESIS_RETURN of RESULT:variable is "SLL" ;
  3079. begin
  3080. if (COUNT >= 0) then
  3081. return SHIFT_LEFT(ARG, COUNT);
  3082. else
  3083. return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), -COUNT));
  3084. end if;
  3085. end "sll";
  3086.  
  3087. ------------------------------------------------------------------------------
  3088. -- Note : Function S.11 is not compatible with VHDL 1076-1987. Comment
  3089. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3090. ------------------------------------------------------------------------------
  3091. -- Id: S.11
  3092. function "srl" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is
  3093. -- Synthesis directives :
  3094. variable RESULT : UNSIGNED (ARG'LENGTH-1 downto 0) ;
  3095. attribute SYNTHESIS_RETURN of RESULT:variable is "SRL" ;
  3096. begin
  3097. if (COUNT >= 0) then
  3098. return SHIFT_RIGHT(ARG, COUNT);
  3099. else
  3100. return SHIFT_LEFT(ARG, -COUNT);
  3101. end if;
  3102. end "srl";
  3103.  
  3104. ------------------------------------------------------------------------------
  3105. -- Note : Function S.12 is not compatible with VHDL 1076-1987. Comment
  3106. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3107. ------------------------------------------------------------------------------
  3108. -- Id: S.12
  3109. function "srl" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is
  3110. -- Synthesis directives :
  3111. variable RESULT : SIGNED (ARG'LENGTH-1 downto 0) ;
  3112. attribute SYNTHESIS_RETURN of RESULT:variable is "SRL" ;
  3113. begin
  3114. if (COUNT >= 0) then
  3115. return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), COUNT));
  3116. else
  3117. return SHIFT_LEFT(ARG, -COUNT);
  3118. end if;
  3119. end "srl";
  3120.  
  3121. ------------------------------------------------------------------------------
  3122. -- Note : Function S.13 is not compatible with VHDL 1076-1987. Comment
  3123. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3124. ------------------------------------------------------------------------------
  3125. -- Id: S.13
  3126. function "rol" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is
  3127. -- Synthesis directives :
  3128. variable RESULT : UNSIGNED (ARG'LENGTH-1 downto 0) ;
  3129. attribute SYNTHESIS_RETURN of RESULT:variable is "ROL" ;
  3130. begin
  3131. if (COUNT >= 0) then
  3132. return ROTATE_LEFT(ARG, COUNT);
  3133. else
  3134. return ROTATE_RIGHT(ARG, -COUNT);
  3135. end if;
  3136. end "rol";
  3137.  
  3138. ------------------------------------------------------------------------------
  3139. -- Note : Function S.14 is not compatible with VHDL 1076-1987. Comment
  3140. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3141. ------------------------------------------------------------------------------
  3142. -- Id: S.14
  3143. function "rol" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is
  3144. -- Synthesis directives :
  3145. variable RESULT : SIGNED (ARG'LENGTH-1 downto 0) ;
  3146. attribute SYNTHESIS_RETURN of RESULT:variable is "ROL" ;
  3147. begin
  3148. if (COUNT >= 0) then
  3149. return ROTATE_LEFT(ARG, COUNT);
  3150. else
  3151. return ROTATE_RIGHT(ARG, -COUNT);
  3152. end if;
  3153. end "rol";
  3154.  
  3155. ------------------------------------------------------------------------------
  3156. -- Note : Function S.15 is not compatible with VHDL 1076-1987. Comment
  3157. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3158. ------------------------------------------------------------------------------
  3159. -- Id: S.15
  3160. function "ror" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is
  3161. -- Synthesis directives :
  3162. variable RESULT : UNSIGNED (ARG'LENGTH-1 downto 0) ;
  3163. attribute SYNTHESIS_RETURN of RESULT:variable is "ROR" ;
  3164. begin
  3165. if (COUNT >= 0) then
  3166. return ROTATE_RIGHT(ARG, COUNT);
  3167. else
  3168. return ROTATE_LEFT(ARG, -COUNT);
  3169. end if;
  3170. end "ror";
  3171.  
  3172. ------------------------------------------------------------------------------
  3173. -- Note : Function S.16 is not compatible with VHDL 1076-1987. Comment
  3174. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3175. ------------------------------------------------------------------------------
  3176. -- Id: S.16
  3177. function "ror" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is
  3178. -- Synthesis directives :
  3179. variable RESULT : SIGNED (ARG'LENGTH-1 downto 0) ;
  3180. attribute SYNTHESIS_RETURN of RESULT:variable is "ROR" ;
  3181. begin
  3182. if (COUNT >= 0) then
  3183. return ROTATE_RIGHT(ARG, COUNT);
  3184. else
  3185. return ROTATE_LEFT(ARG, -COUNT);
  3186. end if;
  3187. end "ror";
  3188.  
  3189. --============================================================================
  3190.  
  3191. -- Id: D.1
  3192. function TO_INTEGER (ARG: UNSIGNED) return NATURAL is
  3193. constant ARG_LEFT: INTEGER := ARG'LENGTH-1;
  3194. alias XXARG: UNSIGNED(ARG_LEFT downto 0) is ARG;
  3195. variable XARG: UNSIGNED(ARG_LEFT downto 0);
  3196. variable RESULT: NATURAL := 0;
  3197. -- Synthesis directives :
  3198. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3199. begin
  3200. if (ARG'LENGTH < 1) then
  3201. assert NO_WARNING
  3202. report "NUMERIC_STD.TO_INTEGER: null detected, returning 0"
  3203. severity WARNING;
  3204. return 0;
  3205. end if;
  3206. XARG := TO_01(XXARG, 'X');
  3207. if (XARG(XARG'LEFT)='X') then
  3208. assert NO_WARNING
  3209. report "NUMERIC_STD.TO_INTEGER: metavalue detected, returning 0"
  3210. severity WARNING;
  3211. return 0;
  3212. end if;
  3213. for I in XARG'RANGE loop
  3214. RESULT := RESULT+RESULT;
  3215. if XARG(I) = '1' then
  3216. RESULT := RESULT + 1;
  3217. end if;
  3218. end loop;
  3219. return RESULT;
  3220. end TO_INTEGER;
  3221.  
  3222. -- Id: D.2
  3223. function TO_INTEGER (ARG: SIGNED) return INTEGER is
  3224. variable XARG: SIGNED(ARG'LENGTH-1 downto 0);
  3225. -- Synthesis directives :
  3226. variable RESULT : INTEGER ;
  3227. attribute IS_SIGNED of ARG:constant is TRUE ;
  3228. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3229. begin
  3230. if (ARG'LENGTH < 1) then
  3231. assert NO_WARNING
  3232. report "NUMERIC_STD.TO_INTEGER: null detected, returning 0"
  3233. severity WARNING;
  3234. return 0;
  3235. end if;
  3236. XARG := TO_01(ARG, 'X');
  3237. if (XARG(XARG'LEFT)='X') then
  3238. assert NO_WARNING
  3239. report "NUMERIC_STD.TO_INTEGER: metavalue detected, returning 0"
  3240. severity WARNING;
  3241. return 0;
  3242. end if;
  3243. if XARG(XARG'LEFT) = '0' then
  3244. return TO_INTEGER(UNSIGNED(XARG));
  3245. else
  3246. return (- (TO_INTEGER(UNSIGNED(- (XARG + 1)))) -1);
  3247. end if;
  3248. end TO_INTEGER;
  3249.  
  3250. -- Id: D.3
  3251. function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED is
  3252. variable RESULT: UNSIGNED(SIZE-1 downto 0);
  3253. variable I_VAL: NATURAL := ARG;
  3254. -- Synthesis directives :
  3255. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3256. begin
  3257. if (SIZE < 1) then return NAU;
  3258. end if;
  3259. for I in 0 to RESULT'LEFT loop
  3260. if (I_VAL mod 2) = 0 then
  3261. RESULT(I) := '0';
  3262. else RESULT(I) := '1';
  3263. end if;
  3264. I_VAL := I_VAL/2;
  3265. end loop;
  3266. if not(I_VAL =0) then
  3267. assert NO_WARNING
  3268. report "NUMERIC_STD.TO_UNSIGNED: vector truncated"
  3269. severity WARNING;
  3270. end if;
  3271. return RESULT;
  3272. end TO_UNSIGNED;
  3273.  
  3274. -- Id: D.4
  3275. function TO_SIGNED (ARG: INTEGER; SIZE: NATURAL) return SIGNED is
  3276. variable RESULT: SIGNED(SIZE-1 downto 0);
  3277. variable B_VAL: STD_LOGIC := '0';
  3278. variable I_VAL: INTEGER := ARG;
  3279. -- Synthesis directives :
  3280. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3281. begin
  3282. if (SIZE < 1) then return NAS;
  3283. end if;
  3284. if (ARG < 0) then
  3285. B_VAL := '1';
  3286. I_VAL := -(ARG+1);
  3287. end if;
  3288. for I in 0 to RESULT'LEFT loop
  3289. if (I_VAL mod 2) = 0 then
  3290. RESULT(I) := B_VAL;
  3291. else
  3292. RESULT(I) := not B_VAL;
  3293. end if;
  3294. I_VAL := I_VAL/2;
  3295. end loop;
  3296. if ((I_VAL/=0) or (B_VAL/=RESULT(RESULT'LEFT))) then
  3297. assert NO_WARNING
  3298. report "NUMERIC_STD.TO_SIGNED: vector truncated"
  3299. severity WARNING;
  3300. end if;
  3301. return RESULT;
  3302. end TO_SIGNED;
  3303.  
  3304. --============================================================================
  3305.  
  3306. -- Id: R.1
  3307. function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED is
  3308. alias INVEC: SIGNED(ARG'LENGTH-1 downto 0) is ARG;
  3309. variable RESULT: SIGNED(NEW_SIZE-1 downto 0) := (others => '0');
  3310. constant BOUND: INTEGER := MIN(ARG'LENGTH, RESULT'LENGTH)-2;
  3311. -- VERIFIC: The RESIZE() function for signed does NOT behave the same as the FEEDTHROUGH pragma does. It does truncation a bit different. Cannot use pragma. Issue 2044
  3312. -- attribute IS_SIGNED of ARG:constant is TRUE ;
  3313. ---attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3314. begin
  3315. if (NEW_SIZE < 1) then return NAS;
  3316. end if;
  3317. if (ARG'LENGTH = 0) then return RESULT;
  3318. end if;
  3319. RESULT := (others => ARG(ARG'LEFT));
  3320. if BOUND >= 0 then
  3321. RESULT(BOUND downto 0) := INVEC(BOUND downto 0);
  3322. end if;
  3323. return RESULT;
  3324. end RESIZE;
  3325.  
  3326. -- Id: R.2
  3327. function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED is
  3328. constant ARG_LEFT: INTEGER := ARG'LENGTH-1;
  3329. alias XARG: UNSIGNED(ARG_LEFT downto 0) is ARG;
  3330. variable RESULT: UNSIGNED(NEW_SIZE-1 downto 0) := (others => '0');
  3331. -- Synthesis directives :
  3332. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3333. begin
  3334. if (NEW_SIZE < 1) then return NAU;
  3335. end if;
  3336. if XARG'LENGTH =0 then return RESULT;
  3337. end if;
  3338. if (RESULT'LENGTH < ARG'LENGTH) then
  3339. RESULT(RESULT'LEFT downto 0) := XARG(RESULT'LEFT downto 0);
  3340. else
  3341. RESULT(RESULT'LEFT downto XARG'LEFT+1) := (others => '0');
  3342. RESULT(XARG'LEFT downto 0) := XARG;
  3343. end if;
  3344. return RESULT;
  3345. end RESIZE;
  3346.  
  3347. --============================================================================
  3348.  
  3349. -- Id: L.1
  3350. function "not" (L: UNSIGNED) return UNSIGNED is
  3351. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3352. begin
  3353. RESULT := UNSIGNED(not(STD_LOGIC_VECTOR(L)));
  3354. return RESULT;
  3355. end "not";
  3356.  
  3357. -- Id: L.2
  3358. function "and" (L, R: UNSIGNED) return UNSIGNED is
  3359. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3360. begin
  3361. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) and STD_LOGIC_VECTOR(R));
  3362. return RESULT;
  3363. end "and";
  3364.  
  3365. -- Id: L.3
  3366. function "or" (L, R: UNSIGNED) return UNSIGNED is
  3367. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3368. begin
  3369. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) or STD_LOGIC_VECTOR(R));
  3370. return RESULT;
  3371. end "or";
  3372.  
  3373. -- Id: L.4
  3374. function "nand" (L, R: UNSIGNED) return UNSIGNED is
  3375. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3376. begin
  3377. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) nand STD_LOGIC_VECTOR(R));
  3378. return RESULT;
  3379. end "nand";
  3380.  
  3381. -- Id: L.5
  3382. function "nor" (L, R: UNSIGNED) return UNSIGNED is
  3383. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3384. begin
  3385. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) nor STD_LOGIC_VECTOR(R));
  3386. return RESULT;
  3387. end "nor";
  3388.  
  3389. -- Id: L.6
  3390. function "xor" (L, R: UNSIGNED) return UNSIGNED is
  3391. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3392. begin
  3393. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) xor STD_LOGIC_VECTOR(R));
  3394. return RESULT;
  3395. end "xor";
  3396.  
  3397. ------------------------------------------------------------------------------
  3398. -- Note : Function L.7 is not compatible with VHDL 1076-1987. Comment
  3399. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3400. ------------------------------------------------------------------------------
  3401. -- Id: L.7
  3402. function "xnor" (L, R: UNSIGNED) return UNSIGNED is
  3403. variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);
  3404. begin
  3405. RESULT := UNSIGNED(STD_LOGIC_VECTOR(L) xnor STD_LOGIC_VECTOR(R));
  3406. return RESULT;
  3407. end "xnor";
  3408.  
  3409. -- Id: L.8
  3410. function "not" (L: SIGNED) return SIGNED is
  3411. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3412. begin
  3413. RESULT := SIGNED(not(STD_LOGIC_VECTOR(L)));
  3414. return RESULT;
  3415. end "not";
  3416.  
  3417. -- Id: L.9
  3418. function "and" (L, R: SIGNED) return SIGNED is
  3419. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3420. begin
  3421. RESULT := SIGNED(STD_LOGIC_VECTOR(L) and STD_LOGIC_VECTOR(R));
  3422. return RESULT;
  3423. end "and";
  3424.  
  3425. -- Id: L.10
  3426. function "or" (L, R: SIGNED) return SIGNED is
  3427. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3428. begin
  3429. RESULT := SIGNED(STD_LOGIC_VECTOR(L) or STD_LOGIC_VECTOR(R));
  3430. return RESULT;
  3431. end "or";
  3432.  
  3433. -- Id: L.11
  3434. function "nand" (L, R: SIGNED) return SIGNED is
  3435. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3436. begin
  3437. RESULT := SIGNED(STD_LOGIC_VECTOR(L) nand STD_LOGIC_VECTOR(R));
  3438. return RESULT;
  3439. end "nand";
  3440.  
  3441. -- Id: L.12
  3442. function "nor" (L, R: SIGNED) return SIGNED is
  3443. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3444. begin
  3445. RESULT := SIGNED(STD_LOGIC_VECTOR(L) nor STD_LOGIC_VECTOR(R));
  3446. return RESULT;
  3447. end "nor";
  3448.  
  3449. -- Id: L.13
  3450. function "xor" (L, R: SIGNED) return SIGNED is
  3451. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3452. begin
  3453. RESULT := SIGNED(STD_LOGIC_VECTOR(L) xor STD_LOGIC_VECTOR(R));
  3454. return RESULT;
  3455. end "xor";
  3456.  
  3457. ------------------------------------------------------------------------------
  3458. -- Note : Function L.14 is not compatible with VHDL 1076-1987. Comment
  3459. -- out the function (declaration and body) for VHDL 1076-1987 compatibility.
  3460. ------------------------------------------------------------------------------
  3461. -- Id: L.14
  3462. function "xnor" (L, R: SIGNED) return SIGNED is
  3463. variable RESULT: SIGNED(L'LENGTH-1 downto 0);
  3464. begin
  3465. RESULT := SIGNED(STD_LOGIC_VECTOR(L) xnor STD_LOGIC_VECTOR(R));
  3466. return RESULT;
  3467. end "xnor";
  3468.  
  3469. --============================================================================
  3470.  
  3471. -- support constants for STD_MATCH:
  3472.  
  3473. type BOOLEAN_TABLE is array(STD_ULOGIC, STD_ULOGIC) of BOOLEAN;
  3474.  
  3475. constant MATCH_TABLE: BOOLEAN_TABLE := (
  3476. --------------------------------------------------------------------------
  3477. -- U X 0 1 Z W L H -
  3478. --------------------------------------------------------------------------
  3479. (FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE), -- | U |
  3480. (FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE), -- | X |
  3481. (FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE), -- | 0 |
  3482. (FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE), -- | 1 |
  3483. (FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE), -- | Z |
  3484. (FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE), -- | W |
  3485. (FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE), -- | L |
  3486. (FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE), -- | H |
  3487. ( TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) -- | - |
  3488. );
  3489.  
  3490. -- Id: M.1
  3491. function STD_MATCH (L, R: STD_ULOGIC) return BOOLEAN is
  3492. variable VALUE: STD_ULOGIC;
  3493. begin
  3494. return MATCH_TABLE(L, R);
  3495. end STD_MATCH;
  3496.  
  3497. -- Id: M.2
  3498. function STD_MATCH (L, R: UNSIGNED) return BOOLEAN is
  3499. alias LV: UNSIGNED(1 to L'LENGTH) is L;
  3500. alias RV: UNSIGNED(1 to R'LENGTH) is R;
  3501. begin
  3502. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  3503. assert NO_WARNING
  3504. report "NUMERIC_STD.STD_MATCH: null detected, returning FALSE"
  3505. severity WARNING;
  3506. return FALSE;
  3507. end if;
  3508. if LV'LENGTH /= RV'LENGTH then
  3509. assert NO_WARNING
  3510. report "NUMERIC_STD.STD_MATCH: L'LENGTH /= R'LENGTH, returning FALSE"
  3511. severity WARNING;
  3512. return FALSE;
  3513. else
  3514. for I in LV'LOW to LV'HIGH loop
  3515. if not (MATCH_TABLE(LV(I), RV(I))) then
  3516. return FALSE;
  3517. end if;
  3518. end loop;
  3519. return TRUE;
  3520. end if;
  3521. end STD_MATCH;
  3522.  
  3523. -- Id: M.3
  3524. function STD_MATCH (L, R: SIGNED) return BOOLEAN is
  3525. alias LV: SIGNED(1 to L'LENGTH) is L;
  3526. alias RV: SIGNED(1 to R'LENGTH) is R;
  3527. begin
  3528. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  3529. assert NO_WARNING
  3530. report "NUMERIC_STD.STD_MATCH: null detected, returning FALSE"
  3531. severity WARNING;
  3532. return FALSE;
  3533. end if;
  3534. if LV'LENGTH /= RV'LENGTH then
  3535. assert NO_WARNING
  3536. report "NUMERIC_STD.STD_MATCH: L'LENGTH /= R'LENGTH, returning FALSE"
  3537. severity WARNING;
  3538. return FALSE;
  3539. else
  3540. for I in LV'LOW to LV'HIGH loop
  3541. if not (MATCH_TABLE(LV(I), RV(I))) then
  3542. return FALSE;
  3543. end if;
  3544. end loop;
  3545. return TRUE;
  3546. end if;
  3547. end STD_MATCH;
  3548.  
  3549. -- Id: M.4
  3550. function STD_MATCH (L, R: STD_LOGIC_VECTOR) return BOOLEAN is
  3551. alias LV: STD_LOGIC_VECTOR(1 to L'LENGTH) is L;
  3552. alias RV: STD_LOGIC_VECTOR(1 to R'LENGTH) is R;
  3553. begin
  3554. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  3555. assert NO_WARNING
  3556. report "NUMERIC_STD.STD_MATCH: null detected, returning FALSE"
  3557. severity WARNING;
  3558. return FALSE;
  3559. end if;
  3560. if LV'LENGTH /= RV'LENGTH then
  3561. assert NO_WARNING
  3562. report "NUMERIC_STD.STD_MATCH: L'LENGTH /= R'LENGTH, returning FALSE"
  3563. severity WARNING;
  3564. return FALSE;
  3565. else
  3566. for I in LV'LOW to LV'HIGH loop
  3567. if not (MATCH_TABLE(LV(I), RV(I))) then
  3568. return FALSE;
  3569. end if;
  3570. end loop;
  3571. return TRUE;
  3572. end if;
  3573. end STD_MATCH;
  3574.  
  3575. -- Id: M.5
  3576. function STD_MATCH (L, R: STD_ULOGIC_VECTOR) return BOOLEAN is
  3577. alias LV: STD_ULOGIC_VECTOR(1 to L'LENGTH) is L;
  3578. alias RV: STD_ULOGIC_VECTOR(1 to R'LENGTH) is R;
  3579. begin
  3580. if ((L'LENGTH < 1) or (R'LENGTH < 1)) then
  3581. assert NO_WARNING
  3582. report "NUMERIC_STD.STD_MATCH: null detected, returning FALSE"
  3583. severity WARNING;
  3584. return FALSE;
  3585. end if;
  3586. if LV'LENGTH /= RV'LENGTH then
  3587. assert NO_WARNING
  3588. report "NUMERIC_STD.STD_MATCH: L'LENGTH /= R'LENGTH, returning FALSE"
  3589. severity WARNING;
  3590. return FALSE;
  3591. else
  3592. for I in LV'LOW to LV'HIGH loop
  3593. if not (MATCH_TABLE(LV(I), RV(I))) then
  3594. return FALSE;
  3595. end if;
  3596. end loop;
  3597. return TRUE;
  3598. end if;
  3599. end STD_MATCH;
  3600.  
  3601. --============================================================================
  3602.  
  3603. -- function TO_01 is used to convert vectors to the
  3604. -- correct form for exported functions,
  3605. -- and to report if there is an element which
  3606. -- is not in (0, 1, H, L).
  3607.  
  3608. -- Id: T.1
  3609. function TO_01 (S: UNSIGNED; XMAP: STD_LOGIC := '0') return UNSIGNED is
  3610. variable RESULT: UNSIGNED(S'LENGTH-1 downto 0);
  3611. variable BAD_ELEMENT: BOOLEAN := FALSE;
  3612. alias XS: UNSIGNED(S'LENGTH-1 downto 0) is S;
  3613. -- Synthesis directives :
  3614. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3615. begin
  3616. if (S'LENGTH < 1) then
  3617. assert NO_WARNING
  3618. report "NUMERIC_STD.TO_01: null detected, returning NAU"
  3619. severity WARNING;
  3620. return NAU;
  3621. end if;
  3622. for I in RESULT'RANGE loop
  3623. case XS(I) is
  3624. when '0' | 'L' => RESULT(I) := '0';
  3625. when '1' | 'H' => RESULT(I) := '1';
  3626. when others => BAD_ELEMENT := TRUE;
  3627. end case;
  3628. end loop;
  3629. if BAD_ELEMENT then
  3630. for I in RESULT'RANGE loop
  3631. RESULT(I) := XMAP; -- standard fixup
  3632. end loop;
  3633. end if;
  3634. return RESULT;
  3635. end TO_01;
  3636.  
  3637. -- Id: T.2
  3638. function TO_01 (S: SIGNED; XMAP: STD_LOGIC := '0') return SIGNED is
  3639. variable RESULT: SIGNED(S'LENGTH-1 downto 0);
  3640. variable BAD_ELEMENT: BOOLEAN := FALSE;
  3641. alias XS: SIGNED(S'LENGTH-1 downto 0) is S;
  3642. -- Synthesis directives :
  3643. attribute SYNTHESIS_RETURN of RESULT:variable is "FEED_THROUGH" ;
  3644. begin
  3645. if (S'LENGTH < 1) then
  3646. assert NO_WARNING
  3647. report "NUMERIC_STD.TO_01: null detected, returning NAS"
  3648. severity WARNING;
  3649. return NAS;
  3650. end if;
  3651. for I in RESULT'RANGE loop
  3652. case XS(I) is
  3653. when '0' | 'L' => RESULT(I) := '0';
  3654. when '1' | 'H' => RESULT(I) := '1';
  3655. when others => BAD_ELEMENT := TRUE;
  3656. end case;
  3657. end loop;
  3658. if BAD_ELEMENT then
  3659. for I in RESULT'RANGE loop
  3660. RESULT(I) := XMAP; -- standard fixup
  3661. end loop;
  3662. end if;
  3663. return RESULT;
  3664. end TO_01;
  3665.  
  3666. --============================================================================
  3667.  
  3668. end NUMERIC_STD;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement