LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Find Resources
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Wed Apr 26 02:42:05 CEST 2006
    Subject: [cvs-checkins] MODIFIED: mdct ...
    Top
    Date: 00/06/04 26:02:42

    Modified: mdct/source/testbench COMPILE_TIMING.DO INPIMAGE.VHD
    MDCTTB_PKG.vhd MDCT_TB.DO MDCT_TB.VHD wave.do
    Added: mdct/source/testbench random1.vhd
    Log:
    Redesigned. Fully pipelined, always ready for data design


    Revision Changes Path
    1.2 mdct/source/testbench/COMPILE_TIMING.DO

    http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/COMPILE_TIMING.DO.diff?r1=1.1&r2=1.2

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: COMPILE_TIMING.DO
    ===================================================================
    RCS file: /cvsroot/mikel262/mdct/source/testbench/COMPILE_TIMING.DO,v
    retrieving revision 1.1
    retrieving revision 1.2
    diff -u -b -r1.1 -r1.2
    --- COMPILE_TIMING.DO 15 Apr 2006 12:57:12 -0000 1.1
    +++ COMPILE_TIMING.DO 26 Apr 2006 00:42:05 -0000 1.2
    @@ -40,6 +40,7 @@
    vcom SOURCE/DCT2D.VHD
    vcom SOURCE/DBUFCTL.VHD
    vcom SYNTHESIS/MDCT_TEMP_2/MDCT_OUT.VHD
    +vcom SOURCE/TESTBENCH/random1.VHD
    vcom SOURCE/TESTBENCH/CLKGEN.VHD
    vcom SOURCE/TESTBENCH/MDCTTB_PKG.VHD
    vcom SOURCE/TESTBENCH/INPIMAGE.VHD



    1.3 mdct/source/testbench/INPIMAGE.VHD

    http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/INPIMAGE.VHD.diff?r1=1.2&r2=1.3

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: INPIMAGE.VHD
    ===================================================================
    RCS file: /cvsroot/mikel262/mdct/source/testbench/INPIMAGE.VHD,v
    retrieving revision 1.2
    retrieving revision 1.3
    diff -u -b -r1.2 -r1.3
    --- INPIMAGE.VHD 22 Apr 2006 01:41:25 -0000 1.2
    +++ INPIMAGE.VHD 26 Apr 2006 00:42:05 -0000 1.3
    @@ -29,6 +29,7 @@
    library WORK;
    use WORK.MDCT_PKG.all;
    use WORK.MDCTTB_PKG.all;
    + use WORK.RNG.all;

    entity INPIMAGE is
    port (
    @@ -54,6 +55,7 @@

    signal rst_s : STD_LOGIC;
    signal test_inp : INTEGER;
    + signal test_stim : INTEGER;
    signal test_out : INTEGER;
    signal xcon_s : INTEGER;
    signal ycon_s : INTEGER;
    @@ -71,6 +73,9 @@
    variable i : INTEGER := 0;
    variable j : INTEGER := 0;
    variable INSERT_DELAYS : BOOLEAN := FALSE;
    + variable unf: Uniform := InitUniform(7, 0.0, 2.0);
    + variable rnd: real := 0.0;
    + variable xi : INTEGER := 0;

    -------------------------------------
    -- wait for defined number of clock cycles
    @@ -159,9 +164,6 @@
    xcon_s <= x_blk_cnt*N+j;
    ycon_s <= y_blk_cnt*N+i;
    waitposedge;
    - while(ready = '0') loop
    - waitposedge;
    - end loop;
    if INSERT_DELAYS = TRUE then
    dv <= '0';
    waitposedge(40);
    @@ -179,6 +181,7 @@
    -- process begin
    ---------------------------
    begin
    + test_stim <= 0;
    dv <= '0';
    imageo <= (others => '0');
    rst_s <= '1';
    @@ -188,14 +191,12 @@
    -------------------------
    -- test 1
    -------------------------
    + test_stim <= 1;
    for i in 0 to 7 loop
    for j in 0 to 7 loop
    dv <= '1';
    imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W));
    waitposedge; - while(ready = '0') loop - waitposedge; - end loop; end loop; end loop; @@ -207,14 +208,12 @@ ------------------------- -- test 2 ------------------------- + test_stim <= 2; for i in 0 to 7 loop for j in 0 to 7 loop dv <= '1'; imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W)); waitposedge; - while(ready = '0') loop - waitposedge; - end loop; end loop; end loop; @@ -226,14 +225,12 @@ ------------------------- -- test 3 ------------------------- + test_stim <= 3; for i in 0 to 7 loop for j in 0 to 7 loop dv <= '1'; imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data2(i,j)),IP_W)); waitposedge; - while(ready = '0') loop - waitposedge; - end loop; end loop; end loop; @@ -245,14 +242,12 @@ ------------------------- -- test 4 ------------------------- + test_stim <= 4; for i in 0 to 7 loop for j in 0 to 7 loop dv <= '1'; - imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W)); - waitposedge; - while(ready = '0') loop + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W)); waitposedge; - end loop; dv <= '0'; waitposedge; end loop; @@ -266,14 +261,12 @@ ------------------------- -- test 5 ------------------------- + test_stim <= 5; for i in 0 to 7 loop for j in 0 to 7 loop dv <= '1'; imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W)); waitposedge; - while(ready = '0') loop - waitposedge; - end loop; dv <= '0'; waitposedge(25); end loop; @@ -285,9 +278,74 @@ ------------------------ ------------------------- + -- test 6-16 + ------------------------- + + for x in 0 to 10 loop + test_stim <= test_stim+1; + for i in 0 to 7 loop + for j in 0 to 7 loop + dv <= '1'; + if x rem 2 = 0 then + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W)); + else + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data3(i,j)),IP_W)); + end if; + waitposedge; + end loop; + end loop; + end loop; + + dv <= '0'; + waitposedge; + ------------------------ + + ------------------------- + -- test 17-33 + ------------------------- + + for x in 0 to 48 loop + test_stim <= test_stim+1; + if xi < 4 then + xi := xi + 1; + else + xi := 0; + end if; + for i in 0 to 7 loop + for j in 0 to 7 loop + dv <= '1'; + + case xi is + when 0 => + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data1(i,j)),IP_W)); + when 1 => + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W)); + when 2 => + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data3(i,j)),IP_W)); + when 3 => + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data4(i,j)),IP_W)); + when others => + imageo <= STD_LOGIC_VECTOR(TO_UNSIGNED(INTEGER(input_data0(i,j)),IP_W)); + end case; + waitposedge; + dv <= '0'; + GenRnd(unf); + rnd := unf.rnd; + waitposedge(INTEGER(rnd)); + end loop; + end loop; + end loop; + + dv <= '0'; + waitposedge; + ------------------------ + + ------------------------- -- test 6 ------------------------- + if RUN_FULL_IMAGE = TRUE then read_image; + end if; ------------------------- -- test 7 @@ -313,6 +371,7 @@ variable raport_str : STRING(1 to 255); variable ref_matrix : I_MATRIX_TYPE; variable dcto_matrix : I_MATRIX_TYPE; + variable xi : INTEGER := 0; ------------------------------------- -- wait for defined number of clock cycles ------------------------------------- @@ -448,8 +507,6 @@ end loop; end loop; - waitposedge; - CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); ------------------------- @@ -477,8 +534,6 @@ end loop; end loop; - waitposedge; - CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); ------------------------- @@ -506,8 +561,6 @@ end loop; end loop; - waitposedge; - CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); ------------------------- @@ -516,7 +569,7 @@ ------------------------- test_inp <= 4; -- compute reference coefficients - ref_matrix := COMPUTE_REF_DCT1D(input_data1,TRUE); + ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE); for i in 0 to N-1 loop j := 0; @@ -535,8 +588,6 @@ end loop; end loop; - waitposedge; - CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); ------------------------- @@ -564,9 +615,82 @@ end loop; end loop; + CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); + ------------------------- + + ------------------------- + -- test 6-16 + ------------------------- + for x in 0 to 10 loop + test_inp <= test_inp + 1; + -- compute reference coefficients + if x rem 2 = 0 then + ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE); + else + ref_matrix := COMPUTE_REF_DCT1D(input_data3,TRUE); + end if; + for i in 0 to N-1 loop + j := 0; + while(true) loop + + waitposedge; + if odv1 = '1' then + dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 )); + j := j + 1; + end if; + + if j = N then + exit; + end if; + + end loop; + end loop; + CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); + end loop; + ------------------------- + + ------------------------- + -- test 17-33 + ------------------------- + for x in 0 to 48 loop + test_inp <= test_inp + 1; + -- compute reference coefficients + if xi < 4 then + xi := xi + 1; + else + xi := 0; + end if; + case xi is + when 0 => + ref_matrix := COMPUTE_REF_DCT1D(input_data1,TRUE); + when 1 => + ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE); + when 2 => + ref_matrix := COMPUTE_REF_DCT1D(input_data3,TRUE); + when 3 => + ref_matrix := COMPUTE_REF_DCT1D(input_data4,TRUE); + when others => + ref_matrix := COMPUTE_REF_DCT1D(input_data0,TRUE); + end case; + + for i in 0 to N-1 loop + j := 0; + while(true) loop + waitposedge; + if odv1 = '1' then + dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto1 )); + j := j + 1; + end if; + + if j = N then + exit; + end if; + end loop; + end loop; CMP_MATRIX(ref_matrix,dcto_matrix,MAX_ERROR_1D,error_matrix,error_cnt); + end loop; ------------------------- ------------------------- @@ -574,7 +698,9 @@ ------------------------- test_inp <= 6; + if RUN_FULL_IMAGE = TRUE then read_image_for1dct(error_cnt); + end if; ------------------------- ------------------------- @@ -618,6 +744,7 @@ variable dcto_matrix : I_MATRIX_TYPE; variable tmp_matrix : I_MATRIX_TYPE; variable psnr : REAL; + variable xi : INTEGER := 0; ------------------------------------- -- wait for defined number of clock cycles ------------------------------------- @@ -935,7 +1062,7 @@ -- test 4 ------------------------- test_out <= 4; - tmp_matrix := input_data1; + tmp_matrix := input_data0; -- compute reference coefficients ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE); ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE); @@ -995,15 +1122,103 @@ CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt); idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix); - --error_idct_matrix := CMP_MATRIX(tmp_matrix,idcto_matrix,MAX_ERROR_2D); psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix); ------------------------- ------------------------- + -- test 6-16 + ------------------------- + for x in 0 to 10 loop + test_out <= test_out+1; + + if x rem 2 = 0 then + tmp_matrix := input_data0; + else + tmp_matrix := input_data3; + end if; + -- compute reference coefficients + ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE); + ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE); + + for i in 0 to N-1 loop + j := 0; + while(true) loop + + waitposedge; + if odv = '1' then + dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto )); + j := j + 1; + end if; + + if j = N then + exit; + end if; + + end loop; + end loop; + + CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt); + idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix); + psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix); + end loop; + ------------------------- + + ------------------------- + -- test 17-33 + ------------------------- + for x in 0 to 48 loop + test_out <= test_out+1; + if xi < 4 then + xi := xi + 1; + else + xi := 0; + end if; + case xi is + when 0 => + tmp_matrix := input_data1; + when 1 => + tmp_matrix := input_data0; + when 2 => + tmp_matrix := input_data3; + when 3 => + tmp_matrix := input_data4; + when others => + tmp_matrix := input_data0; + end case; + -- compute reference coefficients + ref_matrix_1d := COMPUTE_REF_DCT1D(tmp_matrix,TRUE); + ref_matrix_2d := COMPUTE_REF_DCT1D(ref_matrix_1d,FALSE); + + for i in 0 to N-1 loop + j := 0; + while(true) loop + + waitposedge; + if odv = '1' then + dcto_matrix(j,i) := TO_INTEGER(SIGNED( dcto )); + j := j + 1; + end if; + + if j = N then + exit; + end if; + + end loop; + end loop; + + CMP_MATRIX(ref_matrix_2d,dcto_matrix,MAX_ERROR_2D,error_matrix,error_cnt); + idcto_matrix := COMPUTE_REF_IDCT(dcto_matrix); + psnr := COMPUTE_PSNR(tmp_matrix,idcto_matrix); + end loop; + ------------------------- + + ------------------------- -- test 6 ------------------------- test_out <= 6; + if RUN_FULL_IMAGE = TRUE then read_image_for2dct(error_cnt); + end if; ------------------------- ------------------------- 1.3 mdct/source/testbench/MDCTTB_PKG.vhd http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/MDCTTB_PKG.vhd.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: MDCTTB_PKG.vhd =================================================================== RCS file: /cvsroot/mikel262/mdct/source/testbench/MDCTTB_PKG.vhd,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- MDCTTB_PKG.vhd 16 Apr 2006 02:30:08 -0000 1.2 +++ MDCTTB_PKG.vhd 26 Apr 2006 00:42:05 -0000 1.3 @@ -77,6 +77,7 @@ constant ENABLE_QUANTIZATION_C : BOOLEAN := FALSE; constant HEX_BASE : INTEGER := 16; constant DEC_BASE : INTEGER := 10; + constant RUN_FULL_IMAGE : BOOLEAN := FALSE; constant FILEIN_NAME_C : STRING := "SOURCE\TESTBENCH\lena512.txt"; constant FILEERROR_NAME_C : STRING := "SOURCE\TESTBENCH\imagee.txt"; constant FILEIMAGEO_NAME_C : STRING := "SOURCE\TESTBENCH\imageo.txt"; @@ -130,6 +131,29 @@ (000,000,000,000,000,000,000,000), (000,000,000,000,000,000,000,000) ); + constant input_data3 : I_MATRIX_TYPE := + ( + (55,89,0,2,35,34,100,255), + (144,151,153,151,159,156,156,156), + (150,155,165,163,158,126,156,156), + (254,000,255,255,000,245,254,255), + (159,199,161,162,162,133,155,165), + (231,000,255,235,000,255,254,253), + (162,162,161,163,162,157,157,157), + (11,12,167,165,166,167,101,108) + ); + + constant input_data4 : I_MATRIX_TYPE := + ( + (135,14,145,15,155,15,155,15), + (140,15,151,15,152,15,153,15), + (154,15,165,16,156,15,157,15), + (158,16,168,16,169,15,150,15), + (15,161,16,162,16,153,15,154), + (165,16,166,16,167,15,158,15), + (16,169,16,160,16,152,15,153), + (164,16,165,16,165,15,156,15) + ); -- from JPEG standard (but not in standard itself!) constant Q_JPEG_STD : I_MATRIX_TYPE := @@ -337,7 +361,7 @@ for a in 0 to N - 1 loop for b in 0 to N - 1 loop error_matrix_v(a,b) := ref_matrix(a,b) - dcto_matrix(a,b); - if error_matrix_v(a,b) > max_error then + if abs(error_matrix_v(a,b)) > max_error then error_cnt := error_cnt + 1; assert false report "E01: DCT max error violated!" 1.3 mdct/source/testbench/MDCT_TB.DO http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/MDCT_TB.DO.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: MDCT_TB.DO =================================================================== RCS file: /cvsroot/mikel262/mdct/source/testbench/MDCT_TB.DO,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- MDCT_TB.DO 21 Apr 2006 02:02:19 -0000 1.2 +++ MDCT_TB.DO 26 Apr 2006 00:42:05 -0000 1.3 @@ -41,6 +41,7 @@ vcom SOURCE/DCT2D.VHD vcom SOURCE/DBUFCTL.VHD vcom SOURCE/MDCT.VHD +vcom SOURCE/TESTBENCH/random1.VHD vcom SOURCE/TESTBENCH/CLKGEN.VHD vcom SOURCE/TESTBENCH/MDCTTB_PKG.VHD vcom SOURCE/TESTBENCH/INPIMAGE.VHD 1.2 mdct/source/testbench/MDCT_TB.VHD http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/MDCT_TB.VHD.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: MDCT_TB.VHD =================================================================== RCS file: /cvsroot/mikel262/mdct/source/testbench/MDCT_TB.VHD,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- MDCT_TB.VHD 15 Apr 2006 12:58:59 -0000 1.1 +++ MDCT_TB.VHD 26 Apr 2006 00:42:05 -0000 1.2 @@ -45,7 +45,7 @@ dcti : in std_logic_vector(IP_W-1 downto 0); idv : in STD_LOGIC; - ready : out STD_LOGIC; -- ready for input data + fiforead : out STD_LOGIC; -- ready for input data odv : out STD_LOGIC; dcto : out std_logic_vector(COE_W-1 downto 0); -- debug @@ -89,7 +89,7 @@ signal dcti_s : STD_LOGIC_VECTOR(IP_W-1 downto 0); signal idv_s : STD_LOGIC; -signal ready_s : STD_LOGIC; +signal fiforead_s : STD_LOGIC; signal odv_s : STD_LOGIC; signal dcto_s : STD_LOGIC_VECTOR(COE_W-1 downto 0); signal odv1_s : STD_LOGIC; @@ -110,7 +110,7 @@ dcti => dcti_s, idv => idv_s, - ready => ready_s, + fiforead => fiforead_s, odv => odv_s, dcto => dcto_s, odv1 => odv1_s, @@ -134,7 +134,7 @@ U_INPIMAGE : INPIMAGE port map ( clk => clk_s, - ready => ready_s, + ready => fiforead_s, odv1 => odv1_s, dcto1 => dcto1_s, odv => odv_s, 1.4 mdct/source/testbench/wave.do http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/wave.do.diff?r1=1.3&r2=1.4 (In the diff below, changes in quantity of whitespace are not shown.) Index: wave.do =================================================================== RCS file: /cvsroot/mikel262/mdct/source/testbench/wave.do,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- wave.do 20 Apr 2006 00:18:00 -0000 1.3 +++ wave.do 26 Apr 2006 00:42:05 -0000 1.4 @@ -1,83 +1,67 @@ onerror {resume} quietly WaveActivateNextPane {} 0 +quietly virtual signal -install /tb_mdct/u_mdct/u_dct1d { /tb_mdct/u_mdct/u_dct1d/col_reg(2 downto 1)} coLreg2 add wave -noupdate -format Literal /tb_mdct/u_inpimage/outimage_proc/error_matrix add wave -noupdate -format Literal /tb_mdct/u_inpimage/outimage_proc/dcto_matrix +add wave -noupdate -format Literal /tb_mdct/u_inpimage/test_stim add wave -noupdate -format Literal /tb_mdct/u_inpimage/test_inp add wave -noupdate -format Literal /tb_mdct/u_inpimage/ycon_s add wave -noupdate -format Literal /tb_mdct/u_inpimage/xcon_s add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_inpimage/testend add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/rst -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/requestwr -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/requestrd -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/releasewr -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/releaserd -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchwr -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchrd -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem1_full_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem2_full_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem1_lock_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem2_lock_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/clk add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/dcti add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/idv -add wave -noupdate -format Logic /tb_mdct/u_inpimage/ready -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/istate_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/state_reg -add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct1d/latch_done_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u1_rome0/datao +add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/clk add wave -noupdate -format Logic /tb_mdct/u_mdct/odv1 add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/dcto1 add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ramwe add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/ramwaddro add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct1d/ramdatai -add wave -noupdate -format Literal /tb_mdct/u_inpimage/error_dcto1_matrix_s -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ready_reg +add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/inpcnt_reg +add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/coLreg2 add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/col_reg +add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/col_2_reg add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/row_reg +add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/stage2_cnt_reg +add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct1d/stage2_reg add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct1d/databuf_reg add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct1d/latchbuf_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/col_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/row_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/inpcnt_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/cnt_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ramdatai_s -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ramwe_s -add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/i -add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/j +add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchwr +add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchrd add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct2d/clk add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct2d/rst add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/odv add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct2d/dcto +add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct2d/stage1_reg +add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct2d/stage2_reg +add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct2d/stage2_cnt_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/colram_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/rowram_reg add wave -noupdate -format Literal -radix unsigned /tb_mdct/u_mdct/u_dct2d/ramraddro add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct2d/ramdatao add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct2d/latchbuf_reg add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u_dct2d/databuf_reg +add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dct1d/wmemsel add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/col_reg add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/row_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/state_reg -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/istate_reg add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/dataready -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/cnt_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/latch_done_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct2d/completed_reg +add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ramdatai_s +add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dct1d/ramwe_s +add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/i +add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/j +add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/error_matrix +add wave -noupdate -format Literal /tb_mdct/u_inpimage/error_dct_matrix_s +add wave -noupdate -format Literal -radix decimal /tb_mdct/u_mdct/u1_ram/mem +add wave -noupdate -format Literal /tb_mdct/u_mdct/u2_ram/mem add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dbufctl/clk add wave -noupdate -format Logic /tb_mdct/u_mdct/u_dbufctl/rst -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/requestwr -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/requestrd -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/releasewr -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/releaserd add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchwr add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchrd -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/reqwrfail -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/reqrdfail add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchwr_reg add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/memswitchrd_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem1_full_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem2_full_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem1_lock_reg -add wave -noupdate -format Logic -radix hexadecimal /tb_mdct/u_mdct/u_dbufctl/mem2_lock_reg add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/i add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/j add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/error_cnt @@ -85,7 +69,6 @@ add wave -noupdate -format Literal /tb_mdct/u_inpimage/outimage_proc/j add wave -noupdate -format Literal /tb_mdct/u_inpimage/outimage_proc/error_cnt add wave -noupdate -format Literal /tb_mdct/u_inpimage/outimage_proc/raport_str -add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/error_matrix add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/ref_matrix_1d add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/ref_matrix_2d add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/dcto_matrix @@ -96,21 +79,22 @@ add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/psnr add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/i add wave -noupdate -format Literal /tb_mdct/u_inpimage/inpimage_proc/j -add wave -noupdate -format Literal /tb_mdct/u_inpimage/error_dct_matrix_s add wave -noupdate -format Literal /tb_mdct/u_inpimage/error_dcto1_matrix_s -add wave -noupdate -format Literal -radix hexadecimal /tb_mdct/u_mdct/u1_rome0/addr -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_romo0/datao -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_rome0/addr -add wave -noupdate -format Logic /tb_mdct/u_mdct/u1_rome0/clk -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_rome0/datao -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_rome0/raddr -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_romo0/addr -add wave -noupdate -format Logic /tb_mdct/u_mdct/u1_romo0/clk -add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_romo0/raddr +add wave -noupdate -format Logic /tb_mdct/u_mdct/u1_ram/clk +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/d +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/waddr +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/raddr +add wave -noupdate -format Logic /tb_mdct/u_mdct/u1_ram/we +add wave -noupdate -format Logic /tb_mdct/u_mdct/u1_ram/clk +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/q +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/mem +add wave -noupdate -format Literal /tb_mdct/u_mdct/u1_ram/read_addr +add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/i +add wave -noupdate -format Literal /tb_mdct/u_inpimage/final_outimage_proc/j TreeUpdate [SetDefaultTree] -WaveRestoreCursors {{Cursor 1} {2168745 ps} 0} +WaveRestoreCursors {{Cursor 1} {220350000 ps} 0} configure wave -namecolwidth 155 -configure wave -valuecolwidth 40 +configure wave -valuecolwidth 103 configure wave -justifyvalue left configure wave -signalnamewidth 1 configure wave -snapdistance 10 @@ -122,4 +106,4 @@ configure wave -griddelta 40 configure wave -timeline 0 update -WaveRestoreZoom {0 ps} {3002 ns} +WaveRestoreZoom {218222050 ps} {222338850 ps} 1.1 mdct/source/testbench/random1.vhd http://www.opencores.org/cvsweb.shtml/mdct/source/testbench/random1.vhd?rev=1.1&content-type=text/x-cvsweb-markup Index: random1.vhd =================================================================== -- Random number generators (RNG) -- Author: Gnanasekaran Swaminathan -- Random number generator algorithm is due to D. E. Knuth as -- given in W. H. Press et al., "Numerical Recipes in C: The Art -- of Scientific Computing," New York: Cambridge Univ. Press, 1988. -- Translated into VHDL by Gnanasekaran Swaminathan <gs4t@v...> -- Other algorithms are from libg++ by Dirk Grunwald <grunwald@c...> -- Translated into VHDL by Gnanasekaran Swaminathan <gs4t@v...> -- math functions factorial, "**", exp, ln, and sqrt are from -- math_functions package due to Tom Ashworth <ashworth@E...> -- USAGE: -- Following 10 random variables are supported: -- Uniform, Negative Exponential, Poisson, Normal, Log Normal, -- Erlang, Geometric, Hyper Geometric, Binomial, Weibull. -- -- Each random variable has its own copy of random number generator. -- Hence, you can have as many random variables of any type as you -- want only limited by the amount of memory your system has. -- -- First a random variable must be initialized using the corresponding -- Init function. Thenceforth, the new value of the random variable can -- can be obtained by a call to GenRnd. -- -- EXAMPLES: -- Uniform random number in [-50, 100] with seed 7 -- process -- variable unf: Uniform := InitUniform(7, -50.0, 100.0); -- variable rnd: real := 0; -- begin -- GenRnd(unf); -- rnd := unf.rnd; -- -50 <= rnd <= 100 -- end; -- -- Negative exponential distribution with mean 25 and seed 13 -- variable nexp: NegExp := InitNegExp(13, 25.0); -- GenRnd(nexp) -- rnd := nexp.rnd; -- 0 <= rnd <= real'High -- -- -- Please send bug reports and additions and subtractions -- to me at gs4t@v... -- -- Enjoy! -- Gnanasekaran Swaminathan package RNG is subtype rn is Real range 0.0 to 1.0; subtype PositiveReal is Real range 0.0 to Real'High; type IntA0to98 is array (0 to 98) of Integer; type distribution is ( UniformDist, NegExpDist, PoissonDist, BinomialDist, GeomDist, HypGeomDist, NormalDist, LogNormalDist, ErlangDist, WeibullDist ); type realParams is array (0 to 10) of Real; subtype intParams is Integer; subtype booleanParams is Boolean; type RndNum is record rnd : rn; init : Integer; iy : Integer; ir : IntA0to98; status : Boolean; end record; type random is record rnd: Real; r: RndNum; a: realParams; b: intParams; c: booleanParams; dist: distribution; end record; type Uniform is record rnd : Real; pHigh : Real; pLow : Real; delta : Real; r : RndNum; end record; type NegExp is record rnd : Real; pMean : PositiveReal; r : RndNum; end record; type Poisson is record rnd : Real; pMean : PositiveReal; r : RndNum; end record; type Normal is record rnd : Real; pMean : Real; pStdDev : Real; pVariance : Real; CachedNormal : Real; haveCachedNormal: Boolean; r : RndNum; end record; type LogNormal is record rnd : Real; pLogMean : Real; pLogVariance : Real; n : Normal; end record; type Erlang is record rnd : Real; pMean : Real; pVariance : Real; a : Real; k : Integer; r : RndNum; end record; type Binomial is record rnd : Real; pU : Real; pN : Integer; r : RndNum; end record; type Geom is record rnd : Real; pMean : Real; r : RndNum; end record; type HypGeom is record rnd : Real; pMean : Real; pVariance : Real; pP : Real; r : RndNum; end record; type Weibull is record rnd : Real; pAlpha : Real; pInvAlpha : Real; pBeta : Real; r : RndNum; end record; constant LN2: real := 0.693147181; function factorial (n: integer) return real; function "**"(z: Real; y: Real) return Real; function ln (z: Real) return Real; function ln1p(z: Real) return Real; function exp (z: Real) return Real; function sqrt(z: Real) return Real; procedure GenRnd(r: inout RndNum; seed: in Integer := 13); procedure GenRnd(r: inout Uniform); procedure GenRnd(r: inout NegExp); procedure GenRnd(r: inout Poisson); procedure GenRnd(r: inout Normal); procedure GenRnd(r: inout LogNormal); procedure GenRnd(r: inout Erlang); procedure GenRnd(r: inout Binomial); procedure GenRnd(r: inout Geom); procedure GenRnd(r: inout HypGeom); procedure GenRnd(r: inout Weibull); procedure GenRnd(r: inout random); -- Initialization functions function InitRndNum (seed: in Integer := 13) return RndNum; function InitUniform (seed: Integer := 13; low: Real := 0.0; high: Real := 100.0) return Uniform; function InitNegExp (seed: Integer := 13; mean: PositiveReal := 50.0) return NegExp; function InitPoisson (seed: Integer := 13; mean: PositiveReal := 50.0) return Poisson; function InitNormal (seed: Integer := 13; mean: Real := 0.0; var: Real := 100.0) return Normal; function InitLogNormal (seed: Integer := 13; mean: Real := 50.0; var: Real := 100.0) return LogNormal; function InitErlang (seed: Integer := 13; mean: Real := 50.0; var: Real := 100.0) return Erlang; function InitBinomial (seed: Integer := 13; n: Integer := 0; u: Real := 0.0) return Binomial; function InitGeom (seed: Integer := 13; mean: Real := 0.0) return Geom; function InitHypGeom (seed: Integer := 13; mean: Real := 0.0; var: Real := 0.0) return HypGeom; function InitWeibull (seed: Integer := 13; alpha: Real := 0.0; beta: Real := 0.0) return Weibull; function InitUniform (low: Real := 0.0; high: Real := 100.0; seed: Integer := 13) return random; function InitNegExp (mean: PositiveReal := 50.0; seed: Integer := 13) return random; function InitPoisson (mean: PositiveReal := 50.0; seed: Integer := 13) return random; function InitNormal (mean: Real := 0.0; var: Real := 100.0; seed: Integer := 13) return random; function InitLogNormal (mean: Real := 50.0; var: Real := 100.0; seed: Integer := 13) return random; function InitErlang (mean: Real := 50.0; var: Real := 100.0; seed: Integer := 13) return random; function InitBinomial (n: Integer := 0; u: Real := 0.0; seed: Integer := 13) return random; function InitGeom (mean: Real := 0.0; seed: Integer := 13) return random; function InitHypGeom (mean: Real := 0.0; var: Real := 0.0; seed: Integer := 13) return random; function InitWeibull (alpha: Real := 0.0; beta: Real := 0.0; seed: Integer := 13) return random; -- conversion functions function CvtRandom (uni: in Uniform) return random; function CvtRandom (nex: in NegExp) return random; function CvtRandom (poi: in Poisson) return random; function CvtRandom (nom: in Normal) return random; function CvtRandom (lnom: in LogNormal) return random; function CvtRandom (erl: in Erlang) return random; function CvtRandom (bin: in Binomial) return random; function CvtRandom (geo: in Geom) return random; function CvtRandom (hypg: in HypGeom) return random; function CvtRandom (wei: in Weibull) return random; function CvtUniform (r: in random) return Uniform; function CvtNegExp (r: in random) return NegExp; function CvtPoisson (r: in random) return Poisson; function CvtNormal (r: in random) return Normal; function CvtLogNormal (r: in random) return LogNormal; function CvtErlang (r: in random) return Erlang; function CvtBinomial (r: in random) return Binomial; function CvtGeom (r: in random) return Geom; function CvtHypGeom (r: in random) return HypGeom; function CvtWeibull (r: in random) return Weibull; end RNG; package body RNG is ------------------------------------------------------------------------------- function factorial(n : integer) return real is variable result : Integer; begin result := 1; if (n > 1) then for i in 2 to n loop result := result * i; end loop; end if; return Real(result); end factorial; ------------------------------------------------------------------------------- function "**" (z: Real; y: Real) return Real is begin return exp(y * ln(z)); end; ------------------------------------------------------------------------------- function ln (z : real) return real is variable Result : real; variable tmpx : real; variable n : integer; variable acc : integer; begin assert not (z <= 0.0) report "ERROR : Can't take the ln of a negative number" severity error; tmpx := z; n := 0; --reduce z to a number less than one in order --to use a more accurate model that converges --much faster. This will render the log function --to ln(z) = ln(tmpx) + n * ln(2) where ln(2) is --defined as a constant. while (tmpx >= 1.0) loop tmpx := tmpx / 2.0; n := n +1; end loop; --acc determines the number of iterations of the series --these values are results from comparisons with the SUN --log() C function at a accuracy of at least 0.00001. if (tmpx < 0.5) then acc := 100; else acc := 20; end if; tmpx := tmpx - 1.0; result := real(n) * LN2; n := 1; while (n < acc) loop result := result + (tmpx**n)/real(n) - (tmpx**(n+1))/real(n+1); n := n +2; end loop; return Result; end ln; ------------------------------------------------------------------------------- function ln1p(z: Real) return Real is begin assert false report "ln1p is not implemented" severity error; return ln(z); end; ------------------------------------------------------------------------------- function exp (z : real) return real is variable result,tmp : real; variable i : integer; begin if (z = 0.0) then result := 1.0; else result := z + 1.0; i := 2; tmp := z*z/2.0; result := result + tmp; while (abs(tmp) > 0.000005) loop i := i +1; tmp := tmp * z / Real(i); result := result + tmp; end loop; end if; return result; end exp; ------------------------------------------------------------------------------- function sqrt(z: Real) return Real is begin assert z >= 0.0 report "sqrt (negative number) is undefined" severity error; return z ** 0.5; end; ------------------------------------------------------------------------------- procedure GenRnd(r: inout RndNum; seed: in Integer := 13) is constant RN_M : Integer := 714025; constant RN_IA: Integer := 1366; constant RN_IC: Integer := 150889; variable j : Integer := 0; begin if (not r.status) then r.status := True; r.init := seed; r.init := abs ( (RN_IC - r.init) mod RN_M ); for i in 0 to 1 loop for j in 1 to 97 loop r.init := (RN_IA * r.init + RN_IC) mod RN_M; r.ir(j) := r.init; end loop; end loop; r.init := (RN_IA * r.init + RN_IC) mod RN_M; r.iy := r.init; r.rnd := REAL(r.iy) / REAL(RN_M); return; end if; j := 1 + 97 * r.iy / RN_M; assert (1 <= j and j <= 97) report "this cannon happen in GenRnd(RndNum)" severity error; r.iy := r.ir(j); r.init := (RN_IA * r.init + RN_IC) mod RN_M; r.ir(j) := r.init; r.rnd := REAL(r.iy) / REAL(RN_M); end GenRnd; -- RndNum ------------------------------------------------------------------------------- procedure GenRnd(r: inout Uniform) is begin assert r.r.status report "Uniform variable is not initialized" severity error; GenRnd(r.r); r.rnd := r.pLow + r.delta * r.r.rnd; end GenRnd; -- Uniform ------------------------------------------------------------------------------- procedure GenRnd(r: inout NegExp) is begin assert r.r.status report "NegExp variable is not initialized" severity error; GenRnd(r.r); r.rnd := - r.pMean * ln(1.0 - r.r.rnd); -- ln1p will be better here end GenRnd; -- NegExp ------------------------------------------------------------------------------- procedure GenRnd(r: inout Poisson) is variable product: Real := 1.0; variable bound: Real := 0.0; begin assert r.r.status report "Poisson variable is not initialized" severity error; bound := exp(-1.0 * r.pMean); r.rnd := -1.0; while (product >= bound) loop r.rnd := r.rnd + 1.0; GenRnd(r.r); product := product * r.r.rnd; end loop; end GenRnd; -- Poisson ------------------------------------------------------------------------------- procedure GenRnd(r: inout Normal) is variable v1: Real := 0.0; variable v2: Real := 0.0; variable w : Real := 0.0; variable x1: Real := 0.0; variable x2: Real := 0.0; begin assert r.r.status report "Normal variable is not initialized" severity error; if (r.haveCachedNormal) then r.haveCachedNormal := False; r.rnd := r.cachedNormal * r.pStdDev + r.pMean; return; end if; while (True) loop GenRnd(r.r); v1 := 2.0 * r.r.rnd - 1.0; GenRnd(r.r); v2 := 2.0 * r.r.rnd - 1.0; w := v1 * v1 + v2* v2; if ( w <= 1.0 ) then w := sqrt(-2.0 * ln (w) / w); x1 := v1 * w; x2 := v2 * w; r.haveCachedNormal := True; r.CachedNormal := x2; r.rnd := x1 * r.pStdDev + r.pMean; return; end if; end loop; end GenRnd; -- Normal ------------------------------------------------------------------------------- procedure GenRnd(r: inout LogNormal) is begin assert r.n.r.status report "LogNormal variable is not initialized" severity error; GenRnd(r.n); r.rnd := exp(r.n.rnd); end GenRnd; -- LogNormal ------------------------------------------------------------------------------- procedure GenRnd(r: inout Erlang) is variable prod : Real := 1.0; begin assert r.r.status report "Erlang variable is not initialized" severity error; for i in 1 to r.k loop GenRnd(r.r); prod := prod * r.r.rnd; end loop; r.rnd := - ln( prod ) / r.a; end GenRnd; -- Erlang ------------------------------------------------------------------------------- procedure GenRnd(r: inout Binomial) is begin assert r.r.status report "Binomial variable is not initialized" severity error; r.rnd := 0.0; for i in 1 to r.pN loop GenRnd(r.r); if (r.r.rnd < r.pU) then r.rnd := r.rnd + 1.0; end if; end loop; end GenRnd; -- Binomial ------------------------------------------------------------------------------- procedure GenRnd(r: inout Geom) is begin assert r.r.status report "Geom variable is not initialized" severity error; r.rnd := 1.0; GenRnd(r.r); while (r.r.rnd < r.pMean) loop r.rnd := r.rnd + 1.0; GenRnd(r.r); end loop; end GenRnd; -- Geom ------------------------------------------------------------------------------- procedure GenRnd(r: inout HypGeom) is variable z: Real := 0.0; begin assert r.r.status report "HypGeom variable is not initialized" severity error; GenRnd(r.r); if (r.r.rnd > r.pP) then z := 1.0 - r.pP; else z := r.pP; end if; GenRnd(r.r); r.rnd := -r.pMean * ln( r.r.rnd )/ (2.0*z); end GenRnd; -- HypGeom ------------------------------------------------------------------------------- procedure GenRnd(r: inout Weibull) is begin assert r.r.status report "Weibull variable r is not initialized" severity error; GenRnd(r.r); r.rnd := ( -r.pBeta * ln(1.0 - r.r.rnd) ) ** r.pInvAlpha; end GenRnd; -- Weibull ------------------------------------------------------------------------------- function InitRndNum (seed: in Integer := 13) return RndNum is constant RN_M : Integer := 714025; constant RN_IA: Integer := 1366; constant RN_IC: Integer := 150889; variable j : Integer := 0; variable r : RndNum; begin r.status := True; r.init := seed; r.init := abs ( (RN_IC - r.init) mod RN_M ); for i in 0 to 1 loop for j in 1 to 97 loop r.init := (RN_IA * r.init + RN_IC) mod RN_M; r.ir(j) := r.init; end loop; end loop; r.init := (RN_IA * r.init + RN_IC) mod RN_M; r.iy := r.init; return r; end InitRndNum; ------------------------------------------------------------------------------- function InitUniform (seed: Integer := 13; low: Real := 0.0; high: Real := 100.0) return Uniform is variable r : Uniform; begin r.r.status := False; if (low < high) then r.pLow := low; r.pHigh := high; else r.pLow := high; r.pHigh := low; end if; r.delta := high-low; GenRnd(r.r, seed); return r; end InitUniform; ------------------------------------------------------------------------------- function InitNegExp (seed: Integer := 13; mean: PositiveReal := 50.0) return NegExp is variable r : NegExp; begin r.r.status := False; r.pMean := mean; GenRnd(r.r, seed); return r; end InitNegExp; ------------------------------------------------------------------------------- function InitPoisson (seed: Integer := 13; mean: PositiveReal := 50.0) return Poisson is variable r : Poisson; begin r.r.status := False; r.pMean := mean; GenRnd(r.r, seed); return r; end InitPoisson; ------------------------------------------------------------------------------- function InitNormal (seed: Integer := 13; mean: Real := 0.0; var: Real := 100.0) return Normal is variable r : Normal; begin r.r.status := False; r.haveCachedNormal := False; r.pMean := mean; r.pVariance := var; r.pStdDev := sqrt(r.pVariance); GenRnd(r.r, seed); return r; end InitNormal; ------------------------------------------------------------------------------- function InitLogNormal (seed: Integer := 13; mean: Real := 50.0; var: Real := 100.0) return LogNormal is variable m2: Real := 0.0; variable mn: Real := 0.0; variable sd: Real := 0.0; variable r : LogNormal; begin r.n.r.status := False; r.pLogMean := mean; r.pLogVariance := var; m2 := r.pLogMean * r.pLogMean; mn := ln( m2 / sqrt(r.pLogVariance + m2) ); sd := sqrt( ln( (r.pLogVariance + m2) / m2 ) ); r.n := InitNormal(seed, mn, sd); return r; end InitLogNormal; ------------------------------------------------------------------------------- function InitErlang (seed: Integer := 13; mean: Real := 50.0; var: Real := 100.0) return Erlang is variable r : Erlang; begin r.r.status := False; r.pMean := mean; r.pVariance := var; r.k := Integer(r.pMean*r.pMean/r.pVariance+0.5); if (r.k <= 0) then r.k := 1; end if; r.a := Real(r.k) / r.pMean; GenRnd(r.r, seed); return r; end InitErlang; ------------------------------------------------------------------------------- function InitBinomial (seed: Integer := 13; n: Integer := 0; u: Real := 0.0) return Binomial is variable r : Binomial; begin r.r.status := False; r.pN := n; r.pU := u; GenRnd(r.r, seed); return r; end InitBinomial; ------------------------------------------------------------------------------- function InitGeom (seed: Integer := 13; mean: Real := 0.0) return Geom is variable r : Geom; begin r.r.status := False; r.pMean := mean; GenRnd(r.r, seed); return r; end InitGeom; ------------------------------------------------------------------------------- function InitHypGeom (seed: Integer := 13; mean: Real := 0.0; var: Real := 0.0) return HypGeom is variable z: Real := 0.0; variable r : HypGeom; begin r.r.status := False; r.pMean := mean; r.pVariance := var; z := r.pVariance / (r.pMean * r.pMean); z := sqrt( (z-1.0) / (z+1.0) ); r.pP := 0.5 * ( 1.0 - z ); GenRnd(r.r, seed); return r; end InitHypGeom; ------------------------------------------------------------------------------- function InitWeibull (seed: Integer := 13; alpha: Real := 0.0; beta: Real := 0.0) return Weibull is variable r : Weibull; begin r.r.status := False; r.pAlpha := alpha; r.pBeta := beta; r.pInvAlpha := 1.0 / r.pAlpha; GenRnd(r.r, seed); return r; end InitWeibull; ------------------------------------------------------------------------------- function InitUniform (low: Real := 0.0; high: Real := 100.0; seed: Integer := 13) return random is begin return CvtRandom (InitUniform (seed, low, high)); end InitUniform; ------------------------------------------------------------------------------- function InitNegExp (mean: PositiveReal := 50.0; seed: Integer := 13) return random is begin return CvtRandom (InitNegExp (seed, mean)); end InitNegExp; ------------------------------------------------------------------------------- function InitPoisson (mean: PositiveReal := 50.0; seed: Integer := 13) return random is begin return CvtRandom (InitPoisson (seed, mean)); end InitPoisson; ------------------------------------------------------------------------------- function InitNormal (mean: Real := 0.0; var: Real := 100.0; seed: Integer := 13) return random is begin return CvtRandom (InitNormal (seed, mean, var)); end InitNormal; ------------------------------------------------------------------------------- function InitLogNormal (mean: Real := 50.0; var: Real := 100.0; seed: Integer := 13) return random is begin return CvtRandom (InitLogNormal (seed, mean, var)); end InitLogNormal; ------------------------------------------------------------------------------- function InitErlang (mean: Real := 50.0; var: Real := 100.0; seed: Integer := 13) return random is begin return CvtRandom (InitErlang (seed, mean, var)); end InitErlang; ------------------------------------------------------------------------------- function InitBinomial (n: Integer := 0; u: Real := 0.0; seed: Integer := 13) return random is begin return CvtRandom (InitBinomial (seed, n, u)); end InitBinomial; ------------------------------------------------------------------------------- function InitGeom (mean: Real := 0.0; seed: Integer := 13) return random is begin return CvtRandom (InitGeom (seed, mean)); end InitGeom; ------------------------------------------------------------------------------- function InitHypGeom (mean: Real := 0.0; var: Real := 0.0; seed: Integer := 13) return random is begin return CvtRandom (InitHypGeom (seed, mean, var)); end InitHypGeom; ------------------------------------------------------------------------------- function InitWeibull (alpha: Real := 0.0; beta: Real := 0.0; seed: Integer := 13) return random is begin return CvtRandom (InitWeibull (seed, alpha, beta)); end InitWeibull; ------------------------------------------------------------------------------- procedure GenRnd (r: inout random) is variable unf : Uniform; variable nex : NegExp; variable poi : Poisson; variable nom : Normal; variable lnom : LogNormal; variable erl : Erlang; variable geo : Geom; variable hypg : HypGeom; variable bin : Binomial; variable wei : Weibull; begin case r.dist is when UniformDist => unf := (r.rnd, r.a(2), r.a(1), r.a(3), r.r); GenRnd(unf); r.rnd := unf.rnd; r.r := unf.r; return; when NegExpDist => nex := (r.rnd, PositiveReal'(r.a(1)), r.r); GenRnd(nex); r.rnd := nex.rnd; r.r := nex.r; return; when PoissonDist => poi := (r.rnd, PositiveReal'(r.a(1)), r.r); GenRnd(poi); r.rnd := poi.rnd; r.r := poi.r; return; when NormalDist => nom := (r.rnd, r.a(1), r.a(3), r.a(2), r.a(4), r.c, r.r); GenRnd(nom); r.rnd := nom.rnd; r.r := nom.r; r.a(4):= nom.CachedNormal; r.c := nom.haveCachedNormal; return; when LogNormalDist => nom := (r.rnd, r.a(1), r.a(3), r.a(2), r.a(4), r.c, r.r); lnom := (r.rnd, r.a(5), r.a(6), nom); GenRnd(lnom); r.rnd := lnom.rnd; r.r := lnom.n.r; r.a(4):= lnom.n.CachedNormal; r.c := lnom.n.haveCachedNormal; return; when ErlangDist => erl := (r.rnd, r.a(1), r.a(2), r.a(3), r.b, r.r); GenRnd(erl); r.rnd := erl.rnd; r.r := erl.r; return; when BinomialDist => bin := (r.rnd, r.a(1), r.b, r.r); GenRnd(bin); r.rnd := bin.rnd; r.r := bin.r; return; when GeomDist => geo := (r.rnd, r.a(1), r.r); GenRnd(geo); r.rnd := geo.rnd; r.r := geo.r; return; when HypGeomDist => hypg := (r.rnd, r.a(1), r.a(2), r.a(3), r.r); GenRnd(hypg); r.rnd := hypg.rnd; r.r := hypg.r; return; when WeibullDist => wei := (r.rnd, r.a(1), r.a(3), r.a(2), r.r); GenRnd(wei); r.rnd := wei.rnd; r.r := wei.r; return; end case; end GenRnd; ------------------------------------------------------------------------------- function CvtRandom (uni: in Uniform) return random is variable r : random; begin r.dist := UniformDist; r.rnd := uni.rnd; r.a(1) := uni.pLow; r.a(2) := uni.pHigh; r.a(3) := uni.delta; r.r := uni.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (nex: in NegExp) return random is variable r : random; begin r.dist := NegExpDist; r.rnd := nex.rnd; r.a(1) := nex.pMean; r.r := nex.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (poi: in Poisson) return random is variable r : random; begin r.dist := PoissonDist; r.rnd := poi.rnd; r.a(1) := poi.pMean; r.r := poi.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (nom: in Normal) return random is variable r : random; begin r.dist := NormalDist; r.rnd := nom.rnd; r.a(1) := nom.pMean; r.a(2) := nom.pVariance; r.a(3) := nom.pStdDev; r.a(4) := nom.CachedNormal; r.c := nom.haveCachedNormal; r.r := nom.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (lnom: in LogNormal) return random is variable r : random := CvtRandom(lnom.n); begin r.dist := LogNormalDist; r.a(5) := lnom.pLogMean; r.a(6) := lnom.pLogVariance; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (erl: in Erlang) return random is variable r : random; begin r.dist := ErlangDist; r.rnd := erl.rnd; r.a(1) := erl.pMean; r.a(2) := erl.pVariance; r.a(3) := erl.a; r.b := erl.k; r.r := erl.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (bin: in Binomial) return random is variable r : random; begin r.dist := BinomialDist; r.rnd := bin.rnd; r.a(1) := bin.pU; r.b := bin.pN; r.r := bin.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (geo: in Geom) return random is variable r : random; begin r.dist := GeomDist; r.a(1) := geo.pMean; r.r := geo.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (hypg: in HypGeom) return random is variable r : random; begin r.dist := HypGeomDist; r.a(1) := hypg.pMean; r.a(2) := hypg.pVariance; r.a(3) := hypg.pP; r.r := hypg.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtRandom (wei: in Weibull) return random is variable r : random; begin r.dist := WeibullDist; r.a(1) := wei.pAlpha; r.a(2) := wei.pBeta; r.a(3) := wei.pInvAlpha; r.r := wei.r; return r; end CvtRandom; ------------------------------------------------------------------------------- function CvtUniform (r: in random) return Uniform is variable uni : Uniform := (r.rnd, r.a(2), r.a(1), r.a(3), r.r); begin return uni; end CvtUniform; ------------------------------------------------------------------------------- function CvtNegExp (r: in random) return NegExp is variable nex : NegExp := (r.rnd, PositiveReal'(r.a(1)), r.r); begin return nex; end CvtNegExp; ------------------------------------------------------------------------------- function CvtPoisson (r: in random) return Poisson is variable poi : Poisson := (r.rnd, PositiveReal'(r.a(1)), r.r); begin return poi; end CvtPoisson; ------------------------------------------------------------------------------- function CvtNormal (r: in random) return Normal is variable nom : Normal := (r.rnd, r.a(1), r.a(3), r.a(2), r.a(4), r.c, r.r); begin return nom; end CvtNormal; ------------------------------------------------------------------------------- function CvtLogNormal (r: in random) return LogNormal is variable nom : Normal := (r.rnd, r.a(1), r.a(3), r.a(2), r.a(4), r.c, r.r); variable lnom : LogNormal := (r.rnd, r.a(5), r.a(6), nom); begin return lnom; end CvtLogNormal; ------------------------------------------------------------------------------- function CvtErlang (r: in random) return Erlang is variable erl : Erlang := (r.rnd, r.a(1), r.a(2), r.a(3), r.b, r.r); begin return erl; end CvtErlang; ------------------------------------------------------------------------------- function CvtBinomial (r: in random) return Binomial is variable bin : Binomial := (r.rnd, r.a(1), r.b, r.r); begin return bin; end CvtBinomial; ------------------------------------------------------------------------------- function CvtGeom (r: in random) return Geom is variable geo : Geom := (r.rnd, r.a(1), r.r); begin return geo; end CvtGeom; ------------------------------------------------------------------------------- function CvtHypGeom (r: in random) return HypGeom is variable hypg : HypGeom := (r.rnd, r.a(1), r.a(2), r.a(3), r.r); begin return hypg; end CvtHypGeom; ------------------------------------------------------------------------------- function CvtWeibull (r: in random) return Weibull is variable wei : Weibull := (r.rnd, r.a(1), r.a(3), r.a(2), r.r); begin return wei; end CvtWeibull; ------------------------------------------------------------------------------- end RNG;

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.