-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapmem.v
137 lines (123 loc) · 4.03 KB
/
wrapmem.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
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
132
133
134
135
136
137
module wrappermem (
input wire [31:0] data_i,
input wire [1:0] byteadd,
input wire [2:0] fun3,
input wire mem_en,
input wire Load,
input wire [31:0]wrap_load_in,
output reg [3:0] masking,
output reg [31:0] data_o,
output reg [31:0] wrap_load_out
);
always @(*) begin
if (mem_en) begin
masking = 4'b0000;
if(fun3==3'b000)begin //sb
case (byteadd)
00: begin
masking = 4'b0001;
data_o = data_i;
end
01: begin
masking = 4'b0010;
data_o = {data_i[31:16],data_i[7:0],data_i[7:0]};
end
10: begin
masking = 4'b0100;
data_o = {data_i[31:24],data_i[7:0],data_i[15:0]};
end
11: begin
masking = 4'b1000;
data_o = {data_i[7:0],data_i[23:0]};
end
endcase
end
if(fun3==3'b001)begin //sh
case (byteadd)
00: begin
masking = 4'b0011;
data_o = data_i;
end
01: begin
masking = 4'b0110;
data_o = {data_i[31:24],data_i[15:0],data_i[7:0]};
end
10: begin
masking = 4'b1100;
data_o = {data_i[15:0],data_i[15:0]};
end
endcase
end
if(fun3==3'b010) begin //sw
masking = 4'b1111;
data_o = data_i;
end
end
if (Load)begin
if(fun3==3'b000)begin //lb
case (byteadd)
00: begin
wrap_load_out = {{24{wrap_load_in[7]}},wrap_load_in[7:0]};
end
01: begin
wrap_load_out = {{24{wrap_load_in[15]}},wrap_load_in[15:8]};
end
10: begin
wrap_load_out = {{24{wrap_load_in[23]}},wrap_load_in[23:16]};
end
11: begin
wrap_load_out = {{24{wrap_load_in[31]}},wrap_load_in[31:24]};
end
endcase
end
if(fun3==3'b001)begin //lh
case (byteadd)
00: begin
wrap_load_out = {{16{wrap_load_in[15]}},wrap_load_in[15:0]};
end
01: begin
wrap_load_out = {{16{wrap_load_in[23]}},wrap_load_in[23:8]};
end
10: begin
wrap_load_out = {{16{wrap_load_in[31]}},wrap_load_in[31:16]};
end
endcase
end
if(fun3==3'b010) begin //lw
wrap_load_out = wrap_load_in;
end
if(fun3==3'b100)begin //lbu
case (byteadd)
00: begin
wrap_load_out = {24'b0,wrap_load_in[7:0]};
end
01: begin
wrap_load_out = {24'b0,wrap_load_in[15:8]};
end
10: begin
wrap_load_out = {24'b0,wrap_load_in[23:16]};
end
11: begin
wrap_load_out = {24'b0,wrap_load_in[31:24]};
end
endcase
end
if(fun3==3'b101)begin //lhu
case (byteadd)
00: begin
wrap_load_out = {16'b0,wrap_load_in[15:0]};
end
01: begin
wrap_load_out = {16'b0,wrap_load_in[23:8]};
end
10: begin
wrap_load_out = {16'b0,wrap_load_in[31:16]};
end
endcase
end
if(fun3==3'b110) begin //lwu
wrap_load_out = wrap_load_in;
end
end
end
endmodule