decoder.isa revision 2052
12207SN/A////////////////////////////////////////////////////////////////////
25254Sksewell@umich.edu//
35254Sksewell@umich.edu// The actual MIPS32 ISA decoder
42207SN/A// -----------------------------
55254Sksewell@umich.edu// The following instructions are specified in the MIPS32 ISA
65254Sksewell@umich.edu// Specification. Decoding closely follows the style specified
75254Sksewell@umich.edu// in the MIPS32 ISAthe specification document starting with Table
85254Sksewell@umich.edu// A-2 (document available @ www.mips.com)
95254Sksewell@umich.edu//
105254Sksewell@umich.edu//@todo: Distinguish "unknown/future" use insts from "reserved"
115254Sksewell@umich.edu// ones
125254Sksewell@umich.edudecode OPCODE_HI default FailUnimpl::unknown() {
135254Sksewell@umich.edu
145254Sksewell@umich.edu    // Derived From ... Table A-2 MIPS32 ISA Manual
152207SN/A    0x0: decode OPCODE_LO default FailUnimpl::reserved(){
165254Sksewell@umich.edu
175254Sksewell@umich.edu        0x0: decode FUNCTION_HI {
185254Sksewell@umich.edu            0x0: decode FUNCTION_LO {
195254Sksewell@umich.edu              0x1: decode MOVCI {
205254Sksewell@umich.edu                format BasicOp {
215254Sksewell@umich.edu                  0: movf({{ if( xc->miscRegs.fpcr == 0) Rd = Rs}});
225254Sksewell@umich.edu                  1: movt({{ if( xc->miscRegs.fpcr == 1) Rd = Rs}});
235254Sksewell@umich.edu                }
245254Sksewell@umich.edu              }
255254Sksewell@umich.edu
265254Sksewell@umich.edu              format BasicOp {
272665Ssaidi@eecs.umich.edu
285254Sksewell@umich.edu                //Table A-3 Note: "1. Specific encodings of the rt, rd, and sa fields
295254Sksewell@umich.edu                //are used to distinguish among the SLL, NOP, SSNOP and EHB functions."
305254Sksewell@umich.edu
312207SN/A                0x0: sll({{ Rd = Rt.uw << SA; }});
322207SN/A
3311793Sbrandon.potter@amd.com                0x2: decode SRL {
3411793Sbrandon.potter@amd.com                   0: srl({{ Rd = Rt.uw >> SA; }});
352474SN/A
368229Snate@binkert.org                   //Hardcoded assuming 32-bit ISA, probably need parameter here
372454SN/A                   1: rotr({{ Rd = (Rt.uw << (32 - SA)) | (Rt.uw >> SA);}});
3812334Sgabeblack@google.com                 }
392680Sktlim@umich.edu
408232Snate@binkert.org                 0x3: sra({{ Rd = Rt.sw >> SA; }});
416650Sksewell@umich.edu
4212431Sgabeblack@google.com                 0x4: sllv({{ Rd = Rt.uw << Rs<4:0>; }});
4311854Sbrandon.potter@amd.com
446650Sksewell@umich.edu                 0x6: decode SRLV {
456650Sksewell@umich.edu                   0: srlv({{ Rd = Rt.uw >> Rs<4:0>; }});
4611800Sbrandon.potter@amd.com
472474SN/A                   //Hardcoded assuming 32-bit ISA, probably need parameter here
482207SN/A                   1: rotrv({{ Rd = (Rt.uw << (32 - Rs<4:0>)) | (Rt.uw >> Rs<4:0>);}});
492447SN/A                 }
502474SN/A
512447SN/A                 0x7: srav({{ Rd = Rt.sw >> Rs<4:0>; }});
5212431Sgabeblack@google.com              }
5312448Sgabeblack@google.com            }
5412448Sgabeblack@google.com
5512432Sgabeblack@google.com            0x1: decode FUNCTION_LO {
562474SN/A
5712441Sgabeblack@google.com              //Table A-3 Note: "Specific encodings of the hint field are used
582686Sksewell@umich.edu              //to distinguish JR from JR.HB and JALR from JALR.HB"
592686Sksewell@umich.edu              format Jump {
6011905SBrandon.Potter@amd.com                0x0: jr(IsReturn);
6111905SBrandon.Potter@amd.com                0x1: jalr(IsCall,IsReturn);
6211905SBrandon.Potter@amd.com              }
632474SN/A
642474SN/A              format BasicOp {
6511905SBrandon.Potter@amd.com                0x2: movz({{ if (Rt == 0) Rd = Rs; }});
662474SN/A                0x3: movn({{ if (Rt != 0) Rd = Rs; }});
672686Sksewell@umich.edu              }
6811905SBrandon.Potter@amd.com
6911905SBrandon.Potter@amd.com              format Trap {
7011905SBrandon.Potter@amd.com                0x4: syscall({{ xc->syscall()}},IsNonSpeculative);
712686Sksewell@umich.edu                0x5: break({{ }});
726811SMatt DeVuyst                0x7: sync({{ }});
7311905SBrandon.Potter@amd.com              }
7411905SBrandon.Potter@amd.com            }
7511905SBrandon.Potter@amd.com
7611905SBrandon.Potter@amd.com            0x2: decode FUNCTION_LO {
772474SN/A              format BasicOp {
782474SN/A                0x0: mfhi({{ Rd = xc->miscRegs.hi; }});
792474SN/A                0x1: mthi({{ xc->miscRegs.hi = Rs; }});
8011851Sbrandon.potter@amd.com                0x2: mflo({{ Rd = xc->miscRegs.lo; }});
812474SN/A                0x3: mtlo({{ xc->miscRegs.lo = Rs; }});
8211851Sbrandon.potter@amd.com              }
836650Sksewell@umich.edu            };
8410318Sandreas.hansson@arm.com
852474SN/A            0x3: decode FUNCTION_LO {
865958Sgblack@eecs.umich.edu              format IntOp {
876811SMatt DeVuyst                0x0: mult({{
886650Sksewell@umich.edu                        INT64 temp1 = Rs.sw * Rt.sw;
8911851Sbrandon.potter@amd.com                        xc->miscRegs.hi->temp1<63:32>;
906650Sksewell@umich.edu                        xc->miscRegs.lo->temp1<31:0>
916811SMatt DeVuyst                }});
926811SMatt DeVuyst
9311389Sbrandon.potter@amd.com                0x1: multu({{
9411389Sbrandon.potter@amd.com                        INT64 temp1 = Rs.uw * Rt.uw;
9511389Sbrandon.potter@amd.com                        xc->miscRegs.hi->temp1<63:32>;
966650Sksewell@umich.edu                        xc->miscRegs.lo->temp1<31:0>
976650Sksewell@umich.edu                        Rd.sw = Rs.uw * Rt.uw;
986650Sksewell@umich.edu                }});
9913894Sgabeblack@google.com
1006811SMatt DeVuyst                0x2: div({{
1016811SMatt DeVuyst                        xc->miscRegs.hi = Rs.sw % Rt.sw;
1026811SMatt DeVuyst                        xc->miscRegs.lo = Rs.sw / Rt.sw;
1036811SMatt DeVuyst                        }});
1046811SMatt DeVuyst
10513894Sgabeblack@google.com                0x3: divu({{
1066811SMatt DeVuyst                        xc->miscRegs.hi = Rs.uw % Rt.uw;
10713894Sgabeblack@google.com                        xc->miscRegs.lo = Rs.uw / Rt.uw;
1086811SMatt DeVuyst                        }});
1096811SMatt DeVuyst              }
1106811SMatt DeVuyst            };
11113894Sgabeblack@google.com
11213894Sgabeblack@google.com            0x4: decode FUNCTION_LO {
11313894Sgabeblack@google.com              format IntOp {
1146811SMatt DeVuyst                0x0: add({{  Rd.sw = Rs.sw + Rt.sw;}});
11513894Sgabeblack@google.com                0x1: addu({{ Rd.uw = Rs.uw + Rt.uw;}});
1166811SMatt DeVuyst                0x2: sub({{ Rd.sw = Rs.sw - Rt.sw;}});
11713894Sgabeblack@google.com                0x3: subu({{ Rd.uw = Rs.uw - Rt.uw;}});
11811389Sbrandon.potter@amd.com                0x4: and({{ Rd.sw = Rs.uw & Rt.uw;}});
11911389Sbrandon.potter@amd.com                0x5: or({{ Rd.sw = Rs.uw | Rt.uw;}});
12011389Sbrandon.potter@amd.com                0x6: xor({{ Rd.sw = Rs.uw ^ Rt.uw;}});
12113894Sgabeblack@google.com                0x7: nor({{ Rd.sw = ~(Rs.uw | Rt.uw);}});
1226811SMatt DeVuyst              }
12313894Sgabeblack@google.com            }
1246811SMatt DeVuyst
12513894Sgabeblack@google.com            0x5: decode FUNCTION_LO {
12613894Sgabeblack@google.com              format IntOp{
12713894Sgabeblack@google.com                0x2: slt({{  Rd.sw = ( Rs.sw < Rt.sw ) ? 1 : 0}});
12813894Sgabeblack@google.com                0x3: sltu({{ Rd.uw = ( Rs.uw < Rt.uw ) ? 1 : 0}});
1296811SMatt DeVuyst              }
1306811SMatt DeVuyst            };
1316811SMatt DeVuyst
1326650Sksewell@umich.edu            0x6: decode FUNCTION_LO {
1336650Sksewell@umich.edu              format Trap {
1346811SMatt DeVuyst                 0x0: tge({{ }});
1356811SMatt DeVuyst                 0x1: tgeu({{ }});
1366650Sksewell@umich.edu                 0x2: tlt({{ }});
1376650Sksewell@umich.edu                 0x3: tltu({{ }});
1386650Sksewell@umich.edu                 0x4: teq({{ }});
1396650Sksewell@umich.edu                 0x6: tne({{ }});
1406650Sksewell@umich.edu              }
1416650Sksewell@umich.edu            }
1426650Sksewell@umich.edu        }
1436650Sksewell@umich.edu
1446650Sksewell@umich.edu        0x1: decode REGIMM_HI {
1456650Sksewell@umich.edu            0x0: decode REGIMM_LO {
1466811SMatt DeVuyst              format Branch {
1476811SMatt DeVuyst                0x0: bltz({{ cond = (Rs.sq < 0); }});
1486811SMatt DeVuyst                0x1: bgez({{ cond = (Rs.sq >= 0); }});
1496811SMatt DeVuyst
1506811SMatt DeVuyst                //MIPS obsolete instructions
1516650Sksewell@umich.edu                0x2: bltzl({{ cond = (Rs.sq < 0); }});
1526650Sksewell@umich.edu                0x3: bgezl({{ cond = (Rs.sq >= 0); }});
15311905SBrandon.Potter@amd.com              }
1546650Sksewell@umich.edu            }
15511905SBrandon.Potter@amd.com
15611905SBrandon.Potter@amd.com            0x1: decode REGIMM_LO {
1576650Sksewell@umich.edu              format Trap {
15811905SBrandon.Potter@amd.com                 0x0: tgei({{ }});
15911905SBrandon.Potter@amd.com                 0x1: tgeiu({{ }});
1606650Sksewell@umich.edu                 0x2: tlti({{ }});
16111905SBrandon.Potter@amd.com                 0x3: tltiu({{ }});
16211905SBrandon.Potter@amd.com                 0x4: teqi({{ }});
1636811SMatt DeVuyst                 0x6: tnei({{ }});
1646811SMatt DeVuyst              }
1656811SMatt DeVuyst            }
1666811SMatt DeVuyst
1676650Sksewell@umich.edu            0x2: decode REGIMM_LO {
1686650Sksewell@umich.edu              format Branch {
1696811SMatt DeVuyst                0x0: bltzal({{ cond = (Rs.sq < 0); }});
1706650Sksewell@umich.edu                0x1: bgezal({{ cond = (Rs.sq >= 0); }});
1716811SMatt DeVuyst
1726650Sksewell@umich.edu                //MIPS obsolete instructions
17311905SBrandon.Potter@amd.com                0x2: bltzall({{ cond = (Rs.sq < 0); }});
1746650Sksewell@umich.edu                0x3: bgezall({{ cond = (Rs.sq >= 0); }});
1756650Sksewell@umich.edu              }
1766650Sksewell@umich.edu            }
1776650Sksewell@umich.edu
1786650Sksewell@umich.edu            0x3: decode REGIMM_LO {
1796811SMatt DeVuyst              format Trap {
18013894Sgabeblack@google.com                0x7: synci({{ }});
18113894Sgabeblack@google.com              }
18213894Sgabeblack@google.com            }
18313894Sgabeblack@google.com        }
1846811SMatt DeVuyst
1856811SMatt DeVuyst        format Jump {
1866811SMatt DeVuyst            0x2: j();
18713894Sgabeblack@google.com            0x3: jal(IsCall);
18813894Sgabeblack@google.com        }
18913894Sgabeblack@google.com
1906811SMatt DeVuyst        format Branch {
1916650Sksewell@umich.edu            0x4: beq({{ cond = (Rs.sq == 0); }});
1926650Sksewell@umich.edu            0x5: bne({{ cond = (Rs.sq !=  0); }});
1936650Sksewell@umich.edu            0x6: blez({{ cond = (Rs.sq <= 0); }});
1946650Sksewell@umich.edu            0x7: bgtz({{ cond = (Rs.sq > 0); }});
19511905SBrandon.Potter@amd.com        }
1966650Sksewell@umich.edu    };
19711389Sbrandon.potter@amd.com
1986650Sksewell@umich.edu    0x1: decode OPCODE_LO default FailUnimpl::reserved(){
1996650Sksewell@umich.edu        format IntOp {
2006650Sksewell@umich.edu            0x0: addi({{ Rt.sw = Rs.sw + INTIMM; }});
20113615Sgabeblack@google.com            0x1: addiu({{ Rt.uw = Rs.uw + INTIMM;}});
20211851Sbrandon.potter@amd.com            0x2: slti({{ Rt.sw = ( Rs.sw < INTIMM ) ? 1 : 0 }});
2035958Sgblack@eecs.umich.edu            0x3: sltiu({{ Rt.uw = ( Rs.uw < INTIMM ) ? 1 : 0 }});
2045958Sgblack@eecs.umich.edu            0x4: andi({{ Rt.sw = Rs.sw & INTIMM;}});
2056701Sgblack@eecs.umich.edu            0x5: ori({{ Rt.sw = Rs.sw | INTIMM;}});
2065958Sgblack@eecs.umich.edu            0x6: xori({{ Rt.sw = Rs.sw ^ INTIMM;}});
2075958Sgblack@eecs.umich.edu            0x7: lui({{ Rt = INTIMM << 16}});
2085958Sgblack@eecs.umich.edu        };
20913615Sgabeblack@google.com    };
2105958Sgblack@eecs.umich.edu
2115958Sgblack@eecs.umich.edu    0x2: decode OPCODE_LO default FailUnimpl::reserved(){
2125958Sgblack@eecs.umich.edu
2135958Sgblack@eecs.umich.edu      //Table A-11 MIPS32 COP0 Encoding of rs Field
2145958Sgblack@eecs.umich.edu      0x0: decode RS_MSB {
2155958Sgblack@eecs.umich.edu        0x0: decode RS {
21611851Sbrandon.potter@amd.com
2175958Sgblack@eecs.umich.edu           format BasicOp {
21810223Ssteve.reinhardt@amd.com                0x0: mfc0({{
2195958Sgblack@eecs.umich.edu                        //The contents of the coprocessor 0 register specified by the
2205958Sgblack@eecs.umich.edu                        //combination of rd and sel are loaded into general register
22110223Ssteve.reinhardt@amd.com                        //rt. Note that not all coprocessor 0 registers support the
2225958Sgblack@eecs.umich.edu                        //sel field. In those instances, the sel field must be zero.
2235958Sgblack@eecs.umich.edu
22413388Sgabeblack@google.com                        if (SEL > 0)
22510223Ssteve.reinhardt@amd.com                                panic("Can't Handle Cop0 with register select yet\n");
2265958Sgblack@eecs.umich.edu
2275958Sgblack@eecs.umich.edu                        uint64_t reg_num = Rd.uw;
228
229                        Rt = xc->miscRegs.cop0[reg_num];
230                        }});
231
232                0xC: mtc0({{
233                        //The contents of the coprocessor 0 register specified by the
234                        //combination of rd and sel are loaded into general register
235                        //rt. Note that not all coprocessor 0 registers support the
236                        //sel field. In those instances, the sel field must be zero.
237
238                        if (SEL > 0)
239                                panic("Can't Handle Cop0 with register select yet\n");
240
241                        uint64_t reg_num = Rd.uw;
242
243                        xc->miscRegs.cop0[reg_num] = Rt;
244                        }});
245
246                0xA: rdpgpr({{
247                        //Accessing Previous Shadow Set Register Number
248                        uint64_t prev = xc->miscRegs.cop0[SRSCtl][PSS];
249                        uint64_t reg_num = Rt.uw;
250
251                        Rd = xc->shadowIntRegFile[prev][reg_num];
252                        }});
253            }
254
255          0xB: decode SC {
256            format BasicOp {
257                0x0: di({{
258                        //Accessing Coprocessor 0 "Status" Register
259                        Rt.sw = xc->miscRegs.cop0[12];
260                        xc->miscRegs.cop0[12][INTERRUPT_ENABLE] = 0;
261                        }});
262
263                0x1: ei({{
264                        //Accessing Coprocessor 0 "Status" Register
265                        Rt.sw = xc->miscRegs.cop0[12];
266                        xc->miscRegs.cop0[12][INTERRUPT_ENABLE] = 1;
267                        }});
268            }
269          }
270
271          0xE: BasicOp::wrpgpr({{
272                        //Accessing Previous Shadow Set Register Number
273                        uint64_t prev = xc->miscRegs.cop0[SRSCtl][PSS];
274                        uint64_t reg_num = Rd.uw;
275
276                        xc->shadowIntRegFile[prev][reg_num] = Rt;
277                        }});
278        }
279
280        //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO
281        0x1: decode FUNCTION {
282          format Trap {
283                0x01: tlbr({{ }});
284                0x02: tlbwi({{ }});
285                0x06: tlbwr({{ }});
286                0x08: tlbp({{ }});
287          }
288
289          format WarnUnimpl {
290                0x18: eret({{ }});
291                0x1F: deret({{ }});
292                0x20: wait({{ }});
293          }
294        }
295      }
296
297      //Table A-13 MIPS32 COP1 Encoding of rs Field
298      0x1: decode RS_MSB {
299
300        0x0: decode RS_HI {
301          0x0: decode RS_LO {
302            format FloatOp {
303              0x0: mfc1({{ Rt = Fs<31:0>; }});
304              0x2: cfc1({{ Rt = xc->miscRegs.fpcr[Fs];}});
305              0x3: mfhc1({{ Rt = Fs<63:32>;}});
306              0x4: mtc1({{ Fs<31:0> = Rt}});
307              0x6: ctc1({{ xc->miscRegs.fpcr[Fs] = Rt;}});
308              0x7: mftc1({{ Fs<63:32> = Rt}});
309            }
310          }
311
312          0x1: decode ND {
313            0x0: decode TF {
314              format Branch {
315                0x0: bc1f({{ cond = (xc->miscRegs.fpcr == 0); }});
316                0x1: bc1t({{ cond = (xc->miscRegs.fpcr == 1); }});
317              }
318            }
319
320            0x1: decode TF {
321              format Branch {
322                0x0: bc1fl({{ cond = (xc->miscRegs.fpcr == 0); }});
323                0x1: bc1tl({{ cond = (xc->miscRegs.fpcr == 1); }});
324              }
325            }
326          }
327        }
328
329        0x1: decode RS_HI {
330          0x2: decode RS_LO {
331
332            //Table A-14 MIPS32 COP1 Encoding of Function Field When rs=S
333            //(( single-word ))
334            0x0: decode RS_HI {
335              0x0: decode RS_LO {
336                format FloatOp {
337                  0x0: add_fmt({{ }});
338                  0x1: sub_fmt({{ }});
339                  0x2: mul_fmt({{ }});
340                  0x3: div_fmt({{ }});
341                  0x4: sqrt_fmt({{ }});
342                  0x5: abs_fmt({{ }});
343                  0x6: mov_fmt({{ }});
344                  0x7: neg_fmt({{ }});
345                }
346              }
347
348              0x1: decode RS_LO {
349                //only legal for 64 bit
350                format Float64Op {
351                  0x0: round_l({{ }});
352                  0x1: trunc_l({{ }});
353                  0x2: ceil_l({{ }});
354                  0x3: floor_l({{ }});
355                }
356
357                format FloatOp {
358                  0x4: round_w({{ }});
359                  0x5: trunc_w({{ }});
360                  0x6: ceil_w({{ }});
361                  0x7: floor_w({{ }});
362                }
363              }
364
365              0x2: decode RS_LO {
366                0x1: decode MOVCF {
367                  format FloatOp {
368                    0x0: movf_fmt({{ }});
369                    0x1: movt_fmt({{ }});
370                  }
371                }
372
373                format BasicOp {
374                  0x2: movz({{ if (Rt == 0) Rd = Rs; }});
375                  0x3: movn({{ if (Rt != 0) Rd = Rs; }});
376                }
377
378                format Float64Op {
379                  0x2: recip({{ }});
380                  0x3: rsqrt{{ }});
381                }
382              }
383
384              0x4: decode RS_LO {
385                0x1: cvt_d({{ }});
386                0x4: cvt_w({{ }});
387
388                //only legal for 64 bit
389                format Float64Op {
390                  0x5: cvt_l({{ }});
391                  0x6: cvt_ps({{ }});
392                }
393              }
394            }
395
396            //Table A-15 MIPS32 COP1 Encoding of Function Field When rs=D
397            0x1: decode RS_HI {
398              0x0: decode RS_LO {
399                format FloatOp {
400                  0x0: add_fmt({{ }});
401                  0x1: sub_fmt({{ }});
402                  0x2: mul_fmt({{ }});
403                  0x3: div_fmt({{ }});
404                  0x4: sqrt_fmt({{ }});
405                  0x5: abs_fmt({{ }});
406                  0x6: mov_fmt({{ }});
407                  0x7: neg_fmt({{ }});
408                }
409              }
410
411              0x1: decode RS_LO {
412                //only legal for 64 bit
413                format FloatOp64 {
414                  0x0: round_l({{ }});
415                  0x1: trunc_l({{ }});
416                  0x2: ceil_l({{ }});
417                  0x3: floor_l({{ }});
418                }
419
420                format FloatOp {
421                  0x4: round_w({{ }});
422                  0x5: trunc_w({{ }});
423                  0x6: ceil_w({{ }});
424                  0x7: floor_w({{ }});
425                }
426              }
427
428              0x2: decode RS_LO {
429                0x1: decode MOVCF {
430                  format FloatOp {
431                    0x0: movf_fmt({{ }});
432                    0x1: movt_fmt({{ }});
433                  }
434                }
435
436                format BasicOp {
437                  0x2: movz({{ if (Rt == 0) Rd = Rs; }});
438                  0x3: movn({{ if (Rt != 0) Rd = Rs; }});
439                }
440
441                format FloatOp64 {
442                  0x5: recip({{ }});
443                  0x6: rsqrt{{ }});
444                }
445              }
446
447              0x4: decode RS_LO {
448                format FloatOp {
449                  0x0: cvt_s({{ }});
450                  0x4: cvt_w({{ }});
451                }
452
453                //only legal for 64 bit
454                format FloatOp64 {
455                  0x5: cvt_l({{ }});
456                }
457              }
458            }
459
460            //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=W
461            0x4: decode FUNCTION {
462              format FloatOp {
463                0x10: cvt_s({{ }});
464                0x10: cvt_d({{ }});
465              }
466            }
467
468            //Table A-16 MIPS32 COP1 Encoding of Function Field When rs=L1
469            //Note: "1. Format type L is legal only if 64-bit floating point operations
470            //are enabled."
471            0x5: decode FUNCTION_HI {
472              format FloatOp {
473                0x10: cvt_s({{ }});
474                0x11: cvt_d({{ }});
475              }
476            }
477
478            //Table A-17 MIPS64 COP1 Encoding of Function Field When rs=PS1
479            //Note: "1. Format type PS is legal only if 64-bit floating point operations
480            //are enabled. "
481            0x6: decode RS_HI {
482              0x0: decode RS_LO {
483                format FloatOp64 {
484                  0x0: add_fmt({{ }});
485                  0x1: sub_fmt({{ }});
486                  0x2: mul_fmt({{ }});
487                  0x5: abs_fmt({{ }});
488                  0x6: mov_fmt({{ }});
489                  0x7: neg_fmt({{ }});
490                }
491              }
492
493              0x2: decode RS_LO {
494                0x1: decode MOVCF {
495                  format FloatOp64 {
496                    0x0: movf_fmt({{ }});
497                    0x1: movt_fmt({{ }});
498                  }
499                }
500
501              }
502
503              0x4: decode RS_LO {
504                0x0: FloatOp64::cvt_s_pu({{ }});
505              }
506
507              0x5: decode RS_LO {
508                format FloatOp64 {
509                  0x0: cvt_s_pl({{ }});
510                  0x4: pll_s_pl({{ }});
511                  0x5: plu_s_pl({{ }});
512                  0x6: pul_s_pl({{ }});
513                  0x7: puu_s_pl({{ }});
514                }
515              }
516            }
517      }
518
519      //Table A-19 MIPS32 COP2 Encoding of rs Field
520      0x2: decode RS_MSB {
521        0x0: decode RS_HI {
522          0x0: decode RS_LO {
523            format WarnUnimpl {
524                0x0: mfc2({{ }});
525                0x2: cfc2({{ }});
526                0x3: mfhc2({{ }});
527                0x4: mtc2({{ }});
528                0x6: ctc2({{ }});
529                0x7: mftc2({{ }});
530            }
531          }
532
533          0x1: decode ND {
534            0x0: decode TF {
535              format Branch {
536                0x0: bc2f({{ cond = (xc->miscRegs.cop2cc == 0); }}, COP2);
537                0x1: bc2t({{ cond = (xc->miscRegs.cop2cc == 1); }}, COP2}});
538              }
539            }
540
541            0x1: decode TF {
542              format Branch {
543                0x0: bc2fl({{ cond = (xc->miscRegs.cop2cc == 0); }}, COP2}});
544                0x1: bc2tl({{ cond = (xc->miscRegs.cop2cc == 1); }}, COP2}});
545              }
546            }
547          }
548        }
549      }
550
551      //Table A-20 MIPS64 COP1X Encoding of Function Field 1
552      //Note: "COP1X instructions are legal only if 64-bit floating point
553      //operations are enabled."
554      0x3: decode FUNCTION_HI {
555        0x0: decode FUNCTION_LO {
556                format Memory {
557                  0x0: lwxc1({{ }});
558                  0x1: ldxc1({{ }});
559                  0x5: luxc1({{ }});
560                }
561        }
562
563        0x1: decode FUNCTION_LO {
564                format Memory {
565                  0x0: swxc1({{ }});
566                  0x1: sdxc1({{ }});
567                  0x5: suxc1({{ }});
568                  0x7: prefx({{ }});
569                }
570        }
571
572        format FloatOp {
573                0x3: alnv_ps({{ }});
574
575                0x4: decode FUNCTION_LO {
576                  0x0: madd_s({{ }});
577                  0x1: madd_d({{ }});
578                  0x6: madd_ps({{ }});
579                }
580
581                0x5: decode FUNCTION_LO {
582                  0x0: msub_s({{ }});
583                  0x1: msub_d({{ }});
584                  0x6: msub_ps({{ }});
585                }
586
587                0x6: decode FUNCTION_LO {
588                  0x0: nmadd_s({{ }});
589                  0x1: nmadd_d({{ }});
590                  0x6: nmadd_ps({{ }});
591                }
592
593                0x7: decode FUNCTION_LO {
594                  0x0: nmsub_s({{ }});
595                  0x1: nmsub_d({{ }});
596                  0x6: nmsub_ps({{ }});
597                }
598        }
599      }
600
601      //MIPS obsolete instructions
602        format Branch {
603              0x4: beql({{ cond = (Rs.sq == 0); }});
604              0x5: bnel({{ cond = (Rs.sq != 0); }});
605              0x6: blezl({{ cond = (Rs.sq <= 0); }});
606              0x7: bgtzl({{ cond = (Rs.sq > 0); }});
607        }
608    };
609
610    0x3: decode OPCODE_LO default FailUnimpl::reserved() {
611
612        //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field
613        0x4: decode FUNCTION_HI {
614
615            0x0: decode FUNCTION_LO {
616                format IntOp {
617                   0x0: madd({{
618                        INT64 temp1 = Hi.sw << 32 | Lo.sw >> 32;
619                        temp1 = temp1 + (Rs.sw * Rt.sw);
620                        xc->miscRegs.hi->temp1<63:32>;
621                        xc->miscRegs.lo->temp1<31:0>
622                        }});
623
624                   0x1: maddu({{
625                        INT64 temp1 = Hi.uw << 32 | Lo.uw >> 32;
626                        temp1 = temp1 + (Rs.uw * Rt.uw);
627                        xc->miscRegs.hi->temp1<63:32>;
628                        xc->miscRegs.lo->temp1<31:0>
629                        }});
630
631                   0x2: mul({{ 	Rd.sw = Rs.sw * Rt.sw; 	}});
632
633                   0x4: msub({{
634                        INT64 temp1 = Hi.sw << 32 | Lo.sw >> 32;
635                        temp1 = temp1 - (Rs.sw * Rt.sw);
636                        xc->miscRegs.hi->temp1<63:32>;
637                        xc->miscRegs.lo->temp1<31:0>
638                        }});
639
640                   0x5: msubu({{
641                        INT64 temp1 = Hi.uw << 32 | Lo.uw >> 32;
642                        temp1 = temp1 - (Rs.uw * Rt.uw);
643                        xc->miscRegs.hi->temp1<63:32>;
644                        xc->miscRegs.lo->temp1<31:0>
645                        }});
646                }
647            }
648
649            0x4: decode FUNCTION_LO {
650                  format BasicOp {
651                      0x0: clz({{
652                        int cnt = 0;
653                        int idx = 0;
654                        while ( Rs.uw<idx>!= 1) {
655                                cnt++;
656                                idx--;
657                        }
658
659                        Rd.uw = cnt;
660                        }});
661
662                      0x1: clo({{
663                        int cnt = 0;
664                        int idx = 0;
665                        while ( Rs.uw<idx>!= 0) {
666                                cnt++;
667                                idx--;
668                        }
669
670                        Rd.uw = cnt;
671                        }});
672                  }
673            }
674
675            0x7: decode FUNCTION_LO {
676              0x7: WarnUnimpl::sdbbp({{ }});
677            }
678        }
679
680        //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2 of the Architecture
681        0x7: decode FUNCTION_HI {
682
683          0x0: decode FUNCTION_LO {
684                format WarnUnimpl {
685                    0x1: ext({{ }});
686                    0x4: ins({{ }});
687                }
688          }
689
690          //Table A-10 MIPS32 BSHFL Encoding of sa Field
691          0x4: decode SA {
692                format BasicOp {
693                    0x02: wsbh({{ }});
694                    0x10: seb({{ Rd.sw = /* sext32(Rt<7>,24)  | */ Rt<7:0>}});
695                    0x18: seh({{ Rd.sw = /* sext32(Rt<15>,16) | */ Rt<15:0>}});
696                }
697          }
698
699          0x6: decode FUNCTION_LO {
700            0x7: BasicOp::rdhwr({{ }});
701          }
702        }
703    };
704
705    0x4: decode OPCODE_LO default FailUnimpl::reserved() {
706        format Memory {
707            0x0: lb({{ EA = Rs + disp; }}, {{ Rb.sw = Mem.sb; }});
708            0x1: lh({{ EA = Rs + disp; }}, {{ Rb.sw = Mem.sh; }});
709            0x2: lwl({{ EA = Rs + disp; }}, {{ Rb.sw = Mem.sw; }}, WordAlign);
710            0x3: lw({{ EA = Rs + disp; }}, {{ Rb.uq = Mem.sb; }});
711            0x4: lbu({{ EA = Rs + disp; }}, {{ Rb.uw = Mem.ub; }});
712            0x5: lhu({{ EA = Rs + disp; }}, {{ Rb.uw = Mem.uh; }});
713            0x6: lwr({{ EA = Rs + disp; }}, {{ Rb.uw = Mem.uw; }}, WordAlign);
714        };
715
716        0x7: FailUnimpl::reserved({{ }});
717    };
718
719    0x5: decode OPCODE_LO default FailUnimpl::reserved() {
720        format Memory {
721            0x0: sb({{ EA = Rs + disp; }}, {{ Mem.ub = Rt<7:0>; }});
722            0x1: sh({{ EA = Rs + disp; }},{{ Mem.uh = Rt<15:0>; }});
723            0x2: swl({{ EA = Rs + disp; }},{{ Mem.ub = Rt<31:0>; }},WordAlign);
724            0x3: sw({{ EA = Rs + disp; }},{{ Mem.ub = Rt<31:0>; }});
725            0x6: swr({{ EA = Rs + disp; }},{{ Mem.ub = Rt<31:0>; }},WordAlign);
726        };
727
728        format WarnUnimpl {
729            0x4: reserved({{ }});
730            0x5: reserved({{ }});
731            0x7: cache({{ }});
732        };
733
734    };
735
736    0x6: decode OPCODE_LO default FailUnimpl::reserved() {
737        format Memory {
738            0x0: ll({{ }});
739            0x1: lwc1({{ EA = Rs + disp; }},{{ Ft<31:0> = Mem.uf; }});
740            0x5: ldc1({{ EA = Rs + disp; }},{{ Ft<63:0> = Mem.df; }});
741        };
742    };
743
744    0x7: decode OPCODE_LO default FailUnimpl::reserved() {
745        format Memory {
746            0x0: sc({{ }});
747            0x1: swc1({{ EA = Rs + disp; }},{{ Mem.uf = Ft<31:0>; }});
748            0x5: sdc1({{ EA = Rs + disp; }},{{ Mem.df = Ft<63:0>; }});
749        };
750
751    }
752}
753
754
755