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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_iexpander.v] - Blame information for rev 59

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_iexpander.v
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
// ============================================================================
24
//
25
`include ".\FT64_defines.vh"
26
 
27
module FT64_iexpander(cinstr,expand);
28
input [15:0] cinstr;
29
output reg [47:0] expand;
30
 
31
// Maps a subset of registers for compressed instructions.
32
function [4:0] fnRp;
33
input [2:0] rg;
34
case(rg)
35
3'd0:   fnRp = 5'd1;            // return value 0
36
3'd1:   fnRp = 5'd3;            // temp
37
3'd2:   fnRp = 5'd4;            // temp
38
3'd3:   fnRp = 5'd11;           // regvar
39
3'd4:   fnRp = 5'd12;           // regvar
40
3'd5:   fnRp = 5'd18;           // arg1
41
3'd6:   fnRp = 5'd19;           // arg2
42
3'd7:   fnRp = 5'd20;           // arg3
43
endcase
44
endfunction
45
 
46
always @*
47
casez({cinstr[15:12],cinstr[6]})
48
5'b00000:       // NOP / ADDI
49
        case(cinstr[4:0])
50
        5'd31:  begin
51
                        expand[47:32] = 16'h0000;
52
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'b0};
53
                        expand[17:13] = cinstr[4:0];
54
                        expand[12:8] = cinstr[4:0];
55
                        expand[7:6] = 2'b10;
56
                        expand[5:0] = `ADDI;
57
                        end
58
        default:
59
                        begin
60
                        expand[47:32] = 16'h0000;
61 58 robfinch
                        expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[5]};
62 48 robfinch
                        expand[17:13] = cinstr[4:0];
63
                        expand[12:8] = cinstr[4:0];
64
                        expand[7:6] = 2'b10;
65
                        expand[5:0] = `ADDI;
66
                        end
67
        endcase
68
5'b00010:       // SYS
69
                        if (cinstr[4:0]==5'd0) begin
70
                                expand[47:32] = 16'h0000;
71
                                expand[5:0] = `BRK;
72
                                expand[7:6] = 2'b10;
73
                                expand[15:8] = {3'd1,cinstr[11:8],cinstr[5]};
74
                                expand[16] = 1'b0;
75 59 robfinch
                                expand[20:17] = 4'd0;
76
                                expand[23:21] = 3'd1;
77 48 robfinch
                                expand[31:24] = 8'd0;
78
                        end
79
                        // LDI
80
                        else begin
81
                                expand[47:32] = 16'h0000;
82
                                expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[5]};
83
                                expand[17:13] = cinstr[4:0];
84
                                expand[12:8] = 5'd0;
85
                                expand[7:6] = 2'b10;
86
                                expand[5:0] = `ORI;
87
                        end
88
5'b00100:       // RET / ANDI
89
                        if (cinstr[4:0]==5'd0) begin
90
                                expand[47:32] = 16'h0000;
91
                                expand[5:0] = `RET;
92
                                expand[7:6] = 2'b10;
93
                                expand[12:8] = 5'd31;
94
                                expand[17:13] = 5'd29;
95
                                expand[31:18] = {8'd0,cinstr[11:8],cinstr[5],3'd0};
96
                        end
97
                        else begin
98
                                expand[47:32] = 16'h0000;
99
                                expand[5:0] = `ANDI;
100
                                expand[7:6] = 2'b10;
101
                                expand[12:8] = cinstr[4:0];
102
                                expand[17:13] = cinstr[4:0];
103
                                expand[31:18] = {{11{cinstr[11]}},cinstr[11:8],cinstr[5]};
104
                        end
105
5'b00110:       // SHLI
106
                        begin
107
                        expand[47:32] = 16'h0000;
108
                        expand[31:26] = 6'h0F;  // immediate mode 0-31
109
                        expand[25:23] = 3'd0;   // SHL
110
                        expand[22:18] = {cinstr[11:8],cinstr[5]};       // amount
111
                        expand[17:13] = cinstr[4:0];
112
                        expand[12:8] = cinstr[4:0];
113
                        expand[7:6] = 2'b10;
114
                        expand[5:0] = 8'h02;             // R2 instruction
115
                        end
116
5'b01000:
117
                        case(cinstr[5:4])
118
                        2'd0:           // SHRI
119
                                begin
120
                                expand[47:32] = 16'h0000;
121
                                expand[31:26] = 6'h0F;          // shift immediate 0-31
122
                                expand[25:23] = 3'd1;           // SHR
123
                                expand[22:18] = {cinstr[11:8],cinstr[3]};       // amount
124
                                expand[17:13] = fnRp(cinstr[2:0]);
125
                                expand[12:8] = fnRp(cinstr[2:0]);
126
                                expand[7:6] = 2'b10;
127
                                expand[5:0] = 8'h02;             // R2 instruction
128
                                end
129
                        2'd1:           // ASRI
130
                                begin
131
                                expand[47:32] = 16'h0000;
132
                                expand[31:26] = 6'h0F;          // shift immediate 0-31
133
                                expand[25:23] = 3'd3;           // ASR
134
                                expand[22:18] = {cinstr[11:8],cinstr[3]};       // amount
135
                                expand[17:13] = fnRp(cinstr[2:0]);
136
                                expand[12:8] = fnRp(cinstr[2:0]);
137
                                expand[7:6] = 2'b10;
138
                                expand[5:0] = 8'h02;             // R2 instruction
139
                                end
140
                        2'd2:           // ORI
141
                                begin
142
                                expand[47:32] = 16'h0000;
143
                                expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[3]};
144
                                expand[17:13] = fnRp(cinstr[2:0]);
145
                                expand[12:8] = fnRp(cinstr[2:0]);
146
                                expand[7:6] = 2'b10;
147
                                expand[5:0] = `ORI;
