-
Notifications
You must be signed in to change notification settings - Fork 4
/
scalar_multiplier_v_32b.v
64 lines (53 loc) · 1.62 KB
/
scalar_multiplier_v_32b.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
/****************************************************************************
* scala_multiplier_v_32b.v
****************************************************************************/
/**
* Module: scalar_multiplier_v_32b
*
* TODO: Add module documentation
*/
module scalar_multiplier_v_32b # (
parameter WIDTH = 32
) (
input [WIDTH-1 : 0 ] scalar,
input [WIDTH-1 : 0 ] in,
output [WIDTH-1 : 0 ] out
);
parameter TMP_WIDTH = 16;
wire signed [TMP_WIDTH-1 : 0] tmp_scalar;
wire signed [TMP_WIDTH-1 : 0] tmp_in;
wire signed [WIDTH-1 : 0] tmp_out;
reg signed [TMP_WIDTH-1 : 0] partial [TMP_WIDTH-1 : 0];
assign tmp_scalar = scalar[TMP_WIDTH-1:0];
assign tmp_in = in[TMP_WIDTH-1:0];
assign out = tmp_out;
generate
genvar i;
for (i = 0; i < TMP_WIDTH; i = i + 1) begin
always @(scalar,in) begin
if (~scalar[i])
partial[i] <= 16'h0;
else begin
partial[i] <= tmp_in>>>(TMP_WIDTH-i);
end
end
end
endgenerate
assign tmp_out =
(partial[15]<<15)
+ (partial[14]<<14)
+ (partial[13]<<13)
+ (partial[12]<<12)
+ (partial[11]<<11)
+ (partial[10]<<10)
+ (partial[9]<<9)
+ (partial[8]<<8)
+ (partial[7]<<7)
+ (partial[6]<<6)
+ (partial[5]<<5)
+ (partial[4]<<4)
+ (partial[3]<<3)
+ (partial[2]<<2)
+ (partial[1]<<1)
+ partial[0];
endmodule