forked from sheldonucr/ucr-eecs168-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcd_dpath.v
73 lines (54 loc) · 1.36 KB
/
gcd_dpath.v
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
//=========================================================================
// RTL Model of GCD Unit Datpath
//-------------------------------------------------------------------------
//
module gcdGCDUnitDpath#( parameter W = 16 )
(
//data inputs/outputs
input [W-1:0] operands_bits_A,
input [W-1:0] operands_bits_B,
output [W-1:0] result_bits_data,
//global inputs
input clk, reset,
//control signal inputs and outputs
input B_mux_sel, A_en, B_en,
input [1:0] A_mux_sel,
output B_zero,
output A_lt_B
);
reg [W-1:0] A_reg;
reg [W-1:0] B_reg;
wire [W-1:0] A_next;
wire [W-1:0] B_next;
wire [W-1:0] sub_out;
// Combinational
// ------------
assign A_next
= A_mux_sel == 2'b00 ? operands_bits_A
: A_mux_sel == 2'b01 ? B_reg
: A_mux_sel == 2'b10 ? sub_out
: {W{1'bx}};
assign B_next
= B_mux_sel == 1'b0 ? operands_bits_B
: B_mux_sel == 1'b1 ? A_reg
: {W{1'bx}};
// Subtract
assign sub_out = A_reg - B_reg;
// Zero?
assign B_zero = (B_reg == 0) ? 1'b1 : 1'b0;
// LT
assign A_lt_B = (A_reg < B_reg) ? 1'b1 : 1'b0;
// Assign output
assign result_bits_data = A_reg;
// Sequential
// ---------
always @ (posedge clk or posedge reset) begin
if(reset) begin
A_reg <= 0;
B_reg <= 0;
end else begin
if (A_en) A_reg <= A_next;
if (B_en) B_reg <= B_next;
end
end
endmodule