148
                                end
149
                        2'd3:
150
                                case(cinstr[11:10])
151
                                2'd0:   begin
152
                                                expand[47:32] = 16'h0000;
153
                                                expand[31:26] = `SUB;
154
                                                expand[25:23] = 3'b011; // word size
155
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
156
                                                expand[17:13] = fnRp(cinstr[2:0]);
157
                                                expand[12:8] = fnRp(cinstr[2:0]);
158
                                                expand[7:6] = 2'b10;
159
                                                expand[5:0] = 8'h02;             // R2 instruction
160
                                                end
161
                                2'd1:   begin
162
                                                expand[47:32] = 16'h0000;
163
                                                expand[31:26] = `AND;
164
                                                expand[25:23] = 3'b011; // word size
165
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
166
                                                expand[17:13] = fnRp(cinstr[2:0]);
167
                                                expand[12:8] = fnRp(cinstr[2:0]);
168
                                                expand[7:6] = 2'b10;
169
                                                expand[5:0] = 8'h02;             // R2 instruction
170
                                                end
171
                                2'd2:   begin
172
                                                expand[47:32] = 16'h0000;
173
                                                expand[31:26] = `OR;
174
                                                expand[25:23] = 3'b011; // word size
175
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
176
                                                expand[17:13] = fnRp(cinstr[2:0]);
177
                                                expand[12:8] = fnRp(cinstr[2:0]);
178
                                                expand[7:6] = 2'b10;
179
                                                expand[5:0] = 8'h02;             // R2 instruction
180
                                                end
181
                                2'd3:   begin
182
                                                expand[47:32] = 16'h0000;
183
                                                expand[31:26] = `XOR;
184
                                                expand[25:23] = 3'b011; // word size
185
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
186
                                                expand[17:13] = fnRp(cinstr[2:0]);
187
                                                expand[12:8] = fnRp(cinstr[2:0]);
188
                                                expand[7:6] = 2'b10;
189
                                                expand[5:0] = 8'h02;             // R2 instruction
190
                                                end
191
                                endcase
192
                        endcase
193
5'b01110:
194
                begin
195
                        expand[47:32] = 16'h0000;
196
                        expand[31:21] = {{1{cinstr[11]}},{cinstr[11:8],cinstr[5:0]}};
197
                        expand[20:18] = 3'd0;           // BEQ
198
                        expand[17:8] = 10'd0;            // r0==r0
199
                        expand[7:6] = 2'b10;
200
                        expand[5:0] = `Bcc;              // 0x38
201
                end
202
5'b10??0:
203
                begin
204
                        expand[47:32] = 16'h0000;
205 52 robfinch
                        expand[31:21] = {{4{cinstr[13]}},cinstr[13:8],cinstr[5]};
206 48 robfinch
                        expand[20:18] = 3'd0;                   // BEQ
207
                        expand[17:13] = 5'd0;                   // r0
208
                        expand[12:8] = cinstr[4:0];      // Ra
209
                        expand[7:6] = 2'b10;
210
                        expand[5:0] = `Bcc;
211
                end
212
5'b11??0:
213
                begin
214
                        expand[47:32] = 16'h0000;
215 52 robfinch
                        expand[31:21] = {{4{cinstr[13]}},cinstr[13:8],cinstr[5]};
216 48 robfinch
                        expand[20:18] = 3'd1;                   // BNE
217
                        expand[17:13] = 5'd0;                   // r0
218
                        expand[12:8] = cinstr[4:0];      // Ra
219
                        expand[7:6] = 2'b10;
220
                        expand[5:0] = `Bcc;
221
                end
222
5'b00001:
223
                begin
224
                        expand[47:32] = 16'h0000;
225
                        expand[31:26] = `MOV;
226
                        expand[25:23] = 3'd7;                   // move current to current
227
                        expand[22:18] = 5'd0;                   // register set (ignored)
228
                        expand[17:13] = {cinstr[11:8],cinstr[5]};
229
                        expand[12:8] = cinstr[4:0];
230
                        expand[7:6] = 2'b10;
231 51 robfinch
                        expand[5:0] = 6'h02;
232 48 robfinch
                end
233
5'b00011:       // ADD
234
                begin
235
                        expand[47:32] = 16'h0000;
