Mips16InstrFormats.td
16.3 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
//===- Mips16InstrFormats.td - Mips Instruction Formats ----*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// Describe MIPS instructions format
//
// CPU INSTRUCTION FORMATS
//
// funct or f Function field
//
// immediate 4-,5-,8- or 11-bit immediate, branch displacement, or
// or imm address displacement
//
// op 5-bit major operation code
//
// rx 3-bit source or destination register
//
// ry 3-bit source or destination register
//
// rz 3-bit source or destination register
//
// sa 3- or 5-bit shift amount
//
//===----------------------------------------------------------------------===//
// Base class for Mips 16 Format
// This class does not depend on the instruction size
//
class MipsInst16_Base<dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>: Instruction
{
let Namespace = "Mips";
let OutOperandList = outs;
let InOperandList = ins;
let AsmString = asmstr;
let Pattern = pattern;
let Itinerary = itin;
let Predicates = [InMips16Mode];
}
//
// Generic Mips 16 Format
//
class MipsInst16<dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>:
MipsInst16_Base<outs, ins, asmstr, pattern, itin>
{
field bits<16> Inst;
bits<5> Opcode = 0;
// Top 5 bits are the 'opcode' field
let Inst{15-11} = Opcode;
let Size=2;
field bits<16> SoftFail = 0;
}
//
// For 32 bit extended instruction forms.
//
class MipsInst16_32<dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>:
MipsInst16_Base<outs, ins, asmstr, pattern, itin>
{
field bits<32> Inst;
let Size=4;
field bits<32> SoftFail = 0;
}
class MipsInst16_EXTEND<dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>:
MipsInst16_32<outs, ins, asmstr, pattern, itin>
{
let Inst{31-27} = 0b11110;
}
// Mips Pseudo Instructions Format
class MipsPseudo16<dag outs, dag ins, string asmstr, list<dag> pattern>:
MipsInst16<outs, ins, asmstr, pattern, IIPseudo> {
let isCodeGenOnly = 1;
let isPseudo = 1;
}
//===----------------------------------------------------------------------===//
// Format I instruction class in Mips : <|opcode|imm11|>
//===----------------------------------------------------------------------===//
class FI16<bits<5> op, dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<11> imm11;
let Opcode = op;
let Inst{10-0} = imm11;
}
//===----------------------------------------------------------------------===//
// Format RI instruction class in Mips : <|opcode|rx|imm8|>
//===----------------------------------------------------------------------===//
class FRI16<bits<5> op, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<8> imm8;
let Opcode = op;
let Inst{10-8} = rx;
let Inst{7-0} = imm8;
}
//===----------------------------------------------------------------------===//
// Format RR instruction class in Mips : <|opcode|rx|ry|funct|>
//===----------------------------------------------------------------------===//
class FRR16<bits<5> _funct, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> ry;
bits<5> funct;
let Opcode = 0b11101;
let funct = _funct;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-0} = funct;
}
class FRRBreak16<dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<6> Code;
bits<5> funct;
let Opcode = 0b11101;
let funct = 0b00101;
let Inst{10-5} = Code;
let Inst{4-0} = funct;
}
//
// For conversion functions.
//
class FRR_SF16<bits<5> _funct, bits<3> _subfunct, dag outs, dag ins,
string asmstr, list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> subfunct;
bits<5> funct;
let Opcode = 0b11101; // RR
let funct = _funct;
let subfunct = _subfunct;
let Inst{10-8} = rx;
let Inst{7-5} = subfunct;
let Inst{4-0} = funct;
}
//
// just used for breakpoint (hardware and software) instructions.
//
class FC16<bits<5> _funct, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<6> _code; // code is a keyword in tablegen
bits<5> funct;
let Opcode = 0b11101; // RR
let funct = _funct;
let Inst{10-5} = _code;
let Inst{4-0} = funct;
}
//
// J(AL)R(C) subformat
//
class FRR16_JALRC<bits<1> _nd, bits<1> _l, bits<1> r_a,
dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<1> nd;
bits<1> l;
bits<1> ra;
let nd = _nd;
let l = _l;
let ra = r_a;
let Opcode = 0b11101;
let Inst{10-8} = rx;
let Inst{7} = nd;
let Inst{6} = l;
let Inst{5} = ra;
let Inst{4-0} = 0;
}
//===----------------------------------------------------------------------===//
// Format RRI instruction class in Mips : <|opcode|rx|ry|imm5|>
//===----------------------------------------------------------------------===//
class FRRI16<bits<5> op, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> ry;
bits<5> imm5;
let Opcode = op;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-0} = imm5;
}
//===----------------------------------------------------------------------===//
// Format RRR instruction class in Mips : <|opcode|rx|ry|rz|f|>
//===----------------------------------------------------------------------===//
class FRRR16<bits<2> _f, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> ry;
bits<3> rz;
bits<2> f;
let Opcode = 0b11100;
let f = _f;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-2} = rz;
let Inst{1-0} = f;
}
//===----------------------------------------------------------------------===//
// Format RRI-A instruction class in Mips : <|opcode|rx|ry|f|imm4|>
//===----------------------------------------------------------------------===//
class FRRI_A16<bits<1> _f, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> ry;
bits<1> f;
bits<4> imm4;
let Opcode = 0b01000;
let f = _f;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4} = f;
let Inst{3-0} = imm4;
}
//===----------------------------------------------------------------------===//
// Format Shift instruction class in Mips : <|opcode|rx|ry|sa|f|>
//===----------------------------------------------------------------------===//
class FSHIFT16<bits<2> _f, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> rx;
bits<3> ry;
bits<3> sa;
bits<2> f;
let Opcode = 0b00110;
let f = _f;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-2} = sa;
let Inst{1-0} = f;
}
//===----------------------------------------------------------------------===//
// Format i8 instruction class in Mips : <|opcode|funct|imm8>
//===----------------------------------------------------------------------===//
class FI816<bits<3> _func, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> func;
bits<8> imm8;
let Opcode = 0b01100;
let func = _func;
let Inst{10-8} = func;
let Inst{7-0} = imm8;
}
//===----------------------------------------------------------------------===//
// Format i8_MOVR32 instruction class in Mips : <|opcode|func|ry|r32>
//===----------------------------------------------------------------------===//
class FI8_MOVR3216<dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<4> ry;
bits<4> r32;
let Opcode = 0b01100;
let Inst{10-8} = 0b111;
let Inst{7-4} = ry;
let Inst{3-0} = r32;
}
//===----------------------------------------------------------------------===//
// Format i8_MOV32R instruction class in Mips : <|opcode|func|r32|rz>
//===----------------------------------------------------------------------===//
class FI8_MOV32R16<dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<3> func;
bits<5> r32;
bits<3> rz;
let Opcode = 0b01100;
let Inst{10-8} = 0b101;
let Inst{7-5} = r32{2-0};
let Inst{4-3} = r32{4-3};
let Inst{2-0} = rz;
}
//===----------------------------------------------------------------------===//
// Format i8_SVRS instruction class in Mips :
// <|opcode|svrs|s|ra|s0|s1|framesize>
//===----------------------------------------------------------------------===//
class FI8_SVRS16<bits<1> _s, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16<outs, ins, asmstr, pattern, itin>
{
bits<1> s;
bits<1> ra = 0;
bits<1> s0 = 0;
bits<1> s1 = 0;
bits<4> framesize = 0;
let s =_s;
let Opcode = 0b01100;
let Inst{10-8} = 0b100;
let Inst{7} = s;
let Inst{6} = ra;
let Inst{5} = s0;
let Inst{4} = s1;
let Inst{3-0} = framesize;
}
//===----------------------------------------------------------------------===//
// Format JAL instruction class in Mips16 :
// <|opcode|svrs|s|ra|s0|s1|framesize>
//===----------------------------------------------------------------------===//
class FJAL16<bits<1> _X, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_32<outs, ins, asmstr, pattern, itin>
{
bits<1> X;
bits<26> imm26;
let X = _X;
let Inst{31-27} = 0b00011;
let Inst{26} = X;
let Inst{25-21} = imm26{20-16};
let Inst{20-16} = imm26{25-21};
let Inst{15-0} = imm26{15-0};
}
//===----------------------------------------------------------------------===//
// Format EXT-I instruction class in Mips16 :
// <|EXTEND|imm10:5|imm15:11|op|0|0|0|0|0|0|imm4:0>
//===----------------------------------------------------------------------===//
class FEXT_I16<bits<5> _eop, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<16> imm16;
bits<5> eop;
let eop = _eop;
let Inst{26-21} = imm16{10-5};
let Inst{20-16} = imm16{15-11};
let Inst{15-11} = eop;
let Inst{10-5} = 0;
let Inst{4-0} = imm16{4-0};
}
//===----------------------------------------------------------------------===//
// Format ASMACRO instruction class in Mips16 :
// <EXTEND|select|p4|p3|RRR|p2|p1|p0>
//===----------------------------------------------------------------------===//
class FASMACRO16<dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<3> select;
bits<3> p4;
bits<5> p3;
bits<5> RRR = 0b11100;
bits<3> p2;
bits<3> p1;
bits<5> p0;
let Inst{26-24} = select;
let Inst{23-21} = p4;
let Inst{20-16} = p3;
let Inst{15-11} = RRR;
let Inst{10-8} = p2;
let Inst{7-5} = p1;
let Inst{4-0} = p0;
}
//===----------------------------------------------------------------------===//
// Format EXT-RI instruction class in Mips16 :
// <|EXTEND|imm10:5|imm15:11|op|rx|0|0|0|imm4:0>
//===----------------------------------------------------------------------===//
class FEXT_RI16<bits<5> _op, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<16> imm16;
bits<5> op;
bits<3> rx;
let op = _op;
let Inst{26-21} = imm16{10-5};
let Inst{20-16} = imm16{15-11};
let Inst{15-11} = op;
let Inst{10-8} = rx;
let Inst{7-5} = 0;
let Inst{4-0} = imm16{4-0};
}
//===----------------------------------------------------------------------===//
// Format EXT-RRI instruction class in Mips16 :
// <|EXTEND|imm10:5|imm15:11|op|rx|ry|imm4:0>
//===----------------------------------------------------------------------===//
class FEXT_RRI16<bits<5> _op, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<5> op;
bits<16> imm16;
bits<3> rx;
bits<3> ry;
let op=_op;
let Inst{26-21} = imm16{10-5};
let Inst{20-16} = imm16{15-11};
let Inst{15-11} = op;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-0} = imm16{4-0};
}
//===----------------------------------------------------------------------===//
// Format EXT-RRI-A instruction class in Mips16 :
// <|EXTEND|imm10:4|imm14:11|RRI-A|rx|ry|f|imm3:0>
//===----------------------------------------------------------------------===//
class FEXT_RRI_A16<bits<1> _f, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<15> imm15;
bits<3> rx;
bits<3> ry;
bits<1> f;
let f = _f;
let Inst{26-20} = imm15{10-4};
let Inst{19-16} = imm15{14-11};
let Inst{15-11} = 0b01000;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4} = f;
let Inst{3-0} = imm15{3-0};
}
//===----------------------------------------------------------------------===//
// Format EXT-SHIFT instruction class in Mips16 :
// <|EXTEND|sa 4:0|s5|0|SHIFT|rx|ry|0|f>
//===----------------------------------------------------------------------===//
class FEXT_SHIFT16<bits<2> _f, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<6> sa6;
bits<3> rx;
bits<3> ry;
bits<2> f;
let f = _f;
let Inst{26-22} = sa6{4-0};
let Inst{21} = sa6{5};
let Inst{20-16} = 0;
let Inst{15-11} = 0b00110;
let Inst{10-8} = rx;
let Inst{7-5} = ry;
let Inst{4-2} = 0;
let Inst{1-0} = f;
}
//===----------------------------------------------------------------------===//
// Format EXT-I8 instruction class in Mips16 :
// <|EXTEND|imm10:5|imm15:11|I8|funct|0|imm4:0>
//===----------------------------------------------------------------------===//
class FEXT_I816<bits<3> _funct, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<16> imm16;
bits<5> I8;
bits<3> funct;
let funct = _funct;
let I8 = 0b00110;
let Inst{26-21} = imm16{10-5};
let Inst{20-16} = imm16{15-11};
let Inst{15-11} = I8;
let Inst{10-8} = funct;
let Inst{7-5} = 0;
let Inst{4-0} = imm16{4-0};
}
//===----------------------------------------------------------------------===//
// Format EXT-I8_SVRS instruction class in Mips16 :
// <|EXTEND|xsregs|framesize7:4|aregs|I8|SVRS|s|ra|s0|s1|framesize3:0>
//===----------------------------------------------------------------------===//
class FEXT_I8_SVRS16<bits<1> s_, dag outs, dag ins, string asmstr,
list<dag> pattern, InstrItinClass itin>:
MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin>
{
bits<3> xsregs =0;
bits<8> framesize =0;
bits<3> aregs =0;
bits<5> I8 = 0b01100;
bits<3> SVRS = 0b100;
bits<1> s;
bits<1> ra = 0;
bits<1> s0 = 0;
bits<1> s1 = 0;
let s= s_;
let Inst{26-24} = xsregs;
let Inst{23-20} = framesize{7-4};
let Inst{19} = 0;
let Inst{18-16} = aregs;
let Inst{15-11} = I8;
let Inst{10-8} = SVRS;
let Inst{7} = s;
let Inst{6} = ra;
let Inst{5} = s0;
let Inst{4} = s1;
let Inst{3-0} = framesize{3-0};
}