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

Subversion Repositories or1200_hp

[/] [or1200_hp/] [trunk/] [rtl/] [rtl_cm4/] [verilog/] [or1200_mem2reg.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tobil
//////////////////////////////////////////////////////////////////////
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_cm4(
85
                clk_i_cml_1,
86
                clk_i_cml_2,
87
                addr, lsu_op, memdata, regdata);
88
 
89
 
90
input clk_i_cml_1;
91
input clk_i_cml_2;
92
reg [ 4 - 1 : 0 ] lsu_op_cml_2;
93
reg [ 4 - 1 : 0 ] lsu_op_cml_1;
94
 
95
 
96
 
97
parameter width = `OR1200_OPERAND_WIDTH;
98
 
99
//
100
// I/O
101
//
102
input   [1:0]                    addr;
103
input   [`OR1200_LSUOP_WIDTH-1:0]        lsu_op;
104
input   [width-1:0]              memdata;
105
output  [width-1:0]              regdata;
106
 
107
 
108
//
109
// In the past faster implementation of mem2reg (today probably slower)
110
//
111
`ifdef OR1200_IMPL_MEM2REG2
112
 
113
`define OR1200_M2R_BYTE0 4'b0000
114
`define OR1200_M2R_BYTE1 4'b0001
115
`define OR1200_M2R_BYTE2 4'b0010
116
`define OR1200_M2R_BYTE3 4'b0011
117
`define OR1200_M2R_EXTB0 4'b0100
118
`define OR1200_M2R_EXTB1 4'b0101
119
`define OR1200_M2R_EXTB2 4'b0110
120
`define OR1200_M2R_EXTB3 4'b0111
121
`define OR1200_M2R_ZERO  4'b0000
122
 
123
reg     [7:0]                    regdata_hh;
124
reg     [7:0]                    regdata_hl;
125
reg     [7:0]                    regdata_lh;
126
reg     [7:0]                    regdata_ll;
127
reg     [width-1:0]              aligned;
128
reg     [3:0]                    sel_byte0, sel_byte1,
129
                                sel_byte2, sel_byte3;
130
 
131
assign regdata = {regdata_hh, regdata_hl, regdata_lh, regdata_ll};
132
 
133
//
134
// Byte select 0
135
//
136
always @(addr or lsu_op) begin
137
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
138
                {3'b01x, 2'b00}:                        // lbz/lbs 0
139
                        sel_byte0 = `OR1200_M2R_BYTE3;  // take byte 3
140
                {3'b01x, 2'b01},                        // lbz/lbs 1
141
                {3'b10x, 2'b00}:                        // lhz/lhs 0
142
                        sel_byte0 = `OR1200_M2R_BYTE2;  // take byte 2
143
                {3'b01x, 2'b10}:                        // lbz/lbs 2
144
                        sel_byte0 = `OR1200_M2R_BYTE1;  // take byte 1
145
                default:                                // all other cases
146
                        sel_byte0 = `OR1200_M2R_BYTE0;  // take byte 0
147
        endcase
148
end
149
 
150
//
151
// Byte select 1
152
//
153
always @(addr or lsu_op) begin
154
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
155
                {3'b010, 2'bxx}:                        // lbz
156
                        sel_byte1 = `OR1200_M2R_ZERO;   // zero extend
157
                {3'b011, 2'b00}:                        // lbs 0
158
                        sel_byte1 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
159
                {3'b011, 2'b01}:                        // lbs 1
160
                        sel_byte1 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
161
                {3'b011, 2'b10}:                        // lbs 2
162
                        sel_byte1 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
163
                {3'b011, 2'b11}:                        // lbs 3
164
                        sel_byte1 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
165
                {3'b10x, 2'b00}:                        // lhz/lhs 0
166
                        sel_byte1 = `OR1200_M2R_BYTE3;  // take byte 3
167
                default:                                // all other cases
168
                        sel_byte1 = `OR1200_M2R_BYTE1;  // take byte 1
169
        endcase
170
end
171
 
172
//
173
// Byte select 2
174
//
175
always @(addr or lsu_op) begin
176
        casex({lsu_op[2:0], addr})       // synopsys parallel_case
177
                {3'b010, 2'bxx},                        // lbz
178
                {3'b100, 2'bxx}:                        // lhz
179
                        sel_byte2 = `OR1200_M2R_ZERO;   // zero extend
180
                {3'b011, 2'b00},                        // lbs 0
181
                {3'b101, 2'b00}:                        // lhs 0
182
                        sel_byte2 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
183
                {3'b011, 2'b01}:                        // lbs 1
184
                        sel_byte2 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
185
                {3'b011, 2'b10},                        // lbs 2
186
                {3'b101, 2'b10}:                        // lhs 0
187
                        sel_byte2 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
188
                {3'b011, 2'b11}:                        // lbs 3
