Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4236 lines
164 KiB

  1. --
  2. -- File Name: CoveragePkg.vhd
  3. -- Design Unit Name: CoveragePkg
  4. -- Revision: STANDARD VERSION, revision 2014.01
  5. --
  6. -- Maintainer: Jim Lewis email: jim@synthworks.com
  7. -- Contributor(s):
  8. -- Jim Lewis SynthWorks
  9. -- Matthias Alles Creonic. Inspired GetMinBinVal, GetMinPoint, GetCov
  10. -- Jerry Kaczynski Aldec. Inspired GetBin function
  11. --
  12. --
  13. -- Package Defines
  14. -- Functional coverage modeling utilities and data structure
  15. --
  16. -- Developed for:
  17. -- SynthWorks Design Inc.
  18. -- VHDL Training Classes
  19. -- 11898 SW 128th Ave. Tigard, Or 97223
  20. -- http://www.SynthWorks.com
  21. --
  22. -- Latest standard version available at:
  23. -- http://www.SynthWorks.com/downloads
  24. --
  25. -- Revision History: See also CoveragePkg_release_notes.pdf
  26. -- Date Version Description
  27. -- 06/2010: 0.1 Initial revision
  28. -- 09/2010 Release in SynthWorks' VHDL Testbenches and Verification classes
  29. -- 02/2011: 1.0 Requires VHDL-2008 types integer_vector and boolean_vecctor
  30. -- Changed CoverBinType to facilitage long term support of cross coverage
  31. -- 02/2011: 1.1 Added GetMinCov, GetMaxCov, CountCovHoles, GetCovHole
  32. -- 04/2011: 2.0 Added protected type based data structure: CovPType
  33. -- 06/2011: 2.1 Removed signal based coverage modeling
  34. -- 07/2011: 2.2 Added randomization with coverage goals (AtLeast), weight, and percentage thresholds
  35. -- Revised RandCovPoint, RandCovBinVal, AddBins, AddCross, GenBin, Added SetWeightMode
  36. -- Randomization with weights/weight modes
  37. -- Cleaned up parameter naming
  38. -- 11/2011: 2.2a Changed constants ALL_RANGE, ZERO_BIN, and ONE_BIN to have a 1 index
  39. -- rather than 0 to match the range of BinVal
  40. -- 12/2011: 2.2b Fixed minor inconsistencies on interface declarations.
  41. -- Package RandomPkg is assumed to be in the same library as CoveragePkg
  42. -- 01/2012: 2.3 Added Function GetBin from Jerry K.
  43. -- Made write for RangeArrayType visible
  44. -- 01/2012: 2.4
  45. -- Revised AddBins and AddCross to handle merging and deletion for overlapping bins
  46. -- Note merging is an experimental feature.
  47. -- Renamed RandCovHole to RandCovBinVal - maintained old version calls new
  48. -- Renamed GetCovHole to GetHoleBinVal - maintained old version calls new
  49. -- 04/2013: 2013.04
  50. -- Revised AddBins and AddCross s.t. bin merging is off by default.
  51. -- Added SetMerging to enable/disable merging.
  52. -- Note: Merging is an experimental feature and still evolving.
  53. -- Revised AddBins and AddCross to check for changes in BinVal size (different size bin).
  54. -- Added RandCovPoint for integer.
  55. -- Added SetThresholding and SetCovThreshold(Percent) to enable/disable(default) thresholding.
  56. -- Revised RandCovPoint and RandCovBinVal to use new mechanism.
  57. -- Added SetCovTarget to increase/decrease coverage goals for longer/shorter simulation runs.
  58. -- Made CovTarget the default percentage goal (via overloading) for methods RandCovPoint,
  59. -- RandCovBinVal, IsCovered, CountCovHoles, GetHoleBinVal, and WriteCovHoles
  60. -- Revised SetIllegalMode and ICover to support ILLEGAL_FAILURE (severity FAILURE on illegal bin).
  61. -- Added manual bin iteration support.
  62. -- BinIndex: GetNumBins, GetMinIndex, GetMaxIndex
  63. -- BinVal: GetBinVal(BinIndex), GetMinBinVal, GetMaxBinVal
  64. -- Point: GetPoint (BinIndex), GetMinPoint, GetMaxPoint
  65. -- Added GetCov to return the current percent done of the entire coverage model.
  66. -- Added FileOpenWriteBin and FileCloseWriteBin to specify default file for WriteBin, WriteCovHoles, and DumpBin
  67. -- Added CompareBins to facilitate comparing two coverage models.
  68. -- Revised WriteBin, WriteCovHoles, and WriteCovDb to check for uninitialized model.
  69. -- Revised WriteBins and WriteCovHoles to only print weight if the selected WeightMode uses the weight.
  70. -- Added IsInitialized to check if a coverage model is initialized.
  71. -- Added GetBinInfo and GetBinValLength to get bin information
  72. -- Changed WriteCovDb default for File_Open_Kind to WRITE_MODE
  73. -- Revised WriteCovDb and ReadCovDb for new internal control/state variables
  74. -- Removed IgnoreBin with AtLeast and Weight parameters. These are zero for ignore bins.
  75. -- Revised method naming for consistency. The following have changed:
  76. -- New Name Old Name Why
  77. -- CovBinErrCnt GetErrorCount Consistency between packages
  78. -- GetMinCount GetMinCov[return integer] Naming clarity
  79. -- GetMaxCount GetMaxCov[return integer] Naming clarity
  80. -- SetName SetItemName SetName now does multi-line messages
  81. -- Deprecated usage of the AtLeast parameter (integer) with the following methods:
  82. -- RandCovPoint, RandCovBinVal, IsCovered, CountCovHoles,
  83. -- GetHoleBinVal, and WriteCovHoles.
  84. -- 5/2013 2013.05
  85. -- No changes of substance.
  86. -- Removed extra variable declaration in functions GetHoleBinval,
  87. -- RandCovBinVal, RandCovHole, GetHoleBinVal
  88. -- Using work.RandomPkg.NULL_RANGE_TYPE to remove NULL range warnings
  89. -- 1/2014 2014.01
  90. -- Revised ReadCovDb to support merging of coverage models
  91. -- Revised RandCovPoint and RandCovBinVal to log the bin index in the LastIndex variable
  92. -- Revised ICover to look in bin referenced by LastIndex first
  93. -- Added GetLastIndex and GetLastBinVal
  94. -- Revised AddBins and AddCross bin merging to allow arbitrary CountBin overlap (facilitated by LastIndex)
  95. -- Note: Merging is an experimental feature and still evolving.
  96. -- Split SetName into SetMessage (headers) and SetName (printing illegal bins)
  97. -- Added methods GetItemCount and GetTotalCovGoal
  98. -- Revised GetCov to use CovTarget and overloaded to use a PercentCov parameter.
  99. --
  100. -- Development Notes:
  101. -- The coverage procedures are named ICover to avoid conflicts with
  102. -- future language changes which may add cover as a keyword
  103. -- Procedure WriteBin writes each CovBin on a separate line, as such
  104. -- it was inappropriate to overload either textio write or to_string
  105. -- In the notes VHDL-2008 notes refers to
  106. -- composites with unconstrained elements
  107. --
  108. --
  109. -- Copyright (c) 2010 - 2013 by SynthWorks Design Inc. All rights reserved.
  110. --
  111. -- Verbatim copies of this source file may be used and
  112. -- distributed without restriction.
  113. --
  114. -- This source file is free software; you can redistribute it
  115. -- and/or modify it under the terms of the ARTISTIC License
  116. -- as published by The Perl Foundation; either version 2.0 of
  117. -- the License, or (at your option) any later version.
  118. --
  119. -- This source is distributed in the hope that it will be
  120. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  121. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  122. -- PURPOSE. See the Artistic License for details.
  123. --
  124. -- You should have received a copy of the license with this source.
  125. -- If not download it from,
  126. -- http://www.perlfoundation.org/artistic_license_2_0
  127. --
  128. -- Credits:
  129. -- CovBinBaseType is inspired by a structure proposed in the
  130. -- paper "Functional Coverage - without SystemVerilog!"
  131. -- by Alan Fitch and Doug Smith. Presented at DVCon 2010
  132. -- However the approach in their paper uses entities and
  133. -- architectures where this approach relies on functions
  134. -- and procedures, so the usage models differ greatly however.
  135. --
  136. library ieee ;
  137. use ieee.std_logic_1164.all ;
  138. use ieee.numeric_std.all ;
  139. use ieee.math_real.all ;
  140. use std.textio.all ;
  141. -- comment out following 2 lines with VHDL-2008. Leave in for VHDL-2002
  142. -- library ieee_proposed ; -- remove with VHDL-2008
  143. -- use ieee_proposed.standard_additions.all ; -- remove with VHDL-2008
  144. use work.RandomBasePkg.all ;
  145. use work.RandomPkg.all ;
  146. use work.MessagePkg.all ;
  147. package CoveragePkg is
  148. -- CovPType allocates bins that are multiples of MIN_NUM_BINS
  149. constant MIN_NUM_BINS : integer := 2**7 ; -- power of 2
  150. type RangeType is record
  151. min : integer ;
  152. max : integer ;
  153. end record ;
  154. type RangeArrayType is array (integer range <>) of RangeType ;
  155. constant ALL_RANGE : RangeArrayType := (1=>(Integer'left, Integer'right)) ;
  156. procedure write ( file f : text ; BinVal : RangeArrayType ) ;
  157. procedure write ( variable buf : inout line ; constant BinVal : in RangeArrayType) ;
  158. -- CovBinBaseType.action values.
  159. -- Note that coverage counting depends on these values
  160. constant COV_COUNT : integer := 1 ;
  161. constant COV_IGNORE : integer := 0 ;
  162. constant COV_ILLEGAL : integer := -1 ;
  163. -- Used for easy manual entry. Order: min, max, action
  164. -- Intentionally did not use a record to allow other input
  165. -- formats in the future with VHDL-2008 unconstrained arrays
  166. -- of unconstrained elements
  167. type CovBinManualType is array (natural range <>) of integer_vector(0 to 2) ;
  168. type CovBinBaseType is record
  169. BinVal : RangeArrayType(1 to 1) ;
  170. Action : integer ;
  171. Count : integer ;
  172. AtLeast : integer ;
  173. Weight : integer ;
  174. end record ;
  175. type CovBinType is array (natural range <>) of CovBinBaseType ;
  176. constant ALL_BIN : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  177. constant ALL_COUNT : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  178. constant ALL_ILLEGAL : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_ILLEGAL, Count => 0, AtLeast => 0, Weight => 0 )) ;
  179. constant ALL_IGNORE : CovBinType := (0 => ( BinVal => ALL_RANGE, Action => COV_IGNORE, Count => 0, AtLeast => 0, Weight => 0 )) ;
  180. constant ZERO_BIN : CovBinType := (0 => ( BinVal => (1=>(0,0)), Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  181. constant ONE_BIN : CovBinType := (0 => ( BinVal => (1=>(1,1)), Action => COV_COUNT, Count => 0, AtLeast => 1, Weight => 1 )) ;
  182. constant NULL_BIN : CovBinType(work.RandomPkg.NULL_RANGE_TYPE) := (others => ( BinVal => ALL_RANGE, Action => integer'high, Count => 0, AtLeast => integer'high, Weight => integer'high )) ;
  183. type CountModeType is (COUNT_FIRST, COUNT_ALL) ;
  184. type IllegalModeType is (ILLEGAL_ON, ILLEGAL_FAILURE, ILLEGAL_OFF) ;
  185. type WeightModeType is (AT_LEAST, WEIGHT, REMAIN, REMAIN_EXP, REMAIN_SCALED, REMAIN_WEIGHT ) ;
  186. -- In VHDL-2008 CovMatrix?BaseType and CovMatrix?Type will be subsumed
  187. -- by CovBinBaseType and CovBinType with RangeArrayType as an unconstrained array.
  188. type CovMatrix2BaseType is record
  189. BinVal : RangeArrayType(1 to 2) ;
  190. Action : integer ;
  191. Count : integer ;
  192. AtLeast : integer ;
  193. Weight : integer ;
  194. end record ;
  195. type CovMatrix2Type is array (natural range <>) of CovMatrix2BaseType ;
  196. type CovMatrix3BaseType is record
  197. BinVal : RangeArrayType(1 to 3) ;
  198. Action : integer ;
  199. Count : integer ;
  200. AtLeast : integer ;
  201. Weight : integer ;
  202. end record ;
  203. type CovMatrix3Type is array (natural range <>) of CovMatrix3BaseType ;
  204. type CovMatrix4BaseType is record
  205. BinVal : RangeArrayType(1 to 4) ;
  206. Action : integer ;
  207. Count : integer ;
  208. AtLeast : integer ;
  209. Weight : integer ;
  210. end record ;
  211. type CovMatrix4Type is array (natural range <>) of CovMatrix4BaseType ;
  212. type CovMatrix5BaseType is record
  213. BinVal : RangeArrayType(1 to 5) ;
  214. Action : integer ;
  215. Count : integer ;
  216. AtLeast : integer ;
  217. Weight : integer ;
  218. end record ;
  219. type CovMatrix5Type is array (natural range <>) of CovMatrix5BaseType ;
  220. type CovMatrix6BaseType is record
  221. BinVal : RangeArrayType(1 to 6) ;
  222. Action : integer ;
  223. Count : integer ;
  224. AtLeast : integer ;
  225. Weight : integer ;
  226. end record ;
  227. type CovMatrix6Type is array (natural range <>) of CovMatrix6BaseType ;
  228. type CovMatrix7BaseType is record
  229. BinVal : RangeArrayType(1 to 7) ;
  230. Action : integer ;
  231. Count : integer ;
  232. AtLeast : integer ;
  233. Weight : integer ;
  234. end record ;
  235. type CovMatrix7Type is array (natural range <>) of CovMatrix7BaseType ;
  236. type CovMatrix8BaseType is record
  237. BinVal : RangeArrayType(1 to 8) ;
  238. Action : integer ;
  239. Count : integer ;
  240. AtLeast : integer ;
  241. Weight : integer ;
  242. end record ;
  243. type CovMatrix8Type is array (natural range <>) of CovMatrix8BaseType ;
  244. type CovMatrix9BaseType is record
  245. BinVal : RangeArrayType(1 to 9) ;
  246. Action : integer ;
  247. Count : integer ;
  248. AtLeast : integer ;
  249. Weight : integer ;
  250. end record ;
  251. type CovMatrix9Type is array (natural range <>) of CovMatrix9BaseType ;
  252. ------------------------------------------------------------
  253. function ToMinPoint (A : RangeArrayType) return integer ;
  254. function ToMinPoint (A : RangeArrayType) return integer_vector ;
  255. -- BinVal to Minimum Point
  256. ------------------------------------------------------------
  257. procedure ToRandPoint(
  258. -- BinVal to Random Point
  259. -- better as a function, however, inout not supported on functions
  260. ------------------------------------------------------------
  261. variable RV : inout RandomPType ;
  262. constant BinVal : in RangeArrayType ;
  263. variable result : out integer
  264. ) ;
  265. ------------------------------------------------------------
  266. procedure ToRandPoint(
  267. -- BinVal to Random Point
  268. ------------------------------------------------------------
  269. variable RV : inout RandomPType ;
  270. constant BinVal : in RangeArrayType ;
  271. variable result : out integer_vector
  272. ) ;
  273. ------------------------------------------------------------------------------------------
  274. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  275. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  276. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  277. ------------------------------------------------------------------------------------------
  278. type CovPType is protected
  279. procedure FileOpenWriteBin (FileName : string; OpenKind : File_Open_Kind ) ;
  280. procedure FileCloseWriteBin ;
  281. -- procedure FileOpenWriteCovDb (FileName : string; OpenKind : File_Open_Kind ) ;
  282. -- procedure FileCloseWriteCovDb ;
  283. procedure SetIllegalMode (A : IllegalModeType) ;
  284. procedure SetWeightMode (A : WeightModeType; Scale : real := 1.0) ;
  285. procedure SetName (NameIn : String) ;
  286. procedure SetMessage (MessageIn : String) ;
  287. procedure DeallocateName ; -- clear name
  288. procedure DeallocateMessage ; -- clear message
  289. procedure SetThresholding(A : boolean := TRUE ) ; -- 2.5
  290. procedure SetCovThreshold (Percent : real) ;
  291. procedure SetCovTarget (Percent : real) ; -- 2.5
  292. impure function GetCovTarget return real ; -- 2.5
  293. procedure SetMerging(A : boolean := TRUE ) ; -- 2.5
  294. procedure SetCountMode (A : CountModeType) ;
  295. procedure InitSeed (S : string ) ;
  296. procedure InitSeed (I : integer ) ;
  297. procedure SetSeed (RandomSeedIn : RandomSeedType ) ;
  298. impure function GetSeed return RandomSeedType ;
  299. procedure SetBinSize (NewNumBins : integer) ;
  300. ------------------------------------------------------------
  301. procedure AddBins (
  302. AtLeast : integer ;
  303. Weight : integer ;
  304. CovBin : CovBinType
  305. ) ;
  306. procedure AddBins (AtLeast : integer ; CovBin : CovBinType) ;
  307. procedure AddBins (CovBin : CovBinType) ;
  308. ------------------------------------------------------------
  309. procedure AddCross(
  310. AtLeast : integer ;
  311. Weight : integer ;
  312. Bin1, Bin2 : CovBinType ;
  313. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  314. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  315. ) ;
  316. ------------------------------------------------------------
  317. procedure AddCross(
  318. AtLeast : integer ;
  319. Bin1, Bin2 : CovBinType ;
  320. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  321. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  322. ) ;
  323. ------------------------------------------------------------
  324. procedure AddCross(
  325. Bin1, Bin2 : CovBinType ;
  326. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  327. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  328. ) ;
  329. procedure Deallocate ;
  330. procedure ICoverLast ;
  331. procedure ICover( CovPoint : integer) ;
  332. procedure ICover( CovPoint : integer_vector) ;
  333. procedure SetCovZero ;
  334. impure function IsInitialized return boolean ;
  335. impure function GetNumBins return integer ;
  336. impure function GetMinIndex return integer ;
  337. impure function GetMinCov return real ; -- PercentCov
  338. impure function GetMinCount return integer ; -- Count
  339. impure function GetMaxIndex return integer ;
  340. impure function GetMaxCov return real ; -- PercentCov
  341. impure function GetMaxCount return integer ; -- Count
  342. impure function CountCovHoles ( PercentCov : real ) return integer ;
  343. impure function CountCovHoles return integer ;
  344. impure function IsCovered return boolean ;
  345. impure function IsCovered ( PercentCov : real ) return boolean ;
  346. impure function GetCov ( PercentCov : real ) return real ;
  347. impure function GetCov return real ; -- PercentCov of entire model/all bins
  348. impure function GetItemCount return integer ;
  349. impure function GetTotalCovGoal ( PercentCov : real ) return integer ;
  350. impure function GetTotalCovGoal return integer ;
  351. impure function GetLastIndex return integer ;
  352. -- Return BinVal
  353. impure function GetBinVal ( BinIndex : integer ) return RangeArrayType ;
  354. impure function GetLastBinVal return RangeArrayType ;
  355. impure function RandCovBinVal ( PercentCov : real ) return RangeArrayType ;
  356. impure function RandCovBinVal return RangeArrayType ;
  357. impure function GetMinBinVal return RangeArrayType ;
  358. impure function GetMaxBinVal return RangeArrayType ;
  359. impure function GetHoleBinVal ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType ;
  360. impure function GetHoleBinVal ( PercentCov : real ) return RangeArrayType ;
  361. impure function GetHoleBinVal ( ReqHoleNum : integer := 1 ) return RangeArrayType ;
  362. -- Return Points
  363. impure function RandCovPoint return integer ;
  364. impure function RandCovPoint ( PercentCov : real ) return integer ;
  365. impure function RandCovPoint return integer_vector ;
  366. impure function RandCovPoint ( PercentCov : real ) return integer_vector ;
  367. impure function GetPoint ( BinIndex : integer ) return integer ;
  368. impure function GetPoint ( BinIndex : integer ) return integer_vector ;
  369. impure function GetMinPoint return integer ;
  370. impure function GetMinPoint return integer_vector ;
  371. impure function GetMaxPoint return integer ;
  372. impure function GetMaxPoint return integer_vector ;
  373. -- GetBin returns an internal value of the coverage data structure
  374. -- The return value may change as the package evolves
  375. -- Use it only for debugging.
  376. -- GetBinInfo is a for development only.
  377. impure function GetBinInfo ( BinIndex : integer ) return CovBinBaseType ;
  378. impure function GetBinValLength return integer ;
  379. impure function GetBin ( BinIndex : integer ) return CovBinBaseType ;
  380. impure function GetBin ( BinIndex : integer ) return CovMatrix2BaseType ;
  381. impure function GetBin ( BinIndex : integer ) return CovMatrix3BaseType ;
  382. impure function GetBin ( BinIndex : integer ) return CovMatrix4BaseType ;
  383. impure function GetBin ( BinIndex : integer ) return CovMatrix5BaseType ;
  384. impure function GetBin ( BinIndex : integer ) return CovMatrix6BaseType ;
  385. impure function GetBin ( BinIndex : integer ) return CovMatrix7BaseType ;
  386. impure function GetBin ( BinIndex : integer ) return CovMatrix8BaseType ;
  387. impure function GetBin ( BinIndex : integer ) return CovMatrix9BaseType ;
  388. -- procedure WriteBin ( file f : text ) ;
  389. procedure WriteBin ;
  390. procedure WriteBin ( FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  391. procedure WriteCovHoles ;
  392. procedure WriteCovHoles ( PercentCov : real ) ;
  393. procedure WriteCovHoles ( FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  394. procedure WriteCovHoles ( FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  395. procedure DumpBin ; -- Development only
  396. procedure ReadCovDb (FileName : string; Merge : boolean := FALSE) ;
  397. procedure WriteCovDb (FileName : string; OpenKind : File_Open_Kind := WRITE_MODE ) ;
  398. impure function GetErrorCount return integer ;
  399. -- These support usage of cross coverage constants
  400. -- Also support the older AddBins(GenCross(...)) methodology
  401. -- which has been replaced by AddCross
  402. procedure AddBins (CovBin : CovMatrix2Type) ;
  403. procedure AddBins (CovBin : CovMatrix3Type) ;
  404. procedure AddBins (CovBin : CovMatrix4Type) ;
  405. procedure AddBins (CovBin : CovMatrix5Type) ;
  406. procedure AddBins (CovBin : CovMatrix6Type) ;
  407. procedure AddBins (CovBin : CovMatrix7Type) ;
  408. procedure AddBins (CovBin : CovMatrix8Type) ;
  409. procedure AddBins (CovBin : CovMatrix9Type) ;
  410. ------------------------------------------------------------
  411. -- Remaining are Deprecated
  412. --
  413. -- Deprecated. Replaced by SetName with multi-line support
  414. procedure SetItemName (ItemNameIn : String) ; -- deprecated
  415. -- Deprecated. Consistency across packages
  416. impure function CovBinErrCnt return integer ;
  417. -- Deprecated. Due to name changes to promote greater consistency
  418. -- Maintained for backward compatibility.
  419. -- RandCovHole replaced by RandCovBinVal
  420. impure function RandCovHole ( PercentCov : real ) return RangeArrayType ; -- Deprecated
  421. impure function RandCovHole return RangeArrayType ; -- Deprecated
  422. -- GetCovHole replaced by GetHoleBinVal
  423. impure function GetCovHole ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType ;
  424. impure function GetCovHole ( PercentCov : real ) return RangeArrayType ;
  425. impure function GetCovHole ( ReqHoleNum : integer := 1 ) return RangeArrayType ;
  426. -- Deprecated/ Subsumed by versions with PercentCov Parameter
  427. -- Maintained for backward compatibility only and
  428. -- may be removed in the future.
  429. impure function GetMinCov return integer ;
  430. impure function GetMaxCov return integer ;
  431. impure function CountCovHoles ( AtLeast : integer ) return integer ;
  432. impure function IsCovered ( AtLeast : integer ) return boolean ;
  433. impure function RandCovBinVal ( AtLeast : integer ) return RangeArrayType ;
  434. impure function RandCovHole ( AtLeast : integer ) return RangeArrayType ; -- Deprecated
  435. impure function RandCovPoint (AtLeast : integer ) return integer ;
  436. impure function RandCovPoint (AtLeast : integer ) return integer_vector ;
  437. impure function GetHoleBinVal ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType ;
  438. impure function GetCovHole ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType ;
  439. procedure WriteCovHoles ( AtLeast : integer ) ;
  440. procedure WriteCovHoles ( FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) ;
  441. end protected CovPType ;
  442. ------------------------------------------------------------------------------------------
  443. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  444. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  445. ------------------------------------------------------------------------------------------
  446. ------------------------------------------------------------
  447. -- Experimental. Intended primarily for development.
  448. procedure CompareBins (
  449. ------------------------------------------------------------
  450. variable Bin1 : inout CovPType ;
  451. variable Bin2 : inout CovPType ;
  452. variable ErrorCount : inout integer
  453. ) ;
  454. --
  455. -- Support for AddBins and AddCross
  456. --
  457. ------------------------------------------------------------
  458. function GenBin(
  459. ------------------------------------------------------------
  460. AtLeast : integer ;
  461. Weight : integer ;
  462. Min, Max : integer ;
  463. NumBin : integer
  464. ) return CovBinType ;
  465. -- Each item in range in a separate CovBin
  466. function GenBin(AtLeast : integer ; Min, Max, NumBin : integer ) return CovBinType ;
  467. function GenBin(Min, Max, NumBin : integer ) return CovBinType ;
  468. function GenBin(Min, Max : integer) return CovBinType ;
  469. function GenBin(A : integer) return CovBinType ;
  470. ------------------------------------------------------------
  471. function IllegalBin ( Min, Max, NumBin : integer ) return CovBinType ;
  472. ------------------------------------------------------------
  473. -- All items in range in a single CovBin
  474. function IllegalBin ( Min, Max : integer ) return CovBinType ;
  475. function IllegalBin ( A : integer ) return CovBinType ;
  476. ----------------------------------------------------------
  477. -- function IgnoreBin (
  478. ----------------------------------------------------------
  479. -- AtLeast : integer ;
  480. -- Weight : integer ;
  481. -- Min, Max : integer ;
  482. -- NumBin : integer
  483. -- ) return CovBinType ;
  484. -- function IgnoreBin (AtLeast : integer ; Min, Max, NumBin : integer) return CovBinType ;
  485. -- All items in range in a single CovBin
  486. ------------------------------------------------------------
  487. function IgnoreBin (Min, Max, NumBin : integer) return CovBinType ;
  488. ------------------------------------------------------------
  489. function IgnoreBin (Min, Max : integer) return CovBinType ;
  490. function IgnoreBin (A : integer) return CovBinType ;
  491. ------------------------------------------------------------
  492. function GenBin (
  493. -- Manual entry format for CovBin within lots of extra parens
  494. ------------------------------------------------------------
  495. ManualBin : CovBinManualType
  496. ) return CovBinType ;
  497. -- With VHDL-2008, there will be one GenCross that returns CovBinType
  498. -- and has inputs initialized to NULL_BIN - see AddCross
  499. ------------------------------------------------------------
  500. function GenCross( -- 2
  501. -- Cross existing bins
  502. -- Use AddCross for adding values directly to coverage database
  503. -- Use GenCross for constants
  504. ------------------------------------------------------------
  505. AtLeast : integer ;
  506. Weight : integer ;
  507. Bin1, Bin2 : CovBinType
  508. ) return CovMatrix2Type ;
  509. function GenCross(AtLeast : integer ; Bin1, Bin2 : CovBinType) return CovMatrix2Type ;
  510. function GenCross(Bin1, Bin2 : CovBinType) return CovMatrix2Type ;
  511. ------------------------------------------------------------
  512. function GenCross( -- 3
  513. ------------------------------------------------------------
  514. AtLeast : integer ;
  515. Weight : integer ;
  516. Bin1, Bin2, Bin3 : CovBinType
  517. ) return CovMatrix3Type ;
  518. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type ;
  519. function GenCross( Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type ;
  520. ------------------------------------------------------------
  521. function GenCross( -- 4
  522. ------------------------------------------------------------
  523. AtLeast : integer ;
  524. Weight : integer ;
  525. Bin1, Bin2, Bin3, Bin4 : CovBinType
  526. ) return CovMatrix4Type ;
  527. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type ;
  528. function GenCross( Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type ;
  529. ------------------------------------------------------------
  530. function GenCross( -- 5
  531. ------------------------------------------------------------
  532. AtLeast : integer ;
  533. Weight : integer ;
  534. Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType
  535. ) return CovMatrix5Type ;
  536. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type ;
  537. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type ;
  538. ------------------------------------------------------------
  539. function GenCross( -- 6
  540. ------------------------------------------------------------
  541. AtLeast : integer ;
  542. Weight : integer ;
  543. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType
  544. ) return CovMatrix6Type ;
  545. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type ;
  546. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type ;
  547. ------------------------------------------------------------
  548. function GenCross( -- 7
  549. ------------------------------------------------------------
  550. AtLeast : integer ;
  551. Weight : integer ;
  552. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType
  553. ) return CovMatrix7Type ;
  554. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type ;
  555. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type ;
  556. ------------------------------------------------------------
  557. function GenCross( -- 8
  558. ------------------------------------------------------------
  559. AtLeast : integer ;
  560. Weight : integer ;
  561. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType
  562. ) return CovMatrix8Type ;
  563. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type ;
  564. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type ;
  565. ------------------------------------------------------------
  566. function GenCross( -- 9
  567. ------------------------------------------------------------
  568. AtLeast : integer ;
  569. Weight : integer ;
  570. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType
  571. ) return CovMatrix9Type ;
  572. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type ;
  573. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type ;
  574. ------------------------------------------------------------
  575. procedure increment( signal Count : inout integer ) ;
  576. procedure increment( signal Count : inout integer ; enable : boolean ) ;
  577. procedure increment( signal Count : inout integer ; enable : std_ulogic ) ;
  578. ------------------------------------------------------------
  579. -- Utilities. Remove if added to std.standard
  580. function to_integer ( B : boolean ) return integer ;
  581. function to_integer ( SL : std_logic ) return integer ;
  582. function to_integer_vector ( BV : boolean_vector ) return integer_vector ;
  583. function to_integer_vector ( SLV : std_logic_vector ) return integer_vector ;
  584. end package CoveragePkg ;
  585. --- //////////////////////////////////////////////////////////////////////////////////////////////
  586. --- //////////////////////////////////////////////////////////////////////////////////////////////
  587. package body CoveragePkg is
  588. ------------------------------------------------------------
  589. function inside (
  590. -- package local
  591. ------------------------------------------------------------
  592. CovPoint : integer ;
  593. BinVal : RangeType
  594. ) return boolean is
  595. begin
  596. return CovPoint >= BinVal.min and CovPoint <= BinVal.max ;
  597. end function inside ;
  598. ------------------------------------------------------------
  599. function inside (
  600. -- package local
  601. ------------------------------------------------------------
  602. CovPoint : integer_vector ;
  603. BinVal : RangeArrayType
  604. ) return boolean is
  605. alias iCovPoint : integer_vector(BinVal'range) is CovPoint ;
  606. begin
  607. for i in BinVal'range loop
  608. if not (iCovPoint(i) >= BinVal(i).min and iCovPoint(i) <= BinVal(i).max) then
  609. return FALSE ;
  610. end if ;
  611. end loop ;
  612. return TRUE ;
  613. end function inside ;
  614. ------------------------------------------------------------
  615. function inside (
  616. -- package local, used by InsertBin
  617. -- True when BinVal1 is inside BinVal2
  618. ------------------------------------------------------------
  619. BinVal1 : RangeArrayType ;
  620. BinVal2 : RangeArrayType
  621. ) return boolean is
  622. alias iBinVal2 : RangeArrayType(BinVal1'range) is BinVal2 ;
  623. begin
  624. for i in BinVal1'range loop
  625. if not (BinVal1(i).min >= iBinVal2(i).min and BinVal1(i).max <= iBinVal2(i).max) then
  626. return FALSE ;
  627. end if ;
  628. end loop ;
  629. return TRUE ;
  630. end function inside ;
  631. ------------------------------------------------------------
  632. procedure write (
  633. variable buf : inout line ;
  634. CovPoint : integer_vector
  635. ) is
  636. -- package local. called by ICover
  637. ------------------------------------------------------------
  638. alias iCovPoint : integer_vector(1 to CovPoint'length) is CovPoint ;
  639. begin
  640. write(buf, "(" & integer'image(iCovPoint(1)) ) ;
  641. for i in 2 to iCovPoint'right loop
  642. write(buf, "," & integer'image(iCovPoint(i)) ) ;
  643. end loop ;
  644. swrite(buf, ")") ;
  645. end procedure write ;
  646. ------------------------------------------------------------
  647. procedure write ( file f : text ; BinVal : RangeArrayType ) is
  648. -- called by WriteBin and WriteCovHoles
  649. ------------------------------------------------------------
  650. begin
  651. for i in BinVal'range loop
  652. if BinVal(i).min = BinVal(i).max then
  653. write(f, "(" & integer'image(BinVal(i).min) & ") " ) ;
  654. elsif (BinVal(i).min = integer'left) and (BinVal(i).max = integer'right) then
  655. write(f, "(ALL) " ) ;
  656. else
  657. write(f, "(" & integer'image(BinVal(i).min) & " to " &
  658. integer'image(BinVal(i).max) & ") " ) ;
  659. end if ;
  660. end loop ;
  661. end procedure write ;
  662. ------------------------------------------------------------
  663. procedure write (
  664. -- called by WriteBin and WriteCovHoles
  665. ------------------------------------------------------------
  666. variable buf : inout line ;
  667. constant BinVal : in RangeArrayType
  668. ) is
  669. ------------------------------------------------------------
  670. begin
  671. for i in BinVal'range loop
  672. if BinVal(i).min = BinVal(i).max then
  673. write(buf, "(" & integer'image(BinVal(i).min) & ") " ) ;
  674. elsif (BinVal(i).min = integer'left) and (BinVal(i).max = integer'right) then
  675. swrite(buf, "(ALL) " ) ;
  676. else
  677. write(buf, "(" & integer'image(BinVal(i).min) & " to " &
  678. integer'image(BinVal(i).max) & ") " ) ;
  679. end if ;
  680. end loop ;
  681. end procedure write ;
  682. ------------------------------------------------------------
  683. procedure WriteBinVal (
  684. -- package local for now
  685. ------------------------------------------------------------
  686. variable buf : inout line ;
  687. constant BinVal : in RangeArrayType
  688. ) is
  689. begin
  690. for i in BinVal'range loop
  691. write(buf, BinVal(i).min) ;
  692. write(buf, ' ') ;
  693. write(buf, BinVal(i).max) ;
  694. write(buf, ' ') ;
  695. end loop ;
  696. end procedure WriteBinVal ;
  697. ------------------------------------------------------------
  698. -- package local
  699. function failed (InValid : boolean ; Message : string := " ") return boolean is
  700. -- Move to TextUtilPkg and make visible?
  701. ------------------------------------------------------------
  702. begin
  703. if InValid then
  704. report Message severity failure ;
  705. end if ;
  706. return InValid ;
  707. end function failed ;
  708. ------------------------------------------------------------
  709. -- package local
  710. procedure EmptyOrCommentLine (
  711. -- Better as Function, but not supported in VHDL functions
  712. ------------------------------------------------------------
  713. variable L : InOut line ;
  714. variable Empty : out boolean
  715. ) is
  716. variable Valid : boolean ;
  717. variable Char : character ;
  718. constant NBSP : CHARACTER := CHARACTER'val(160); -- space character
  719. begin
  720. Empty := TRUE ;
  721. -- if line empty (null or 0 length), Empty = TRUE
  722. if L = null or L.all'length = 0 then
  723. return ;
  724. end if ;
  725. -- if line starts with '#', empty = TRUE
  726. if L.all(1) = '#' then
  727. return ;
  728. end if ;
  729. -- if line starts with '--', empty = TRUE
  730. if L.all'length >= 2 and L.all(1) = '-' and L.all(2) = '-' then
  731. return ;
  732. end if ;
  733. -- Otherwise, remove white space and check for end of line
  734. -- Code borrowed from David Bishop, skip_whitespace
  735. WhiteSpLoop : while L /= null and L.all'length > 0 loop
  736. if (L.all(1) = ' ' or L.all(1) = NBSP or L.all(1) = HT) then
  737. read (L, Char, Valid) ;
  738. else
  739. Empty := FALSE ;
  740. exit WhiteSpLoop ;
  741. end if ;
  742. end loop WhiteSpLoop ;
  743. end procedure EmptyOrCommentLine ;
  744. ------------------------------------------------------------
  745. -- package local for now
  746. procedure read (
  747. -- if public, also create one that does not use valid flag
  748. ------------------------------------------------------------
  749. variable buf : inout line ;
  750. variable BinVal : out RangeArrayType ;
  751. variable Valid : out boolean
  752. ) is
  753. variable ReadValid : boolean ;
  754. begin
  755. for i in BinVal'range loop
  756. read(buf, BinVal(i).min, ReadValid) ;
  757. exit when not ReadValid ;
  758. read(buf, BinVal(i).max, ReadValid) ;
  759. exit when not ReadValid ;
  760. end loop ;
  761. Valid := ReadValid ;
  762. end procedure read ;
  763. -- ------------------------------------------------------------
  764. function BinLengths (
  765. -- package local, used by AddCross, GenCross
  766. -- ------------------------------------------------------------
  767. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  768. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  769. ) return integer_vector is
  770. variable result : integer_vector(1 to 20) := (others => 0 ) ;
  771. variable i : integer := result'left ;
  772. variable Len : integer ;
  773. begin
  774. loop
  775. case i is
  776. when 1 => Len := Bin1'length ;
  777. when 2 => Len := Bin2'length ;
  778. when 3 => Len := Bin3'length ;
  779. when 4 => Len := Bin4'length ;
  780. when 5 => Len := Bin5'length ;
  781. when 6 => Len := Bin6'length ;
  782. when 7 => Len := Bin7'length ;
  783. when 8 => Len := Bin8'length ;
  784. when 9 => Len := Bin9'length ;
  785. when 10 => Len := Bin10'length ;
  786. when 11 => Len := Bin11'length ;
  787. when 12 => Len := Bin12'length ;
  788. when 13 => Len := Bin13'length ;
  789. when 14 => Len := Bin14'length ;
  790. when 15 => Len := Bin15'length ;
  791. when 16 => Len := Bin16'length ;
  792. when 17 => Len := Bin17'length ;
  793. when 18 => Len := Bin18'length ;
  794. when 19 => Len := Bin19'length ;
  795. when 20 => Len := Bin20'length ;
  796. when others => Len := 0 ;
  797. end case ;
  798. result(i) := Len ;
  799. exit when Len = 0 ;
  800. i := i + 1 ;
  801. exit when i = 21 ;
  802. end loop ;
  803. return result(1 to (i-1)) ;
  804. end function BinLengths ;
  805. -- ------------------------------------------------------------
  806. function CalcNumCrossBins ( BinLens : integer_vector ) return integer is
  807. -- package local, used by AddCross
  808. -- ------------------------------------------------------------
  809. variable result : integer := 1 ;
  810. begin
  811. for i in BinLens'range loop
  812. result := result * BinLens(i) ;
  813. end loop ;
  814. return result ;
  815. end function CalcNumCrossBins ;
  816. -- ------------------------------------------------------------
  817. procedure IncBinIndex (
  818. -- package local, used by AddCross
  819. -- ------------------------------------------------------------
  820. variable BinIndex : inout integer_vector ;
  821. constant BinLens : in integer_vector
  822. ) is
  823. alias aBinIndex : integer_vector(1 to BinIndex'length) is BinIndex ;
  824. alias aBinLens : integer_vector(aBinIndex'range) is BinLens ;
  825. begin
  826. -- increment right most one, then if overflow, increment next
  827. -- assumes bins numbered from 1 to N. - assured by ConcatenateBins
  828. for i in aBinIndex'reverse_range loop
  829. aBinIndex(i) := aBinIndex(i) + 1 ;
  830. exit when aBinIndex(i) <= aBinLens(i) ;
  831. aBinIndex(i) := 1 ;
  832. end loop ;
  833. end procedure IncBinIndex ;
  834. -- ------------------------------------------------------------
  835. function ConcatenateBins (
  836. -- package local, used by AddCross
  837. -- ------------------------------------------------------------
  838. BinIndex : integer_vector ;
  839. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  840. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  841. ) return CovBinType is
  842. alias aBin1 : CovBinType (1 to Bin1'length) is Bin1 ;
  843. alias aBin2 : CovBinType (1 to Bin2'length) is Bin2 ;
  844. alias aBin3 : CovBinType (1 to Bin3'length) is Bin3 ;
  845. alias aBin4 : CovBinType (1 to Bin4'length) is Bin4 ;
  846. alias aBin5 : CovBinType (1 to Bin5'length) is Bin5 ;
  847. alias aBin6 : CovBinType (1 to Bin6'length) is Bin6 ;
  848. alias aBin7 : CovBinType (1 to Bin7'length) is Bin7 ;
  849. alias aBin8 : CovBinType (1 to Bin8'length) is Bin8 ;
  850. alias aBin9 : CovBinType (1 to Bin9'length) is Bin9 ;
  851. alias aBin10 : CovBinType (1 to Bin10'length) is Bin10 ;
  852. alias aBin11 : CovBinType (1 to Bin11'length) is Bin11 ;
  853. alias aBin12 : CovBinType (1 to Bin12'length) is Bin12 ;
  854. alias aBin13 : CovBinType (1 to Bin13'length) is Bin13 ;
  855. alias aBin14 : CovBinType (1 to Bin14'length) is Bin14 ;
  856. alias aBin15 : CovBinType (1 to Bin15'length) is Bin15 ;
  857. alias aBin16 : CovBinType (1 to Bin16'length) is Bin16 ;
  858. alias aBin17 : CovBinType (1 to Bin17'length) is Bin17 ;
  859. alias aBin18 : CovBinType (1 to Bin18'length) is Bin18 ;
  860. alias aBin19 : CovBinType (1 to Bin19'length) is Bin19 ;
  861. alias aBin20 : CovBinType (1 to Bin20'length) is Bin20 ;
  862. alias aBinIndex : integer_vector(1 to BinIndex'length) is BinIndex ;
  863. variable result : CovBinType(aBinIndex'range) ;
  864. begin
  865. for i in aBinIndex'range loop
  866. case i is
  867. when 1 => result(i) := aBin1(aBinIndex(i)) ;
  868. when 2 => result(i) := aBin2(aBinIndex(i)) ;
  869. when 3 => result(i) := aBin3(aBinIndex(i)) ;
  870. when 4 => result(i) := aBin4(aBinIndex(i)) ;
  871. when 5 => result(i) := aBin5(aBinIndex(i)) ;
  872. when 6 => result(i) := aBin6(aBinIndex(i)) ;
  873. when 7 => result(i) := aBin7(aBinIndex(i)) ;
  874. when 8 => result(i) := aBin8(aBinIndex(i)) ;
  875. when 9 => result(i) := aBin9(aBinIndex(i)) ;
  876. when 10 => result(i) := aBin10(aBinIndex(i)) ;
  877. when 11 => result(i) := aBin11(aBinIndex(i)) ;
  878. when 12 => result(i) := aBin12(aBinIndex(i)) ;
  879. when 13 => result(i) := aBin13(aBinIndex(i)) ;
  880. when 14 => result(i) := aBin14(aBinIndex(i)) ;
  881. when 15 => result(i) := aBin15(aBinIndex(i)) ;
  882. when 16 => result(i) := aBin16(aBinIndex(i)) ;
  883. when 17 => result(i) := aBin17(aBinIndex(i)) ;
  884. when 18 => result(i) := aBin18(aBinIndex(i)) ;
  885. when 19 => result(i) := aBin19(aBinIndex(i)) ;
  886. when 20 => result(i) := aBin20(aBinIndex(i)) ;
  887. when others => report "ConcatenateBins: More than 20 bins not supported" severity failure ;
  888. end case ;
  889. end loop ;
  890. return result ;
  891. end function ConcatenateBins ;
  892. ------------------------------------------------------------
  893. function MergeState( CrossBins : CovBinType) return integer is
  894. -- package local, Used by AddCross, GenCross
  895. ------------------------------------------------------------
  896. variable resultState : integer ;
  897. begin
  898. resultState := COV_COUNT ;
  899. for i in CrossBins'range loop
  900. if CrossBins(i).action = COV_ILLEGAL then
  901. return COV_ILLEGAL ;
  902. end if ;
  903. if CrossBins(i).action = COV_IGNORE then
  904. resultState := COV_IGNORE ;
  905. end if ;
  906. end loop ;
  907. return resultState ;
  908. end function MergeState ;
  909. ------------------------------------------------------------
  910. function MergeBinVal( CrossBins : CovBinType) return RangeArrayType is
  911. -- package local, Used by AddCross, GenCross
  912. ------------------------------------------------------------
  913. alias aCrossBins : CovBinType(1 to CrossBins'length) is CrossBins ;
  914. variable BinVal : RangeArrayType(aCrossBins'range) ;
  915. begin
  916. for i in aCrossBins'range loop
  917. BinVal(i to i) := aCrossBins(i).BinVal ;
  918. end loop ;
  919. return BinVal ;
  920. end function MergeBinVal ;
  921. ------------------------------------------------------------
  922. function MergeAtLeast(
  923. -- package local, Used by AddCross, GenCross
  924. ------------------------------------------------------------
  925. Action : in integer ;
  926. AtLeast : in integer ;
  927. CrossBins : in CovBinType
  928. ) return integer is
  929. variable Result : integer := AtLeast ;
  930. begin
  931. if Action /= COV_COUNT then
  932. return 0 ;
  933. end if ;
  934. for i in CrossBins'range loop
  935. if CrossBins(i).Action = Action then
  936. Result := maximum (Result, CrossBins(i).AtLeast) ;
  937. end if ;
  938. end loop ;
  939. return result ;
  940. end function MergeAtLeast ;
  941. ------------------------------------------------------------
  942. function MergeWeight(
  943. -- package local, Used by AddCross, GenCross
  944. ------------------------------------------------------------
  945. Action : in integer ;
  946. Weight : in integer ;
  947. CrossBins : in CovBinType
  948. ) return integer is
  949. variable Result : integer := Weight ;
  950. begin
  951. if Action /= COV_COUNT then
  952. return 0 ;
  953. end if ;
  954. for i in CrossBins'range loop
  955. if CrossBins(i).Action = Action then
  956. Result := maximum (Result, CrossBins(i).Weight) ;
  957. end if ;
  958. end loop ;
  959. return result ;
  960. end function MergeWeight ;
  961. ------------------------------------------------------------
  962. function ToMinPoint (A : RangeArrayType) return integer is
  963. -- Used in testing
  964. ------------------------------------------------------------
  965. begin
  966. return A(A'left).min ;
  967. end function ToMinPoint ;
  968. ------------------------------------------------------------
  969. function ToMinPoint (A : RangeArrayType) return integer_vector is
  970. -- Used in testing
  971. ------------------------------------------------------------
  972. variable result : integer_vector(A'range) ;
  973. begin
  974. for i in A'range loop
  975. result(i) := A(i).min ;
  976. end loop ;
  977. return result ;
  978. end function ToMinPoint ;
  979. ------------------------------------------------------------
  980. procedure ToRandPoint(
  981. ------------------------------------------------------------
  982. variable RV : inout RandomPType ;
  983. constant BinVal : in RangeArrayType ;
  984. variable result : out integer
  985. ) is
  986. begin
  987. result := RV.RandInt(BinVal(BinVal'left).min, BinVal(BinVal'left).max) ;
  988. end procedure ToRandPoint ;
  989. ------------------------------------------------------------
  990. procedure ToRandPoint(
  991. ------------------------------------------------------------
  992. variable RV : inout RandomPType ;
  993. constant BinVal : in RangeArrayType ;
  994. variable result : out integer_vector
  995. ) is
  996. variable VectorVal : integer_vector(BinVal'range) ;
  997. begin
  998. for i in BinVal'range loop
  999. VectorVal(i) := RV.RandInt(BinVal(i).min, BinVal(i).max) ;
  1000. end loop ;
  1001. result := VectorVal ;
  1002. end procedure ToRandPoint ;
  1003. ------------------------------------------------------------------------------------------
  1004. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1005. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1006. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  1007. ------------------------------------------------------------------------------------------
  1008. type CovPType is protected body
  1009. -- Name Data Structure
  1010. variable Message : MessagePType ;
  1011. -- CoverageBin Data Structures
  1012. type RangeArrayPtrType is access RangeArrayType ;
  1013. type CovBinBaseTempType is record
  1014. BinVal : RangeArrayPtrType ;
  1015. Action : integer ;
  1016. Count : integer ;
  1017. AtLeast : integer ;
  1018. Weight : integer ;
  1019. PercentCov : real ;
  1020. OrderCount : integer ;
  1021. end record CovBinBaseTempType ;
  1022. type CovBinTempType is array (natural range <>) of CovBinBaseTempType ;
  1023. type CovBinPtrType is access CovBinTempType ;
  1024. variable CovBinPtr : CovBinPtrType ;
  1025. variable NumBins : integer := 0 ;
  1026. variable BinValLength : integer := 1 ;
  1027. variable OrderCount : integer := 0 ; -- for statistics
  1028. variable ItemCount : integer := 0 ; -- Count of randomizations
  1029. variable LastIndex : integer := 1 ; -- Index of last randomization
  1030. -- Internal Modes and Names
  1031. variable IllegalMode : IllegalModeType := ILLEGAL_ON ;
  1032. variable WeightMode : WeightModeType := AT_LEAST ;
  1033. variable WeightScale : real := 1.0 ;
  1034. variable ThresholdingEnable : boolean := FALSE ; -- thresholding disabled by default
  1035. variable CovThreshold : real := 45.0 ;
  1036. variable CovTarget : real := 100.0 ;
  1037. variable MergingEnable : boolean := FALSE ; -- merging disabled by default
  1038. variable CountMode : CountModeType := COUNT_FIRST ;
  1039. -- Randomization Variable
  1040. variable RV : RandomPType ;
  1041. variable RvSeedInit : boolean := FALSE ;
  1042. file WriteBinFile : text ;
  1043. variable WriteBinFileInit : boolean := FALSE ;
  1044. -- file WriteCovDbFile : text ;
  1045. -- variable WriteCovDbFileInit : boolean := FALSE ;
  1046. ------------------------------------------------------------
  1047. procedure FileOpenWriteBin (FileName : string; OpenKind : File_Open_Kind ) is
  1048. ------------------------------------------------------------
  1049. begin
  1050. WriteBinFileInit := TRUE ;
  1051. file_open( WriteBinFile , FileName , OpenKind );
  1052. end procedure FileOpenWriteBin ;
  1053. ------------------------------------------------------------
  1054. procedure FileCloseWriteBin is
  1055. ------------------------------------------------------------
  1056. begin
  1057. WriteBinFileInit := FALSE ;
  1058. file_close( WriteBinFile) ;
  1059. end procedure FileCloseWriteBin ;
  1060. -- ------------------------------------------------------------
  1061. -- procedure FileOpenWriteCovDb (FileName : string; OpenKind : File_Open_Kind ) is
  1062. -- ------------------------------------------------------------
  1063. -- begin
  1064. -- WriteCovDbFileInit := TRUE ;
  1065. -- file_open( WriteCovDbFile , FileName , OpenKind );
  1066. -- end procedure FileOpenWriteCovDb ;
  1067. --
  1068. -- ------------------------------------------------------------
  1069. -- procedure FileCloseWriteCovDb is
  1070. -- ------------------------------------------------------------
  1071. -- begin
  1072. -- WriteCovDbFileInit := FALSE ;
  1073. -- file_close( WriteCovDbFile );
  1074. -- end procedure FileCloseWriteCovDb ;
  1075. ------------------------------------------------------------
  1076. procedure SetIllegalMode (A : IllegalModeType) is
  1077. ------------------------------------------------------------
  1078. begin
  1079. IllegalMode := A ;
  1080. end procedure SetIllegalMode ;
  1081. ------------------------------------------------------------
  1082. procedure SetWeightMode (A : WeightModeType; Scale : real := 1.0) is
  1083. ------------------------------------------------------------
  1084. variable buf : line ;
  1085. begin
  1086. WeightMode := A ;
  1087. WeightScale := Scale ;
  1088. if (WeightMode = REMAIN_EXP) and (WeightScale > 2.0) then
  1089. swrite(buf, "%%WARNING: WeightScale > 2.0 and large Counts can cause RandCovPoint to fail due to integer values out of range") ;
  1090. writeline(OUTPUT, buf) ;
  1091. end if ;
  1092. if (WeightScale < 1.0) and (WeightMode = REMAIN_WEIGHT or WeightMode = REMAIN_SCALED) then
  1093. report "WeightScale must be > 1.0 when WeightMode = REMAIN_WEIGHT or WeightMode = REMAIN_SCALED"
  1094. severity failure ;
  1095. WeightScale := 1.0 ;
  1096. end if;
  1097. if WeightScale <= 0.0 then
  1098. report "WeightScale must be > 0.0" severity failure ;
  1099. WeightScale := 1.0 ;
  1100. end if;
  1101. end procedure SetWeightMode ;
  1102. ------------------------------------------------------------
  1103. procedure SetName (NameIn : String) is
  1104. ------------------------------------------------------------
  1105. begin
  1106. Message.SetName(NameIn) ;
  1107. if not RvSeedInit then -- Init seed if not initialized
  1108. RV.InitSeed(NameIn) ;
  1109. RvSeedInit := TRUE ;
  1110. end if ;
  1111. end procedure SetName ;
  1112. ------------------------------------------------------------
  1113. procedure SetMessage (MessageIn : String) is
  1114. ------------------------------------------------------------
  1115. begin
  1116. Message.SetMessage(MessageIn) ;
  1117. if not RvSeedInit then -- Init seed if not initialized
  1118. RV.InitSeed(MessageIn) ;
  1119. RvSeedInit := TRUE ;
  1120. end if ;
  1121. end procedure SetMessage ;
  1122. ------------------------------------------------------------
  1123. -- pt local for now -- file formal parameter not allowed with a public method
  1124. procedure WriteBinName ( file f : text ; S : string ; Prefix : string := "%%" ) is
  1125. ------------------------------------------------------------
  1126. variable MessageCount : integer ;
  1127. variable buf : line ;
  1128. begin
  1129. MessageCount := Message.GetMessageCount ;
  1130. if MessageCount = 0 then
  1131. if Prefix'length + S'length > 0 then
  1132. write(buf, Prefix & S) ;
  1133. writeline(f, buf) ;
  1134. -- write(f, Prefix & S & LF);
  1135. end if ;
  1136. else
  1137. write(buf, Prefix & S & Message.GetMessage(1)) ;
  1138. writeline(f, buf) ;
  1139. for i in 2 to MessageCount loop
  1140. write(buf, Prefix & Message.GetMessage(i)) ;
  1141. writeline(f, buf) ;
  1142. end loop ;
  1143. end if ;
  1144. end procedure WriteBinName ;
  1145. ------------------------------------------------------------
  1146. procedure DeallocateMessage is
  1147. ------------------------------------------------------------
  1148. begin
  1149. Message.DeallocateMessage ;
  1150. end procedure DeallocateMessage ;
  1151. ------------------------------------------------------------
  1152. procedure DeallocateName is
  1153. ------------------------------------------------------------
  1154. begin
  1155. Message.DeallocateName ;
  1156. end procedure DeallocateName ;
  1157. ------------------------------------------------------------
  1158. procedure SetThresholding (A : boolean := TRUE ) is
  1159. ------------------------------------------------------------
  1160. begin
  1161. ThresholdingEnable := A ;
  1162. end procedure SetThresholding ;
  1163. ------------------------------------------------------------
  1164. procedure SetCovThreshold (Percent : real) is
  1165. ------------------------------------------------------------
  1166. begin
  1167. ThresholdingEnable := TRUE ;
  1168. if Percent >= 0.0 then
  1169. CovThreshold := Percent + 0.0001 ; -- used in less than
  1170. else
  1171. CovThreshold := 0.0001 ; -- used in less than
  1172. report "Invalid Threshold Value " & real'image(Percent) severity failure ;
  1173. end if ;
  1174. end procedure SetCovThreshold ;
  1175. ------------------------------------------------------------
  1176. procedure SetCovTarget (Percent : real) is
  1177. ------------------------------------------------------------
  1178. begin
  1179. CovTarget := Percent ;
  1180. end procedure SetCovTarget ;
  1181. ------------------------------------------------------------
  1182. impure function GetCovTarget return real is
  1183. ------------------------------------------------------------
  1184. begin
  1185. return CovTarget ;
  1186. end function GetCovTarget ;
  1187. ------------------------------------------------------------
  1188. procedure SetMerging (A : boolean := TRUE ) is
  1189. ------------------------------------------------------------
  1190. begin
  1191. MergingEnable := A ;
  1192. end procedure SetMerging ;
  1193. ------------------------------------------------------------
  1194. procedure SetCountMode (A : CountModeType) is
  1195. ------------------------------------------------------------
  1196. begin
  1197. CountMode := A ;
  1198. end procedure SetCountMode ;
  1199. ------------------------------------------------------------
  1200. procedure InitSeed (S : string ) is
  1201. ------------------------------------------------------------
  1202. begin
  1203. RV.InitSeed(S) ;
  1204. RvSeedInit := TRUE ;
  1205. end procedure InitSeed ;
  1206. ------------------------------------------------------------
  1207. procedure InitSeed (I : integer ) is
  1208. ------------------------------------------------------------
  1209. begin
  1210. RV.InitSeed(I) ;
  1211. RvSeedInit := TRUE ;
  1212. end procedure InitSeed ;
  1213. ------------------------------------------------------------
  1214. procedure SetSeed (RandomSeedIn : RandomSeedType ) is
  1215. ------------------------------------------------------------
  1216. begin
  1217. RV.SetSeed(RandomSeedIn) ;
  1218. RvSeedInit := TRUE ;
  1219. end procedure SetSeed ;
  1220. ------------------------------------------------------------
  1221. impure function GetSeed return RandomSeedType is
  1222. ------------------------------------------------------------
  1223. begin
  1224. return RV.GetSeed ;
  1225. end function GetSeed ;
  1226. ------------------------------------------------------------
  1227. procedure SetBinSize (NewNumBins : integer) is
  1228. -- Sets a CovBin to a particular size
  1229. -- Use for small bins to save space or large bins to
  1230. -- suppress the resize and copy as a CovBin autosizes.
  1231. ------------------------------------------------------------
  1232. variable oldCovBinPtr : CovBinPtrType ;
  1233. begin
  1234. if CovBinPtr = NULL then
  1235. CovBinPtr := new CovBinTempType(1 to NewNumBins) ;
  1236. elsif NewNumBins > CovBinPtr'length then
  1237. -- make message bigger
  1238. oldCovBinPtr := CovBinPtr ;
  1239. CovBinPtr := new CovBinTempType(1 to NewNumBins) ;
  1240. CovBinPtr.all(1 to NumBins) := oldCovBinPtr.all(1 to NumBins) ;
  1241. deallocate(oldCovBinPtr) ;
  1242. end if ;
  1243. end procedure SetBinSize ;
  1244. ------------------------------------------------------------
  1245. -- pt local
  1246. procedure CheckBinValLength( CurBinValLength : integer ; Caller : string ) is
  1247. begin
  1248. if NumBins = 0 then
  1249. BinValLength := CurBinValLength ; -- number of points in cross
  1250. else
  1251. assert BinValLength = CurBinValLength
  1252. report Caller & ": Cross bins with different sizes prohibited"
  1253. severity failure ;
  1254. end if;
  1255. end procedure CheckBinValLength ;
  1256. ------------------------------------------------------------
  1257. -- pt local
  1258. impure function NormalizeNumBins( ReqNumBins : integer ) return integer is
  1259. variable NormNumBins : integer := MIN_NUM_BINS ;
  1260. begin
  1261. while NormNumBins < ReqNumBins loop
  1262. NormNumBins := NormNumBins + MIN_NUM_BINS ;
  1263. end loop ;
  1264. return NormNumBins ;
  1265. end function NormalizeNumBins ;
  1266. ------------------------------------------------------------
  1267. -- pt local
  1268. procedure GrowBins (ReqNumBins : integer) is
  1269. variable oldCovBinPtr : CovBinPtrType ;
  1270. variable NewNumBins : integer ;
  1271. begin
  1272. NewNumBins := NumBins + ReqNumBins ;
  1273. if CovBinPtr = NULL then
  1274. CovBinPtr := new CovBinTempType(1 to NormalizeNumBins(NewNumBins)) ;
  1275. elsif NewNumBins > CovBinPtr'length then
  1276. -- make message bigger
  1277. oldCovBinPtr := CovBinPtr ;
  1278. CovBinPtr := new CovBinTempType(1 to NormalizeNumBins(NewNumBins)) ;
  1279. CovBinPtr.all(1 to NumBins) := oldCovBinPtr.all(1 to NumBins) ;
  1280. deallocate(oldCovBinPtr) ;
  1281. end if ;
  1282. end procedure GrowBins ;
  1283. ------------------------------------------------------------
  1284. -- pt local, called by InsertBin
  1285. -- Finds index of bin if it is inside an existing bins
  1286. procedure FindBinInside(
  1287. BinVal : RangeArrayType ;
  1288. Position : out integer ;
  1289. FoundInside : out boolean
  1290. ) is
  1291. begin
  1292. Position := NumBins + 1 ;
  1293. FoundInside := FALSE ;
  1294. FindLoop : for i in NumBins downto 1 loop
  1295. -- skip this CovBin if CovPoint is not in it
  1296. next FindLoop when not inside(BinVal, CovBinPtr(i).BinVal.all) ;
  1297. Position := i ;
  1298. FoundInside := TRUE ;
  1299. exit ;
  1300. end loop ;
  1301. end procedure FindBinInside ;
  1302. ------------------------------------------------------------
  1303. -- pt local
  1304. -- Inserts values into a new bin.
  1305. -- Called by InsertBin
  1306. procedure InsertNewBin(
  1307. BinVal : RangeArrayType ;
  1308. Action : integer ;
  1309. Count : integer ;
  1310. AtLeast : integer ;
  1311. Weight : integer ;
  1312. PercentCov : real := 0.0
  1313. ) is
  1314. begin
  1315. NumBins := NumBins + 1 ;
  1316. CovBinPtr.all(NumBins).BinVal := new RangeArrayType'(BinVal) ;
  1317. CovBinPtr.all(NumBins).Action := Action ;
  1318. CovBinPtr.all(NumBins).Count := Count ;
  1319. CovBinPtr.all(NumBins).AtLeast := AtLeast ;
  1320. CovBinPtr.all(NumBins).Weight := Weight ;
  1321. CovBinPtr.all(NumBins).PercentCov := PercentCov ;
  1322. CovBinPtr.all(NumBins).OrderCount := 0 ; --- Metrics for evaluating randomization order Temp
  1323. end procedure InsertNewBin ;
  1324. ------------------------------------------------------------
  1325. -- pt local
  1326. -- Inserts values into a new bin.
  1327. -- Called by InsertBin
  1328. procedure MergeBin (
  1329. Position : Natural ;
  1330. Count : integer ;
  1331. AtLeast : integer ;
  1332. Weight : integer
  1333. ) is
  1334. begin
  1335. CovBinPtr.all(Position).Count := CovBinPtr.all(Position).Count + Count ;
  1336. CovBinPtr.all(Position).AtLeast := CovBinPtr.all(Position).AtLeast + AtLeast ;
  1337. CovBinPtr.all(Position).Weight := CovBinPtr.all(Position).Weight + Weight ;
  1338. CovBinPtr.all(Position).PercentCov :=
  1339. real(CovBinPtr.all(Position).Count)*100.0/maximum(real(CovBinPtr.all(Position).AtLeast), 1.0) ;
  1340. end procedure MergeBin ;
  1341. ------------------------------------------------------------
  1342. -- pt local
  1343. -- All insertion comes here
  1344. -- Enforces the general insertion use model:
  1345. -- Earlier bins supercede later bins - except with COUNT_ALL
  1346. -- Add Illegal and Ignore bins first to remove regions of larger count bins
  1347. -- Later ignore bins can be used to miss an illegal catch-all
  1348. -- Add Illegal bins last as a catch-all to find things that missed other bins
  1349. procedure InsertBin(
  1350. BinVal : RangeArrayType ;
  1351. Action : integer ;
  1352. Count : integer ;
  1353. AtLeast : integer ;
  1354. Weight : integer ;
  1355. PercentCov : real := 0.0
  1356. ) is
  1357. variable Position : integer ;
  1358. variable FoundInside : boolean ;
  1359. begin
  1360. if not MergingEnable then
  1361. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  1362. else -- handle merging
  1363. -- future optimization, FindBinInside only checks against Ignore and Illegal bins
  1364. FindBinInside(BinVal, Position, FoundInside) ;
  1365. if not FoundInside then
  1366. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  1367. elsif Action = COV_COUNT then
  1368. -- when check only ignore and illegal bins, only action is to drop
  1369. if CovBinPtr.all(Position).Action /= COV_COUNT then
  1370. null ; -- drop count bin when it is inside a Illegal or Ignore bin
  1371. elsif CovBinPtr.all(Position).BinVal.all = BinVal then
  1372. -- Bins match, so merge the count values
  1373. MergeBin (Position, Count, AtLeast, Weight) ;
  1374. else
  1375. -- Bins overlap, but do not match, insert new bin
  1376. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  1377. end if;
  1378. elsif Action = COV_IGNORE then
  1379. -- when check only ignore and illegal bins, only action is to report error
  1380. if CovBinPtr.all(Position).Action = COV_COUNT then
  1381. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  1382. else
  1383. report "InsertBin (AddBins/AddCross): ignore bin dropped. It is a subset of prior bin" severity error ;
  1384. end if;
  1385. elsif Action = COV_ILLEGAL then
  1386. -- when check only ignore and illegal bins, only action is to report error
  1387. if CovBinPtr.all(Position).Action = COV_COUNT then
  1388. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  1389. else
  1390. report "InsertBin (AddBins/AddCross): illegal bin dropped. It is a subset of prior bin" severity error ;
  1391. end if;
  1392. end if ;
  1393. end if ; -- merging enabled
  1394. end procedure InsertBin ;
  1395. ------------------------------------------------------------
  1396. procedure AddBins (
  1397. ------------------------------------------------------------
  1398. AtLeast : integer ;
  1399. Weight : integer ;
  1400. CovBin : CovBinType
  1401. ) is
  1402. variable calcAtLeast : integer ;
  1403. variable calcWeight : integer ;
  1404. begin
  1405. CheckBinValLength( 1, "AddBins") ;
  1406. GrowBins(CovBin'length) ;
  1407. for i in CovBin'range loop
  1408. if CovBin(i).Action = COV_COUNT then
  1409. calcAtLeast := maximum(AtLeast, CovBin(i).AtLeast) ;
  1410. calcWeight := maximum(Weight, CovBin(i).Weight) ;
  1411. else
  1412. calcAtLeast := 0 ;
  1413. calcWeight := 0 ;
  1414. end if ;
  1415. InsertBin(
  1416. BinVal => CovBin(i).BinVal,
  1417. Action => CovBin(i).Action,
  1418. Count => CovBin(i).Count,
  1419. AtLeast => calcAtLeast,
  1420. Weight => calcWeight
  1421. ) ;
  1422. end loop ;
  1423. end procedure AddBins ;
  1424. ------------------------------------------------------------
  1425. procedure AddBins (AtLeast : integer ; CovBin : CovBinType) is
  1426. ------------------------------------------------------------
  1427. begin
  1428. AddBins(AtLeast, 0, CovBin) ;
  1429. end procedure AddBins ;
  1430. ------------------------------------------------------------
  1431. procedure AddBins (CovBin : CovBinType) is
  1432. ------------------------------------------------------------
  1433. begin
  1434. AddBins(0, 0, CovBin) ;
  1435. end procedure AddBins ;
  1436. ------------------------------------------------------------
  1437. procedure AddCross(
  1438. -- Cross existing bins
  1439. ------------------------------------------------------------
  1440. AtLeast : integer ;
  1441. Weight : integer ;
  1442. Bin1, Bin2 : CovBinType ;
  1443. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1444. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1445. ) is
  1446. constant BIN_LENS : integer_vector :=
  1447. BinLengths(
  1448. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1449. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1450. ) ;
  1451. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  1452. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  1453. variable CrossBins : CovBinType(BinIndex'range) ;
  1454. variable calcAction, calcCount, calcAtLeast, calcWeight : integer ;
  1455. variable calcBinVal : RangeArrayType(BinIndex'range) ;
  1456. begin
  1457. CheckBinValLength( BIN_LENS'length, "AddCross") ;
  1458. GrowBins(NUM_NEW_BINS) ;
  1459. calcCount := 0 ;
  1460. for MatrixIndex in 1 to NUM_NEW_BINS loop
  1461. CrossBins := ConcatenateBins(BinIndex,
  1462. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1463. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1464. ) ;
  1465. calcAction := MergeState(CrossBins) ;
  1466. calcBinVal := MergeBinVal(CrossBins) ;
  1467. calcAtLeast := MergeAtLeast( calcAction, AtLeast, CrossBins) ;
  1468. calcWeight := MergeWeight ( calcAction, Weight, CrossBins) ;
  1469. InsertBin(calcBinVal, calcAction, calcCount, calcAtLeast, calcWeight) ;
  1470. IncBinIndex( BinIndex, BIN_LENS) ; -- increment right most one, then if overflow, increment next
  1471. end loop ;
  1472. end procedure AddCross ;
  1473. ------------------------------------------------------------
  1474. procedure AddCross(
  1475. -- Cross existing bins
  1476. ------------------------------------------------------------
  1477. AtLeast : integer ;
  1478. Bin1, Bin2 : CovBinType ;
  1479. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1480. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1481. ) is
  1482. begin
  1483. AddCross(AtLeast, 0,
  1484. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1485. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1486. ) ;
  1487. end procedure AddCross ;
  1488. ------------------------------------------------------------
  1489. procedure AddCross(
  1490. -- Cross existing bins
  1491. ------------------------------------------------------------
  1492. Bin1, Bin2 : CovBinType ;
  1493. Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11, Bin12, Bin13,
  1494. Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20 : CovBinType := NULL_BIN
  1495. ) is
  1496. begin
  1497. AddCross(0, 0,
  1498. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9, Bin10, Bin11,
  1499. Bin12, Bin13, Bin14, Bin15, Bin16, Bin17, Bin18, Bin19, Bin20
  1500. ) ;
  1501. end procedure AddCross ;
  1502. ------------------------------------------------------------
  1503. procedure Deallocate is
  1504. ------------------------------------------------------------
  1505. begin
  1506. for i in 1 to NumBins loop
  1507. deallocate(CovBinPtr(i).BinVal) ;
  1508. end loop ;
  1509. deallocate(CovBinPtr) ;
  1510. Message.Deallocate ;
  1511. -- Restore internal variables to their default values
  1512. NumBins := 0 ;
  1513. OrderCount := 0 ;
  1514. BinValLength := 1 ;
  1515. IllegalMode := ILLEGAL_ON ;
  1516. WeightMode := AT_LEAST ;
  1517. WeightScale := 1.0 ;
  1518. ThresholdingEnable := FALSE ;
  1519. CovThreshold := 45.0 ;
  1520. CovTarget := 100.0 ;
  1521. MergingEnable := FALSE ;
  1522. CountMode := COUNT_FIRST ;
  1523. -- RvSeedInit := FALSE ;
  1524. end procedure deallocate ;
  1525. ------------------------------------------------------------
  1526. -- Local
  1527. procedure ICoverIndex( Index : integer ; CovPoint : integer_vector ) is
  1528. ------------------------------------------------------------
  1529. variable buf : line ;
  1530. begin
  1531. -- Update Count, PercentCov
  1532. CovBinPtr(Index).Count := CovBinPtr(Index).Count + CovBinPtr(Index).action ;
  1533. CovBinPtr(Index).PercentCov := real(CovBinPtr(Index).Count)*100.0/maximum(real(CovBinPtr(Index).AtLeast), 1.0) ;
  1534. -- OrderCount handling - Statistics
  1535. OrderCount := OrderCount + 1 ;
  1536. CovBinPtr(Index).OrderCount := OrderCount + CovBinPtr(Index).OrderCount ;
  1537. if CovBinPtr(Index).action = COV_ILLEGAL and IllegalMode /= ILLEGAL_OFF then
  1538. write(buf, "%% " & Message.GetName & " Illegal Value: " ) ;
  1539. if CovPoint = NULL_INTV then
  1540. swrite(buf, "LastIndex Value") ;
  1541. else
  1542. write(buf, CovPoint) ;
  1543. end if ;
  1544. write(buf, " is in an illegal Bin. " & "Time: " & time'image(now)) ;
  1545. writeline(OUTPUT, buf) ;
  1546. if IllegalMode = ILLEGAL_FAILURE then
  1547. report Message.GetName & " Illegal Value" severity failure ;
  1548. end if ;
  1549. end if ;
  1550. end procedure ICoverIndex ;
  1551. ------------------------------------------------------------
  1552. procedure ICoverLast is
  1553. ------------------------------------------------------------
  1554. begin
  1555. ICoverIndex(LastIndex, NULL_INTV) ;
  1556. end procedure ICoverLast ;
  1557. ------------------------------------------------------------
  1558. procedure ICover ( CovPoint : integer) is
  1559. ------------------------------------------------------------
  1560. begin
  1561. ICover((1=> CovPoint)) ;
  1562. end procedure ICover ;
  1563. ------------------------------------------------------------
  1564. procedure ICover( CovPoint : integer_vector) is
  1565. ------------------------------------------------------------
  1566. variable Found : boolean := FALSE ;
  1567. begin
  1568. if CountMode = COUNT_FIRST and inside(CovPoint, CovBinPtr(LastIndex).BinVal.all) then
  1569. ICoverIndex(LastIndex, CovPoint) ;
  1570. Found := TRUE ;
  1571. end if;
  1572. if not Found then
  1573. CovLoop : for i in 1 to NumBins loop
  1574. -- skip this CovBin if CovPoint is not in it
  1575. next CovLoop when not inside(CovPoint, CovBinPtr(i).BinVal.all) ;
  1576. -- Mark Covered
  1577. ICoverIndex(i, CovPoint) ;
  1578. exit CovLoop when CountMode = COUNT_FIRST ; -- only find first one
  1579. end loop CovLoop ;
  1580. end if ;
  1581. end procedure ICover ;
  1582. ------------------------------------------------------------
  1583. procedure SetCovZero is
  1584. ------------------------------------------------------------
  1585. begin
  1586. for i in 1 to NumBins loop
  1587. CovBinPtr(i).Count := 0 ;
  1588. CovBinPtr(i).PercentCov := 0.0 ;
  1589. CovBinPtr(i).OrderCount := 0 ;
  1590. end loop ;
  1591. OrderCount := 0 ;
  1592. end procedure SetCovZero ;
  1593. ------------------------------------------------------------
  1594. impure function IsInitialized return boolean is
  1595. ------------------------------------------------------------
  1596. begin
  1597. return NumBins > 0 ;
  1598. end function IsInitialized ;
  1599. ------------------------------------------------------------
  1600. impure function GetNumBins return integer is
  1601. ------------------------------------------------------------
  1602. begin
  1603. return NumBins ;
  1604. end function GetNumBins ;
  1605. ------------------------------------------------------------
  1606. impure function GetMinIndex return integer is
  1607. ------------------------------------------------------------
  1608. variable MinCov : real := real'right ; -- big number
  1609. variable MinIndex : integer := NumBins ;
  1610. begin
  1611. CovLoop : for i in 1 to NumBins loop
  1612. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MinCov then
  1613. MinCov := CovBinPtr(i).PercentCov ;
  1614. MinIndex := i ;
  1615. end if ;
  1616. end loop CovLoop ;
  1617. return MinIndex ;
  1618. end function GetMinIndex ;
  1619. ------------------------------------------------------------
  1620. impure function GetMinCov return real is
  1621. ------------------------------------------------------------
  1622. variable MinCov : real := real'right ; -- big number
  1623. begin
  1624. CovLoop : for i in 1 to NumBins loop
  1625. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MinCov then
  1626. MinCov := CovBinPtr(i).PercentCov ;
  1627. end if ;
  1628. end loop CovLoop ;
  1629. return MinCov ;
  1630. end function GetMinCov ;
  1631. ------------------------------------------------------------
  1632. impure function GetMinCount return integer is
  1633. ------------------------------------------------------------
  1634. variable MinCount : integer := integer'right ; -- big number
  1635. begin
  1636. CovLoop : for i in 1 to NumBins loop
  1637. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < MinCount then
  1638. MinCount := CovBinPtr(i).Count ;
  1639. end if ;
  1640. end loop CovLoop ;
  1641. return MinCount ;
  1642. end function GetMinCount ;
  1643. ------------------------------------------------------------
  1644. impure function GetMaxIndex return integer is
  1645. ------------------------------------------------------------
  1646. variable MaxCov : real := 0.0 ;
  1647. variable MaxIndex : integer := NumBins ;
  1648. begin
  1649. CovLoop : for i in 1 to NumBins loop
  1650. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov > MaxCov then
  1651. MaxCov := CovBinPtr(i).PercentCov ;
  1652. MaxIndex := i ;
  1653. end if ;
  1654. end loop CovLoop ;
  1655. return MaxIndex ;
  1656. end function GetMaxIndex ;
  1657. ------------------------------------------------------------
  1658. impure function GetMaxCov return real is
  1659. ------------------------------------------------------------
  1660. variable MaxCov : real := 0.0 ;
  1661. begin
  1662. CovLoop : for i in 1 to NumBins loop
  1663. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov > MaxCov then
  1664. MaxCov := CovBinPtr(i).PercentCov ;
  1665. end if ;
  1666. end loop CovLoop ;
  1667. return MaxCov ;
  1668. end function GetMaxCov ;
  1669. ------------------------------------------------------------
  1670. impure function GetMaxCount return integer is
  1671. ------------------------------------------------------------
  1672. variable MaxCount : integer := 0 ;
  1673. begin
  1674. CovLoop : for i in 1 to NumBins loop
  1675. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count > MaxCount then
  1676. MaxCount := CovBinPtr(i).Count ;
  1677. end if ;
  1678. end loop CovLoop ;
  1679. return MaxCount ;
  1680. end function GetMaxCount ;
  1681. ------------------------------------------------------------
  1682. impure function CountCovHoles ( PercentCov : real ) return integer is
  1683. ------------------------------------------------------------
  1684. variable HoleCount : integer := 0 ;
  1685. begin
  1686. CovLoop : for i in 1 to NumBins loop
  1687. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  1688. HoleCount := HoleCount + 1 ;
  1689. end if ;
  1690. end loop CovLoop ;
  1691. return HoleCount ;
  1692. end function CountCovHoles ;
  1693. ------------------------------------------------------------
  1694. impure function CountCovHoles return integer is
  1695. ------------------------------------------------------------
  1696. begin
  1697. return CountCovHoles(CovTarget) ;
  1698. end function CountCovHoles ;
  1699. ------------------------------------------------------------
  1700. impure function IsCovered ( PercentCov : real ) return boolean is
  1701. ------------------------------------------------------------
  1702. begin
  1703. -- assert NumBins >= 1 report "IsCovered: Empty Coverage Model" severity failure ;
  1704. return CountCovHoles(PercentCov) = 0 ;
  1705. end function IsCovered ;
  1706. ------------------------------------------------------------
  1707. impure function IsCovered return boolean is
  1708. ------------------------------------------------------------
  1709. begin
  1710. -- assert NumBins >= 1 report "IsCovered: Empty Coverage Model" severity failure ;
  1711. return CountCovHoles(CovTarget) = 0 ;
  1712. end function IsCovered ;
  1713. ------------------------------------------------------------
  1714. impure function GetCov ( PercentCov : real ) return real is
  1715. ------------------------------------------------------------
  1716. variable TotalCovGoal, TotalCovCount, ScaledCovGoal : integer := 0 ;
  1717. begin
  1718. BinLoop : for i in 1 to NumBins loop
  1719. if CovBinPtr(i).action = COV_COUNT then
  1720. ScaledCovGoal := integer(ceil(PercentCov * real(CovBinPtr(i).AtLeast)/100.0)) ;
  1721. TotalCovGoal := TotalCovGoal + ScaledCovGoal ;
  1722. if CovBinPtr(i).Count <= ScaledCovGoal then
  1723. TotalCovCount := TotalCovCount + CovBinPtr(i).Count ;
  1724. else
  1725. -- do not count the extra values that exceed their cov goal
  1726. TotalCovCount := TotalCovCount + ScaledCovGoal ;
  1727. end if ;
  1728. end if ;
  1729. end loop BinLoop ;
  1730. return 100.0 * real(TotalCovCount) / real(TotalCovGoal) ;
  1731. end function GetCov ;
  1732. ------------------------------------------------------------
  1733. impure function GetCov return real is
  1734. ------------------------------------------------------------
  1735. variable TotalCovGoal, TotalCovCount : integer := 0 ;
  1736. begin
  1737. return GetCov( CovTarget ) ;
  1738. end function GetCov ;
  1739. ------------------------------------------------------------
  1740. impure function GetItemCount return integer is
  1741. ------------------------------------------------------------
  1742. begin
  1743. return ItemCount ;
  1744. end function GetItemCount ;
  1745. ------------------------------------------------------------
  1746. impure function GetTotalCovGoal ( PercentCov : real ) return integer is
  1747. ------------------------------------------------------------
  1748. variable TotalCovGoal, ScaledCovGoal : integer := 0 ;
  1749. begin
  1750. BinLoop : for i in 1 to NumBins loop
  1751. if CovBinPtr(i).action = COV_COUNT then
  1752. ScaledCovGoal := integer(ceil(PercentCov * real(CovBinPtr(i).AtLeast)/100.0)) ;
  1753. TotalCovGoal := TotalCovGoal + ScaledCovGoal ;
  1754. end if ;
  1755. end loop BinLoop ;
  1756. return TotalCovGoal ;
  1757. end function GetTotalCovGoal ;
  1758. ------------------------------------------------------------
  1759. impure function GetTotalCovGoal return integer is
  1760. ------------------------------------------------------------
  1761. begin
  1762. return GetTotalCovGoal(CovTarget) ;
  1763. end function GetTotalCovGoal ;
  1764. ------------------------------------------------------------
  1765. impure function GetLastIndex return integer is
  1766. ------------------------------------------------------------
  1767. begin
  1768. return LastIndex ;
  1769. end function GetLastIndex ;
  1770. ------------------------------------------------------------
  1771. impure function GetHoleBinVal ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType is
  1772. ------------------------------------------------------------
  1773. variable HoleCount : integer := 0 ;
  1774. variable buf : line ;
  1775. begin
  1776. CovLoop : for i in 1 to NumBins loop
  1777. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  1778. HoleCount := HoleCount + 1 ;
  1779. if HoleCount = ReqHoleNum then
  1780. return CovBinPtr(i).BinVal.all ;
  1781. end if ;
  1782. end if ;
  1783. end loop CovLoop ;
  1784. write(buf, "%%Error GetHoleBinVal did not find hole. " &
  1785. "HoleCount = " & integer'image(HoleCount) &
  1786. "ReqHoleNum = " & integer'image(ReqHoleNum) & LF) ;
  1787. writeline(OUTPUT, buf) ;
  1788. return CovBinPtr(NumBins).BinVal.all ;
  1789. end function GetHoleBinVal ;
  1790. ------------------------------------------------------------
  1791. impure function GetHoleBinVal ( PercentCov : real ) return RangeArrayType is
  1792. ------------------------------------------------------------
  1793. begin
  1794. return GetHoleBinVal(1, PercentCov) ;
  1795. end function GetHoleBinVal ;
  1796. ------------------------------------------------------------
  1797. impure function GetHoleBinVal ( ReqHoleNum : integer := 1 ) return RangeArrayType is
  1798. ------------------------------------------------------------
  1799. begin
  1800. return GetHoleBinVal(ReqHoleNum, CovTarget) ;
  1801. end function GetHoleBinVal ;
  1802. ------------------------------------------------------------
  1803. impure function CalcWeight ( BinIndex : integer ; MaxCovPercent : real ) return integer is
  1804. -- pt local
  1805. ------------------------------------------------------------
  1806. begin
  1807. case WeightMode is
  1808. when AT_LEAST => -- AtLeast
  1809. return CovBinPtr(BinIndex).AtLeast ;
  1810. when WEIGHT => -- Weight
  1811. return CovBinPtr(BinIndex).Weight ;
  1812. when REMAIN => -- (Adjust * AtLeast) - Count
  1813. return integer( Ceil( MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  1814. CovBinPtr(BinIndex).Count ;
  1815. when REMAIN_EXP => -- Weight * (REMAIN **WeightScale)
  1816. -- Experimental may be removed
  1817. -- CAUTION: for large numbers and/or WeightScale > 2.0, result can be > 2**31 (max integer value)
  1818. -- both Weight and WeightScale default to 1
  1819. return CovBinPtr(BinIndex).Weight *
  1820. integer( Ceil (
  1821. ( (MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0) -
  1822. real(CovBinPtr(BinIndex).Count) ) ** WeightScale ) );
  1823. when REMAIN_SCALED => -- (WeightScale * Adjust * AtLeast) - Count
  1824. -- Experimental may be removed
  1825. -- Biases remainder toward AT_LEAST value.
  1826. -- WeightScale must be > 1.0
  1827. return integer( Ceil( WeightScale * MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  1828. CovBinPtr(BinIndex).Count ;
  1829. when REMAIN_WEIGHT => -- Weight * ((WeightScale * Adjust * AtLeast) - Count)
  1830. -- Experimental may be removed
  1831. -- WeightScale must be > 1.0
  1832. return CovBinPtr(BinIndex).Weight * (
  1833. integer( Ceil( WeightScale * MaxCovPercent * real(CovBinPtr(BinIndex).AtLeast)/100.0)) -
  1834. CovBinPtr(BinIndex).Count) ;
  1835. end case ;
  1836. end function CalcWeight ;
  1837. ------------------------------------------------------------
  1838. impure function RandHoleIndex ( CovTargetPercent : real ) return integer is
  1839. -- pt local
  1840. ------------------------------------------------------------
  1841. variable WeightVec : integer_vector(0 to NumBins-1) ; -- Prep for change to DistInt
  1842. variable MaxCovPercent : real ;
  1843. variable MinCovPercent : real ;
  1844. begin
  1845. ItemCount := ItemCount + 1 ;
  1846. MinCovPercent := GetMinCov ;
  1847. if ThresholdingEnable then
  1848. MaxCovPercent := MinCovPercent + CovThreshold ;
  1849. if MinCovPercent < CovTargetPercent then
  1850. -- Clip at CovTargetPercent until reach CovTargetPercent
  1851. MaxCovPercent := minimum(MaxCovPercent, CovTargetPercent);
  1852. end if ;
  1853. else
  1854. if MinCovPercent < CovTargetPercent then
  1855. MaxCovPercent := CovTargetPercent ;
  1856. else
  1857. -- Done, Enable all bins
  1858. MaxCovPercent := GetMaxCov + 1.0 ;
  1859. -- MaxCovPercent := real'right ; -- weight scale issues
  1860. end if ;
  1861. end if ;
  1862. CovLoop : for i in 1 to NumBins loop
  1863. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < MaxCovPercent then
  1864. -- Calculate Weight based on WeightMode
  1865. -- Scale to current percentage goal: MaxCov which can be < or > 100.0
  1866. WeightVec(i-1) := CalcWeight(i, MaxCovPercent) ;
  1867. else
  1868. WeightVec(i-1) := 0 ;
  1869. end if ;
  1870. end loop CovLoop ;
  1871. -- DistInt returns integer range 0 to Numbins-1
  1872. -- Caution: DistInt can fail when sum(WeightVec) > 2**31
  1873. -- See notes in CalcWeight for REMAIN_EXP
  1874. LastIndex := 1 + RV.DistInt( WeightVec ) ; -- return range 1 to NumBins
  1875. return LastIndex ;
  1876. end function RandHoleIndex ;
  1877. ------------------------------------------------------------
  1878. impure function GetBinVal ( BinIndex : integer ) return RangeArrayType is
  1879. ------------------------------------------------------------
  1880. begin
  1881. return CovBinPtr( BinIndex ).BinVal.all ;
  1882. end function GetBinVal ;
  1883. ------------------------------------------------------------
  1884. impure function GetLastBinVal return RangeArrayType is
  1885. ------------------------------------------------------------
  1886. begin
  1887. return CovBinPtr( LastIndex ).BinVal.all ;
  1888. end function GetLastBinVal ;
  1889. ------------------------------------------------------------
  1890. impure function RandCovBinVal ( PercentCov : real ) return RangeArrayType is
  1891. ------------------------------------------------------------
  1892. begin
  1893. return CovBinPtr( RandHoleIndex(PercentCov) ).BinVal.all ; -- GetBinVal
  1894. end function RandCovBinVal ;
  1895. ------------------------------------------------------------
  1896. impure function RandCovBinVal return RangeArrayType is
  1897. ------------------------------------------------------------
  1898. begin
  1899. -- use global coverage target
  1900. return CovBinPtr( RandHoleIndex( CovTarget ) ).BinVal.all ; -- GetBinVal
  1901. end function RandCovBinVal ;
  1902. ------------------------------------------------------------
  1903. impure function GetMinBinVal return RangeArrayType is
  1904. ------------------------------------------------------------
  1905. begin
  1906. -- use global coverage target
  1907. return GetBinVal( GetMinIndex ) ;
  1908. end function GetMinBinVal ;
  1909. ------------------------------------------------------------
  1910. impure function GetMaxBinVal return RangeArrayType is
  1911. ------------------------------------------------------------
  1912. begin
  1913. -- use global coverage target
  1914. return GetBinVal( GetMaxIndex ) ;
  1915. end function GetMaxBinVal ;
  1916. ------------------------------------------------------------
  1917. -- impure function RandCovPoint( BinVal : RangeArrayType ) return integer_vector is
  1918. impure function ToRandPoint( BinVal : RangeArrayType ) return integer_vector is
  1919. -- pt local
  1920. ------------------------------------------------------------
  1921. variable CovPoint : integer_vector(BinVal'range) ;
  1922. variable normCovPoint : integer_vector(1 to BinVal'length) ;
  1923. begin
  1924. for i in BinVal'range loop
  1925. CovPoint(i) := RV.RandInt(BinVal(i).min, BinVal(i).max) ;
  1926. end loop ;
  1927. normCovPoint := CovPoint ;
  1928. return normCovPoint ;
  1929. end function ToRandPoint ;
  1930. ------------------------------------------------------------
  1931. impure function ToRandPoint( BinVal : RangeArrayType ) return integer is
  1932. -- pt local
  1933. ------------------------------------------------------------
  1934. begin
  1935. return RV.RandInt(BinVal(BinVal'left).min, BinVal(BinVal'left).max) ;
  1936. end function ToRandPoint ;
  1937. ------------------------------------------------------------
  1938. impure function RandCovPoint return integer is
  1939. ------------------------------------------------------------
  1940. begin
  1941. return ToRandPoint(RandCovBinVal(CovTarget)) ;
  1942. end function RandCovPoint ;
  1943. ------------------------------------------------------------
  1944. impure function RandCovPoint ( PercentCov : real ) return integer is
  1945. ------------------------------------------------------------
  1946. begin
  1947. return ToRandPoint(RandCovBinVal(PercentCov)) ;
  1948. end function RandCovPoint ;
  1949. ------------------------------------------------------------
  1950. impure function RandCovPoint return integer_vector is
  1951. ------------------------------------------------------------
  1952. begin
  1953. return ToRandPoint(RandCovBinVal(CovTarget)) ;
  1954. end function RandCovPoint ;
  1955. ------------------------------------------------------------
  1956. impure function RandCovPoint ( PercentCov : real ) return integer_vector is
  1957. ------------------------------------------------------------
  1958. begin
  1959. return ToRandPoint(RandCovBinVal(PercentCov)) ;
  1960. end function RandCovPoint ;
  1961. ------------------------------------------------------------
  1962. impure function GetPoint ( BinIndex : integer ) return integer is
  1963. ------------------------------------------------------------
  1964. begin
  1965. return ToRandPoint(GetBinVal(BinIndex)) ;
  1966. end function GetPoint ;
  1967. ------------------------------------------------------------
  1968. impure function GetPoint ( BinIndex : integer ) return integer_vector is
  1969. ------------------------------------------------------------
  1970. begin
  1971. return ToRandPoint(GetBinVal(BinIndex)) ;
  1972. end function GetPoint ;
  1973. ------------------------------------------------------------
  1974. impure function GetMinPoint return integer is
  1975. ------------------------------------------------------------
  1976. begin
  1977. return ToRandPoint(GetBinVal( GetMinIndex )) ;
  1978. end function GetMinPoint ;
  1979. ------------------------------------------------------------
  1980. impure function GetMinPoint return integer_vector is
  1981. ------------------------------------------------------------
  1982. begin
  1983. return ToRandPoint(GetBinVal( GetMinIndex )) ;
  1984. end function GetMinPoint ;
  1985. ------------------------------------------------------------
  1986. impure function GetMaxPoint return integer is
  1987. ------------------------------------------------------------
  1988. begin
  1989. return ToRandPoint(GetBinVal( GetMaxIndex )) ;
  1990. end function GetMaxPoint ;
  1991. ------------------------------------------------------------
  1992. impure function GetMaxPoint return integer_vector is
  1993. ------------------------------------------------------------
  1994. begin
  1995. return ToRandPoint(GetBinVal( GetMaxIndex )) ;
  1996. end function GetMaxPoint ;
  1997. -- ------------------------------------------------------------
  1998. -- Intended as a stand in until we get a more general GetBin
  1999. impure function GetBinInfo ( BinIndex : integer ) return CovBinBaseType is
  2000. -- ------------------------------------------------------------
  2001. variable result : CovBinBaseType ;
  2002. begin
  2003. result.BinVal := ALL_RANGE;
  2004. result.Action := CovBinPtr(BinIndex).Action;
  2005. result.Count := CovBinPtr(BinIndex).Count;
  2006. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2007. result.Weight := CovBinPtr(BinIndex).Weight;
  2008. return result ;
  2009. end function GetBinInfo ;
  2010. -- ------------------------------------------------------------
  2011. -- Intended as a stand in until we get a more general GetBin
  2012. impure function GetBinValLength return integer is
  2013. -- ------------------------------------------------------------
  2014. begin
  2015. return BinValLength ;
  2016. end function GetBinValLength ;
  2017. -- Eventually the multiple GetBin functions will be replaced by a
  2018. -- a single GetBin that returns CovBinBaseType with BinVal as an
  2019. -- unconstrained element
  2020. -- ------------------------------------------------------------
  2021. impure function GetBin ( BinIndex : integer ) return CovBinBaseType is
  2022. -- ------------------------------------------------------------
  2023. variable result : CovBinBaseType ;
  2024. begin
  2025. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2026. result.Action := CovBinPtr(BinIndex).Action;
  2027. result.Count := CovBinPtr(BinIndex).Count;
  2028. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2029. result.Weight := CovBinPtr(BinIndex).Weight;
  2030. return result ;
  2031. end function GetBin ;
  2032. -- ------------------------------------------------------------
  2033. impure function GetBin ( BinIndex : integer ) return CovMatrix2BaseType is
  2034. -- ------------------------------------------------------------
  2035. variable result : CovMatrix2BaseType ;
  2036. begin
  2037. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2038. result.Action := CovBinPtr(BinIndex).Action;
  2039. result.Count := CovBinPtr(BinIndex).Count;
  2040. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2041. result.Weight := CovBinPtr(BinIndex).Weight;
  2042. return result ;
  2043. end function GetBin ;
  2044. -- ------------------------------------------------------------
  2045. impure function GetBin ( BinIndex : integer ) return CovMatrix3BaseType is
  2046. -- ------------------------------------------------------------
  2047. variable result : CovMatrix3BaseType ;
  2048. begin
  2049. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2050. result.Action := CovBinPtr(BinIndex).Action;
  2051. result.Count := CovBinPtr(BinIndex).Count;
  2052. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2053. result.Weight := CovBinPtr(BinIndex).Weight;
  2054. return result ;
  2055. end function GetBin ;
  2056. -- ------------------------------------------------------------
  2057. impure function GetBin ( BinIndex : integer ) return CovMatrix4BaseType is
  2058. -- ------------------------------------------------------------
  2059. variable result : CovMatrix4BaseType ;
  2060. begin
  2061. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2062. result.Action := CovBinPtr(BinIndex).Action;
  2063. result.Count := CovBinPtr(BinIndex).Count;
  2064. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2065. result.Weight := CovBinPtr(BinIndex).Weight;
  2066. return result ;
  2067. end function GetBin ;
  2068. -- ------------------------------------------------------------
  2069. impure function GetBin ( BinIndex : integer ) return CovMatrix5BaseType is
  2070. -- ------------------------------------------------------------
  2071. variable result : CovMatrix5BaseType ;
  2072. begin
  2073. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2074. result.Action := CovBinPtr(BinIndex).Action;
  2075. result.Count := CovBinPtr(BinIndex).Count;
  2076. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2077. result.Weight := CovBinPtr(BinIndex).Weight;
  2078. return result ;
  2079. end function GetBin ;
  2080. -- ------------------------------------------------------------
  2081. impure function GetBin ( BinIndex : integer ) return CovMatrix6BaseType is
  2082. -- ------------------------------------------------------------
  2083. variable result : CovMatrix6BaseType ;
  2084. begin
  2085. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2086. result.Action := CovBinPtr(BinIndex).Action;
  2087. result.Count := CovBinPtr(BinIndex).Count;
  2088. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2089. result.Weight := CovBinPtr(BinIndex).Weight;
  2090. return result ;
  2091. end function GetBin ;
  2092. -- ------------------------------------------------------------
  2093. impure function GetBin ( BinIndex : integer ) return CovMatrix7BaseType is
  2094. -- ------------------------------------------------------------
  2095. variable result : CovMatrix7BaseType ;
  2096. begin
  2097. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2098. result.Action := CovBinPtr(BinIndex).Action;
  2099. result.Count := CovBinPtr(BinIndex).Count;
  2100. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2101. result.Weight := CovBinPtr(BinIndex).Weight;
  2102. return result ;
  2103. end function GetBin ;
  2104. -- ------------------------------------------------------------
  2105. impure function GetBin ( BinIndex : integer ) return CovMatrix8BaseType is
  2106. -- ------------------------------------------------------------
  2107. variable result : CovMatrix8BaseType ;
  2108. begin
  2109. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2110. result.Action := CovBinPtr(BinIndex).Action;
  2111. result.Count := CovBinPtr(BinIndex).Count;
  2112. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2113. result.Weight := CovBinPtr(BinIndex).Weight;
  2114. return result ;
  2115. end function GetBin ;
  2116. -- ------------------------------------------------------------
  2117. impure function GetBin ( BinIndex : integer ) return CovMatrix9BaseType is
  2118. -- ------------------------------------------------------------
  2119. variable result : CovMatrix9BaseType ;
  2120. begin
  2121. result.BinVal := CovBinPtr(BinIndex).BinVal.all;
  2122. result.Action := CovBinPtr(BinIndex).Action;
  2123. result.Count := CovBinPtr(BinIndex).Count;
  2124. result.AtLeast := CovBinPtr(BinIndex).AtLeast;
  2125. result.Weight := CovBinPtr(BinIndex).Weight;
  2126. return result ;
  2127. end function GetBin ;
  2128. ------------------------------------------------------------
  2129. -- pt local for now -- file formal parameter not allowed with method
  2130. procedure WriteBin ( file f : text ) is
  2131. ------------------------------------------------------------
  2132. variable buf : line ;
  2133. begin
  2134. WriteBinName(f, "WriteBin: ") ;
  2135. if NumBins < 1 then
  2136. swrite(buf, "%%FATAL, Coverage Model is empty. Nothing to print.") ;
  2137. writeline(f, buf) ;
  2138. report "Coverage model is empty. Nothing to print." severity failure ;
  2139. end if ;
  2140. for i in 1 to NumBins loop -- CovBinPtr.all'range
  2141. if CovBinPtr(i).count < 0 then
  2142. swrite(buf, "%%Illegal Bin:") ;
  2143. write(buf, CovBinPtr(i).BinVal.all) ;
  2144. write(buf, " Count = " & integer'image(-CovBinPtr(i).count)) ;
  2145. write(buf, "" & LF) ;
  2146. elsif CovBinPtr(i).action = COV_COUNT then
  2147. swrite(buf, "%% Bin:") ;
  2148. write(buf, CovBinPtr(i).BinVal.all) ;
  2149. write(buf, " Count = " & integer'image(CovBinPtr(i).count)) ;
  2150. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2151. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  2152. -- Print Weight only when it is used
  2153. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2154. end if ;
  2155. writeline(f, buf) ;
  2156. end if ;
  2157. end loop ;
  2158. swrite(buf, "") ;
  2159. writeline(f, buf) ;
  2160. end procedure WriteBin ;
  2161. ------------------------------------------------------------
  2162. procedure WriteBin is
  2163. ------------------------------------------------------------
  2164. begin
  2165. if WriteBinFileInit then
  2166. WriteBin(WriteBinFile) ;
  2167. else
  2168. WriteBin(OUTPUT) ;
  2169. end if ;
  2170. end procedure WriteBin ;
  2171. ------------------------------------------------------------
  2172. procedure WriteBin (FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2173. ------------------------------------------------------------
  2174. file BinFile : text open OpenKind is FileName ;
  2175. begin
  2176. WriteBin(BinFile) ;
  2177. end procedure WriteBin ;
  2178. ------------------------------------------------------------
  2179. -- Development only
  2180. -- pt local for now -- file formal parameter not allowed with method
  2181. procedure DumpBin ( file f : text ) is
  2182. ------------------------------------------------------------
  2183. variable buf : line ;
  2184. begin
  2185. WriteBinName(f, "DumpBin: ") ;
  2186. -- if NumBins < 1 then
  2187. -- Write(f, "%%FATAL, Coverage Model is empty. Nothing to print." & LF ) ;
  2188. -- end if ;
  2189. for i in 1 to NumBins loop -- CovBinPtr.all'range
  2190. swrite(buf, "%% Bin:") ;
  2191. write(buf, CovBinPtr(i).BinVal.all) ;
  2192. case CovBinPtr(i).action is
  2193. when COV_COUNT => swrite(buf, " Count = ") ;
  2194. when COV_IGNORE => swrite(buf, " Ignore = ") ;
  2195. when COV_ILLEGAL => swrite(buf, " Illegal = ") ;
  2196. when others => swrite(buf, " BOGUS BOGUS BOGUS = ") ;
  2197. end case ;
  2198. write(buf, CovBinPtr(i).count) ;
  2199. -- write(f, " Count = " & integer'image(CovBinPtr(i).count)) ;
  2200. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2201. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2202. write(buf, " OrderCount = " & integer'image(CovBinPtr(i).OrderCount)) ;
  2203. if CovBinPtr(i).count > 0 then
  2204. write(buf, " Normalized OrderCount = " & integer'image(CovBinPtr(i).OrderCount/CovBinPtr(i).count)) ;
  2205. end if ;
  2206. writeline(f, buf) ;
  2207. end loop ;
  2208. swrite(buf, "") ;
  2209. writeline(f,buf) ;
  2210. end procedure DumpBin ;
  2211. ------------------------------------------------------------
  2212. procedure DumpBin is
  2213. ------------------------------------------------------------
  2214. begin
  2215. if WriteBinFileInit then
  2216. DumpBin(WriteBinFile) ;
  2217. else
  2218. DumpBin(OUTPUT) ;
  2219. end if ;
  2220. end procedure DumpBin ;
  2221. ------------------------------------------------------------
  2222. -- pt local
  2223. procedure WriteCovHoles ( file f : text; PercentCov : real := 100.0 ) is
  2224. ------------------------------------------------------------
  2225. variable buf : line ;
  2226. begin
  2227. WriteBinName(f, "WriteCovHoles: ") ;
  2228. if NumBins < 1 then
  2229. swrite(buf, "%%FATAL, Coverage Model is empty. Nothing to print.") ;
  2230. writeline(f, buf) ;
  2231. report "Coverage model is empty. Nothing to print." severity failure ;
  2232. end if ;
  2233. CovLoop : for i in 1 to NumBins loop
  2234. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).PercentCov < PercentCov then
  2235. swrite(buf, "%% Bin:") ;
  2236. write(buf, CovBinPtr(i).BinVal.all) ;
  2237. write(buf, " Count = " & integer'image(CovBinPtr(i).Count)) ;
  2238. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2239. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  2240. -- Print Weight only when it is used
  2241. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2242. end if ;
  2243. writeline(f, buf) ;
  2244. end if ;
  2245. end loop CovLoop ;
  2246. swrite(buf, "") ;
  2247. writeline(f, buf) ;
  2248. end procedure WriteCovHoles ;
  2249. ------------------------------------------------------------
  2250. procedure WriteCovHoles is
  2251. ------------------------------------------------------------
  2252. begin
  2253. if WriteBinFileInit then
  2254. WriteCovHoles(WriteBinFile, CovTarget) ;
  2255. else
  2256. WriteCovHoles(OUTPUT, CovTarget) ;
  2257. end if;
  2258. end procedure WriteCovHoles ;
  2259. ------------------------------------------------------------
  2260. procedure WriteCovHoles ( PercentCov : real ) is
  2261. ------------------------------------------------------------
  2262. begin
  2263. if WriteBinFileInit then
  2264. WriteCovHoles(WriteBinFile, PercentCov) ;
  2265. else
  2266. WriteCovHoles(OUTPUT, PercentCov) ;
  2267. end if;
  2268. end procedure WriteCovHoles ;
  2269. ------------------------------------------------------------
  2270. procedure WriteCovHoles ( FileName : string; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2271. ------------------------------------------------------------
  2272. file CovHoleFile : text open OpenKind is FileName ;
  2273. begin
  2274. WriteCovHoles(CovHoleFile, CovTarget) ;
  2275. end procedure WriteCovHoles ;
  2276. ------------------------------------------------------------
  2277. procedure WriteCovHoles ( FileName : string; PercentCov : real ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2278. ------------------------------------------------------------
  2279. file CovHoleFile : text open OpenKind is FileName ;
  2280. begin
  2281. WriteCovHoles(CovHoleFile, PercentCov) ;
  2282. end procedure WriteCovHoles ;
  2283. ------------------------------------------------------------
  2284. -- pt local
  2285. impure function FindBin (
  2286. ------------------------------------------------------------
  2287. Merge : boolean ;
  2288. BinVal : RangeArrayType ;
  2289. Action : integer
  2290. ) return integer is
  2291. begin
  2292. if Merge then
  2293. for i in 1 to NumBins loop
  2294. if BinVal = CovBinPtr(i).BinVal.all and Action = CovBinPtr(i).Action then
  2295. return i ;
  2296. end if;
  2297. end loop ;
  2298. end if ;
  2299. return 0 ;
  2300. end function FindBin ;
  2301. ------------------------------------------------------------
  2302. -- pt local
  2303. procedure ReadCovVars (file CovDbFile : text; Good : out boolean ) is
  2304. ------------------------------------------------------------
  2305. variable buf : line ;
  2306. variable Empty : boolean ;
  2307. variable ReadValid : boolean ;
  2308. variable GoodLoop1 : boolean ;
  2309. variable iSeed : RandomSeedType ;
  2310. variable iIllegalMode : integer ;
  2311. variable iWeightMode : integer ;
  2312. variable iWeightScale : real ;
  2313. variable iCovThreshold : real ;
  2314. variable iCountMode : integer ;
  2315. variable iNumberOfMessages : integer ;
  2316. variable iThresholdingEnable : boolean ;
  2317. variable iCovTarget : real ;
  2318. variable iMergingEnable : boolean ;
  2319. begin
  2320. ReadLoop0 : while not EndFile(CovDbFile) loop
  2321. ReadLine(CovDbFile, buf) ;
  2322. EmptyOrCommentLine(buf, Empty) ;
  2323. next when Empty ;
  2324. if buf.all /= "CoveragePkg_Not_Named" then
  2325. Message.SetName(buf.all) ;
  2326. end if ;
  2327. exit ReadLoop0 ;
  2328. end loop ReadLoop0 ;
  2329. ReadLoop1 : while not EndFile(CovDbFile) loop
  2330. ReadLine(CovDbFile, buf) ;
  2331. EmptyOrCommentLine(buf, Empty) ;
  2332. next when Empty ;
  2333. read(buf, iSeed, ReadValid) ;
  2334. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading Seed") ;
  2335. RV.SetSeed( iSeed ) ;
  2336. RvSeedInit := TRUE ;
  2337. read(buf, iCovThreshold, ReadValid) ;
  2338. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading CovThreshold") ;
  2339. CovThreshold := iCovThreshold ;
  2340. read(buf, iIllegalMode, ReadValid) ;
  2341. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading IllegalMode") ;
  2342. IllegalMode := IllegalModeType'val( iIllegalMode ) ;
  2343. read(buf, iWeightMode, ReadValid) ;
  2344. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading WeightMode") ;
  2345. WeightMode := WeightModeType'val( iWeightMode ) ;
  2346. read(buf, iWeightScale, ReadValid) ;
  2347. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading WeightScale") ;
  2348. WeightScale := iWeightScale ;
  2349. read(buf, iCountMode, ReadValid) ;
  2350. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading CountMode") ;
  2351. CountMode := CountModeType'val( iCountMode ) ;
  2352. read(buf, iThresholdingEnable, ReadValid) ;
  2353. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading CountMode") ;
  2354. ThresholdingEnable := iThresholdingEnable ;
  2355. read(buf, iCovTarget, ReadValid) ;
  2356. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading CountMode") ;
  2357. CovTarget := iCovTarget ;
  2358. read(buf, iMergingEnable, ReadValid) ;
  2359. exit ReadLoop1 when failed(not ReadValid, "ReadCovDb: Failed while reading CountMode") ;
  2360. MergingEnable := iMergingEnable ;
  2361. exit ReadLoop1 ;
  2362. end loop ReadLoop1 ;
  2363. GoodLoop1 := ReadValid ;
  2364. ReadLoop2 : while not EndFile(CovDbFile) loop
  2365. ReadLine(CovDbFile, buf) ;
  2366. EmptyOrCommentLine(buf, Empty) ;
  2367. next when Empty ;
  2368. read(buf, iNumberOfMessages, ReadValid) ;
  2369. exit ReadLoop2 when failed(not ReadValid, "ReadCovDb: Failed while reading NumberOfMessages") ;
  2370. for i in 1 to iNumberOfMessages loop
  2371. exit ReadLoop2 when failed(EndFile(CovDbFile), "ReadCovDb: End of File while reading Messages") ;
  2372. ReadLine(CovDbFile, buf) ;
  2373. SetMessage(buf.all) ;
  2374. end loop ;
  2375. exit ReadLoop2 ;
  2376. end loop ReadLoop2 ;
  2377. Good := ReadValid and GoodLoop1 ;
  2378. end procedure ReadCovVars ;
  2379. ------------------------------------------------------------
  2380. -- pt local
  2381. procedure ReadCovDbInfo (
  2382. ------------------------------------------------------------
  2383. File CovDbFile : text ;
  2384. variable NumRangeItems : out integer ;
  2385. variable NumLines : out integer ;
  2386. variable Good : out boolean
  2387. ) is
  2388. variable buf : line ;
  2389. variable ReadValid : boolean ;
  2390. variable Empty : boolean ;
  2391. begin
  2392. ReadLoop : while not EndFile(CovDbFile) loop
  2393. ReadLine(CovDbFile, buf) ;
  2394. EmptyOrCommentLine(buf, Empty) ;
  2395. next when Empty ;
  2396. read(buf, NumRangeItems, ReadValid) ;
  2397. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading NumRangeItems") ;
  2398. read(buf, NumLines, ReadValid) ;
  2399. assert ReadValid
  2400. report "ReadCovDb: Failed while reading NumLines"
  2401. severity failure ;
  2402. exit ;
  2403. end loop ReadLoop ;
  2404. Good := ReadValid ;
  2405. end procedure ReadCovDbInfo ;
  2406. ------------------------------------------------------------
  2407. -- pt local
  2408. procedure ReadCovDbDataBase (
  2409. ------------------------------------------------------------
  2410. File CovDbFile : text ;
  2411. constant NumRangeItems : in integer ;
  2412. constant NumLines : in integer ;
  2413. constant Merge : in boolean ;
  2414. variable Good : out boolean
  2415. ) is
  2416. variable buf : line ;
  2417. variable Empty : boolean ;
  2418. variable ReadValid : boolean ;
  2419. -- Format: Action Count min1 max1 min2 max2 ....
  2420. variable Action : integer ;
  2421. variable Count : integer ;
  2422. variable BinVal : RangeArrayType(1 to NumRangeItems) ;
  2423. variable index : integer ;
  2424. variable AtLeast : integer ;
  2425. variable Weight : integer ;
  2426. variable PercentCov : real ;
  2427. begin
  2428. GrowBins(NumLines) ;
  2429. ReadLoop : for i in 1 to NumLines loop
  2430. exit ReadLoop when failed(EndFile(CovDbFile), "ReadCovDb: Did not read specified number of lines") ;
  2431. ReadLine(CovDbFile, buf) ;
  2432. EmptyOrCommentLine(buf, Empty) ;
  2433. next when Empty ; -- replace with EmptyLine(buf)
  2434. read(buf, Action, ReadValid) ;
  2435. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading Action") ;
  2436. read(buf, Count, ReadValid) ;
  2437. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading Count") ;
  2438. read(buf, AtLeast, ReadValid) ;
  2439. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading AtLeast") ;
  2440. read(buf, Weight, ReadValid) ;
  2441. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading Weight") ;
  2442. read(buf, PercentCov, ReadValid) ;
  2443. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading PercentCov") ;
  2444. read(buf, BinVal, ReadValid) ;
  2445. exit ReadLoop when failed(not ReadValid, "ReadCovDb: Failed while reading BinVal") ;
  2446. index := FindBin(Merge, BinVal, Action) ;
  2447. if index > 0 then -- merge it
  2448. CovBinPtr(index).Count := CovBinPtr(index).Count + Count ;
  2449. CovBinPtr(index).PercentCov := real(CovBinPtr(index).Count)*100.0/maximum(real(CovBinPtr(index).AtLeast), 1.0) ;
  2450. else
  2451. InsertNewBin(BinVal, Action, Count, AtLeast, Weight, PercentCov) ;
  2452. end if ;
  2453. end loop ReadLoop ;
  2454. Good := ReadValid ;
  2455. end ReadCovDbDataBase ;
  2456. ------------------------------------------------------------
  2457. -- pt local
  2458. procedure ReadCovDb (File CovDbFile : text; Merge : boolean := FALSE) is
  2459. ------------------------------------------------------------
  2460. -- Format: Action Count min1 max1 min2 max2
  2461. -- file CovDbFile : text open READ_MODE is FileName ;
  2462. variable NumRangeItems : integer ;
  2463. variable NumLines : integer ;
  2464. variable ReadValid : boolean ;
  2465. begin
  2466. if not Merge then
  2467. Deallocate ; -- remove any old bins
  2468. end if ;
  2469. ReadLoop : loop
  2470. -- Read coverage private variables to the file
  2471. ReadCovVars(CovDbFile, ReadValid) ;
  2472. exit when not ReadValid ;
  2473. -- Get Coverage dimensions and number of items in file.
  2474. ReadCovDbInfo(CovDbFile, NumRangeItems, NumLines, ReadValid) ;
  2475. exit when not ReadValid ;
  2476. -- Read the file
  2477. ReadCovDbDataBase(CovDbFile, NumRangeItems, NumLines, Merge, ReadValid) ;
  2478. exit ;
  2479. end loop ReadLoop ;
  2480. end ReadCovDb ;
  2481. ------------------------------------------------------------
  2482. procedure ReadCovDb (FileName : string; Merge : boolean := FALSE) is
  2483. ------------------------------------------------------------
  2484. -- Format: Action Count min1 max1 min2 max2
  2485. file CovDbFile : text open READ_MODE is FileName ;
  2486. begin
  2487. ReadCovDb(CovDbFile, Merge) ;
  2488. end procedure ReadCovDb ;
  2489. ------------------------------------------------------------
  2490. -- pt local
  2491. procedure WriteCovVars (file CovDbFile : text ) is
  2492. ------------------------------------------------------------
  2493. variable buf : line ;
  2494. begin
  2495. -- write coverage private variables to the file
  2496. if Message.GetName /= "" then
  2497. write(buf, Message.GetName) ;
  2498. else
  2499. swrite(buf, "CoveragePkg_Not_Named") ;
  2500. end if ;
  2501. writeline(CovDbFile, buf) ;
  2502. write(buf, RV.GetSeed ) ;
  2503. write(buf, ' ') ;
  2504. write(buf, CovThreshold) ;
  2505. write(buf, ' ') ;
  2506. write(buf, IllegalModeType'pos(IllegalMode)) ;
  2507. write(buf, ' ') ;
  2508. write(buf, WeightModeType'pos(WeightMode)) ;
  2509. write(buf, ' ') ;
  2510. write(buf, WeightScale) ;
  2511. write(buf, ' ') ;
  2512. write(buf, CountModeType'pos(CountMode)) ;
  2513. write(buf, ' ') ;
  2514. write(buf, ThresholdingEnable) ; -- boolean
  2515. write(buf, ' ') ;
  2516. write(buf, CovTarget) ; -- Real
  2517. write(buf, ' ') ;
  2518. write(buf, MergingEnable) ; -- boolean
  2519. write(buf, ' ') ;
  2520. writeline(CovDbFile, buf) ;
  2521. write(buf, Message.GetMessageCount ) ;
  2522. writeline(CovDbFile, buf) ;
  2523. WriteBinName(CovDbFile, "", "") ;
  2524. end procedure WriteCovVars ;
  2525. ------------------------------------------------------------
  2526. -- pt local
  2527. procedure WriteCovDb (file CovDbFile : text ) is
  2528. ------------------------------------------------------------
  2529. -- Format: Action Count min1 max1 min2 max2
  2530. variable buf : line ;
  2531. begin
  2532. -- write Cover variables to the file
  2533. WriteCovVars( CovDbFile ) ;
  2534. -- write NumRangeItems, NumLines
  2535. write(buf, CovBinPtr(1).BinVal'length) ;
  2536. write(buf, ' ') ;
  2537. write(buf, NumBins) ;
  2538. write(buf, ' ') ;
  2539. writeline(CovDbFile, buf) ;
  2540. -- write coverage to a file
  2541. writeloop : for LineCount in 1 to NumBins loop
  2542. write(buf, CovBinPtr(LineCount).Action) ;
  2543. write(buf, ' ') ;
  2544. write(buf, CovBinPtr(LineCount).Count) ;
  2545. write(buf, ' ') ;
  2546. write(buf, CovBinPtr(LineCount).AtLeast) ;
  2547. write(buf, ' ') ;
  2548. write(buf, CovBinPtr(LineCount).Weight) ;
  2549. write(buf, ' ') ;
  2550. write(buf, CovBinPtr(LineCount).PercentCov) ;
  2551. write(buf, ' ') ;
  2552. WriteBinVal(buf, CovBinPtr(LineCount).BinVal.all) ;
  2553. writeline(CovDbFile, buf) ;
  2554. end loop WriteLoop ;
  2555. end procedure WriteCovDb ;
  2556. ------------------------------------------------------------
  2557. procedure WriteCovDb (FileName : string; OpenKind : File_Open_Kind := WRITE_MODE ) is
  2558. ------------------------------------------------------------
  2559. -- Format: Action Count min1 max1 min2 max2
  2560. file CovDbFile : text open OpenKind is FileName ;
  2561. begin
  2562. WriteCovDb(CovDbFile) ;
  2563. end procedure WriteCovDb ;
  2564. -- ------------------------------------------------------------
  2565. -- procedure WriteCovDb is
  2566. -- ------------------------------------------------------------
  2567. -- begin
  2568. -- if WriteCovDbFileInit then
  2569. -- WriteCovDb(WriteCovDbFile) ;
  2570. -- else
  2571. -- report "CoveragePkg: WriteCovDb file not specified" severity failure ;
  2572. -- end if ;
  2573. -- end procedure WriteCovDb ;
  2574. ------------------------------------------------------------
  2575. impure function GetErrorCount return integer is
  2576. ------------------------------------------------------------
  2577. variable ErrorCnt : integer := 0 ;
  2578. begin
  2579. if NumBins < 1 then
  2580. return 1 ; -- return error if model empty
  2581. else
  2582. for i in 1 to NumBins loop
  2583. if CovBinPtr(i).count < 0 then -- illegal CovBin
  2584. ErrorCnt := ErrorCnt + CovBinPtr(i).count ;
  2585. end if ;
  2586. end loop ;
  2587. return - ErrorCnt ;
  2588. end if ;
  2589. end function GetErrorCount ;
  2590. ------------------------------------------------------------
  2591. -- These support the older AddBins(GenCross(...)) methodology
  2592. -- which has been replaced by AddCross
  2593. ------------------------------------------------------------
  2594. procedure AddBins (CovBin : CovMatrix2Type) is
  2595. ------------------------------------------------------------
  2596. begin
  2597. GrowBins(CovBin'length) ;
  2598. for i in CovBin'range loop
  2599. InsertBin(
  2600. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2601. CovBin(i).AtLeast, CovBin(i).Weight
  2602. ) ;
  2603. end loop ;
  2604. end procedure AddBins ;
  2605. ------------------------------------------------------------
  2606. procedure AddBins (CovBin : CovMatrix3Type) is
  2607. ------------------------------------------------------------
  2608. begin
  2609. GrowBins(CovBin'length) ;
  2610. for i in CovBin'range loop
  2611. InsertBin(
  2612. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2613. CovBin(i).AtLeast, CovBin(i).Weight
  2614. ) ;
  2615. end loop ;
  2616. end procedure AddBins ;
  2617. ------------------------------------------------------------
  2618. procedure AddBins (CovBin : CovMatrix4Type) is
  2619. ------------------------------------------------------------
  2620. begin
  2621. GrowBins(CovBin'length) ;
  2622. for i in CovBin'range loop
  2623. InsertBin(
  2624. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2625. CovBin(i).AtLeast, CovBin(i).Weight
  2626. ) ;
  2627. end loop ;
  2628. end procedure AddBins ;
  2629. ------------------------------------------------------------
  2630. procedure AddBins (CovBin : CovMatrix5Type) is
  2631. ------------------------------------------------------------
  2632. begin
  2633. GrowBins(CovBin'length) ;
  2634. for i in CovBin'range loop
  2635. InsertBin(
  2636. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2637. CovBin(i).AtLeast, CovBin(i).Weight
  2638. ) ;
  2639. end loop ;
  2640. end procedure AddBins ;
  2641. ------------------------------------------------------------
  2642. procedure AddBins (CovBin : CovMatrix6Type) is
  2643. ------------------------------------------------------------
  2644. begin
  2645. GrowBins(CovBin'length) ;
  2646. for i in CovBin'range loop
  2647. InsertBin(
  2648. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2649. CovBin(i).AtLeast, CovBin(i).Weight
  2650. ) ;
  2651. end loop ;
  2652. end procedure AddBins ;
  2653. ------------------------------------------------------------
  2654. procedure AddBins (CovBin : CovMatrix7Type) is
  2655. ------------------------------------------------------------
  2656. begin
  2657. GrowBins(CovBin'length) ;
  2658. for i in CovBin'range loop
  2659. InsertBin(
  2660. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2661. CovBin(i).AtLeast, CovBin(i).Weight
  2662. ) ;
  2663. end loop ;
  2664. end procedure AddBins ;
  2665. ------------------------------------------------------------
  2666. procedure AddBins (CovBin : CovMatrix8Type) is
  2667. ------------------------------------------------------------
  2668. begin
  2669. GrowBins(CovBin'length) ;
  2670. for i in CovBin'range loop
  2671. InsertBin(
  2672. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2673. CovBin(i).AtLeast, CovBin(i).Weight
  2674. ) ;
  2675. end loop ;
  2676. end procedure AddBins ;
  2677. ------------------------------------------------------------
  2678. procedure AddBins (CovBin : CovMatrix9Type) is
  2679. ------------------------------------------------------------
  2680. begin
  2681. GrowBins(CovBin'length) ;
  2682. for i in CovBin'range loop
  2683. InsertBin(
  2684. CovBin(i).BinVal, CovBin(i).Action, CovBin(i).Count,
  2685. CovBin(i).AtLeast, CovBin(i).Weight
  2686. ) ;
  2687. end loop ;
  2688. end procedure AddBins ;
  2689. -- ------------------------------------------------------------
  2690. -- ------------------------------------------------------------
  2691. -- Deprecated. Due to name changes to promote greater consistency
  2692. -- Maintained for backward compatibility.
  2693. -- ------------------------------------------------------------
  2694. ------------------------------------------------------------
  2695. impure function CovBinErrCnt return integer is
  2696. -- Deprecated. Name changed to ErrorCount for package to package consistency
  2697. ------------------------------------------------------------
  2698. begin
  2699. return GetErrorCount ;
  2700. end function CovBinErrCnt ;
  2701. ------------------------------------------------------------
  2702. -- Deprecated. Same as RandCovBinVal
  2703. impure function RandCovHole ( PercentCov : real ) return RangeArrayType is
  2704. ------------------------------------------------------------
  2705. begin
  2706. return RandCovBinVal(PercentCov) ;
  2707. end function RandCovHole ;
  2708. ------------------------------------------------------------
  2709. -- Deprecated. Same as RandCovBinVal
  2710. impure function RandCovHole return RangeArrayType is
  2711. ------------------------------------------------------------
  2712. begin
  2713. return RandCovBinVal ;
  2714. end function RandCovHole ;
  2715. -- GetCovHole replaced by GetHoleBinVal
  2716. ------------------------------------------------------------
  2717. -- Deprecated. Same as GetHoleBinVal
  2718. impure function GetCovHole ( ReqHoleNum : integer ; PercentCov : real ) return RangeArrayType is
  2719. ------------------------------------------------------------
  2720. begin
  2721. return GetHoleBinVal(ReqHoleNum, PercentCov) ;
  2722. end function GetCovHole ;
  2723. ------------------------------------------------------------
  2724. -- Deprecated. Same as GetHoleBinVal
  2725. impure function GetCovHole ( PercentCov : real ) return RangeArrayType is
  2726. ------------------------------------------------------------
  2727. begin
  2728. return GetHoleBinVal(PercentCov) ;
  2729. end function GetCovHole ;
  2730. ------------------------------------------------------------
  2731. -- Deprecated. Same as GetHoleBinVal
  2732. impure function GetCovHole ( ReqHoleNum : integer := 1 ) return RangeArrayType is
  2733. ------------------------------------------------------------
  2734. begin
  2735. return GetHoleBinVal(ReqHoleNum) ;
  2736. end function GetCovHole ;
  2737. -- ------------------------------------------------------------
  2738. -- ------------------------------------------------------------
  2739. -- Deprecated / Subsumed by versions with PercentCov Parameter
  2740. -- Maintained for backward compatibility only and
  2741. -- may be removed in the future.
  2742. -- ------------------------------------------------------------
  2743. ------------------------------------------------------------
  2744. -- Deprecated. Replaced by SetMessage with multi-line support
  2745. procedure SetItemName (ItemNameIn : String) is
  2746. ------------------------------------------------------------
  2747. begin
  2748. SetMessage(ItemNameIn) ;
  2749. end procedure SetItemName ;
  2750. ------------------------------------------------------------
  2751. -- Deprecated. Same as GetMinCount
  2752. impure function GetMinCov return integer is
  2753. ------------------------------------------------------------
  2754. begin
  2755. return GetMinCount ;
  2756. end function GetMinCov ;
  2757. ------------------------------------------------------------
  2758. -- Deprecated. Same as GetMaxCount
  2759. impure function GetMaxCov return integer is
  2760. ------------------------------------------------------------
  2761. begin
  2762. return GetMaxCount ;
  2763. end function GetMaxCov ;
  2764. ------------------------------------------------------------
  2765. -- Deprecated. New versions use PercentCov
  2766. impure function CountCovHoles ( AtLeast : integer ) return integer is
  2767. ------------------------------------------------------------
  2768. variable HoleCount : integer := 0 ;
  2769. begin
  2770. CovLoop : for i in 1 to NumBins loop
  2771. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minimum(AtLeast, CovBinPtr(i).AtLeast) then
  2772. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  2773. HoleCount := HoleCount + 1 ;
  2774. end if ;
  2775. end loop CovLoop ;
  2776. return HoleCount ;
  2777. end function CountCovHoles ;
  2778. ------------------------------------------------------------
  2779. -- Deprecated. New versions use PercentCov
  2780. impure function IsCovered ( AtLeast : integer ) return boolean is
  2781. ------------------------------------------------------------
  2782. begin
  2783. return CountCovHoles(AtLeast) = 0 ;
  2784. end function IsCovered ;
  2785. ------------------------------------------------------------
  2786. impure function CalcWeight ( BinIndex : integer ; MaxAtLeast : integer ) return integer is
  2787. -- pt local
  2788. ------------------------------------------------------------
  2789. begin
  2790. case WeightMode is
  2791. when AT_LEAST =>
  2792. return CovBinPtr(BinIndex).AtLeast ;
  2793. when WEIGHT =>
  2794. return CovBinPtr(BinIndex).Weight ;
  2795. when REMAIN =>
  2796. return MaxAtLeast - CovBinPtr(BinIndex).Count ;
  2797. when REMAIN_SCALED =>
  2798. -- Experimental may be removed
  2799. return integer( Ceil( WeightScale * real(MaxAtLeast))) -
  2800. CovBinPtr(BinIndex).Count ;
  2801. when REMAIN_WEIGHT =>
  2802. -- Experimental may be removed
  2803. return CovBinPtr(BinIndex).Weight * (
  2804. integer( Ceil( WeightScale * real(MaxAtLeast))) -
  2805. CovBinPtr(BinIndex).Count ) ;
  2806. when others =>
  2807. report "Selected Weight Mode not Supported with depricated RandCovPoint(AtLeast), see RandCovPoint(PercentCov)"
  2808. severity failure ;
  2809. return MaxAtLeast - CovBinPtr(BinIndex).Count ;
  2810. end case ;
  2811. end function CalcWeight ;
  2812. ------------------------------------------------------------
  2813. -- Deprecated. New versions use PercentCov
  2814. -- If keep this, need to be able to scale AtLeast Value
  2815. impure function RandHoleIndex ( AtLeast : integer ) return integer is
  2816. -- pt local
  2817. ------------------------------------------------------------
  2818. variable WeightVec : integer_vector(0 to NumBins-1) ; -- Prep for change to DistInt
  2819. variable MinCount, AdjAtLeast, MaxAtLeast : integer ;
  2820. begin
  2821. ItemCount := ItemCount + 1 ;
  2822. MinCount := GetMinCov ;
  2823. -- iAtLeast := integer(ceil(CovTarget * real(AtLeast)/100.0)) ;
  2824. if ThresholdingEnable then
  2825. AdjAtLeast := MinCount + integer(CovThreshold) + 1 ;
  2826. if MinCount < AtLeast then
  2827. -- Clip at AtLeast until reach AtLeast
  2828. AdjAtLeast := minimum(AdjAtLeast, AtLeast) ;
  2829. end if ;
  2830. else
  2831. if MinCount < AtLeast then
  2832. AdjAtLeast := AtLeast ; -- Valid
  2833. else
  2834. -- Done, Enable all bins
  2835. -- AdjAtLeast := integer'right ; -- Get All
  2836. AdjAtLeast := GetMaxCov + 1 ; -- Get All
  2837. end if ;
  2838. end if;
  2839. MaxAtLeast := AdjAtLeast ;
  2840. CovLoop : for i in 1 to NumBins loop
  2841. -- if not ThresholdingEnable then
  2842. -- -- When not thresholding, consider bin Bin.AtLeast
  2843. -- -- iBinAtLeast := integer(ceil(CovTarget * real(CovBinPtr(i).AtLeast)/100.0)) ;
  2844. -- MaxAtLeast := maximum(AdjAtLeast, CovBinPtr(i).AtLeast) ;
  2845. -- end if ;
  2846. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < MaxAtLeast then
  2847. WeightVec(i-1) := CalcWeight(i, MaxAtLeast ) ; -- CovBinPtr(i).Weight ;
  2848. else
  2849. WeightVec(i-1) := 0 ;
  2850. end if ;
  2851. end loop CovLoop ;
  2852. -- DistInt returns integer range 0 to Numbins-1
  2853. LastIndex := 1 + RV.DistInt( WeightVec ) ; -- return range 1 to NumBins
  2854. return LastIndex ;
  2855. end function RandHoleIndex ;
  2856. ------------------------------------------------------------
  2857. -- Deprecated. New versions use PercentCov
  2858. impure function RandCovBinVal (AtLeast : integer ) return RangeArrayType is
  2859. ------------------------------------------------------------
  2860. begin
  2861. return CovBinPtr( RandHoleIndex(AtLeast) ).BinVal.all ; -- GetBinVal
  2862. end function RandCovBinVal ;
  2863. -- Maintained for backward compatibility. Repeated until aliases work for methods
  2864. ------------------------------------------------------------
  2865. -- Deprecated+ New versions use PercentCov. Name change.
  2866. impure function RandCovHole (AtLeast : integer ) return RangeArrayType is
  2867. ------------------------------------------------------------
  2868. begin
  2869. return RandCovBinVal(AtLeast) ; -- GetBinVal
  2870. end function RandCovHole ;
  2871. ------------------------------------------------------------
  2872. -- Deprecated. New versions use PercentCov
  2873. impure function RandCovPoint (AtLeast : integer ) return integer is
  2874. ------------------------------------------------------------
  2875. variable BinVal : RangeArrayType(1 to 1) ;
  2876. begin
  2877. BinVal := RandCovBinVal(AtLeast) ;
  2878. return RV.RandInt(BinVal(1).min, BinVal(1).max) ;
  2879. end function RandCovPoint ;
  2880. ------------------------------------------------------------
  2881. impure function RandCovPoint (AtLeast : integer ) return integer_vector is
  2882. ------------------------------------------------------------
  2883. begin
  2884. return ToRandPoint(RandCovBinVal(AtLeast)) ;
  2885. end function RandCovPoint ;
  2886. ------------------------------------------------------------
  2887. -- Deprecated. New versions use PercentCov
  2888. impure function GetHoleBinVal ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType is
  2889. ------------------------------------------------------------
  2890. variable HoleCount : integer := 0 ;
  2891. variable buf : line ;
  2892. begin
  2893. CovLoop : for i in 1 to NumBins loop
  2894. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minimum(AtLeast, CovBinPtr(i).AtLeast) then
  2895. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  2896. HoleCount := HoleCount + 1 ;
  2897. if HoleCount = ReqHoleNum then
  2898. return CovBinPtr(i).BinVal.all ;
  2899. end if ;
  2900. end if ;
  2901. end loop CovLoop ;
  2902. write(buf, "%%Error GetHoleBinVal did not find hole. " &
  2903. "HoleCount = " & integer'image(HoleCount) &
  2904. "ReqHoleNum = " & integer'image(ReqHoleNum) & LF) ;
  2905. writeline(OUTPUT, buf) ;
  2906. return CovBinPtr(NumBins).BinVal.all ;
  2907. end function GetHoleBinVal ;
  2908. ------------------------------------------------------------
  2909. -- Deprecated+. New versions use PercentCov. Name Change.
  2910. impure function GetCovHole ( ReqHoleNum : integer ; AtLeast : integer ) return RangeArrayType is
  2911. ------------------------------------------------------------
  2912. begin
  2913. return GetHoleBinVal(ReqHoleNum, AtLeast) ;
  2914. end function GetCovHole ;
  2915. ------------------------------------------------------------
  2916. -- pt local
  2917. -- Deprecated. New versions use PercentCov.
  2918. procedure WriteCovHoles ( file f : text; AtLeast : integer ) is
  2919. ------------------------------------------------------------
  2920. -- variable minAtLeast : integer ;
  2921. variable buf : line ;
  2922. begin
  2923. WriteBinName(f, "WriteCovHoles: ") ;
  2924. if NumBins < 1 then
  2925. swrite(buf, "%%FATAL, Coverage Model is empty. Nothing to print.") ;
  2926. writeline(f, buf) ;
  2927. report "Coverage model is empty. Nothing to print." severity failure ;
  2928. end if ;
  2929. CovLoop : for i in 1 to NumBins loop
  2930. -- minAtLeast := minimum(AtLeast,CovBinPtr(i).AtLeast) ;
  2931. -- if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < minAtLeast then
  2932. if CovBinPtr(i).action = COV_COUNT and CovBinPtr(i).Count < AtLeast then
  2933. swrite(buf, "%% Bin:") ;
  2934. write(buf, CovBinPtr(i).BinVal.all) ;
  2935. write(buf, " Count = " & integer'image(CovBinPtr(i).Count)) ;
  2936. write(buf, " AtLeast = " & integer'image(CovBinPtr(i).AtLeast)) ;
  2937. if WeightMode = WEIGHT or WeightMode = REMAIN_WEIGHT then
  2938. -- Print Weight only when it is used
  2939. write(buf, " Weight = " & integer'image(CovBinPtr(i).Weight)) ;
  2940. end if ;
  2941. writeline(f, buf) ;
  2942. end if ;
  2943. end loop CovLoop ;
  2944. swrite(buf, "") ;
  2945. writeline(f, buf) ;
  2946. end procedure WriteCovHoles ;
  2947. ------------------------------------------------------------
  2948. -- Deprecated. New versions use PercentCov.
  2949. procedure WriteCovHoles ( AtLeast : integer ) is
  2950. ------------------------------------------------------------
  2951. begin
  2952. if WriteBinFileInit then
  2953. WriteCovHoles(WriteBinFile, AtLeast) ;
  2954. else
  2955. WriteCovHoles(OUTPUT, AtLeast) ;
  2956. end if;
  2957. end procedure WriteCovHoles ;
  2958. ------------------------------------------------------------
  2959. -- Deprecated. New versions use PercentCov.
  2960. procedure WriteCovHoles ( FileName : string; AtLeast : integer ; OpenKind : File_Open_Kind := APPEND_MODE ) is
  2961. ------------------------------------------------------------
  2962. file CovHoleFile : text open OpenKind is FileName ;
  2963. begin
  2964. WriteCovHoles(CovHoleFile, AtLeast) ;
  2965. end procedure WriteCovHoles ;
  2966. end protected body CovPType ;
  2967. ------------------------------------------------------------------------------------------
  2968. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  2969. -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX CovPType XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  2970. ------------------------------------------------------------------------------------------
  2971. ------------------------------------------------------------
  2972. -- Experimental. Intended primarily for development.
  2973. procedure CompareBins (
  2974. ------------------------------------------------------------
  2975. variable Bin1 : inout CovPType ;
  2976. variable Bin2 : inout CovPType ;
  2977. variable ErrorCount : inout integer
  2978. ) is
  2979. variable NumBins1, NumBins2 : integer ;
  2980. variable BinInfo1, BinInfo2 : CovBinBaseType ;
  2981. variable BinVal1, BinVal2 : RangeArrayType(1 to Bin1.GetBinValLength) ;
  2982. variable buf : line ;
  2983. begin
  2984. NumBins1 := Bin1.GetNumBins ;
  2985. NumBins2 := Bin2.GetNumBins ;
  2986. if (NumBins1 /= NumBins2) then
  2987. write(buf, "Bins have different lengths" & LF) ;
  2988. writeline(OUTPUT, buf) ;
  2989. ErrorCount := ErrorCount + 1 ;
  2990. return ;
  2991. end if ;
  2992. for i in 1 to NumBins1 loop
  2993. BinInfo1 := Bin1.GetBinInfo(i) ;
  2994. BinInfo2 := Bin2.GetBinInfo(i) ;
  2995. BinVal1 := Bin1.GetBinVal(i) ;
  2996. BinVal2 := Bin2.GetBinVal(i) ;
  2997. if BinInfo1 /= BinInfo2 or BinVal1 /= BinVal2 then
  2998. ErrorCount := ErrorCount + 1 ;
  2999. write(buf, "%% Bin:" & integer'image(i) & " miscompare." & LF) ;
  3000. writeline(OUTPUT, buf) ;
  3001. swrite(buf, "%% Bin1: ") ;
  3002. write(buf, BinVal1) ;
  3003. write(buf, " Action = " & integer'image(BinInfo1.action)) ;
  3004. write(buf, " Count = " & integer'image(BinInfo1.count)) ;
  3005. write(buf, " AtLeast = " & integer'image(BinInfo1.AtLeast)) ;
  3006. write(buf, " Weight = " & integer'image(BinInfo1.Weight)) ;
  3007. writeline(OUTPUT, buf) ;
  3008. swrite(buf, "%% Bin2: ") ;
  3009. write(buf, BinVal2) ;
  3010. write(buf, " Action = " & integer'image(BinInfo2.action)) ;
  3011. write(buf, " Count = " & integer'image(BinInfo2.count)) ;
  3012. write(buf, " AtLeast = " & integer'image(BinInfo2.AtLeast)) ;
  3013. write(buf, " Weight = " & integer'image(BinInfo2.Weight)) ;
  3014. writeline(OUTPUT, buf) ;
  3015. end if ;
  3016. end loop ;
  3017. end procedure CompareBins ;
  3018. ------------------------------------------------------------
  3019. -- package local, Used by GenBin, IllegalBin, and IgnoreBin
  3020. function MakeBin(
  3021. ------------------------------------------------------------
  3022. Min, Max : integer ;
  3023. NumBin : integer ;
  3024. AtLeast : integer ;
  3025. Weight : integer ;
  3026. Action : integer
  3027. ) return CovBinType is
  3028. variable iCovBin : CovBinType(1 to NumBin) ;
  3029. variable TotalBins : integer ; -- either real or integer
  3030. variable rMax, rCurMin, rNextMin, rNumItemsInBin, rRemainingBins : real ; -- must be real
  3031. begin
  3032. if Min > Max then
  3033. report "MakeBin (GenBin, IllegalBin, IgnoreBin): Min must be <= Max"
  3034. severity failure ;
  3035. return NULL_BIN ;
  3036. elsif NumBin <= 0 then
  3037. report "MakeBin (GenBin, IllegalBin, IgnoreBin): NumBin must be <= 0"
  3038. severity failure ;
  3039. return NULL_BIN ;
  3040. elsif NumBin = 1 then
  3041. iCovBin(1) := (
  3042. BinVal => (1 => (Min, Max)),
  3043. Action => Action,
  3044. Count => 0,
  3045. Weight => Weight,
  3046. AtLeast => AtLeast
  3047. ) ;
  3048. return iCovBin ;
  3049. else
  3050. rCurMin := real(Min) ;
  3051. rMax := real(Max) ;
  3052. rRemainingBins := (minimum( real(NumBin), rMax - rCurMin + 1.0 )) ;
  3053. TotalBins := integer(rRemainingBins) ;
  3054. for i in iCovBin'range loop
  3055. exit when rRemainingBins = 0.0 ;
  3056. rNumItemsInBin := trunc((rMax - rCurMin + 1.0) / rRemainingBins) ; -- can be too large
  3057. rNextMin := rCurMin + rNumItemsInBin ; -- can be 2**31
  3058. iCovBin(i) := (
  3059. BinVal => (1 => (integer(rCurMin), integer(rNextMin - 1.0))),
  3060. Action => Action,
  3061. Count => 0,
  3062. Weight => Weight,
  3063. AtLeast => AtLeast
  3064. ) ;
  3065. rCurMin := rNextMin ;
  3066. rRemainingBins := rRemainingBins - 1.0 ;
  3067. end loop ;
  3068. return iCovBin(1 to TotalBins) ;
  3069. end if ;
  3070. end function MakeBin ;
  3071. -- Old version with bug
  3072. -- ------------------------------------------------------------
  3073. -- -- package local, Used by GenBin, IllegalBin, and IgnoreBin
  3074. -- function MakeBin(
  3075. -- ------------------------------------------------------------
  3076. -- Min, Max : integer ;
  3077. -- NumBin : integer ;
  3078. -- AtLeast : integer ;
  3079. -- Weight : integer ;
  3080. -- Action : integer
  3081. -- ) return CovBinType is
  3082. -- constant CheckParms : boolean := failed(Min > Max, "MakeBin (GenBin, IllegalBin, IgnoreBin): Min must be <= Max") ;
  3083. -- constant CALC_NUM_BINS : integer := minimum(NumBin, Max-Min+1) ;
  3084. -- variable iCovBin : CovBinType(0 to CALC_NUM_BINS -1) ;
  3085. -- variable CurMin, NextMin, RemainingBins, NumItemsInBin : integer ;
  3086. -- begin
  3087. -- CurMin := Min ;
  3088. -- for i in iCovBin'range loop
  3089. -- RemainingBins := CALC_NUM_BINS - i ;
  3090. -- NumItemsInBin := (Max - CurMin + 1) / RemainingBins ;
  3091. -- NextMin := CurMin + NumItemsInBin ;
  3092. -- iCovBin(i) := (
  3093. -- BinVal => (1 => (CurMin, NextMin - 1)),
  3094. -- Action => Action,
  3095. -- Count => 0,
  3096. -- Weight => Weight,
  3097. -- AtLeast => AtLeast
  3098. -- ) ;
  3099. -- CurMin := NextMin ;
  3100. -- end loop ;
  3101. -- return iCovBin ;
  3102. -- end function MakeBin ;
  3103. ------------------------------------------------------------
  3104. function GenBin(
  3105. ------------------------------------------------------------
  3106. AtLeast : integer ;
  3107. Weight : integer ;
  3108. Min, Max : integer ;
  3109. NumBin : integer
  3110. ) return CovBinType is
  3111. begin
  3112. return MakeBin(
  3113. Min => Min,
  3114. Max => Max,
  3115. NumBin => NumBin,
  3116. AtLeast => AtLeast,
  3117. Weight => Weight,
  3118. Action => COV_COUNT
  3119. ) ;
  3120. end function GenBin ;
  3121. ------------------------------------------------------------
  3122. function GenBin(AtLeast : integer ; Min, Max, NumBin : integer ) return CovBinType is
  3123. ------------------------------------------------------------
  3124. begin
  3125. return MakeBin(
  3126. Min => Min,
  3127. Max => Max,
  3128. NumBin => NumBin,
  3129. AtLeast => AtLeast,
  3130. Weight => 1,
  3131. Action => COV_COUNT
  3132. ) ;
  3133. end function GenBin ;
  3134. ------------------------------------------------------------
  3135. function GenBin( Min, Max, NumBin : integer ) return CovBinType is
  3136. ------------------------------------------------------------
  3137. begin
  3138. return MakeBin(
  3139. Min => Min,
  3140. Max => Max,
  3141. NumBin => NumBin,
  3142. AtLeast => 1,
  3143. Weight => 1,
  3144. Action => COV_COUNT
  3145. ) ;
  3146. end function GenBin ;
  3147. ------------------------------------------------------------
  3148. function GenBin ( Min, Max : integer) return CovBinType is
  3149. ------------------------------------------------------------
  3150. begin
  3151. -- default, create a separate CovBin for each value
  3152. -- AtLeast and Weight = 1 (must use longer version to specify)
  3153. return MakeBin(
  3154. Min => Min,
  3155. Max => Max,
  3156. NumBin => Max - Min + 1,
  3157. AtLeast => 1,
  3158. Weight => 1,
  3159. Action => COV_COUNT
  3160. ) ;
  3161. end function GenBin ;
  3162. ------------------------------------------------------------
  3163. function GenBin ( A : integer) return CovBinType is
  3164. ------------------------------------------------------------
  3165. begin
  3166. -- default, create a separate CovBin for each value
  3167. -- AtLeast and Weight = 1 (must use longer version to specify)
  3168. return MakeBin(
  3169. Min => A,
  3170. Max => A,
  3171. NumBin => 1,
  3172. AtLeast => 1,
  3173. Weight => 1,
  3174. Action => COV_COUNT
  3175. ) ;
  3176. end function GenBin ;
  3177. ------------------------------------------------------------
  3178. function IllegalBin ( Min, Max, NumBin : integer ) return CovBinType is
  3179. ------------------------------------------------------------
  3180. begin
  3181. return MakeBin(
  3182. Min => Min,
  3183. Max => Max,
  3184. NumBin => NumBin,
  3185. AtLeast => 0,
  3186. Weight => 0,
  3187. Action => COV_ILLEGAL
  3188. ) ;
  3189. end function IllegalBin ;
  3190. ------------------------------------------------------------
  3191. function IllegalBin ( Min, Max : integer ) return CovBinType is
  3192. ------------------------------------------------------------
  3193. begin
  3194. -- default, generate one CovBin with the entire range of values
  3195. return MakeBin(
  3196. Min => Min,
  3197. Max => Max,
  3198. NumBin => 1,
  3199. AtLeast => 0,
  3200. Weight => 0,
  3201. Action => COV_ILLEGAL
  3202. ) ;
  3203. end function IllegalBin ;
  3204. ------------------------------------------------------------
  3205. function IllegalBin ( A : integer ) return CovBinType is
  3206. ------------------------------------------------------------
  3207. begin
  3208. return MakeBin(
  3209. Min => A,
  3210. Max => A,
  3211. NumBin => 1,
  3212. AtLeast => 0,
  3213. Weight => 0,
  3214. Action => COV_ILLEGAL
  3215. ) ;
  3216. end function IllegalBin ;
  3217. ----------------------------------------------------------
  3218. -- function IgnoreBin (
  3219. ----------------------------------------------------------
  3220. -- AtLeast : integer ;
  3221. -- Weight : integer ;
  3222. -- Min, Max : integer ;
  3223. -- NumBin : integer
  3224. -- ) return CovBinType is
  3225. -- begin
  3226. -- return MakeBin(
  3227. -- Min => Min,
  3228. -- Max => Max,
  3229. -- NumBin => NumBin,
  3230. -- AtLeast => AtLeast,
  3231. -- Weight => Weight,
  3232. -- Action => COV_IGNORE
  3233. -- ) ;
  3234. -- end function IgnoreBin ;
  3235. ----------------------------------------------------------
  3236. -- function IgnoreBin (AtLeast : integer ; Min, Max, NumBin : integer) return CovBinType is
  3237. ----------------------------------------------------------
  3238. -- begin
  3239. -- return MakeBin(
  3240. -- Min => Min,
  3241. -- Max => Max,
  3242. -- NumBin => NumBin,
  3243. -- AtLeast => AtLeast,
  3244. -- Weight => 0,
  3245. -- Action => COV_IGNORE
  3246. -- ) ;
  3247. -- end function IgnoreBin ;
  3248. ------------------------------------------------------------
  3249. function IgnoreBin (Min, Max, NumBin : integer) return CovBinType is
  3250. ------------------------------------------------------------
  3251. begin
  3252. return MakeBin(
  3253. Min => Min,
  3254. Max => Max,
  3255. NumBin => NumBin,
  3256. AtLeast => 0,
  3257. Weight => 0,
  3258. Action => COV_IGNORE
  3259. ) ;
  3260. end function IgnoreBin ;
  3261. ------------------------------------------------------------
  3262. function IgnoreBin (Min, Max : integer) return CovBinType is
  3263. ------------------------------------------------------------
  3264. begin
  3265. -- default, generate one CovBin with the entire range of values
  3266. return MakeBin(
  3267. Min => Min,
  3268. Max => Max,
  3269. NumBin => 1,
  3270. AtLeast => 0,
  3271. Weight => 0,
  3272. Action => COV_IGNORE
  3273. ) ;
  3274. end function IgnoreBin ;
  3275. ------------------------------------------------------------
  3276. function IgnoreBin (A : integer) return CovBinType is
  3277. ------------------------------------------------------------
  3278. begin
  3279. return MakeBin(
  3280. Min => A,
  3281. Max => A,
  3282. NumBin => 1,
  3283. AtLeast => 0,
  3284. Weight => 0,
  3285. Action => COV_IGNORE
  3286. ) ;
  3287. end function IgnoreBin ;
  3288. ------------------------------------------------------------
  3289. function GenBin (
  3290. -- Manual entry format for CovBin within lots of extra parens
  3291. ------------------------------------------------------------
  3292. ManualBin : CovBinManualType
  3293. ) return CovBinType is
  3294. alias imBin : CovBinManualType (1 to ManualBin'length) is ManualBin ;
  3295. variable iCovBin : CovBinType(imBin'range) ;
  3296. begin
  3297. for i in iCovBin'range loop
  3298. iCovBin(i) := ( (1 => (imBin(i)(0),imBin(i)(1))), imBin(i)(2), 0, 1, 1) ;
  3299. end loop ;
  3300. return iCovBin ;
  3301. end function GenBin ;
  3302. ------------------------------------------------------------
  3303. function GenCross( -- 2
  3304. -- Cross existing bins
  3305. -- Use AddCross for adding values directly to coverage database
  3306. -- Use GenCross for constants
  3307. ------------------------------------------------------------
  3308. AtLeast : integer ;
  3309. Weight : integer ;
  3310. Bin1, Bin2 : CovBinType
  3311. ) return CovMatrix2Type is
  3312. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2) ;
  3313. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3314. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3315. variable CrossBins : CovBinType(BinIndex'range) ;
  3316. variable Action : integer ;
  3317. variable iCovMatrix : CovMatrix2Type(1 to NUM_NEW_BINS) ;
  3318. begin
  3319. for MatrixIndex in iCovMatrix'range loop
  3320. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2) ;
  3321. Action := MergeState(CrossBins) ;
  3322. iCovMatrix(MatrixIndex).action := Action ;
  3323. iCovMatrix(MatrixIndex).count := 0 ;
  3324. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3325. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3326. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3327. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3328. end loop ;
  3329. return iCovMatrix ;
  3330. end function GenCross ;
  3331. ------------------------------------------------------------
  3332. function GenCross(AtLeast : integer ; Bin1, Bin2 : CovBinType) return CovMatrix2Type is
  3333. -- Cross existing bins -- use AddCross instead
  3334. ------------------------------------------------------------
  3335. begin
  3336. return GenCross(AtLeast, 0, Bin1, Bin2) ;
  3337. end function GenCross ;
  3338. ------------------------------------------------------------
  3339. function GenCross(Bin1, Bin2 : CovBinType) return CovMatrix2Type is
  3340. -- Cross existing bins -- use AddCross instead
  3341. ------------------------------------------------------------
  3342. begin
  3343. return GenCross(0, 0, Bin1, Bin2) ;
  3344. end function GenCross ;
  3345. ------------------------------------------------------------
  3346. function GenCross( -- 3
  3347. ------------------------------------------------------------
  3348. AtLeast : integer ;
  3349. Weight : integer ;
  3350. Bin1, Bin2, Bin3 : CovBinType
  3351. ) return CovMatrix3Type is
  3352. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3) ;
  3353. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3354. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3355. variable CrossBins : CovBinType(BinIndex'range) ;
  3356. variable Action : integer ;
  3357. variable iCovMatrix : CovMatrix3Type(1 to NUM_NEW_BINS) ;
  3358. begin
  3359. for MatrixIndex in iCovMatrix'range loop
  3360. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3) ;
  3361. Action := MergeState(CrossBins) ;
  3362. iCovMatrix(MatrixIndex).action := Action ;
  3363. iCovMatrix(MatrixIndex).count := 0 ;
  3364. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3365. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3366. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3367. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3368. end loop ;
  3369. return iCovMatrix ;
  3370. end function GenCross ;
  3371. ------------------------------------------------------------
  3372. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type is
  3373. ------------------------------------------------------------
  3374. begin
  3375. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3) ;
  3376. end function GenCross ;
  3377. ------------------------------------------------------------
  3378. function GenCross( Bin1, Bin2, Bin3 : CovBinType ) return CovMatrix3Type is
  3379. ------------------------------------------------------------
  3380. begin
  3381. return GenCross(0, 0, Bin1, Bin2, Bin3) ;
  3382. end function GenCross ;
  3383. ------------------------------------------------------------
  3384. function GenCross( -- 4
  3385. ------------------------------------------------------------
  3386. AtLeast : integer ;
  3387. Weight : integer ;
  3388. Bin1, Bin2, Bin3, Bin4 : CovBinType
  3389. ) return CovMatrix4Type is
  3390. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4) ;
  3391. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3392. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3393. variable CrossBins : CovBinType(BinIndex'range) ;
  3394. variable Action : integer ;
  3395. variable iCovMatrix : CovMatrix4Type(1 to NUM_NEW_BINS) ;
  3396. begin
  3397. for MatrixIndex in iCovMatrix'range loop
  3398. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4) ;
  3399. Action := MergeState(CrossBins) ;
  3400. iCovMatrix(MatrixIndex).action := Action ;
  3401. iCovMatrix(MatrixIndex).count := 0 ;
  3402. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3403. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3404. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3405. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3406. end loop ;
  3407. return iCovMatrix ;
  3408. end function GenCross ;
  3409. ------------------------------------------------------------
  3410. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type is
  3411. ------------------------------------------------------------
  3412. begin
  3413. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4) ;
  3414. end function GenCross ;
  3415. ------------------------------------------------------------
  3416. function GenCross( Bin1, Bin2, Bin3, Bin4 : CovBinType ) return CovMatrix4Type is
  3417. ------------------------------------------------------------
  3418. begin
  3419. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4) ;
  3420. end function GenCross ;
  3421. ------------------------------------------------------------
  3422. function GenCross( -- 5
  3423. ------------------------------------------------------------
  3424. AtLeast : integer ;
  3425. Weight : integer ;
  3426. Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType
  3427. ) return CovMatrix5Type is
  3428. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5) ;
  3429. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3430. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3431. variable CrossBins : CovBinType(BinIndex'range) ;
  3432. variable Action : integer ;
  3433. variable iCovMatrix : CovMatrix5Type(1 to NUM_NEW_BINS) ;
  3434. begin
  3435. for MatrixIndex in iCovMatrix'range loop
  3436. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  3437. Action := MergeState(CrossBins) ;
  3438. iCovMatrix(MatrixIndex).action := Action ;
  3439. iCovMatrix(MatrixIndex).count := 0 ;
  3440. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3441. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3442. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3443. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3444. end loop ;
  3445. return iCovMatrix ;
  3446. end function GenCross ;
  3447. ------------------------------------------------------------
  3448. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type is
  3449. ------------------------------------------------------------
  3450. begin
  3451. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  3452. end function GenCross ;
  3453. ------------------------------------------------------------
  3454. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5 : CovBinType ) return CovMatrix5Type is
  3455. ------------------------------------------------------------
  3456. begin
  3457. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5) ;
  3458. end function GenCross ;
  3459. ------------------------------------------------------------
  3460. function GenCross( -- 6
  3461. ------------------------------------------------------------
  3462. AtLeast : integer ;
  3463. Weight : integer ;
  3464. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType
  3465. ) return CovMatrix6Type is
  3466. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  3467. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3468. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3469. variable CrossBins : CovBinType(BinIndex'range) ;
  3470. variable Action : integer ;
  3471. variable iCovMatrix : CovMatrix6Type(1 to NUM_NEW_BINS) ;
  3472. begin
  3473. for MatrixIndex in iCovMatrix'range loop
  3474. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  3475. Action := MergeState(CrossBins) ;
  3476. iCovMatrix(MatrixIndex).action := Action ;
  3477. iCovMatrix(MatrixIndex).count := 0 ;
  3478. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3479. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3480. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3481. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3482. end loop ;
  3483. return iCovMatrix ;
  3484. end function GenCross ;
  3485. ------------------------------------------------------------
  3486. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type is
  3487. ------------------------------------------------------------
  3488. begin
  3489. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  3490. end function GenCross ;
  3491. ------------------------------------------------------------
  3492. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6 : CovBinType ) return CovMatrix6Type is
  3493. ------------------------------------------------------------
  3494. begin
  3495. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6) ;
  3496. end function GenCross ;
  3497. ------------------------------------------------------------
  3498. function GenCross( -- 7
  3499. ------------------------------------------------------------
  3500. AtLeast : integer ;
  3501. Weight : integer ;
  3502. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType
  3503. ) return CovMatrix7Type is
  3504. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  3505. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3506. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3507. variable CrossBins : CovBinType(BinIndex'range) ;
  3508. variable Action : integer ;
  3509. variable iCovMatrix : CovMatrix7Type(1 to NUM_NEW_BINS) ;
  3510. begin
  3511. for MatrixIndex in iCovMatrix'range loop
  3512. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  3513. Action := MergeState(CrossBins) ;
  3514. iCovMatrix(MatrixIndex).action := Action ;
  3515. iCovMatrix(MatrixIndex).count := 0 ;
  3516. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3517. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3518. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3519. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3520. end loop ;
  3521. return iCovMatrix ;
  3522. end function GenCross ;
  3523. ------------------------------------------------------------
  3524. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type is
  3525. ------------------------------------------------------------
  3526. begin
  3527. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  3528. end function GenCross ;
  3529. ------------------------------------------------------------
  3530. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7 : CovBinType ) return CovMatrix7Type is
  3531. ------------------------------------------------------------
  3532. begin
  3533. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7) ;
  3534. end function GenCross ;
  3535. ------------------------------------------------------------
  3536. function GenCross( -- 8
  3537. ------------------------------------------------------------
  3538. AtLeast : integer ;
  3539. Weight : integer ;
  3540. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType
  3541. ) return CovMatrix8Type is
  3542. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  3543. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3544. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3545. variable CrossBins : CovBinType(BinIndex'range) ;
  3546. variable Action : integer ;
  3547. variable iCovMatrix : CovMatrix8Type(1 to NUM_NEW_BINS) ;
  3548. begin
  3549. for MatrixIndex in iCovMatrix'range loop
  3550. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  3551. Action := MergeState(CrossBins) ;
  3552. iCovMatrix(MatrixIndex).action := Action ;
  3553. iCovMatrix(MatrixIndex).count := 0 ;
  3554. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3555. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3556. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3557. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3558. end loop ;
  3559. return iCovMatrix ;
  3560. end function GenCross ;
  3561. ------------------------------------------------------------
  3562. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type is
  3563. ------------------------------------------------------------
  3564. begin
  3565. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  3566. end function GenCross ;
  3567. ------------------------------------------------------------
  3568. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8 : CovBinType ) return CovMatrix8Type is
  3569. ------------------------------------------------------------
  3570. begin
  3571. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8) ;
  3572. end function GenCross ;
  3573. ------------------------------------------------------------
  3574. function GenCross( -- 9
  3575. ------------------------------------------------------------
  3576. AtLeast : integer ;
  3577. Weight : integer ;
  3578. Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType
  3579. ) return CovMatrix9Type is
  3580. constant BIN_LENS : integer_vector := BinLengths(Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  3581. constant NUM_NEW_BINS : integer := CalcNumCrossBins(BIN_LENS) ;
  3582. variable BinIndex : integer_vector(1 to BIN_LENS'length) := (others => 1) ;
  3583. variable CrossBins : CovBinType(BinIndex'range) ;
  3584. variable Action : integer ;
  3585. variable iCovMatrix : CovMatrix9Type(1 to NUM_NEW_BINS) ;
  3586. begin
  3587. for MatrixIndex in iCovMatrix'range loop
  3588. CrossBins := ConcatenateBins(BinIndex, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  3589. Action := MergeState(CrossBins) ;
  3590. iCovMatrix(MatrixIndex).action := Action ;
  3591. iCovMatrix(MatrixIndex).count := 0 ;
  3592. iCovMatrix(MatrixIndex).BinVal := MergeBinVal(CrossBins) ;
  3593. iCovMatrix(MatrixIndex).AtLeast := MergeAtLeast( Action, AtLeast, CrossBins) ;
  3594. iCovMatrix(MatrixIndex).Weight := MergeWeight ( Action, Weight, CrossBins) ;
  3595. IncBinIndex( BinIndex, BIN_LENS ) ; -- increment right most one, then if overflow, increment next
  3596. end loop ;
  3597. return iCovMatrix ;
  3598. end function GenCross ;
  3599. ------------------------------------------------------------
  3600. function GenCross( AtLeast : integer ; Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type is
  3601. ------------------------------------------------------------
  3602. begin
  3603. return GenCross(AtLeast, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  3604. end function GenCross ;
  3605. ------------------------------------------------------------
  3606. function GenCross( Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9 : CovBinType ) return CovMatrix9Type is
  3607. ------------------------------------------------------------
  3608. begin
  3609. return GenCross(0, 0, Bin1, Bin2, Bin3, Bin4, Bin5, Bin6, Bin7, Bin8, Bin9) ;
  3610. end function GenCross ;
  3611. ------------------------------------------------------------
  3612. procedure increment( signal Count : inout integer ) is
  3613. ------------------------------------------------------------
  3614. begin
  3615. Count <= Count + 1 ;
  3616. end procedure increment ;
  3617. ------------------------------------------------------------
  3618. procedure increment( signal Count : inout integer ; enable : boolean ) is
  3619. ------------------------------------------------------------
  3620. begin
  3621. if enable then
  3622. Count <= Count + 1 ;
  3623. end if ;
  3624. end procedure increment ;
  3625. ------------------------------------------------------------
  3626. procedure increment( signal Count : inout integer ; enable : std_ulogic ) is
  3627. ------------------------------------------------------------
  3628. begin
  3629. if to_x01(enable) = '1' then
  3630. Count <= Count + 1 ;
  3631. end if ;
  3632. end procedure increment ;
  3633. ------------------------------------------------------------
  3634. function to_integer ( B : boolean ) return integer is
  3635. ------------------------------------------------------------
  3636. begin
  3637. if B then
  3638. return 1 ;
  3639. else
  3640. return 0 ;
  3641. end if ;
  3642. end function to_integer ;
  3643. ------------------------------------------------------------
  3644. function to_integer ( SL : std_logic ) return integer is
  3645. -------------------------------------------------------------
  3646. begin
  3647. case SL is
  3648. when '1' | 'H' => return 1 ;
  3649. when '0' | 'L' => return 0 ;
  3650. when others => return -1 ;
  3651. end case ;
  3652. end function to_integer ;
  3653. ------------------------------------------------------------
  3654. function to_integer_vector ( BV : boolean_vector ) return integer_vector is
  3655. ------------------------------------------------------------
  3656. variable result : integer_vector(BV'range) ;
  3657. begin
  3658. for i in BV'range loop
  3659. result(i) := to_integer(BV(i)) ;
  3660. end loop ;
  3661. return result ;
  3662. end function to_integer_vector ;
  3663. ------------------------------------------------------------
  3664. function to_integer_vector ( SLV : std_logic_vector ) return integer_vector is
  3665. -------------------------------------------------------------
  3666. variable result : integer_vector(SLV'range) ;
  3667. begin
  3668. for i in SLV'range loop
  3669. result(i) := to_integer(SLV(i)) ;
  3670. end loop ;
  3671. return result ;
  3672. end function to_integer_vector ;
  3673. end package body CoveragePkg ;