<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://simhard.com/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://simhard.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Open_Source_VHDL_Verification_Methodology%2FRandomBasePkg.vhd</id>
		<title>Open Source VHDL Verification Methodology/RandomBasePkg.vhd - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://simhard.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Open_Source_VHDL_Verification_Methodology%2FRandomBasePkg.vhd"/>
		<link rel="alternate" type="text/html" href="http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/RandomBasePkg.vhd&amp;action=history"/>
		<updated>2026-07-30T04:27:09Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.21.3</generator>

	<entry>
		<id>http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/RandomBasePkg.vhd&amp;diff=1121&amp;oldid=prev</id>
		<title>ANA в 10:30, 16 августа 2012</title>
		<link rel="alternate" type="text/html" href="http://simhard.com/wiki/index.php?title=Open_Source_VHDL_Verification_Methodology/RandomBasePkg.vhd&amp;diff=1121&amp;oldid=prev"/>
				<updated>2012-08-16T10:30:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{OS-VVM TOC}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
--&lt;br /&gt;
--  File Name:         RandomBasePkg.vhd&lt;br /&gt;
--  Design Unit Name:  RandomBasePkg&lt;br /&gt;
--  Revision:          STANDARD VERSION,  revision 2.0, VHDL-2008&lt;br /&gt;
--&lt;br /&gt;
--  Maintainer:        Jim Lewis      email:  jim@synthworks.com&lt;br /&gt;
--  Contributor(s):&lt;br /&gt;
--     Jim Lewis      jim@synthworks.com&lt;br /&gt;
--&lt;br /&gt;
--&lt;br /&gt;
--  Description:&lt;br /&gt;
--        Defines Base randomization, seed definition, seed generation,&lt;br /&gt;
--        and seed IO functionality for RandomPkg.vhd&lt;br /&gt;
--        Defines:&lt;br /&gt;
--          Procedure Uniform - baseline randomization &lt;br /&gt;
--          Type RandomSeedType - the seed as a single object&lt;br /&gt;
--          function GenRandSeed from integer_vector, integer, or string&lt;br /&gt;
--          IO function to_string, &amp;amp; procedures write, read&lt;br /&gt;
--&lt;br /&gt;
--        In revision 2.0 these types and functions are included by package reference.&lt;br /&gt;
--        Long term these will be passed as generics to RandomGenericPkg&lt;br /&gt;
--&lt;br /&gt;
--&lt;br /&gt;
--  Developed for:&lt;br /&gt;
--        SynthWorks Design Inc.&lt;br /&gt;
--        VHDL Training Classes&lt;br /&gt;
--        11898 SW 128th Ave.  Tigard, Or  97223&lt;br /&gt;
--        http://www.SynthWorks.com&lt;br /&gt;
--&lt;br /&gt;
--  Revision History:&lt;br /&gt;
--    Date       Version    Description&lt;br /&gt;
--    01/2008:   0.1        Initial revision&lt;br /&gt;
--                          Numerous revisions for VHDL Testbenches and Verification&lt;br /&gt;
--    02/2009:   1.0        First Public Released Version&lt;br /&gt;
--    02/25/2009 1.1        Replaced reference to std_2008 with a reference &lt;br /&gt;
--                          to ieee_proposed.standard_additions.all ;&lt;br /&gt;
--    03/01/2011 2.0        STANDARD VERSION&lt;br /&gt;
--                          Fixed abstraction by moving RandomParmType to RandomPkg.vhd &lt;br /&gt;
--&lt;br /&gt;
--&lt;br /&gt;
--  Copyright (c) 2008, 2009, 2010, 2011 by SynthWorks Design Inc.  All rights reserved.&lt;br /&gt;
--&lt;br /&gt;
--  Verbatim copies of this source file may be used and&lt;br /&gt;
--  distributed without restriction.&lt;br /&gt;
--&lt;br /&gt;
--  This source file is free software; you can redistribute it&lt;br /&gt;
--  and/or modify it under the terms of the ARTISTIC License&lt;br /&gt;
--  as published by The Perl Foundation; either version 2.0 of&lt;br /&gt;
--  the License, or (at your option) any later version.&lt;br /&gt;
--&lt;br /&gt;
--  This source is distributed in the hope that it will be&lt;br /&gt;
--  useful, but WITHOUT ANY WARRANTY; without even the implied&lt;br /&gt;
--  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR&lt;br /&gt;
--  PURPOSE. See the Artistic License for details.&lt;br /&gt;
--&lt;br /&gt;
--  You should have received a copy of the license with this source.&lt;br /&gt;
--  If not download it from,&lt;br /&gt;
--     http://www.perlfoundation.org/artistic_license_2_0&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
library ieee ;&lt;br /&gt;
use ieee.math_real.all ;&lt;br /&gt;
use std.textio.all ;&lt;br /&gt;
&lt;br /&gt;
-- comment out following 2 lines with VHDL-2008.  Leave in for VHDL-2002 &lt;br /&gt;
-- library ieee_proposed ;						          -- remove with VHDL-2008&lt;br /&gt;
-- use ieee_proposed.standard_additions.all ;   -- remove with VHDL-2008&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
package RandomBasePkg is&lt;br /&gt;
&lt;br /&gt;
  -- RandomSeedType and Uniform can be replaced by any procedure that&lt;br /&gt;
  -- produces a uniform distribution with 0 &amp;lt;= Value &amp;lt; 1  or  0 &amp;lt; Value &amp;lt; 1&lt;br /&gt;
  -- and maintains the same call interface&lt;br /&gt;
  type RandomSeedType is array (1 to 2) of integer ;&lt;br /&gt;
  procedure Uniform (Result : out real ;  Seed : inout RandomSeedType) ;&lt;br /&gt;