236
                        expand[31:26] = `ADD;
237
                        expand[27:23] = 3'b011; // word size
238
                        expand[22:18] = cinstr[4:0];
239
                        expand[17:13] = {cinstr[11:8],cinstr[5]};
240
                        expand[12:8] = cinstr[4:0];
241
                        expand[7:6] = 2'b10;
242
                        expand[5:0] = 6'h02;             // R2 instruction
243
                end
244
5'b00101:       // JALR
245
                begin
246
                        expand[47:32] = 16'h0000;
247
                        expand[31:18] = 14'd0;
248
                        expand[17:13] = {cinstr[11:8],cinstr[5]};
249
                        expand[12:8] = cinstr[4:0];
250
                        expand[7:6] = 2'b10;
251
                        expand[5:0] = `JAL;
252
                end
253
5'b01001:       // LH Rt,d[SP]
254
                begin
255
                        expand[47:32] = 16'h0000;
256
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
257
                        expand[17:13] = {cinstr[4:0]};
258
                        expand[12:8] = 65'd31;
259
                        expand[7:6] = 2'b10;
260
                        expand[5:0] = `Lx;
261
                end
262
5'b01011:       // LW Rt,d[SP]
263
                begin
264
                        expand[47:32] = 16'h0000;
265
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
266
                        expand[17:13] = cinstr[4:0];
267
                        expand[12:8] = 5'd31;
268
                        expand[7:6] = 2'b10;
269
                        expand[5:0] = `Lx;
270
                end
271
5'b01101:       // LH Rt,d[fP]
272
                begin
273
                        expand[47:32] = 16'h0000;
274
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
275
                        expand[17:13] = cinstr[4:0];
276
                        expand[12:8] = 6'd30;
277
                        expand[7:6] = 2'b10;
278
                        expand[5:0] = `Lx;
279
                end
280
5'b01111:       // LW Rt,d[FP]
281
                begin
282
                        expand[47:32] = 16'h0000;
283
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
284
                        expand[17:13] = cinstr[4:0];
285
                        expand[12:8] = 5'd30;
286
                        expand[7:6] = 2'b10;
287
                        expand[5:0] = `Lx;
288
                end
289
5'b10001:       // SH Rt,d[SP]
290
                begin
291
                        expand[47:32] = 16'h0000;
292
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
293
                        expand[17:13] = cinstr[4:0];
294
                        expand[12:8] = 5'd31;
295
                        expand[7:6] = 2'b10;
296
                        expand[5:0] = `Sx;
297
                end
298
5'b10011:       // SW Rt,d[SP]
299
                begin
300
                        expand[47:32] = 16'h0000;
301
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
302
                        expand[17:13] = cinstr[4:0];
303
                        expand[12:8] = 5'd31;
304
                        expand[7:6] = 2'b10;
305
                        expand[5:0] = `Sx;
306
                end
307
5'b10101:       // SH Rt,d[fP]
308
                begin
309
                        expand[47:32] = 16'h0000;
310
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
311
                        expand[17:13] = cinstr[4:0];
312
                        expand[12:8] = 6'd30;
313
                        expand[7:6] = 2'b10;
314
                        expand[5:0] = `Sx;
315
                end
316
5'b10111:       // SW Rt,d[FP]
317
                begin
318
                        expand[47:32] = 16'h0000;
319
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
320
                        expand[17:13] = cinstr[4:0];
321
                        expand[12:8] = 5'd30;
322
                        expand[7:6] = 2'b10;
323
                        expand[5:0] = `Sx;
324
                end
325
5'b11001:
326
                begin   // LH
327
                        expand[47:32] = 16'h0000;
328
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:10],cinstr[4:3],2'd2};
329
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
330
                        expand[12:8] = fnRp(cinstr[2:0]);
331
                        expand[7:6] = 2'b10;
332
                        expand[5:0] = `Lx;
333
                end
334
5'b11011:       // LW
335
                begin
336
                        expand[47:32] = 16'h0000;
337
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:10],cinstr[4:3],3'd4};
338
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
339
                        expand[12:8] = fnRp(cinstr[2:0]);
340
                        expand[7:6] = 2'b10;
341
                        expand[5:0] = `Lx;
342
                end
343
5'b11101:       // SH
344
                begin
345
                        expand[47:32] = 16'h0000;
346
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:10],cinstr[4:3],2'd2};
347
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
348
                        expand[12:8] = fnRp(cinstr[2:0]);
349
                        expand[7:6] = 2'b10;
350
                        expand[5:0] = `Sx;
351
                end
352
5'b11111:       // SW
353
                begin
354
                        expand[47:32] = 16'h0000;
355
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:10],cinstr[4:3],3'd4};
356
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
357
                        expand[12:8] = fnRp(cinstr[2:0]);
358
                        expand[7:6] = 2'b10;
359
                        expand[5:0] = `Sx;
360
                end
361
default:
362
                begin
363
                        expand[47:8] = 40'd0;
364
                        expand[7:6] = 2'b10;
365
                        expand[5:0] = `NOP;
366
                end
367
endcase
368
 
369
endmodule

powered by: WebSVN 2.1.0

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