OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_mem2reg.v] - Blame information for rev 50

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OR1200's mem2reg alignment                                  ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Two versions of Memory to register data alignment.          ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - make it smaller and faster                               ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Damjan Lampret, lampret@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47
// Revision 1.4  2002/03/29 15:16:56  lampret
48
// Some of the warnings fixed.
49
//
50
// Revision 1.3  2002/03/28 19:14:10  lampret
51
// Changed define name from OR1200_MEM2REG_FAST to OR1200_IMPL_MEM2REG2
52
//
53
// Revision 1.2  2002/01/14 06:18:22  lampret
54
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
55
//
56
// Revision 1.1  2002/01/03 08:16:15  lampret
57
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
58
//
59
// Revision 1.9  2001/10/21 17:57:16  lampret
60
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
61
//
62
// Revision 1.8  2001/10/19 23:28:46  lampret
63
// Fixed some synthesis warnings. Configured with caches and MMUs.
64
//
65
// Revision 1.7  2001/10/14 13:12:09  lampret
66
// MP3 version.
67
//
68
// Revision 1.1.1.1  2001/10/06 10:18:36  igorm
69
// no message
70
//
71
// Revision 1.2  2001/08/09 13:39:33  lampret
72
// Major clean-up.
73
//
74
// Revision 1.1  2001/07/20 00:46:03  lampret
75
// Development version of RTL. Libraries are missing.
76
//
77
//
78
 
79
// synopsys translate_off
80
`include "timescale.v"
81
// synopsys translate_on
82
`include "or1200_defines.v"
83
 
84
module or1200_mem2reg(addr, lsu_op, memdata, regdata);
85
 
86
parameter width = `OR1200_OPERAND_WIDTH;
87
 
88
//
89
// I/O
90
//
91
input   [1:0]                    addr;
92
input   [`OR1200_LSUOP_WIDTH-1:0]        lsu_op;
93
input   [width-1:0]              memdata;
94
output  [width-1:0]              regdata;
95
 
96
 
97
//
98
// In the past faster implementation of mem2reg (today probably slower)
99
//
100
`ifdef OR1200_IMPL_MEM2REG2
101
 
102
`define OR1200_M2R_BYTE0 4'b0000
103
`define OR1200_M2R_BYTE1 4'b0001
104
`define OR1200_M2R_BYTE2 4'b0010
105
`define OR1200_M2R_BYTE3 4'b0011
106
`define OR1200_M2R_EXTB0 4'b0100
107
`define OR1200_M2R_EXTB1 4'b0101
108
`define OR1200_M2R_EXTB2 4'b0110
109
`define OR1200_M2R_EXTB3 4'b0111
110
`define OR1200_M2R_ZERO  4'b0000
111
 
112
reg     [7:0]                    regdata_hh;
113
reg     [7:0]                    regdata_hl;
114
reg     [7:0]                    regdata_lh;
115
reg     [7:0]                    regdata_ll;
116
reg     [width-1:0]              aligned;
117
reg     [3:0]                    sel_byte0, sel_byte1,
118
                                sel_byte2, sel_byte3;
119
 
120
assign regdata = {regdata_hh, regdata_hl, regdata_lh, regdata_ll};
121
 
122
//
123
// Byte select 0
124
//
125
always @(addr or lsu_op) begin
126
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
127
                {3'b01x, 2'b00}:                        // lbz/lbs 0
128
                        sel_byte0 = `OR1200_M2R_BYTE3;  // take byte 3
129
                {3'b01x, 2'b01},                        // lbz/lbs 1
130
                {3'b10x, 2'b00}:                        // lhz/lhs 0
131
                        sel_byte0 = `OR1200_M2R_BYTE2;  // take byte 2
132
                {3'b01x, 2'b10}:                        // lbz/lbs 2
133
                        sel_byte0 = `OR1200_M2R_BYTE1;  // take byte 1
134
                default:                                // all other cases
135
                        sel_byte0 = `OR1200_M2R_BYTE0;  // take byte 0
136
        endcase
137
end
138
 
139
//
140
// Byte select 1
141
//
142
always @(addr or lsu_op) begin
143
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
144
                {3'b010, 2'bxx}:                        // lbz
145
                        sel_byte1 = `OR1200_M2R_ZERO;   // zero extend
146
                {3'b011, 2'b00}:                        // lbs 0
147
                        sel_byte1 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
148
                {3'b011, 2'b01}:                        // lbs 1
149
                        sel_byte1 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
150
                {3'b011, 2'b10}:                        // lbs 2
151
                        sel_byte1 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
152
                {3'b011, 2'b11}:                        // lbs 3
153
                        sel_byte1 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
154
                {3'b10x, 2'b00}:                        // lhz/lhs 0
155
                        sel_byte1 = `OR1200_M2R_BYTE3;  // take byte 3
156
                default:                                // all other cases
