generated from stevehoover/MYTH_Workshop_Assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator_solutions.tlv
55 lines (41 loc) · 1.9 KB
/
calculator_solutions.tlv
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
//This is the Final solution for the 2-cycle Calculator
\m4_TLV_version 1d: tl-x.org
\SV
// This code can be found in: https://github.com/stevehoover/RISC-V_MYTH_Workshop
m4_include_lib(['https://raw.githubusercontent.com/stevehoover/RISC-V_MYTH_Workshop/ecba3769fff373ef6b8f66b3347e8940c859792d/tlv_lib/calculator_shell_lib.tlv'])
\SV
m4_makerchip_module // (Expanded in Nav-TLV pane.)
\TLV
|calc
@0
$reset = *reset;
@1
$valid_or_reset = $valid || $reset;
$valid[0] = $reset ? 0 : (1 + >>1$valid[0]);
$val1[31:0] = >>2$out[31:0];
$val2[31:0] = $rand2[3:0];
?$valid_or_reset
@1
$sum[31:0] = $val1[31:0] + $val2[31:0];
$diff[31:0] = $val1[31:0] - $val2[31:0];
$prod[31:0] = $val1[31:0] * $val2[31:0];
$quot[31:0] = $val1[31:0] / $val2[31:0];
@2
$out[31:0] = $reset ? 0 :
(($op[1:0] == 2'b00) ? $sum[31:0] :
(($op[1:0] == 2'b01) ? $diff[31:0] :
(($op[1:0] == 2'b10) ? $prod[31:0] : $quot[31:0])));
// Macro instantiations for calculator visualization(disabled by default).
// Uncomment to enable visualisation, and also,
// NOTE: If visualization is enabled, $op must be defined to the proper width using the expression below.
// (Any signals other than $rand1, $rand2 that are not explicitly assigned will result in strange errors.)
// You can, however, safely use these specific random signals as described in the videos:
// o $rand1[3:0]
// o $rand2[3:0]
// o $op[x:0]
m4+cal_viz(@3) // Arg: Pipeline stage represented by viz, should be atleast equal to last stage of CALCULATOR logic.
// Assert these to end simulation (before Makerchip cycle limit).
*passed = *cyc_cnt > 40;
*failed = 1'b0;
\SV
endmodule