1 |
d93979b7
|
Arnaud Dieumegard
|
|
2 |
|
|
-- Copyright (C) 1996 Morgan Kaufmann Publishers, Inc
|
3 |
|
|
|
4 |
|
|
-- This file is part of VESTs (Vhdl tESTs).
|
5 |
|
|
|
6 |
|
|
-- VESTs is free software; you can redistribute it and/or modify it
|
7 |
|
|
-- under the terms of the GNU General Public License as published by the
|
8 |
|
|
-- Free Software Foundation; either version 2 of the License, or (at
|
9 |
|
|
-- your option) any later version.
|
10 |
|
|
|
11 |
|
|
-- VESTs is distributed in the hope that it will be useful, but WITHOUT
|
12 |
|
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13 |
|
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14 |
|
|
-- for more details.
|
15 |
|
|
|
16 |
|
|
-- You should have received a copy of the GNU General Public License
|
17 |
|
|
-- along with VESTs; if not, write to the Free Software Foundation,
|
18 |
|
|
-- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
|
|
|
20 |
|
|
-- ---------------------------------------------------------------------
|
21 |
|
|
--
|
22 |
|
|
-- $Id: ch_19_fork-b.vhd,v 1.2 2001-10-26 16:29:36 paw Exp $
|
23 |
|
|
-- $Revision: 1.2 $
|
24 |
|
|
--
|
25 |
|
|
-- ---------------------------------------------------------------------
|
26 |
|
|
|
27 |
|
|
architecture behavior of fork is
|
28 |
|
|
|
29 |
|
|
begin
|
30 |
|
|
|
31 |
|
|
forker : process
|
32 |
|
|
|
33 |
|
|
variable cumulative_probabilities : probability_vector(1 to probabilities'length);
|
34 |
|
|
variable destination : positive range out_arc'range;
|
35 |
|
|
variable probabilities_index : positive range probabilities'range;
|
36 |
|
|
variable number_of_tokens_forked : natural := 0;
|
37 |
|
|
type counter_array is array (positive range out_arc'range) of natural;
|
38 |
|
|
variable number_forked_to_destination : counter_array := (others => 0);
|
39 |
|
|
|
40 |
|
|
variable random_info : random_info_record;
|
41 |
|
|
variable random_number : real;
|
42 |
|
|
|
43 |
|
|
type transaction_vector is array (positive range <>) of boolean;
|
44 |
|
|
variable out_arc_transaction_driving_value : transaction_vector(out_arc'range)
|
45 |
|
|
:= (others => false);
|
46 |
|
|
|
47 |
|
|
use std.textio.all;
|
48 |
|
|
file info_file : text;
|
49 |
|
|
variable L : line;
|
50 |
|
|
|
51 |
|
|
procedure write_summary is
|
52 |
|
|
begin
|
53 |
|
|
write(L, string'("Summary information for fork "));
|
54 |
|
|
write(L, name);
|
55 |
|
|
write(L, string'(" up to time "));
|
56 |
|
|
write(L, now, unit => time_unit);
|
57 |
|
|
writeline(info_file, L);
|
58 |
|
|
write(L, string'(" Number of tokens forked = "));
|
59 |
|
|
write(L, natural(number_of_tokens_forked));
|
60 |
|
|
writeline(info_file, L);
|
61 |
|
|
for destination in out_arc'range loop
|
62 |
|
|
write(L, string'(" Number to output("));
|
63 |
|
|
write(L, destination);
|
64 |
|
|
write(L, string'(") = "));
|
65 |
|
|
write(L, number_forked_to_destination(destination));
|
66 |
|
|
write(L, string'(" ("));
|
67 |
|
|
write(L, real(number_forked_to_destination(destination))
|
68 |
|
|
/ real(number_of_tokens_forked),
|
69 |
|
|
digits => 4);
|
70 |
|
|
write(L, ')');
|
71 |
|
|
writeline(info_file, L);
|
72 |
|
|
end loop;
|
73 |
|
|
writeline(info_file, L);
|
74 |
|
|
end write_summary;
|
75 |
|
|
|
76 |
|
|
procedure write_trace is
|
77 |
|
|
begin
|
78 |
|
|
write(L, string'("Fork "));
|
79 |
|
|
write(L, name);
|
80 |
|
|
write(L, string'(": at "));
|
81 |
|
|
write(L, now, unit => time_unit);
|
82 |
|
|
write(L, string'(" forked to output "));
|
83 |
|
|
write(L, destination);
|
84 |
|
|
write(L, ' ');
|
85 |
|
|
write(L, in_arc.token, time_unit);
|
86 |
|
|
writeline(info_file, L);
|
87 |
|
|
end write_trace;
|
88 |
|
|
|
89 |
|
|
begin
|
90 |
|
|
assert probabilities'length = out_arc'length - 1
|
91 |
|
|
report "incorrent number of probabilities - should be "
|
92 |
|
|
& integer'image(out_arc'length - 1) severity failure;
|
93 |
|
|
cumulative_probabilities := probabilities;
|
94 |
|
|
for index in 2 to cumulative_probabilities'length loop
|
95 |
|
|
cumulative_probabilities(index) := cumulative_probabilities(index - 1)
|
96 |
|
|
+ cumulative_probabilities(index);
|
97 |
|
|
end loop;
|
98 |
|
|
init_uniform( random_info,
|
99 |
|
|
lower_bound => 0.0, upper_bound => 1.0, seed => seed );
|
100 |
|
|
file_open(info_file, info_file_name, write_mode);
|
101 |
|
|
|
102 |
|
|
loop
|
103 |
|
|
wait on info_detail'transaction, in_arc;
|
104 |
|
|
if info_detail'active and info_detail = summary then
|
105 |
|
|
write_summary;
|
106 |
|
|
end if;
|
107 |
|
|
if in_arc'event then
|
108 |
|
|
generate_random(random_info, random_number);
|
109 |
|
|
destination := out_arc'left;
|
110 |
|
|
for index in 1 to cumulative_probabilities'length loop
|
111 |
|
|
exit when random_number < cumulative_probabilities(index);
|
112 |
|
|
if out_arc'ascending then
|
113 |
|
|
destination := destination + 1;
|
114 |
|
|
else
|
115 |
|
|
destination := destination - 1;
|
116 |
|
|
end if;
|
117 |
|
|
end loop;
|
118 |
|
|
out_arc(destination) <= arc_type'( transaction => not out_arc_transaction_driving_value(destination),
|
119 |
|
|
token => in_arc.token );
|
120 |
|
|
out_arc_transaction_driving_value(destination) := not out_arc_transaction_driving_value(destination);
|
121 |
|
|
number_of_tokens_forked := number_of_tokens_forked + 1;
|
122 |
|
|
number_forked_to_destination(destination)
|
123 |
|
|
:= number_forked_to_destination(destination) + 1;
|
124 |
|
|
if info_detail = trace then
|
125 |
|
|
write_trace;
|
126 |
|
|
end if;
|
127 |
|
|
end if;
|
128 |
|
|
end loop;
|
129 |
|
|
end process forker;
|
130 |
|
|
|
131 |
|
|
end behavior;
|