-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathslidesExampleCode.sus
110 lines (76 loc) · 2.34 KB
/
slidesExampleCode.sus
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Recursive Tree Add module recurses smaller copies of itself.
module TreeAdder #(int WIDTH) {
interface TreeAdder : int[WIDTH] values'0 -> int total
if WIDTH == 0 {
// Have to explicitly give zero a latency count.
// Otherwise total's latency can't be determined.
int zero'0 = 0
total = zero
} else if WIDTH == 1 {
total = values[0]
} else {
gen int L_SZ = WIDTH / 2
gen int R_SZ = WIDTH - L_SZ
int[L_SZ] left_part, int[R_SZ] right_part = SplitAt(values)
int left_total = TreeAdder(left_part)
int right_total = TreeAdder(right_part)
// Can add pipelining registers here too.
// Latency Counting will figure it out.
reg total = left_total + right_total
}
}
module use_TreeAdder {
TreeAdder #(WIDTH: 20) t
}
module TreeAdderBaseCase #(int WIDTH) {
interface TreeAdderBaseCase : int[WIDTH] values'0 -> int total
gen int L_SZ = WIDTH / 2
gen int R_SZ = WIDTH - L_SZ
int[L_SZ] left_part, int[R_SZ] right_part = SplitAt(values)
int left_total = TreeAdder(left_part)
int right_total = TreeAdder(right_part)
// Can add pipelining registers here too.
// Latency Counting will figure it out.
reg total = left_total + right_total
}
module pairwiseMultiply #(int SIZE) {
interface pairwiseMultiply: int[SIZE] a -> int[SIZE-1] out
for int I in 0..SIZE-1 {
out[I] = a[I] * a[I+1]
}
}
module use_splitAt {
input int[20] arr
output int x
SplitAt #(T: type int, SIZE: 20, SPLIT_POINT: 2) spl
int[2] a, int[18] b = spl(arr)
int[2] c, int[18] d = SplitAt(arr)
x = a[0] + b[0] + c[0] + d[0]
}
module pairwiseMultiplyFlattened #(int SIZE) {
interface pairwiseMultiplyFlattened: int[SIZE] a -> int[SIZE-1] out
gen int _0 = SIZE-1
for int I in 0.._0 {
int _1 = a[I]
gen int _2 = I+1
int _3 = a[_2]
out[I] = _1 * _3
}
}
module pairwiseMultiplyExecuted /* #(int SIZE = 3)*/ {
interface pairwiseMultiplyExecuted: int[3] a -> int[2] out
out[0] = a[0] * a[1]
out[1] = a[1] * a[2]
}
module BRAMShiftReg #(T, int LATENCY) {
interface BRAMShiftReg: T d_in'0 -> T d_out'LATENCY
state T[LATENCY] memory
state int idx = 0
T out_data = memory[idx]
memory[idx] = d_in
idx = (idx + 1) % LATENCY
d_out = LatencyOffset #(OFFSET: LATENCY)(out_data)
}
module use_bram {
BRAMShiftReg #(T: type bool[3], LATENCY: 10) b
}