forked from stevehoover/LF-Building-a-RISC-V-CPU-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.tlv
More file actions
67 lines (61 loc) · 2.16 KB
/
exercise.tlv
File metadata and controls
67 lines (61 loc) · 2.16 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
\m4_TLV_version 1d: tl-x.org
\SV
// =================================================
// Welcome! New to Makerchip? Try the "Learn" menu.
// =================================================
// Default Makerchip TL-Verilog Code Template
// Macro providing required top-level module definition, random
// stimulus support, and Verilator config.
m4_makerchip_module // (Expanded in Nav-TLV pane.)
//m4_include_lib(['https://raw.githubusercontent.com/stevehoover/LF-Building-a-RISC-V-CPU-Core/main/lib/calc_viz.tlv']).
/* verilator lint_on WIDTH */
\TLV
$reset = *reset;
/*
//Full Adder
$xor = $in1 ^ $in2;
$out = $carry_in ^ $xor;
$carry_out = ($xor & $carry_in) | ($in1 & $in2);
*/
/*
//Vector Operations
$out_add[7:0] = $in1[6:0] + $in2[6:0];
$out_mul[11:0] = $in1[6:0] * $in2[6:0];
*/
/*
// Combinational calculator circuit
$val1_zero[25:0] = 0;
$val2_zero[27:0] = 0;
$val1[31:0] = {$val1_zero , $val1_rand[5:0]};
$val2[31:0] = {$val2_zero , $val2_rand[3:0]};
$sum[31:0] = $val1[31:0] + $val2[31:0];
$diff[31:0] = $val1[31:0] - $val2[31:0];
// Or just this with no range for val1 and val2
// $diff[31:0] = $val1 - $val2;
$prod[31:0] = $val1[31:0] * $val2[31:0];
$quot[31:0] = $val1[31:0] / $val2[31:0];
$out[31:0] = $op[1:0] == 2'b00 ? $sum[31:0] :
$op[1:0] == 1 ? $diff[31:0] :
$op[1:0] == 2 ? $prod[31:0] :
$quot[31:0]; // $op[1:0] == 3
*/
//
//$cnt[15:0] = $reset ? 16'b0 : >>1$cnt + 1;
//
// Combinational calculator circuit
$val1[31:0] = >>1$out[31:0];
$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];
$out[31:0] = $reset ? 32'b0 :
$op[1:0] == 2'b00 ? $sum[31:0] :
$op[1:0] == 1 ? $diff[31:0] :
$op[1:0] == 2 ? $prod[31:0] :
$quot[31:0];
// Assert these to end simulation (before Makerchip cycle limit).
*passed = *cyc_cnt > 40;
*failed = 1'b0;
//m4+calc_viz()
\SV
endmodule