157
                        sel_byte1 = `OR1200_M2R_BYTE1;  // take byte 1
158
        endcase
159
end
160
 
161
//
162
// Byte select 2
163
//
164
always @(addr or lsu_op) begin
165
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
166
                {3'b010, 2'bxx},                        // lbz
167
                {3'b100, 2'bxx}:                        // lhz
168
                        sel_byte2 = `OR1200_M2R_ZERO;   // zero extend
169
                {3'b011, 2'b00},                        // lbs 0
170
                {3'b101, 2'b00}:                        // lhs 0
171
                        sel_byte2 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
172
                {3'b011, 2'b01}:                        // lbs 1
173
                        sel_byte2 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
174
                {3'b011, 2'b10},                        // lbs 2
175
                {3'b101, 2'b10}:                        // lhs 0
176
                        sel_byte2 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
177
                {3'b011, 2'b11}:                        // lbs 3
178
                        sel_byte2 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
179
                default:                                // all other cases
180
                        sel_byte2 = `OR1200_M2R_BYTE2;  // take byte 2
181
        endcase
182
end
183
 
184
//
185
// Byte select 3
186
//
187
always @(addr or lsu_op) begin
188
        casex({lsu_op[2:0], addr}) // synopsys parallel_case
189
                {3'b010, 2'bxx},                        // lbz
190
                {3'b100, 2'bxx}:                        // lhz
191
                        sel_byte3 = `OR1200_M2R_ZERO;   // zero extend
192
                {3'b011, 2'b00},                        // lbs 0
193
                {3'b101, 2'b00}:                        // lhs 0
194
                        sel_byte3 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
195
                {3'b011, 2'b01}:                        // lbs 1
196
                        sel_byte3 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
197
                {3'b011, 2'b10},                        // lbs 2
198
                {3'b101, 2'b10}:                        // lhs 0
199
                        sel_byte3 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
200
                {3'b011, 2'b11}:                        // lbs 3
201
                        sel_byte3 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
202
                default:                                // all other cases
203
                        sel_byte3 = `OR1200_M2R_BYTE3;  // take byte 3
204
        endcase
205
end
206
 
207
//
208
// Byte 0
209
//
210
always @(sel_byte0 or memdata) begin
211
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
212
`ifdef OR1200_CASE_DEFAULT
213
        case(sel_byte0) // synopsys parallel_case infer_mux
214
`else
215
        case(sel_byte0) // synopsys full_case parallel_case infer_mux
216
`endif
217
`else
218
`ifdef OR1200_CASE_DEFAULT
219
        case(sel_byte0) // synopsys parallel_case
220
`else
221
        case(sel_byte0) // synopsys full_case parallel_case
222
`endif
223
`endif
224
                `OR1200_M2R_BYTE0: begin
225
                                regdata_ll = memdata[7:0];
226
                        end
227
                `OR1200_M2R_BYTE1: begin
228
                                regdata_ll = memdata[15:8];
229
                        end
230
                `OR1200_M2R_BYTE2: begin
231
                                regdata_ll = memdata[23:16];
232
                        end
233
`ifdef OR1200_CASE_DEFAULT
234
                default: begin
235
`else
236
                `OR1200_M2R_BYTE3: begin
237
`endif
238
                                regdata_ll = memdata[31:24];
239
                        end
240
        endcase
241
end
242
 
243
//
244
// Byte 1
245
//
246
always @(sel_byte1 or memdata) begin
247
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
248
`ifdef OR1200_CASE_DEFAULT
249
        case(sel_byte1) // synopsys parallel_case infer_mux
250
`else
251
        case(sel_byte1) // synopsys full_case parallel_case infer_mux
252
`endif
253
`else
254
`ifdef OR1200_CASE_DEFAULT
255
        case(sel_byte1) // synopsys parallel_case
256
`else
257
        case(sel_byte1) // synopsys full_case parallel_case
258
`endif
259
`endif
260
                `OR1200_M2R_ZERO: begin
261
                                regdata_lh = 8'h00;
262
                        end
263
                `OR1200_M2R_BYTE1: begin
264
                                regdata_lh = memdata[15:8];
265
                        end
266
                `OR1200_M2R_BYTE3: begin
267
                                regdata_lh = memdata[31:24];
268
                        end
269
                `OR1200_M2R_EXTB0: begin
270
                                regdata_lh = {8{memdata[7]}};
271
                        end
272
                `OR1200_M2R_EXTB1: begin
273
                                regdata_lh = {8{memdata[15]}};
274
                        end
275
                `OR1200_M2R_EXTB2: begin
276
                                regdata_lh = {8{memdata[23]}};
277
                        end
278
`ifdef OR1200_CASE_DEFAULT
279
                default: begin
280
`else
281
                `OR1200_M2R_EXTB3: begin
282
`endif
283
                                regdata_lh = {8{memdata[31]}};
284
                        end
