-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmem_encode.v
75 lines (72 loc) · 1.85 KB
/
dmem_encode.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
74
75
`include "dmem_encdec.vh"
(* nolatches *)
module dmem_encode
( input [1:0] width
, input [1:0] addr
, input write
, input [31:0] wdata
// output
, output [3:0] writeb
, output reg [31:0] encode
);
reg [3:0] write_bits;
(* always_comb *)
always @* begin
case (width)
`ENCDEC_ZERO: begin
write_bits = 4'b0000;
encode = 32'b0;
end
`ENCDEC_BYTE:
case (addr)
2'b00: begin
write_bits = 4'b0001;
encode = {24'b0, wdata[7:0]};
end
2'b01: begin
write_bits = 4'b0010;
encode = {16'b0, wdata[7:0], 8'b0};
end
2'b10: begin
write_bits = 4'b0100;
encode = {8'b0, wdata[7:0], 16'b0};
end
2'b11: begin
write_bits = 4'b1000;
encode = {wdata[7:0], 24'b0};
end
endcase
`ENCDEC_HALF:
case (addr)
2'b00: begin
write_bits = 4'b0011;
encode = {16'b0, wdata[15:0]};
end
2'b01: begin
write_bits = 4'b0110;
encode = {8'b0, wdata[15:0], 8'b0};
end
2'b10: begin
write_bits = 4'b1100;
encode = {wdata[15:0], 16'b0};
end
2'b11: begin
write_bits = 4'b0000;
encode = 32'b0;
end
endcase
`ENCDEC_WORD:
case (addr)
2'b00: begin
write_bits = 4'b1111;
encode = wdata;
end
default: begin
write_bits = 4'b0000;
encode = 32'b0;
end
endcase
endcase
end
assign writeb = write ? write_bits : 4'b0000;
endmodule