189
                        sel_byte2 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
190
                default:                                // all other cases
191
                        sel_byte2 = `OR1200_M2R_BYTE2;  // take byte 2
192
        endcase
193
end
194
 
195
//
196
// Byte select 3
197
//
198
always @(addr or lsu_op) begin
199
        casex({lsu_op[2:0], addr}) // synopsys parallel_case
200
                {3'b010, 2'bxx},                        // lbz
201
                {3'b100, 2'bxx}:                        // lhz
202
                        sel_byte3 = `OR1200_M2R_ZERO;   // zero extend
203
                {3'b011, 2'b00},                        // lbs 0
204
                {3'b101, 2'b00}:                        // lhs 0
205
                        sel_byte3 = `OR1200_M2R_EXTB3;  // sign extend from byte 3
206
                {3'b011, 2'b01}:                        // lbs 1
207
                        sel_byte3 = `OR1200_M2R_EXTB2;  // sign extend from byte 2
208
                {3'b011, 2'b10},                        // lbs 2
209
                {3'b101, 2'b10}:                        // lhs 0
210
                        sel_byte3 = `OR1200_M2R_EXTB1;  // sign extend from byte 1
211
                {3'b011, 2'b11}:                        // lbs 3
212
                        sel_byte3 = `OR1200_M2R_EXTB0;  // sign extend from byte 0
213
                default:                                // all other cases
214
                        sel_byte3 = `OR1200_M2R_BYTE3;  // take byte 3
215
        endcase
216
end
217
 
218
//
219
// Byte 0
220
//
221
always @(sel_byte0 or memdata) begin
222
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
223
`ifdef OR1200_CASE_DEFAULT
224
        case(sel_byte0) // synopsys parallel_case infer_mux
225
`else
226
        case(sel_byte0) // synopsys full_case parallel_case infer_mux
227
`endif
228
`else
229
`ifdef OR1200_CASE_DEFAULT
230
        case(sel_byte0) // synopsys parallel_case
231
`else
232
        case(sel_byte0) // synopsys full_case parallel_case
233
`endif
234
`endif
235
                `OR1200_M2R_BYTE0: begin
236
                                regdata_ll = memdata[7:0];
237
                        end
238
                `OR1200_M2R_BYTE1: begin
239
                                regdata_ll = memdata[15:8];
240
                        end
241
                `OR1200_M2R_BYTE2: begin
242
                                regdata_ll = memdata[23:16];
243
                        end
244
`ifdef OR1200_CASE_DEFAULT
245
                default: begin
246
`else
247
                `OR1200_M2R_BYTE3: begin
248
`endif
249
                                regdata_ll = memdata[31:24];
250
                        end
251
        endcase
252
end
253
 
254
//
255
// Byte 1
256
//
257
always @(sel_byte1 or memdata) begin
258
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
259
`ifdef OR1200_CASE_DEFAULT
260
        case(sel_byte1) // synopsys parallel_case infer_mux
261
`else
262
        case(sel_byte1) // synopsys full_case parallel_case infer_mux
263
`endif
264
`else
265
`ifdef OR1200_CASE_DEFAULT
266
        case(sel_byte1) // synopsys parallel_case
267
`else
268
        case(sel_byte1) // synopsys full_case parallel_case
269
`endif
270
`endif
271
                `OR1200_M2R_ZERO: begin
272
                                regdata_lh = 8'h00;
273
                        end
274
                `OR1200_M2R_BYTE1: begin
275
                                regdata_lh = memdata[15:8];
276
                        end
277
                `OR1200_M2R_BYTE3: begin
278
                                regdata_lh = memdata[31:24];
279
                        end
280
                `OR1200_M2R_EXTB0: begin
281
                                regdata_lh = {8{memdata[7]}};
282
                        end
283
                `OR1200_M2R_EXTB1: begin
284
                                regdata_lh = {8{memdata[15]}};
285
                        end
286
                `OR1200_M2R_EXTB2: begin
287
                                regdata_lh = {8{memdata[23]}};
288
                        end
289
`ifdef OR1200_CASE_DEFAULT
290
                default: begin
291
`else
292
                `OR1200_M2R_EXTB3: begin
293
`endif
294
                                regdata_lh = {8{memdata[31]}};
295
                        end
296
        endcase
297
end
298
 
299
//
300
// Byte 2
301
//
302
always @(sel_byte2 or memdata) begin
303
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
304
`ifdef OR1200_CASE_DEFAULT
305
        case(sel_byte2) // synopsys parallel_case infer_mux
306
`else
307
        case(sel_byte2) // synopsys full_case parallel_case infer_mux
308
`endif
309
`else
310
`ifdef OR1200_CASE_DEFAULT
311
        case(sel_byte2) // synopsys parallel_case
312
`else
313
        case(sel_byte2) // synopsys full_case parallel_case