285
        endcase
286
end
287
 
288
//
289
// Byte 2
290
//
291
always @(sel_byte2 or memdata) begin
292
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
293
`ifdef OR1200_CASE_DEFAULT
294
        case(sel_byte2) // synopsys parallel_case infer_mux
295
`else
296
        case(sel_byte2) // synopsys full_case parallel_case infer_mux
297
`endif
298
`else
299
`ifdef OR1200_CASE_DEFAULT
300
        case(sel_byte2) // synopsys parallel_case
301
`else
302
        case(sel_byte2) // synopsys full_case parallel_case
303
`endif
304
`endif
305
                `OR1200_M2R_ZERO: begin
306
                                regdata_hl = 8'h00;
307
                        end
308
                `OR1200_M2R_BYTE2: begin
309
                                regdata_hl = memdata[23:16];
310
                        end
311
                `OR1200_M2R_EXTB0: begin
312
                                regdata_hl = {8{memdata[7]}};
313
                        end
314
                `OR1200_M2R_EXTB1: begin
315
                                regdata_hl = {8{memdata[15]}};
316
                        end
317
                `OR1200_M2R_EXTB2: begin
318
                                regdata_hl = {8{memdata[23]}};
319
                        end
320
`ifdef OR1200_CASE_DEFAULT
321
                default: begin
322
`else
323
                `OR1200_M2R_EXTB3: begin
324
`endif
325
                                regdata_hl = {8{memdata[31]}};
326
                        end
327
        endcase
328
end
329
 
330
//
331
// Byte 3
332
//
333
always @(sel_byte3 or memdata) begin
334
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
335
`ifdef OR1200_CASE_DEFAULT
336
        case(sel_byte3) // synopsys parallel_case infer_mux
337
`else
338
        case(sel_byte3) // synopsys full_case parallel_case infer_mux
339
`endif
340
`else
341
`ifdef OR1200_CASE_DEFAULT
342
        case(sel_byte3) // synopsys parallel_case
343
`else
344
        case(sel_byte3) // synopsys full_case parallel_case
345
`endif
346
`endif
347
                `OR1200_M2R_ZERO: begin
348
                                regdata_hh = 8'h00;
349
                        end
350
                `OR1200_M2R_BYTE3: begin
351
                                regdata_hh = memdata[31:24];
352
                        end
353
                `OR1200_M2R_EXTB0: begin
354
                                regdata_hh = {8{memdata[7]}};
355
                        end
356
                `OR1200_M2R_EXTB1: begin
357
                                regdata_hh = {8{memdata[15]}};
358
                        end
359
                `OR1200_M2R_EXTB2: begin
360
                                regdata_hh = {8{memdata[23]}};
361
                        end
362
`ifdef OR1200_CASE_DEFAULT
363
                `OR1200_M2R_EXTB3: begin
364
`else
365
                `OR1200_M2R_EXTB3: begin
366
`endif
367
                                regdata_hh = {8{memdata[31]}};
368
                        end
369
        endcase
370
end
371
 
372
`else
373
 
374
//
375
// Straightforward implementation of mem2reg
376
//
377
 
378
reg     [width-1:0]              regdata;
379
reg     [width-1:0]              aligned;
380
 
381
//
382
// Alignment
383
//
384
always @(addr or memdata) begin
385
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
386
        case(addr) // synopsys parallel_case infer_mux
387
`else
388
        case(addr) // synopsys parallel_case
389
`endif
390
                2'b00:
391
                        aligned = memdata;
392
                2'b01:
393
                        aligned = {memdata[23:0], 8'b0};
394
                2'b10:
395
                        aligned = {memdata[15:0], 16'b0};
396
                2'b11:
397
                        aligned = {memdata[7:0], 24'b0};
398
        endcase
399
end
400
 
401
//
402
// Bytes
403
//
404
always @(lsu_op or aligned) begin
405
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
406
        case(lsu_op) // synopsys parallel_case infer_mux
407
`else
408
        case(lsu_op) // synopsys parallel_case
409
`endif
410
                `OR1200_LSUOP_LBZ: begin
411
                                regdata[7:0] = aligned[31:24];
412
                                regdata[31:8] = 24'b0;
413
                        end
414
                `OR1200_LSUOP_LBS: begin
415
                                regdata[7:0] = aligned[31:24];
416
                                regdata[31:8] = {24{aligned[31]}};
417
                        end
418
                `OR1200_LSUOP_LHZ: begin
419
                                regdata[15:0] = aligned[31:16];
420
                                regdata[31:16] = 16'b0;
421
                        end
422
                `OR1200_LSUOP_LHS: begin
423
                                regdata[15:0] = aligned[31:16];
424
                                regdata[31:16] = {16{aligned[31]}};
425
                        end
426
                default:
427
                                regdata = aligned;
428
        endcase
429
end
430
 
431
`endif
432
 
433
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.