-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparamwidth.va
More file actions
67 lines (63 loc) · 1.98 KB
/
Copy pathparamwidth.va
File metadata and controls
67 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
`include "disciplines.vams"
// Enhancement-91: parameter-dependent declaration widths. A net/port/array
// range whose bounds reference a parameter (`[0:N-1]`, `[0:bits-1]`) is folded
// to a literal range using the parameter's elaboration-time default, so the
// bus machinery (E-3) and array machinery (E-14) see a constant width. The
// width is fixed at the default -- a structural parameter (one OSDI descriptor
// per module), see Enhancement-91.md.
// (1) parameter-SIZED array + a runtime loop over the parameter (E-70): the
// harmonic sum sum_{k=0}^{N-1} vref/(k+1).
module wsum4(out);
parameter integer N = 4;
parameter real vref = 1.0;
output out; electrical out;
real w[0:N-1];
integer k;
analog begin : b
real acc;
acc = 0.0;
for (k = 0; k < N; k = k + 1) begin
w[k] = vref / (k + 1);
acc = acc + w[k];
end
V(out) <+ acc;
end
endmodule
// (2) same source shape, a different default N -- the array width (and so the
// sum) tracks the parameter default.
module wsum8(out);
parameter integer N = 8;
parameter real vref = 1.0;
output out; electrical out;
real w[0:N-1];
integer k;
analog begin : b
real acc;
acc = 0.0;
for (k = 0; k < N; k = k + 1) begin
w[k] = vref / (k + 1);
acc = acc + w[k];
end
V(out) <+ acc;
end
endmodule
// (3) parameter-WIDTH node bus: `[0:bits-1]` folds from the default (4 bits).
module busout4(out);
parameter integer bits = 4;
output [0:bits-1] out;
electrical [0:bits-1] out;
analog begin
V(out[0]) <+ 0.25; V(out[1]) <+ 0.5;
V(out[2]) <+ 0.75; V(out[3]) <+ 1.0;
end
endmodule
// (4) the same, a wider default -- the bus (and terminal count) tracks it.
module busout6(out);
parameter integer bits = 6;
output [0:bits-1] out;
electrical [0:bits-1] out;
analog begin
V(out[0]) <+ 0.1; V(out[1]) <+ 0.2; V(out[2]) <+ 0.3;
V(out[3]) <+ 0.4; V(out[4]) <+ 0.5; V(out[5]) <+ 0.6;
end
endmodule