&lt;br /&gt;
  -- Translate from integer_vector, integer, or string to RandomSeedType&lt;br /&gt;
  -- Required by RandomPkg.InitSeed&lt;br /&gt;
  -- GenRandSeed makes sure all values are in a valid range&lt;br /&gt;
  function  GenRandSeed(IV : integer_vector) return RandomSeedType ;&lt;br /&gt;
  function  GenRandSeed(I : integer) return RandomSeedType ;&lt;br /&gt;
  function  GenRandSeed(S : string) return RandomSeedType ;&lt;br /&gt;
  &lt;br /&gt;
  -- IO for RandomSeedType.  If use subtype, then create aliases here&lt;br /&gt;
  -- in a similar fashion VHDL-2008 std_logic_textio.&lt;br /&gt;
  -- Not required by RandomPkg&lt;br /&gt;
  function  to_string(A : RandomSeedType) return string ;&lt;br /&gt;
  procedure write(variable L: inout line ; A : RandomSeedType ) ;&lt;br /&gt;
  procedure read (variable L: inout line ; A : out RandomSeedType ; good : out boolean ) ;&lt;br /&gt;
  procedure read (variable L: inout line ; A : out RandomSeedType ) ;&lt;br /&gt;
&lt;br /&gt;
end RandomBasePkg ;&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
package body RandomBasePkg is&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  -- Uniform&lt;br /&gt;
  --   Generate a random number with a Uniform distribution&lt;br /&gt;
  --   Required by RandomPkg.  All randomization is derived from here.&lt;br /&gt;
  --   Value produced must be either: &lt;br /&gt;
  --     0 &amp;lt;= Value &amp;lt; 1  or  0 &amp;lt; Value &amp;lt; 1&lt;br /&gt;
  --&lt;br /&gt;
  --   Current version uses ieee.math_real.Uniform&lt;br /&gt;
  --   This abstraction allows higher precision version &lt;br /&gt;
  --   of a uniform distribution to be used provided&lt;br /&gt;
  --&lt;br /&gt;
  procedure Uniform (&lt;br /&gt;
    Result : out   real ;&lt;br /&gt;
    Seed   : inout RandomSeedType &lt;br /&gt;
  ) is&lt;br /&gt;
  begin&lt;br /&gt;
    ieee.math_real.Uniform (Seed(Seed'left), Seed(Seed'right), Result) ;&lt;br /&gt;
  end procedure Uniform ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  --  GenRandSeed&lt;br /&gt;
  --    Convert integer_vector to RandomSeedType&lt;br /&gt;
  --    Uniform requires two seed values of the form:&lt;br /&gt;
  --        1 &amp;lt;= SEED1 &amp;lt;= 2147483562; 1 &amp;lt;= SEED2 &amp;lt;= 2147483398&lt;br /&gt;
  --&lt;br /&gt;
  --    if 2 seed values are passed to GenRandSeed and they are &lt;br /&gt;
  --    in the above range, then they must remain unmodified.&lt;br /&gt;
  --&lt;br /&gt;
  function GenRandSeed(IV : integer_vector) return RandomSeedType is&lt;br /&gt;
    alias iIV : integer_vector(1 to IV'length) is IV ;&lt;br /&gt;
    variable Seed1 : integer ;&lt;br /&gt;
    variable Seed2 : integer ;&lt;br /&gt;
    constant SEED1_MAX : integer := 2147483562 ;&lt;br /&gt;
    constant SEED2_MAX : integer := 2147483398 ;&lt;br /&gt;
  begin&lt;br /&gt;
    if iIV'Length &amp;lt;= 0 then  -- no seed&lt;br /&gt;
      report &amp;quot;%%FATAL:  GenRandSeed received NULL integer_vector&amp;quot; severity failure ;&lt;br /&gt;
      return (3, 17) ;  -- if continue seed = (3, 17)&lt;br /&gt;
&lt;br /&gt;
    elsif iIV'Length = 1 then  -- one seed value&lt;br /&gt;
      -- inefficient handling, but condition is unlikely&lt;br /&gt;
      return GenRandSeed(iIV(1)) ;  -- generate a seed&lt;br /&gt;
&lt;br /&gt;
    else  -- only use the left two values&lt;br /&gt;
      -- 1 &amp;lt;= SEED1 &amp;lt;= 2147483562&lt;br /&gt;
      -- mod returns 0 to MAX-1, the -1 adjusts legal values, +1 adjusts them back&lt;br /&gt;
      Seed1 := ((iIV(1)-1) mod SEED1_MAX) + 1 ;&lt;br /&gt;
     -- 1 &amp;lt;= SEED2 &amp;lt;= 2147483398&lt;br /&gt;
      Seed2 := ((iIV(2)-1) mod SEED2_MAX) + 1 ;&lt;br /&gt;
      return (Seed1, Seed2) ;&lt;br /&gt;
    end if ;&lt;br /&gt;
  end function GenRandSeed ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  --  GenRandSeed&lt;br /&gt;
  --    transform a single integer into the internal seed&lt;br /&gt;
  --&lt;br /&gt;
  function GenRandSeed(I : integer) return RandomSeedType is&lt;br /&gt;
    variable result : integer_vector(1 to 2) ;&lt;br /&gt;
  begin&lt;br /&gt;
    result(1) := I ;&lt;br /&gt;
    result(2) := I/3 + 1 ;&lt;br /&gt;
    return GenRandSeed(result) ; -- make value ranges legal&lt;br /&gt;
  end function GenRandSeed ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  --  GenRandSeed&lt;br /&gt;
  --    transform a string value into the internal seed&lt;br /&gt;
  --    usage:  RV.GenRandSeed(RV'instance_path));&lt;br /&gt;
  --&lt;br /&gt;
  function GenRandSeed(S : string) return RandomSeedType is&lt;br /&gt;
    constant LEN : integer := S'length ;&lt;br /&gt;
    constant HALF_LEN : integer := LEN/2 ;&lt;br /&gt;
    alias revS : string(LEN downto 1) is S ;&lt;br /&gt;
    variable result : integer_vector(1 to 2) ;&lt;br /&gt;
    variable temp : integer := 0 ;&lt;br /&gt;
  begin&lt;br /&gt;
    for i in 1 to HALF_LEN loop&lt;br /&gt;
      temp := (temp + character'pos(revS(i))) mod (integer'right - 2**8) ;&lt;br /&gt;
    end loop ;&lt;br /&gt;
    result(1) := temp ;&lt;br /&gt;
    for i in HALF_LEN + 1 to LEN loop&lt;br /&gt;
      temp := (temp + character'pos(revS(i))) mod (integer'right - 2**8) ;&lt;br /&gt;
    end loop ;&lt;br /&gt;
    result(2) := temp ;&lt;br /&gt;
    return GenRandSeed(result) ;  -- make value ranges legal&lt;br /&gt;
  end function GenRandSeed ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  function to_string(A : RandomSeedType) return string is&lt;br /&gt;
  begin&lt;br /&gt;
    return to_string(A(A'left)) &amp;amp; &amp;quot; &amp;quot; &amp;amp; to_string(A(A'right)) ;&lt;br /&gt;
  end function to_string ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  procedure write(variable L: inout line ; A : RandomSeedType ) is&lt;br /&gt;
  begin&lt;br /&gt;
    write(L, to_string(A)) ;&lt;br /&gt;
  end procedure ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  procedure read(variable L: inout line ; A : out RandomSeedType ; good : out boolean ) is&lt;br /&gt;
    variable iGood : boolean ;&lt;br /&gt;
  begin&lt;br /&gt;
    for i in A'range loop&lt;br /&gt;
      read(L, A(i), iGood) ;&lt;br /&gt;
      exit when not iGood ;&lt;br /&gt;
    end loop ;&lt;br /&gt;
    good := iGood ;&lt;br /&gt;
  end procedure read ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -----------------------------------------------------------------&lt;br /&gt;
  procedure read(variable L: inout line ; A : out RandomSeedType ) is&lt;br /&gt;
    variable good : boolean ;&lt;br /&gt;
  begin&lt;br /&gt;
      read(L, A, good) ;&lt;br /&gt;
      assert good report &amp;quot;read[line, RandomSeedType] failed&amp;quot; severity error ;&lt;br /&gt;
  end procedure read ;&lt;br /&gt;
  &lt;br /&gt;
end RandomBasePkg ;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Категория:OS-VVM]]&lt;/div&gt;</summary>
		<author><name>ANA</name></author>	</entry>

	</feed>