-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrayret_demo.va
More file actions
79 lines (69 loc) · 2.43 KB
/
Copy patharrayret_demo.va
File metadata and controls
79 lines (69 loc) · 2.43 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
68
69
70
71
72
73
74
75
76
77
78
79
`include "disciplines.vams"
// Enhancement-23 demonstration: array RETURN values from analog functions,
// completing the array-in-functions arc:
// * E-18 array *arguments* (input, by value)
// * E-20 array *output/inout* arguments (write-back)
// * E-23 array *return values* <-- this file
//
// `analog function real[0:n] f;` returns a whole array; at the call site
// `c = f(...)` copies the returned array into the destination array variable.
//
// Both modules implement the same polynomial device
// I(p,n) = c0 + c1*V + c2*V^2 + c3*V^3
// so V(out) tracks the closed form and the AC conductance matches the exact
// derivative (the autodiff Jacobian flowing through the array return).
module polyret(p, n);
inout p, n; electrical p, n;
parameter real c0 = 0.10;
parameter real c1 = 0.50;
parameter real c2 = 0.30;
parameter real c3 = 0.05;
// array RETURN: powers(x) = {1, x, x^2, x^3}
analog function real[0:3] powers;
input x; real x; integer i;
begin
powers[0] = 1.0;
for (i = 1; i < 4; i = i + 1) powers[i] = powers[i - 1] * x;
end
endfunction
real pw[0:3];
real y;
analog begin
pw = powers(V(p, n)); // <-- array return -> aggregate assignment
y = c0*pw[0] + c1*pw[1] + c2*pw[2] + c3*pw[3];
I(p, n) <+ y;
end
endmodule
// Same device, but the returned array is fed straight into an array-*argument*
// function (E-18): array return composed with array argument in one expression.
module polyret_arg(p, n);
inout p, n; electrical p, n;
parameter real c0 = 0.10;
parameter real c1 = 0.50;
parameter real c2 = 0.30;
parameter real c3 = 0.05;
analog function real[0:3] powers;
input x; real x; integer i;
begin
powers[0] = 1.0;
for (i = 1; i < 4; i = i + 1) powers[i] = powers[i - 1] * x;
end
endfunction
// array ARGUMENT (E-18): weighted sum of a whole array
analog function real dot;
input w, v; real w[0:3]; real v[0:3]; integer i;
begin
dot = 0.0;
for (i = 0; i < 4; i = i + 1) dot = dot + w[i] * v[i];
end
endfunction
real coeffs[0:3];
real pw[0:3];
real y;
analog begin
coeffs = '{c0, c1, c2, c3};
pw = powers(V(p, n)); // array return
y = dot(coeffs, pw); // two array arguments (E-18)
I(p, n) <+ y;
end
endmodule