314
`endif
315
`endif
316
                `OR1200_M2R_ZERO: begin
317
                                regdata_hl = 8'h00;
318
                        end
319
                `OR1200_M2R_BYTE2: begin
320
                                regdata_hl = memdata[23:16];
321
                        end
322
                `OR1200_M2R_EXTB0: begin
323
                                regdata_hl = {8{memdata[7]}};
324
                        end
325
                `OR1200_M2R_EXTB1: begin
326
                                regdata_hl = {8{memdata[15]}};
327
                        end
328
                `OR1200_M2R_EXTB2: begin
329
                                regdata_hl = {8{memdata[23]}};
330
                        end
331
`ifdef OR1200_CASE_DEFAULT
332
                default: begin
333
`else
334
                `OR1200_M2R_EXTB3: begin
335
`endif
336
                                regdata_hl = {8{memdata[31]}};
337
                        end
338
        endcase
339
end
340
 
341
//
342
// Byte 3
343
//
344
always @(sel_byte3 or memdata) begin
345
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
346
`ifdef OR1200_CASE_DEFAULT
347
        case(sel_byte3) // synopsys parallel_case infer_mux
348
`else
349
        case(sel_byte3) // synopsys full_case parallel_case infer_mux
350
`endif
351
`else
352
`ifdef OR1200_CASE_DEFAULT
353
        case(sel_byte3) // synopsys parallel_case
354
`else
355
        case(sel_byte3) // synopsys full_case parallel_case
356
`endif
357
`endif
358
                `OR1200_M2R_ZERO: begin
359
                                regdata_hh = 8'h00;
360
                        end
361
                `OR1200_M2R_BYTE3: begin
362
                                regdata_hh = memdata[31:24];
363
                        end
364
                `OR1200_M2R_EXTB0: begin
365
                                regdata_hh = {8{memdata[7]}};
366
                        end
367
                `OR1200_M2R_EXTB1: begin
368
                                regdata_hh = {8{memdata[15]}};
369
                        end
370
                `OR1200_M2R_EXTB2: begin
371
                                regdata_hh = {8{memdata[23]}};
372
                        end
373
`ifdef OR1200_CASE_DEFAULT
374
                `OR1200_M2R_EXTB3: begin
375
`else
376
                `OR1200_M2R_EXTB3: begin
377
`endif
378
                                regdata_hh = {8{memdata[31]}};
379
                        end
380
        endcase
381
end
382
 
383
`else
384
 
385
//
386
// Straightforward implementation of mem2reg
387
//
388
 
389
reg     [width-1:0]              regdata;
390
reg     [width-1:0]              aligned;
391
 
392
//
393
// Alignment
394
//
395
always @(addr or memdata) begin
396
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
397
        case(addr) // synopsys parallel_case infer_mux
398
`else
399
        case(addr) // synopsys parallel_case
400
`endif
401
                2'b00:
402
                        aligned = memdata;
403
                2'b01:
404
                        aligned = {memdata[23:0], 8'b0};
405
                2'b10:
406
                        aligned = {memdata[15:0], 16'b0};
407
                2'b11:
408
                        aligned = {memdata[7:0], 24'b0};
409
        endcase
410
end
411
 
412
//
413
// Bytes
414
//
415
 
416
// SynEDA CoreMultiplier
417
// assignment(s): regdata
418
// replace(s): lsu_op
419
always @(lsu_op_cml_2 or aligned) begin
420
`ifdef OR1200_ADDITIONAL_SYNOPSYS_DIRECTIVES
421
        case(lsu_op_cml_2) // synopsys parallel_case infer_mux
422
`else
423
        case(lsu_op_cml_2) // synopsys parallel_case
424
`endif
425
                `OR1200_LSUOP_LBZ: begin
426
                                regdata[7:0] = aligned[31:24];
427
                                regdata[31:8] = 24'b0;
428
                        end
429
                `OR1200_LSUOP_LBS: begin
430
                                regdata[7:0] = aligned[31:24];
431
                                regdata[31:8] = {24{aligned[31]}};
432
                        end
433
                `OR1200_LSUOP_LHZ: begin
434
                                regdata[15:0] = aligned[31:16];
435
                                regdata[31:16] = 16'b0;
436
                        end
437
                `OR1200_LSUOP_LHS: begin
438
                                regdata[15:0] = aligned[31:16];
439
                                regdata[31:16] = {16{aligned[31]}};
440
                        end
441
                default:
442
                                regdata = aligned;
443
        endcase
444
end
445
 
446
`endif
447
 
448
 
449
always @ (posedge clk_i_cml_1) begin
450
lsu_op_cml_1 <= lsu_op;
451
end
452
always @ (posedge clk_i_cml_2) begin
453
lsu_op_cml_2 <= lsu_op_cml_1;
454
end
455
endmodule
456
 

powered by: WebSVN 2.1.0

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