-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.v
More file actions
131 lines (108 loc) · 2.86 KB
/
testing.v
File metadata and controls
131 lines (108 loc) · 2.86 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
module multiplication_32_bit (
input wire signed [31:0] a,
input wire signed [31:0] b,
output wire[63:0] z
);
integer i,j;
reg [2:0] groupedBits[15:0];
reg [32:0] partialProduct[15:0];
reg [63:0] shiftedPartialProduct[15:0];
reg [63:0] product;
reg [31:0] absA, absB;
always@(a or b) begin
if(a[31] == 1'b1) begin
absA = -a;
end
else if(b[31] == 1'b1) begin
absB = -b;
end
else begin
absA = a;
absB = b;
end
end
wire [32:0] neg_a;
assign neg_a = -absA; // 2s Complement of a
always @(a or b or neg_a) begin
groupedBits[0] = {absB[1], absB[0], 1'b0};
for(i=1; i <= 15; i = i + 1) begin
groupedBits[i] = {absB[2*i+1], absB[2*i], absB[2*i-1]};
end
for(i = 0; i <= 15; i = i + 1) begin
case(groupedBits[i])
3'b001 : partialProduct[i] = {absA[31], absA};
3'b010 : partialProduct[i] = {absA[31], absA};
3'b101 : partialProduct[i] = neg_a;
3'b110 : partialProduct[i] = neg_a;
3'b011 : partialProduct[i] = {neg_a << 1};
3'b100 : partialProduct[i] = {neg_a << 1};
default : partialProduct[i] = 0;
endcase
//shiftedPartialProduct[i] = $signed(partialProduct[i]);
for (i=0 ; i<j ; i = i + 1)
spp[j] = {spp[j], 2'b00};
end
product = shiftedPartialProduct[0];
for(j = 0; j <= 15; j = j + 1) begin
product = product + shiftedPartialProduct[j];
end
if(a[31] == 1'b1 || b[31] == 1'b1) begin
product = -product;
end
end
assign z = product;
endmodule
module multiplication_32_bit (
input wire signed [31:0] a,
input wire signed [31:0] b,
output wire[63:0] z
);
integer i,j;
reg [2:0] groupedBits[15:0];
reg [32:0] partialProduct[15:0];
reg [63:0] shiftedPartialProduct[15:0];
reg [63:0] product;
reg [31:0] absA, absB;
always@(a or b) begin
if(a[31] == 1'b1) begin
absA = -a;
end
else if(b[31] == 1'b1) begin
absB = -b;
end
else begin
absA = a;
absB = b;
end
end
wire [32:0] neg_a;
assign neg_a = -absA; // 2s Complement of a
always @(a or b or neg_a) begin
groupedBits[0] = {absB[1], absB[0], 1'b0};
for(i=1; i <= 15; i = i + 1) begin
groupedBits[i] = {absB[2*i+1], absB[2*i], absB[2*i-1]};
end
for(i = 0; i <= 15; i = i + 1) begin
case(groupedBits[i])
3'b001 : partialProduct[i] = {absA[31], absA};
3'b010 : partialProduct[i] = {absA[31], absA};
3'b101 : partialProduct[i] = neg_a;
3'b110 : partialProduct[i] = neg_a;
3'b011 : partialProduct[i] = {neg_a << 1};
3'b100 : partialProduct[i] = {neg_a << 1};
default : partialProduct[i] = 0;
endcase
//shiftedPartialProduct[i] = $signed(partialProduct[i]);
for (j=0 ; j<i ; j = j + 1)
shiftedPartialProduct[j] = {shiftedPartialProduct[j], 2'b00};
end
product = shiftedPartialProduct[0];
for(j = 0; j <= 15; j = j + 1) begin
product = product + shiftedPartialProduct[j];
end
if(a[31] == 1'b1 || b[31] == 1'b1) begin
product = -product;
end
end
assign z = product;
endmodule