decoder.isa revision 13389
11689SN/A// -*- mode:c++ -*-
28948Sandreas.hansson@arm.com
38707Sandreas.hansson@arm.com// Copyright (c) 2007 MIPS Technologies, Inc.
48707Sandreas.hansson@arm.com// All rights reserved.
58707Sandreas.hansson@arm.com//
68707Sandreas.hansson@arm.com// Redistribution and use in source and binary forms, with or without
78707Sandreas.hansson@arm.com// modification, are permitted provided that the following conditions are
88707Sandreas.hansson@arm.com// met: redistributions of source code must retain the above copyright
98707Sandreas.hansson@arm.com// notice, this list of conditions and the following disclaimer;
108707Sandreas.hansson@arm.com// redistributions in binary form must reproduce the above copyright
118707Sandreas.hansson@arm.com// notice, this list of conditions and the following disclaimer in the
128707Sandreas.hansson@arm.com// documentation and/or other materials provided with the distribution;
138707Sandreas.hansson@arm.com// neither the name of the copyright holders nor the names of its
142325SN/A// contributors may be used to endorse or promote products derived from
157897Shestness@cs.utexas.edu// this software without specific prior written permission.
161689SN/A//
171689SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181689SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191689SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201689SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211689SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221689SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231689SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241689SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251689SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261689SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271689SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281689SN/A//
291689SN/A// Authors: Korey Sewell
301689SN/A//          Brett Miller
311689SN/A//          Jaidev Patwardhan
321689SN/A
331689SN/A////////////////////////////////////////////////////////////////////
341689SN/A//
351689SN/A// The actual MIPS32 ISA decoder
361689SN/A// -----------------------------
371689SN/A// The following instructions are specified in the MIPS32 ISA
381689SN/A// Specification. Decoding closely follows the style specified
391689SN/A// in the MIPS32 ISA specification document starting with Table
402665Ssaidi@eecs.umich.edu// A-2 (document available @ http://www.mips.com)
412665Ssaidi@eecs.umich.edu//
422756Sksewell@umich.edudecode OPCODE_HI default Unknown::unknown() {
437897Shestness@cs.utexas.edu    //Table A-2
441689SN/A    0x0: decode OPCODE_LO {
451689SN/A        0x0: decode FUNCTION_HI {
468779Sgblack@eecs.umich.edu            0x0: decode FUNCTION_LO {
476658Snate@binkert.org                0x1: decode MOVCI {
488887Sgeoffrey.blake@arm.com                    format BasicOp {
498887Sgeoffrey.blake@arm.com                        0: movf({{
508229Snate@binkert.org                            Rd = (getCondCode(FCSR, CC) == 0) ? Rd : Rs;
518229Snate@binkert.org                        }});
528229Snate@binkert.org                        1: movt({{
534762Snate@binkert.org                            Rd = (getCondCode(FCSR, CC) == 1) ? Rd : Rs;
548779Sgblack@eecs.umich.edu                        }});
554762Snate@binkert.org                    }
564762Snate@binkert.org                }
578232Snate@binkert.org
589152Satgutier@umich.edu                format BasicOp {
598232Snate@binkert.org                    //Table A-3 Note: "Specific encodings of the rd, rs, and
608232Snate@binkert.org                    //rt fields are used to distinguish SLL, SSNOP, and EHB
614762Snate@binkert.org                    //functions
624762Snate@binkert.org                    0x0: decode RS  {
638793Sgblack@eecs.umich.edu                        0x0: decode RT_RD {
648779Sgblack@eecs.umich.edu                            0x0: decode SA default Nop::nop() {
654762Snate@binkert.org                                 0x1: ssnop({{;}});
668460SAli.Saidi@ARM.com                                 0x3: ehb({{;}});
674762Snate@binkert.org                            }
685702Ssaidi@eecs.umich.edu                            default: sll({{ Rd = Rt << SA; }});
695702Ssaidi@eecs.umich.edu                        }
708232Snate@binkert.org                    }
715702Ssaidi@eecs.umich.edu
725702Ssaidi@eecs.umich.edu                    0x2: decode RS_SRL {
738737Skoansin.tan@gmail.com                        0x0:decode SRL {
745529Snate@binkert.org                            0: srl({{ Rd = Rt >> SA; }});
752669Sktlim@umich.edu
766221Snate@binkert.org                            //Hardcoded assuming 32-bit ISA,
771060SN/A                            //probably need parameter here
785529Snate@binkert.org                            1: rotr({{
795712Shsul@eecs.umich.edu                                Rd = (Rt << (32 - SA)) | (Rt >> SA);
801060SN/A                            }});
811060SN/A                        }
821060SN/A                    }
832292SN/A
842733Sktlim@umich.edu                    0x3: decode RS {
852292SN/A                        0x0: sra({{
862292SN/A                            uint32_t temp = Rt >> SA;
872292SN/A                            if ( (Rt & 0x80000000) > 0 ) {
882292SN/A                                uint32_t mask = 0x80000000;
898707Sandreas.hansson@arm.com                                for(int i=0; i < SA; i++) {
908707Sandreas.hansson@arm.com                                    temp |= mask;
918975Sandreas.hansson@arm.com                                    mask = mask >> 1;
928707Sandreas.hansson@arm.com                                }
938707Sandreas.hansson@arm.com                            }
948948Sandreas.hansson@arm.com                            Rd = temp;
958948Sandreas.hansson@arm.com                        }});
968948Sandreas.hansson@arm.com                    }
978707Sandreas.hansson@arm.com
988707Sandreas.hansson@arm.com                    0x4: sllv({{ Rd = Rt << Rs<4:0>; }});
998707Sandreas.hansson@arm.com
1008707Sandreas.hansson@arm.com                    0x6: decode SRLV {
1018707Sandreas.hansson@arm.com                        0: srlv({{ Rd = Rt >> Rs<4:0>; }});
1028707Sandreas.hansson@arm.com
1038707Sandreas.hansson@arm.com                        //Hardcoded assuming 32-bit ISA,
1048707Sandreas.hansson@arm.com                        //probably need parameter here
1058707Sandreas.hansson@arm.com                        1: rotrv({{
1068707Sandreas.hansson@arm.com                            Rd = (Rt << (32 - Rs<4:0>)) | (Rt >> Rs<4:0>);
1078707Sandreas.hansson@arm.com                        }});
1088707Sandreas.hansson@arm.com                    }
1098707Sandreas.hansson@arm.com
1108975Sandreas.hansson@arm.com                    0x7: srav({{
1118707Sandreas.hansson@arm.com                        int shift_amt = Rs<4:0>;
1128975Sandreas.hansson@arm.com
1138707Sandreas.hansson@arm.com                        uint32_t temp = Rt >> shift_amt;
1148707Sandreas.hansson@arm.com
1158707Sandreas.hansson@arm.com                        if ((Rt & 0x80000000) > 0) {
1168975Sandreas.hansson@arm.com                            uint32_t mask = 0x80000000;
1178975Sandreas.hansson@arm.com                            for (int i = 0; i < shift_amt; i++) {
1188948Sandreas.hansson@arm.com                                temp |= mask;
1198975Sandreas.hansson@arm.com                                mask = mask >> 1;
1208948Sandreas.hansson@arm.com                            }
1218948Sandreas.hansson@arm.com                        }
1228948Sandreas.hansson@arm.com                        Rd = temp;
1238707Sandreas.hansson@arm.com                    }});
1248707Sandreas.hansson@arm.com                }
1258707Sandreas.hansson@arm.com            }
1268707Sandreas.hansson@arm.com
1278707Sandreas.hansson@arm.com            0x1: decode FUNCTION_LO {
1288707Sandreas.hansson@arm.com                //Table A-3 Note: "Specific encodings of the hint field are
1291060SN/A                //used to distinguish JR from JR.HB and JALR from JALR.HB"
1301755SN/A                format Jump {
1315606Snate@binkert.org                    0x0: decode HINT {
1321060SN/A                        0x1: jr_hb({{
1331060SN/A                            Config1Reg config1 = Config1;
1341060SN/A                            if (config1.ca == 0) {
1351060SN/A                                NNPC = Rs;
1361060SN/A                            } else {
1371755SN/A                                panic("MIPS16e not supported\n");
1381060SN/A                            }
1391060SN/A                        }}, IsReturn, ClearHazards);
1401060SN/A                        default: jr({{
1411060SN/A                            Config1Reg config1 = Config1;
1421060SN/A                            if (config1.ca == 0) {
1431060SN/A                                NNPC = Rs;
1445336Shines@cs.fsu.edu                            } else {
1451060SN/A                                panic("MIPS16e not supported\n");
1464873Sstever@eecs.umich.edu                            }
1471060SN/A                        }}, IsReturn);
1481060SN/A                    }
1491060SN/A
1502829Sksewell@umich.edu                    0x1: decode HINT {
1515606Snate@binkert.org                        0x1: jalr_hb({{
1522829Sksewell@umich.edu                            Rd = NNPC;
1532829Sksewell@umich.edu                            NNPC = Rs;
1542829Sksewell@umich.edu                        }}, IsCall, ClearHazards);
1552829Sksewell@umich.edu                        default: jalr({{
1562829Sksewell@umich.edu                            Rd = NNPC;
1572829Sksewell@umich.edu                            NNPC = Rs;
1582829Sksewell@umich.edu                        }}, IsCall);
1592829Sksewell@umich.edu                    }
1602829Sksewell@umich.edu                }
1612829Sksewell@umich.edu
1622829Sksewell@umich.edu                format BasicOp {
1632829Sksewell@umich.edu                    0x2: movz({{ Rd = (Rt == 0) ? Rs : Rd; }});
1642829Sksewell@umich.edu                    0x3: movn({{ Rd = (Rt != 0) ? Rs : Rd; }});
1652829Sksewell@umich.edu                    0x4: decode FullSystemInt {
1662829Sksewell@umich.edu                        0: syscall_se({{ xc->syscall(R2, &fault); }},
1672829Sksewell@umich.edu                                IsSerializeAfter, IsNonSpeculative);
1682829Sksewell@umich.edu                      default: syscall({{ fault = std::make_shared<SystemCallFault>(); }});
1692829Sksewell@umich.edu                    }
1702829Sksewell@umich.edu                    0x7: sync({{ ; }}, IsMemBarrier);
1712829Sksewell@umich.edu                  0x5: break({{fault = std::make_shared<BreakpointFault>();}});
1722829Sksewell@umich.edu                }
1735336Shines@cs.fsu.edu
1742829Sksewell@umich.edu            }
1754873Sstever@eecs.umich.edu
1762829Sksewell@umich.edu            0x2: decode FUNCTION_LO {
1772829Sksewell@umich.edu                0x0: HiLoRsSelOp::mfhi({{ Rd = HI_RS_SEL; }},
1782829Sksewell@umich.edu                             IntMultOp, IsIprAccess);
1792875Sksewell@umich.edu                0x1: HiLoRdSelOp::mthi({{ HI_RD_SEL = Rs; }});
1805606Snate@binkert.org                0x2: HiLoRsSelOp::mflo({{ Rd = LO_RS_SEL; }},
1812875Sksewell@umich.edu                             IntMultOp, IsIprAccess);
1822875Sksewell@umich.edu                0x3: HiLoRdSelOp::mtlo({{ LO_RD_SEL = Rs; }});
1832875Sksewell@umich.edu            }
1842875Sksewell@umich.edu
1852875Sksewell@umich.edu            0x3: decode FUNCTION_LO {
1862875Sksewell@umich.edu                format HiLoRdSelValOp {
1873859Sbinkertn@umich.edu                    0x0: mult({{ val = Rs_sd * Rt_sd; }}, IntMultOp);
1882875Sksewell@umich.edu                    0x1: multu({{ val = Rs_ud * Rt_ud; }}, IntMultOp);
1892875Sksewell@umich.edu                }
1902875Sksewell@umich.edu
1913859Sbinkertn@umich.edu                format HiLoOp {
1922875Sksewell@umich.edu                    0x2: div({{
1932875Sksewell@umich.edu                        if (Rt_sd != 0) {
1942875Sksewell@umich.edu                            HI0 = Rs_sd % Rt_sd;
1952875Sksewell@umich.edu                            LO0 = Rs_sd / Rt_sd;
1962875Sksewell@umich.edu                        }
1972875Sksewell@umich.edu                    }}, IntDivOp);
1982875Sksewell@umich.edu
1993221Sktlim@umich.edu                    0x3: divu({{
2003221Sktlim@umich.edu                        if (Rt_ud != 0) {
2012875Sksewell@umich.edu                            HI0 = Rs_ud % Rt_ud;
2022875Sksewell@umich.edu                            LO0 = Rs_ud / Rt_ud;
2032875Sksewell@umich.edu                        }
2042875Sksewell@umich.edu                    }}, IntDivOp);
2055336Shines@cs.fsu.edu                }
2062875Sksewell@umich.edu            }
2074873Sstever@eecs.umich.edu
2082875Sksewell@umich.edu            0x4: decode HINT {
2092875Sksewell@umich.edu                0x0: decode FUNCTION_LO {
2102875Sksewell@umich.edu                    format IntOp {
2115595Sgblack@eecs.umich.edu                        0x0: add({{
2122733Sktlim@umich.edu                            uint32_t result;
2133781Sgblack@eecs.umich.edu                            Rd = result = Rs + Rt;
2143781Sgblack@eecs.umich.edu                            if (FullSystem &&
2151060SN/A                                    findOverflow(32, result, Rs, Rt)) {
2165737Scws3k@cs.virginia.edu                                fault = std::make_shared<IntegerOverflowFault>();
2175737Scws3k@cs.virginia.edu                            }
2185737Scws3k@cs.virginia.edu                        }});
2192292SN/A                        0x1: addu({{ Rd = Rs_sw + Rt_sw;}});
2205595Sgblack@eecs.umich.edu                        0x2: sub({{
2215595Sgblack@eecs.umich.edu                            uint32_t result;
2225595Sgblack@eecs.umich.edu                            Rd = result = Rs - Rt;
2235595Sgblack@eecs.umich.edu                            if (FullSystem &&
2245595Sgblack@eecs.umich.edu                                    findOverflow(32, result, Rs, ~Rt)) {
2251060SN/A                                fault = std::make_shared<IntegerOverflowFault>();
2265595Sgblack@eecs.umich.edu                            }
2274329Sktlim@umich.edu                        }});
2281060SN/A                        0x3: subu({{ Rd = Rs_sw - Rt_sw; }});
2295529Snate@binkert.org                        0x4: and({{ Rd = Rs & Rt; }});
2302292SN/A                        0x5: or({{ Rd = Rs | Rt; }});
2312292SN/A                        0x6: xor({{ Rd = Rs ^ Rt; }});
2321060SN/A                        0x7: nor({{ Rd = ~(Rs | Rt); }});
2335595Sgblack@eecs.umich.edu                    }
2344329Sktlim@umich.edu                }
2352292SN/A            }
2365529Snate@binkert.org
2371060SN/A            0x5: decode HINT {
2385529Snate@binkert.org                0x0: decode FUNCTION_LO {
2392292SN/A                    format IntOp{
2402292SN/A                        0x2: slt({{  Rd = (Rs_sw < Rt_sw) ? 1 : 0 }});
2416221Snate@binkert.org                        0x3: sltu({{ Rd = (Rs < Rt) ? 1 : 0 }});
2422292SN/A                    }
2431060SN/A                }
2448707Sandreas.hansson@arm.com            }
2458707Sandreas.hansson@arm.com
2468707Sandreas.hansson@arm.com            0x6: decode FUNCTION_LO {
2472873Sktlim@umich.edu                format Trap {
2482873Sktlim@umich.edu                    0x0: tge({{ cond = (Rs_sw >= Rt_sw); }});
2492873Sktlim@umich.edu                    0x1: tgeu({{ cond = (Rs >= Rt); }});
2502873Sktlim@umich.edu                    0x2: tlt({{ cond = (Rs_sw < Rt_sw); }});
2512873Sktlim@umich.edu                    0x3: tltu({{ cond = (Rs < Rt); }});
2525804Snate@binkert.org                    0x4: teq({{ cond = (Rs_sw == Rt_sw); }});
2532873Sktlim@umich.edu                    0x6: tne({{ cond = (Rs_sw != Rt_sw); }});
2542873Sktlim@umich.edu                }
2551060SN/A            }
2561060SN/A        }
2572292SN/A
2582843Sktlim@umich.edu        0x1: decode REGIMM_HI {
2596221Snate@binkert.org            0x0: decode REGIMM_LO {
2601060SN/A                format Branch {
2613221Sktlim@umich.edu                    0x0: bltz({{ cond = (Rs_sw < 0); }});
2623221Sktlim@umich.edu                    0x1: bgez({{ cond = (Rs_sw >= 0); }});
2633221Sktlim@umich.edu                    0x2: bltzl({{ cond = (Rs_sw < 0); }}, Likely);
2649152Satgutier@umich.edu                    0x3: bgezl({{ cond = (Rs_sw >= 0); }}, Likely);
2653221Sktlim@umich.edu                }
2661681SN/A            }
2672794Sktlim@umich.edu
2682316SN/A            0x1: decode REGIMM_LO {
2698733Sgeoffrey.blake@arm.com                format TrapImm {
2708707Sandreas.hansson@arm.com                    0x0: tgei( {{ cond = (Rs_sw >= (int16_t)INTIMM); }});
2712316SN/A                    0x1: tgeiu({{
2724598Sbinkertn@umich.edu                        cond = (Rs >= (uint32_t)(int32_t)(int16_t)INTIMM);
2734598Sbinkertn@umich.edu                    }});
2744598Sbinkertn@umich.edu                    0x2: tlti( {{ cond = (Rs_sw < (int16_t)INTIMM); }});
2752316SN/A                    0x3: tltiu({{
2768793Sgblack@eecs.umich.edu                        cond = (Rs < (uint32_t)(int32_t)(int16_t)INTIMM);
2778793Sgblack@eecs.umich.edu                    }});
2788793Sgblack@eecs.umich.edu                    0x4: teqi( {{ cond = (Rs_sw == (int16_t)INTIMM); }});
2798793Sgblack@eecs.umich.edu                    0x6: tnei( {{ cond = (Rs_sw != (int16_t)INTIMM); }});
2801681SN/A                }
2812325SN/A            }
2822325SN/A
2832325SN/A            0x2: decode REGIMM_LO {
2841060SN/A                format Branch {
2852292SN/A                    0x0: bltzal({{ cond = (Rs_sw < 0); }}, Link);
2862292SN/A                    0x1: decode RS {
2872292SN/A                        0x0: bal ({{ cond = 1; }}, IsCall, Link);
2882292SN/A                        default: bgezal({{ cond = (Rs_sw >= 0); }}, Link);
2892292SN/A                    }
2902292SN/A                    0x2: bltzall({{ cond = (Rs_sw < 0); }}, Link, Likely);
2911060SN/A                    0x3: bgezall({{ cond = (Rs_sw >= 0); }}, Link, Likely);
2921060SN/A                }
2931060SN/A            }
2941060SN/A
2951060SN/A            0x3: decode REGIMM_LO {
2961060SN/A                // from Table 5-4 MIPS32 REGIMM Encoding of rt Field
2971060SN/A                // (DSP ASE MANUAL)
2981060SN/A                0x4: DspBranch::bposge32({{ cond = (dspctl<5:0> >= 32); }});
2991060SN/A                format WarnUnimpl {
3001060SN/A                    0x7: synci();
3011060SN/A                }
3022292SN/A            }
3031060SN/A        }
3041060SN/A
3051060SN/A        format Jump {
3061060SN/A            0x2: j({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2); }});
3071060SN/A            0x3: jal({{ NNPC = (NPC & 0xF0000000) | (JMPTARG << 2); }},
3081060SN/A                     IsCall, Link);
3091060SN/A        }
3101060SN/A
3112292SN/A        format Branch {
3122292SN/A            0x4: decode RS_RT  {
3132292SN/A                0x0: b({{ cond = 1; }});
3142292SN/A                default: beq({{ cond = (Rs_sw == Rt_sw); }});
3158793Sgblack@eecs.umich.edu            }
3168793Sgblack@eecs.umich.edu            0x5: bne({{ cond = (Rs_sw != Rt_sw); }});
3178793Sgblack@eecs.umich.edu            0x6: blez({{ cond = (Rs_sw <= 0); }});
3188793Sgblack@eecs.umich.edu            0x7: bgtz({{ cond = (Rs_sw > 0); }});
3198793Sgblack@eecs.umich.edu        }
3202831Sksewell@umich.edu    }
3218793Sgblack@eecs.umich.edu
3228793Sgblack@eecs.umich.edu    0x1: decode OPCODE_LO {
3238793Sgblack@eecs.umich.edu        format IntImmOp {
3248793Sgblack@eecs.umich.edu            0x0: addi({{
3258793Sgblack@eecs.umich.edu                uint32_t result;
3262831Sksewell@umich.edu                Rt = result = Rs + imm;
3272292SN/A                if (FullSystem &&
3282316SN/A                        findOverflow(32, result, Rs, imm)) {
3292292SN/A                    fault = std::make_shared<IntegerOverflowFault>();
3302292SN/A                }
3312292SN/A            }});
3322292SN/A            0x1: addiu({{ Rt = Rs_sw + imm; }});
3332292SN/A            0x2: slti({{ Rt = (Rs_sw < imm) ? 1 : 0 }});
3342292SN/A            0x3: sltiu({{ Rt = (Rs < (uint32_t)sextImm) ? 1 : 0;}});
3351060SN/A            0x4: andi({{ Rt = Rs_sw & zextImm; }});
3362292SN/A            0x5: ori({{ Rt = Rs_sw | zextImm; }});
3372292SN/A            0x6: xori({{ Rt = Rs_sw ^ zextImm; }});
3381060SN/A
3396221Snate@binkert.org            0x7: decode RS {
3402307SN/A                0x0: lui({{ Rt = imm << 16; }});
3412292SN/A            }
3422292SN/A        }
3432292SN/A    }
3442325SN/A
3452292SN/A    0x2: decode OPCODE_LO {
3462292SN/A        //Table A-11 MIPS32 COP0 Encoding of rs Field
3472292SN/A        0x0: decode RS_MSB {
3482325SN/A            0x0: decode RS {
3492292SN/A                format CP0Control {
3502292SN/A                    0x0: mfc0({{
3512292SN/A                        Config3Reg config3 = Config3;
3522292SN/A                        PageGrainReg pageGrain = PageGrain;
3532292SN/A                        Rt = CP0_RD_SEL;
3542292SN/A                        /* Hack for PageMask */
3552292SN/A                        if (RD == 5) {
3562292SN/A                            // PageMask
3572292SN/A                            if (config3.sp == 0 || pageGrain.esp == 0)
3582292SN/A                                Rt &= 0xFFFFE7FF;
3592292SN/A                        }
3602325SN/A                    }});
3612292SN/A                    0x4: mtc0({{
3622292SN/A                        CP0_RD_SEL = Rt;
3632292SN/A                        CauseReg cause = Cause;
3642325SN/A                        IntCtlReg intCtl = IntCtl;
3652292SN/A                        if (RD == 11) {
3662292SN/A                            // Compare
3672292SN/A                            if (cause.ti == 1) {
3682292SN/A                                cause.ti = 0;
3692292SN/A                                int offset = 10; // corresponding to cause.ip0
3702292SN/A                                offset += intCtl.ipti - 2;
3712292SN/A                                replaceBits(cause, offset, offset, 0);
3722292SN/A                            }
3733221Sktlim@umich.edu                        }
3743221Sktlim@umich.edu                        Cause = cause;
3753221Sktlim@umich.edu                    }});
3762292SN/A                }
3772292SN/A                format CP0Unimpl {
3782292SN/A                    0x1: dmfc0();
3792292SN/A                    0x5: dmtc0();
3802292SN/A                    default: unknown();
3812292SN/A                }
3826221Snate@binkert.org                format MT_MFTR {
3836221Snate@binkert.org                    // Decode MIPS MT MFTR instruction into sub-instructions
3841060SN/A                    0x8: decode MT_U {
3852292SN/A                        0x0: mftc0({{
3861060SN/A                            data = xc->readRegOtherThread(RegId(MiscRegClass,
3871060SN/A                                                            (RT << 3 | SEL)));
3882292SN/A                        }});
3897823Ssteve.reinhardt@amd.com                        0x1: decode SEL {
3902292SN/A                            0x0: mftgpr({{
3919158Sandreas.hansson@arm.com                                data = xc->readRegOtherThread(
3926221Snate@binkert.org                                                    RegId(IntRegClass, RT));
3933093Sksewell@umich.edu                            }});
3946221Snate@binkert.org                            0x1: decode RT {
3956221Snate@binkert.org                                0x0: mftlo_dsp0({{
3966221Snate@binkert.org                                    data = xc->readRegOtherThread(
3973093Sksewell@umich.edu                                           RegId(IntRegClass, INTREG_DSP_LO0));
3982292SN/A                                }});
3995595Sgblack@eecs.umich.edu                                0x1: mfthi_dsp0({{
4005595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4015595Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_HI0));
4025595Sgblack@eecs.umich.edu                                }});
4035595Sgblack@eecs.umich.edu                                0x2: mftacx_dsp0({{
4046221Snate@binkert.org                                    data = xc->readRegOtherThread(
4058793Sgblack@eecs.umich.edu                                          RegId(IntRegClass, INTREG_DSP_ACX0));
4068793Sgblack@eecs.umich.edu                                }});
4078793Sgblack@eecs.umich.edu                                0x4: mftlo_dsp1({{
4088793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4098793Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_LO1));
4108793Sgblack@eecs.umich.edu                                }});
4118793Sgblack@eecs.umich.edu                                0x5: mfthi_dsp1({{
4128793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4138793Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_HI1));
4148793Sgblack@eecs.umich.edu                                }});
4158793Sgblack@eecs.umich.edu                                0x6: mftacx_dsp1({{
4165595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4178793Sgblack@eecs.umich.edu                                          RegId(IntRegClass, INTREG_DSP_ACX1));
4188793Sgblack@eecs.umich.edu                                }});
4198793Sgblack@eecs.umich.edu                                0x8: mftlo_dsp2({{
4208793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4218793Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_LO2));
4228793Sgblack@eecs.umich.edu                                }});
4235595Sgblack@eecs.umich.edu                                0x9: mfthi_dsp2({{
4248793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4258793Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_HI2));
4268793Sgblack@eecs.umich.edu                                }});
4278793Sgblack@eecs.umich.edu                                0x10: mftacx_dsp2({{
4288793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4295595Sgblack@eecs.umich.edu                                          RegId(IntRegClass, INTREG_DSP_ACX2));
4305595Sgblack@eecs.umich.edu                                }});
4315595Sgblack@eecs.umich.edu                                0x12: mftlo_dsp3({{
4325595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4335595Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_LO3));
4345595Sgblack@eecs.umich.edu                                }});
4355595Sgblack@eecs.umich.edu                                0x13: mfthi_dsp3({{
4365595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4375595Sgblack@eecs.umich.edu                                           RegId(IntRegClass, INTREG_DSP_HI3));
4385595Sgblack@eecs.umich.edu                                }});
4395595Sgblack@eecs.umich.edu                                0x14: mftacx_dsp3({{
4405595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4415595Sgblack@eecs.umich.edu                                          RegId(IntRegClass, INTREG_DSP_ACX3));
4425595Sgblack@eecs.umich.edu                                }});
4435595Sgblack@eecs.umich.edu                                0x16: mftdsp({{
4445595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4455595Sgblack@eecs.umich.edu                                       RegId(IntRegClass, INTREG_DSP_CONTROL));
4465595Sgblack@eecs.umich.edu                                }});
4476221Snate@binkert.org                                default: CP0Unimpl::unknown();
4485595Sgblack@eecs.umich.edu                            }
4498793Sgblack@eecs.umich.edu                            0x2: decode MT_H {
4508793Sgblack@eecs.umich.edu                                0x0: mftc1({{
4518793Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4528793Sgblack@eecs.umich.edu                                                     RegId(FloatRegClass, RT));
4535595Sgblack@eecs.umich.edu                                }});
4546221Snate@binkert.org                                0x1: mfthc1({{
4555595Sgblack@eecs.umich.edu                                    data = xc->readRegOtherThread(
4565595Sgblack@eecs.umich.edu                                                     RegId(FloatRegClass, RT));
4575595Sgblack@eecs.umich.edu                                }});
4585595Sgblack@eecs.umich.edu                            }
4595595Sgblack@eecs.umich.edu                            0x3: cftc1({{
4608876Sandreas.hansson@arm.com                                uint32_t fcsr_val = xc->readRegOtherThread(
4618876Sandreas.hansson@arm.com                                          RegId(FloatRegClass, FLOATREG_FCSR));
4628876Sandreas.hansson@arm.com                                switch (RT) {
4638876Sandreas.hansson@arm.com                                  case 0:
4648876Sandreas.hansson@arm.com                                    data = xc->readRegOtherThread(
4658876Sandreas.hansson@arm.com                                            RegId(MiscRegClass, FLOATREG_FIR));
4666221Snate@binkert.org                                    break;
4676221Snate@binkert.org                                  case 25:
4685595Sgblack@eecs.umich.edu                                    data = (fcsr_val & 0xFE000000 >> 24) |
4695595Sgblack@eecs.umich.edu                                           (fcsr_val & 0x00800000 >> 23);
4705595Sgblack@eecs.umich.edu                                    break;
4711060SN/A                                  case 26:
4721060SN/A                                    data = fcsr_val & 0x0003F07C;
4731060SN/A                                    break;
4741755SN/A                                  case 28:
4751060SN/A                                    data = (fcsr_val & 0x00000F80) |
4761060SN/A                                           (fcsr_val & 0x01000000 >> 21) |
4771060SN/A                                           (fcsr_val & 0x00000003);
4781060SN/A                                    break;
4791060SN/A                                  case 31:
4805595Sgblack@eecs.umich.edu                                    data = fcsr_val;
4811062SN/A                                    break;
4822733Sktlim@umich.edu                                  default:
4832292SN/A                                    fatal("FP Control Value (%d) Not Valid");
4842733Sktlim@umich.edu                                }
4852292SN/A                            }});
4862292SN/A                            default: CP0Unimpl::unknown();
4872292SN/A                        }
4882292SN/A                    }
4892292SN/A                }
4902292SN/A
4912292SN/A                format MT_MTTR {
4922292SN/A                    // Decode MIPS MT MTTR instruction into sub-instructions
4932292SN/A                    0xC: decode MT_U {
4942292SN/A                        0x0: mttc0({{ xc->setRegOtherThread(
4952292SN/A                                     RegId(MiscRegClass, (RD << 3 | SEL)), Rt);
4962292SN/A                                   }});
4978627SAli.Saidi@ARM.com                        0x1: decode SEL {
4988627SAli.Saidi@ARM.com                            0x0: mttgpr({{ xc->setRegOtherThread(
4998627SAli.Saidi@ARM.com                                                   RegId(IntRegClass, RD), Rt);
5008627SAli.Saidi@ARM.com                            }});
5018627SAli.Saidi@ARM.com                            0x1: decode RT {
5028627SAli.Saidi@ARM.com                                0x0: mttlo_dsp0({{ xc->setRegOtherThread(
5032292SN/A                                       RegId(IntRegClass, INTREG_DSP_LO0), Rt);
5042292SN/A                                }});
5052292SN/A                                0x1: mtthi_dsp0({{ xc->setRegOtherThread(
5062292SN/A                                       RegId(IntRegClass, INTREG_DSP_HI0), Rt);
5072292SN/A                                }});
5082292SN/A                                0x2: mttacx_dsp0({{ xc->setRegOtherThread(
5092292SN/A                                      RegId(IntRegClass, INTREG_DSP_ACX0), Rt);
5102292SN/A                                }});
5112292SN/A                                0x4: mttlo_dsp1({{ xc->setRegOtherThread(
5128834Satgutier@umich.edu                                       RegId(IntRegClass, INTREG_DSP_LO1), Rt);
5138834Satgutier@umich.edu                                }});
5148834Satgutier@umich.edu                                0x5: mtthi_dsp1({{ xc->setRegOtherThread(
5158834Satgutier@umich.edu                                       RegId(IntRegClass, INTREG_DSP_HI1), Rt);
5168834Satgutier@umich.edu                                }});
5172292SN/A                                0x6: mttacx_dsp1({{ xc->setRegOtherThread(
5182292SN/A                                      RegId(IntRegClass, INTREG_DSP_ACX1), Rt);
5192292SN/A                                }});
5202292SN/A                                0x8: mttlo_dsp2({{ xc->setRegOtherThread(
5212292SN/A                                       RegId(IntRegClass, INTREG_DSP_LO2), Rt);
5222292SN/A                                }});
5232292SN/A                                0x9: mtthi_dsp2({{ xc->setRegOtherThread(
5242292SN/A                                       RegId(IntRegClass, INTREG_DSP_HI2), Rt);
5254392Sktlim@umich.edu                                }});
5262292SN/A                                0x10: mttacx_dsp2({{ xc->setRegOtherThread(
5272292SN/A                                      RegId(IntRegClass, INTREG_DSP_ACX2), Rt);
5282292SN/A                                }});
5292292SN/A                                0x12: mttlo_dsp3({{ xc->setRegOtherThread(
5302292SN/A                                       RegId(IntRegClass, INTREG_DSP_LO3), Rt);
5314392Sktlim@umich.edu                                }});
5322292SN/A                                0x13: mtthi_dsp3({{ xc->setRegOtherThread(
5332292SN/A                                       RegId(IntRegClass, INTREG_DSP_HI3), Rt);
5342292SN/A                                }});
5352292SN/A                                0x14: mttacx_dsp3({{ xc->setRegOtherThread(
5362292SN/A                                      RegId(IntRegClass, INTREG_DSP_ACX3), Rt);
5374392Sktlim@umich.edu                                }});
5382292SN/A                                0x16: mttdsp({{ xc->setRegOtherThread(
5392292SN/A                                   RegId(IntRegClass, INTREG_DSP_CONTROL), Rt);
5402292SN/A                                }});
5412292SN/A                                default: CP0Unimpl::unknown();
5422292SN/A
5434392Sktlim@umich.edu                            }
5442292SN/A                            0x2: mttc1({{
5455595Sgblack@eecs.umich.edu                                uint64_t data = xc->readRegOtherThread(
5465595Sgblack@eecs.umich.edu                                                     RegId(FloatRegClass, RD));
5475595Sgblack@eecs.umich.edu                                data = insertBits(data, MT_H ? 63 : 31,
5485595Sgblack@eecs.umich.edu                                                  MT_H ? 32 : 0, Rt);
5495595Sgblack@eecs.umich.edu                                xc->setRegOtherThread(RegId(FloatRegClass, RD),
5507897Shestness@cs.utexas.edu                                                      data);
5517897Shestness@cs.utexas.edu                            }});
5527897Shestness@cs.utexas.edu                            0x3: cttc1({{
5537897Shestness@cs.utexas.edu                                uint32_t data;
5547897Shestness@cs.utexas.edu                                switch (RD) {
5557897Shestness@cs.utexas.edu                                  case 25:
5567897Shestness@cs.utexas.edu                                    data = (Rt<7:1> << 25) |  // move 31-25
5577897Shestness@cs.utexas.edu                                           (FCSR & 0x01000000) | // bit 24
5587897Shestness@cs.utexas.edu                                           (FCSR & 0x004FFFFF);  // bit 22-0
5597897Shestness@cs.utexas.edu                                    break;
5607897Shestness@cs.utexas.edu                                  case 26:
5617897Shestness@cs.utexas.edu                                    data = (FCSR & 0xFFFC0000) | // move 31-18
5627897Shestness@cs.utexas.edu                                           Rt<17:12> << 12 |  // bit 17-12
5637897Shestness@cs.utexas.edu                                           // bit 11-7
5647897Shestness@cs.utexas.edu                                           (FCSR & 0x00000F80) << 7 |
5657897Shestness@cs.utexas.edu                                           Rt<6:2> << 2 |     // bit 6-2
5667897Shestness@cs.utexas.edu                                           (FCSR & 0x00000002);  // bit 1...0
5677897Shestness@cs.utexas.edu                                    break;
5687897Shestness@cs.utexas.edu                                  case 28:
5697897Shestness@cs.utexas.edu                                    data = (FCSR & 0xFE000000) | // move 31-25
5707897Shestness@cs.utexas.edu                                           Rt<2:2> << 24 |    // bit 24
5717897Shestness@cs.utexas.edu                                           // bit 23-12
5727897Shestness@cs.utexas.edu                                           (FCSR & 0x00FFF000) << 23 |
5737897Shestness@cs.utexas.edu                                           Rt<11:7> << 7 |    // bit 24
5747897Shestness@cs.utexas.edu                                           (FCSR & 0x000007E) |
5757897Shestness@cs.utexas.edu                                           Rt<1:0>;           // bit 22-0
5767897Shestness@cs.utexas.edu                                    break;
5777897Shestness@cs.utexas.edu                                  case 31:
5787897Shestness@cs.utexas.edu                                    data = Rt;
5797897Shestness@cs.utexas.edu                                    break;
5807897Shestness@cs.utexas.edu                                  default:
5811062SN/A                                    panic("FP Control Value (%d) "
5821062SN/A                                            "Not Available. Ignoring "
5831062SN/A                                            "Access to Floating Control "
5841062SN/A                                            "S""tatus Register", FS);
5851755SN/A                                }
5861060SN/A                                xc->setRegOtherThread(
5872733Sktlim@umich.edu                                    RegId(FloatRegClass, FLOATREG_FCSR), data);
5881060SN/A                            }});
5892292SN/A                            default: CP0Unimpl::unknown();
5902292SN/A                        }
5912325SN/A                    }
5922292SN/A                }
5932292SN/A                0xB: decode RD {
5941060SN/A                    format MT_Control {
5951060SN/A                        0x0: decode POS {
5961060SN/A                            0x0: decode SEL {
5971060SN/A                                0x1: decode SC {
5981060SN/A                                    0x0: dvpe({{
5991060SN/A                                        MVPControlReg mvpControl = MVPControl;
6001060SN/A                                        VPEConf0Reg vpeConf0 = VPEConf0;
6011060SN/A                                        Rt = MVPControl;
6021060SN/A                                        if (vpeConf0.mvp == 1)
6031060SN/A                                            mvpControl.evp = 0;
6048793Sgblack@eecs.umich.edu                                        MVPControl = mvpControl;
6058793Sgblack@eecs.umich.edu                                    }});
6062292SN/A                                    0x1: evpe({{
6072292SN/A                                        MVPControlReg mvpControl = MVPControl;
6081060SN/A                                        VPEConf0Reg vpeConf0 = VPEConf0;
6091060SN/A                                        Rt = MVPControl;
6101060SN/A                                        if (vpeConf0.mvp == 1)
6111060SN/A                                            mvpControl.evp = 1;
6121060SN/A                                        MVPControl = mvpControl;
6131060SN/A                                    }});
6141060SN/A                                   default:CP0Unimpl::unknown();
6152325SN/A                                }
6162292SN/A                                default:CP0Unimpl::unknown();
6172292SN/A                            }
6182292SN/A                            default:CP0Unimpl::unknown();
6192292SN/A                        }
6202292SN/A                        0x1: decode POS {
6212325SN/A                            0xF: decode SEL {
6222867Sktlim@umich.edu                                0x1: decode SC {
6232905Sktlim@umich.edu                                    0x0: dmt({{
6243226Sktlim@umich.edu                                        VPEControlReg vpeControl = VPEControl;
6252325SN/A                                        Rt = vpeControl;
6267823Ssteve.reinhardt@amd.com                                        vpeControl.te = 0;
6273221Sktlim@umich.edu                                        VPEControl = vpeControl;
6283226Sktlim@umich.edu                                    }});
6297823Ssteve.reinhardt@amd.com                                    0x1: emt({{
6302325SN/A                                        VPEControlReg vpeControl = VPEControl;
6312325SN/A                                        Rt = vpeControl;
6327823Ssteve.reinhardt@amd.com                                        vpeControl.te = 1;
6333226Sktlim@umich.edu                                        VPEControl = vpeControl;
6342325SN/A                                    }});
6352292SN/A                                   default:CP0Unimpl::unknown();
6362292SN/A                                }
6378793Sgblack@eecs.umich.edu                                default:CP0Unimpl::unknown();
6388793Sgblack@eecs.umich.edu                            }
6391060SN/A                            default:CP0Unimpl::unknown();
6401060SN/A                        }
6411060SN/A                    }
6421060SN/A                    0xC: decode POS {
6431755SN/A                        0x0: decode SC {
6441060SN/A                            0x0: CP0Control::di({{
6455714Shsul@eecs.umich.edu                                StatusReg status = Status;
6461060SN/A                                ConfigReg config = Config;
6478921Sandreas.hansson@arm.com                                // Rev 2.0 or beyond?
6488921Sandreas.hansson@arm.com                                if (config.ar >= 1) {
6498921Sandreas.hansson@arm.com                                    Rt = status;
6506221Snate@binkert.org                                    status.ie = 0;
6518921Sandreas.hansson@arm.com                                } else {
6528921Sandreas.hansson@arm.com                                    // Enable this else branch once we
6538921Sandreas.hansson@arm.com                                    // actually set values for Config on init
6542292SN/A                                    fault = std::make_shared<ReservedInstructionFault>();
6558707Sandreas.hansson@arm.com                                }
6568707Sandreas.hansson@arm.com                                Status = status;
6578707Sandreas.hansson@arm.com                            }});
6588707Sandreas.hansson@arm.com                            0x1: CP0Control::ei({{
6598707Sandreas.hansson@arm.com                                StatusReg status = Status;
6608707Sandreas.hansson@arm.com                                ConfigReg config = Config;
6618707Sandreas.hansson@arm.com                                if (config.ar >= 1) {
6628863Snilay@cs.wisc.edu                                    Rt = status;
6638793Sgblack@eecs.umich.edu                                    status.ie = 1;
6648793Sgblack@eecs.umich.edu                                } else {
6658793Sgblack@eecs.umich.edu                                    fault = std::make_shared<ReservedInstructionFault>();
6668793Sgblack@eecs.umich.edu                                }
6676034Ssteve.reinhardt@amd.com                            }});
6682292SN/A                            default:CP0Unimpl::unknown();
6692292SN/A                        }
6706221Snate@binkert.org                    }
6716221Snate@binkert.org                    default: CP0Unimpl::unknown();
6722292SN/A                }
6732316SN/A                format CP0Control {
6742292SN/A                    0xA: rdpgpr({{
6752292SN/A                        ConfigReg config = Config;
6762292SN/A                        if (config.ar >= 1) {
6772292SN/A                            // Rev 2 of the architecture
6782292SN/A                            panic("Shadow Sets Not Fully Implemented.\n");
6792292SN/A                        } else {
6802292SN/A                            fault = std::make_shared<ReservedInstructionFault>();
6812292SN/A                        }
6822292SN/A                    }});
6832292SN/A                    0xE: wrpgpr({{
6846221Snate@binkert.org                        ConfigReg config = Config;
6852875Sksewell@umich.edu                        if (config.ar >= 1) {
6866221Snate@binkert.org                            // Rev 2 of the architecture
6875314Sstever@gmail.com                            panic("Shadow Sets Not Fully Implemented.\n");
6882875Sksewell@umich.edu                        } else {
6893226Sktlim@umich.edu                            fault = std::make_shared<ReservedInstructionFault>();
6903226Sktlim@umich.edu                        }
6912875Sksewell@umich.edu                    }});
6922875Sksewell@umich.edu                }
6932875Sksewell@umich.edu            }
6942875Sksewell@umich.edu
6952875Sksewell@umich.edu            //Table A-12 MIPS32 COP0 Encoding of Function Field When rs=CO
6962875Sksewell@umich.edu            0x1: decode FUNCTION {
6972875Sksewell@umich.edu                format CP0Control {
6982875Sksewell@umich.edu                    0x18: eret({{
6992875Sksewell@umich.edu                        StatusReg status = Status;
7002875Sksewell@umich.edu                        ConfigReg config = Config;
7016221Snate@binkert.org                        SRSCtlReg srsCtl = SRSCtl;
7022875Sksewell@umich.edu                        DPRINTF(MipsPRA,"Restoring PC - %x\n",EPC);
7032875Sksewell@umich.edu                        if (status.erl == 1) {
7046221Snate@binkert.org                            status.erl = 0;
7055314Sstever@gmail.com                            NPC = ErrorEPC;
7062875Sksewell@umich.edu                            // Need to adjust NNPC, otherwise things break
7073226Sktlim@umich.edu                            NNPC = ErrorEPC + sizeof(MachInst);
7083226Sktlim@umich.edu                        } else {
7092875Sksewell@umich.edu                            NPC = EPC;
7102875Sksewell@umich.edu                            // Need to adjust NNPC, otherwise things break
7112875Sksewell@umich.edu                            NNPC = EPC + sizeof(MachInst);
7122875Sksewell@umich.edu                            status.exl = 0;
7132875Sksewell@umich.edu                            if (config.ar >=1 &&
7142875Sksewell@umich.edu                                    srsCtl.hss > 0 &&
7152875Sksewell@umich.edu                                    status.bev == 0) {
7162875Sksewell@umich.edu                                srsCtl.css = srsCtl.pss;
7176221Snate@binkert.org                                //xc->setShadowSet(srsCtl.pss);
7188834Satgutier@umich.edu                            }
7196221Snate@binkert.org                        }
7206221Snate@binkert.org                        LLFlag = 0;
7216221Snate@binkert.org                        Status = status;
7226221Snate@binkert.org                        SRSCtl = srsCtl;
7236221Snate@binkert.org                    }}, IsReturn, IsSerializing, IsERET);
7246221Snate@binkert.org
7256221Snate@binkert.org                    0x1F: deret({{
7266221Snate@binkert.org                        DebugReg debug = Debug;
7276221Snate@binkert.org                        if (debug.dm == 1) {
7286221Snate@binkert.org                            debug.dm = 1;
7296221Snate@binkert.org                            debug.iexi = 0;
7308834Satgutier@umich.edu                            NPC = DEPC;
7318834Satgutier@umich.edu                        } else {
7328834Satgutier@umich.edu                            NPC = NPC;
7338834Satgutier@umich.edu                            // Undefined;
7348834Satgutier@umich.edu                        }
7358834Satgutier@umich.edu                        Debug = debug;
7368834Satgutier@umich.edu                    }}, IsReturn, IsSerializing, IsERET);
7378834Satgutier@umich.edu                }
7388834Satgutier@umich.edu                format CP0TLB {
7398834Satgutier@umich.edu                    0x01: tlbr({{
7408834Satgutier@umich.edu                        MipsISA::PTE *PTEntry =
7418834Satgutier@umich.edu                            dynamic_cast<MipsISA::TLB *>(
7428834Satgutier@umich.edu                                xc->tcBase()->getITBPtr())->
7432875Sksewell@umich.edu                                getEntry(Index & 0x7FFFFFFF);
7446221Snate@binkert.org                        if (PTEntry == NULL) {
7452875Sksewell@umich.edu                            fatal("Invalid PTE Entry received on "
7462875Sksewell@umich.edu                                "a TLBR instruction\n");
7472875Sksewell@umich.edu                        }
7482875Sksewell@umich.edu                        /* Setup PageMask */
7497823Ssteve.reinhardt@amd.com                        // If 1KB pages are not enabled, a read of PageMask
7502875Sksewell@umich.edu                        // must return 0b00 in bits 12, 11
7512875Sksewell@umich.edu                        PageMask = (PTEntry->Mask << 11);
7522875Sksewell@umich.edu                        /* Setup EntryHi */
7532875Sksewell@umich.edu                        EntryHi = ((PTEntry->VPN << 11) | (PTEntry->asid));
7542875Sksewell@umich.edu                        /* Setup Entry Lo0 */
7559158Sandreas.hansson@arm.com                        EntryLo0 = ((PTEntry->PFN0 << 6) |
7569158Sandreas.hansson@arm.com                                    (PTEntry->C0 << 3) |
7579158Sandreas.hansson@arm.com                                    (PTEntry->D0 << 2) |
7582875Sksewell@umich.edu                                    (PTEntry->V0 << 1) |
7592875Sksewell@umich.edu                                    PTEntry->G);
7602875Sksewell@umich.edu                        /* Setup Entry Lo1 */
7612875Sksewell@umich.edu                        EntryLo1 = ((PTEntry->PFN1 << 6) |
7622875Sksewell@umich.edu                                    (PTEntry->C1 << 3) |
7632875Sksewell@umich.edu                                    (PTEntry->D1 << 2) |
7642875Sksewell@umich.edu                                    (PTEntry->V1 << 1) |
7658627SAli.Saidi@ARM.com                                    PTEntry->G);
7668627SAli.Saidi@ARM.com                    }}); // Need to hook up to TLB
7677823Ssteve.reinhardt@amd.com
7682875Sksewell@umich.edu                    0x02: tlbwi({{
7692875Sksewell@umich.edu                        //Create PTE
7702875Sksewell@umich.edu                        MipsISA::PTE newEntry;
7712875Sksewell@umich.edu                        //Write PTE
7722875Sksewell@umich.edu                        newEntry.Mask = (Addr)(PageMask >> 11);
7732875Sksewell@umich.edu                        newEntry.VPN = (Addr)(EntryHi >> 11);
7743221Sktlim@umich.edu                        /*  PageGrain _ ESP                    Config3 _ SP */
7758737Skoansin.tan@gmail.com                        if (bits(PageGrain, 28) == 0 || bits(Config3, 4) ==0) {
7768737Skoansin.tan@gmail.com                            // If 1KB pages are *NOT* enabled, lowest bits of
7772875Sksewell@umich.edu                            // the mask are 0b11 for TLB writes
7782875Sksewell@umich.edu                            newEntry.Mask |= 0x3;
7792875Sksewell@umich.edu                            // Reset bits 0 and 1 if 1KB pages are not enabled
7802875Sksewell@umich.edu                            newEntry.VPN &= 0xFFFFFFFC;
7817823Ssteve.reinhardt@amd.com                        }
7823221Sktlim@umich.edu                        newEntry.asid = (uint8_t)(EntryHi & 0xFF);
7833221Sktlim@umich.edu
7842875Sksewell@umich.edu                        newEntry.PFN0 = (Addr)(EntryLo0 >> 6);
7852875Sksewell@umich.edu                        newEntry.PFN1 = (Addr)(EntryLo1 >> 6);
7863221Sktlim@umich.edu                        newEntry.D0 = (bool)((EntryLo0 >> 2) & 1);
7873221Sktlim@umich.edu                        newEntry.D1 = (bool)((EntryLo1 >> 2) & 1);
7883221Sktlim@umich.edu                        newEntry.V1 = (bool)((EntryLo1 >> 1) & 1);
7892875Sksewell@umich.edu                        newEntry.V0 = (bool)((EntryLo0 >> 1) & 1);
7902875Sksewell@umich.edu                        newEntry.G = (bool)((EntryLo0 & EntryLo1) & 1);
7912875Sksewell@umich.edu                        newEntry.C0 = (uint8_t)((EntryLo0 >> 3) & 0x7);
7922875Sksewell@umich.edu                        newEntry.C1 = (uint8_t)((EntryLo1 >> 3) & 0x7);
7932875Sksewell@umich.edu                        /* Now, compute the AddrShiftAmount and OffsetMask -
7946221Snate@binkert.org                           TLB optimizations */
7952875Sksewell@umich.edu                        /* Addr Shift Amount for 1KB or larger pages */
7962875Sksewell@umich.edu                        if ((newEntry.Mask & 0xFFFF) == 3) {
7978737Skoansin.tan@gmail.com                            newEntry.AddrShiftAmount = 12;
7983221Sktlim@umich.edu                        } else if ((newEntry.Mask & 0xFFFF) == 0x0000) {
7995570Snate@binkert.org                            newEntry.AddrShiftAmount = 10;
8003859Sbinkertn@umich.edu                        } else if ((newEntry.Mask & 0xFFFC) == 0x000C) {
8012910Sksewell@umich.edu                            newEntry.AddrShiftAmount = 14;
8028627SAli.Saidi@ARM.com                        } else if ((newEntry.Mask & 0xFFF0) == 0x0030) {
8038627SAli.Saidi@ARM.com                            newEntry.AddrShiftAmount = 16;
8048627SAli.Saidi@ARM.com                        } else if ((newEntry.Mask & 0xFFC0) == 0x00C0) {
8052875Sksewell@umich.edu                            newEntry.AddrShiftAmount = 18;
8062875Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFF00) == 0x0300) {
8072875Sksewell@umich.edu                            newEntry.AddrShiftAmount = 20;
8082875Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFC00) == 0x0C00) {
8092875Sksewell@umich.edu                            newEntry.AddrShiftAmount = 22;
8106221Snate@binkert.org                        } else if ((newEntry.Mask & 0xF000) == 0x3000) {
8112875Sksewell@umich.edu                            newEntry.AddrShiftAmount = 24;
8122910Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xC000) == 0xC000) {
8132910Sksewell@umich.edu                            newEntry.AddrShiftAmount = 26;
8148737Skoansin.tan@gmail.com                        } else if ((newEntry.Mask & 0x30000) == 0x30000) {
8152875Sksewell@umich.edu                            newEntry.AddrShiftAmount = 28;
8162875Sksewell@umich.edu                        } else {
8172875Sksewell@umich.edu                            fatal("Invalid Mask Pattern Detected!\n");
8182875Sksewell@umich.edu                        }
8196221Snate@binkert.org                        newEntry.OffsetMask =
8202292SN/A                            (1 << newEntry.AddrShiftAmount) - 1;
8212847Sksewell@umich.edu
8222292SN/A                        auto ptr = dynamic_cast<MipsISA::TLB *>(
8232683Sktlim@umich.edu                            xc->tcBase()->getITBPtr());
8248793Sgblack@eecs.umich.edu                        Config3Reg config3 = Config3;
8258793Sgblack@eecs.umich.edu                        PageGrainReg pageGrain = PageGrain;
8268793Sgblack@eecs.umich.edu                        int SP = 0;
8278793Sgblack@eecs.umich.edu                        if (bits(config3, config3.sp) == 1 &&
8288793Sgblack@eecs.umich.edu                            bits(pageGrain, pageGrain.esp) == 1) {
8292292SN/A                            SP = 1;
8302292SN/A                        }
8312292SN/A                        ptr->insertAt(newEntry, Index & 0x7FFFFFFF, SP);
8322292SN/A                    }});
8332292SN/A                    0x06: tlbwr({{
8342292SN/A                        //Create PTE
8352292SN/A                        MipsISA::PTE newEntry;
8362292SN/A                        //Write PTE
8372292SN/A                        newEntry.Mask = (Addr)(PageMask >> 11);
8382292SN/A                        newEntry.VPN = (Addr)(EntryHi >> 11);
8392292SN/A                        /*  PageGrain _ ESP                    Config3 _ SP */
8402292SN/A                        if (bits(PageGrain, 28) == 0 ||
8412292SN/A                            bits(Config3, 4) == 0) {
8422292SN/A                            // If 1KB pages are *NOT* enabled, lowest bits of
8432292SN/A                            // the mask are 0b11 for TLB writes
8442292SN/A                            newEntry.Mask |= 0x3;
8452292SN/A                            // Reset bits 0 and 1 if 1KB pages are not enabled
8462292SN/A                            newEntry.VPN &= 0xFFFFFFFC;
8472847Sksewell@umich.edu                        }
8482292SN/A                        newEntry.asid = (uint8_t)(EntryHi & 0xFF);
8492847Sksewell@umich.edu
8507720Sgblack@eecs.umich.edu                        newEntry.PFN0 = (Addr)(EntryLo0 >> 6);
8512292SN/A                        newEntry.PFN1 = (Addr)(EntryLo1 >> 6);
8522680Sktlim@umich.edu                        newEntry.D0 = (bool)((EntryLo0 >> 2) & 1);
8532292SN/A                        newEntry.D1 = (bool)((EntryLo1 >> 2) & 1);
8542292SN/A                        newEntry.V1 = (bool)((EntryLo1 >> 1) & 1);
8552292SN/A                        newEntry.V0 = (bool)((EntryLo0 >> 1) & 1);
8562292SN/A                        newEntry.G = (bool)((EntryLo0 & EntryLo1) & 1);
8572292SN/A                        newEntry.C0 = (uint8_t)((EntryLo0 >> 3) & 0x7);
8582292SN/A                        newEntry.C1 = (uint8_t)((EntryLo1 >> 3) & 0x7);
8592292SN/A                        /* Now, compute the AddrShiftAmount and OffsetMask -
8602292SN/A                           TLB optimizations */
8612292SN/A                        /* Addr Shift Amount for 1KB or larger pages */
8622292SN/A                        if ((newEntry.Mask & 0xFFFF) == 3){
8636221Snate@binkert.org                            newEntry.AddrShiftAmount = 12;
8642292SN/A                        } else if ((newEntry.Mask & 0xFFFF) == 0x0000) {
8652877Sksewell@umich.edu                            newEntry.AddrShiftAmount = 10;
8662847Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFFFC) == 0x000C) {
8672847Sksewell@umich.edu                            newEntry.AddrShiftAmount = 14;
8682847Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFFF0) == 0x0030) {
8695364Sksewell@umich.edu                            newEntry.AddrShiftAmount = 16;
8705364Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFFC0) == 0x00C0) {
8715364Sksewell@umich.edu                            newEntry.AddrShiftAmount = 18;
8725364Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFF00) == 0x0300) {
8735364Sksewell@umich.edu                            newEntry.AddrShiftAmount = 20;
8745364Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xFC00) == 0x0C00) {
8752847Sksewell@umich.edu                            newEntry.AddrShiftAmount = 22;
8762847Sksewell@umich.edu                        } else if ((newEntry.Mask & 0xF000) == 0x3000) {
8772292SN/A                            newEntry.AddrShiftAmount = 24;
8782292SN/A                        } else if ((newEntry.Mask & 0xC000) == 0xC000) {
8792292SN/A                            newEntry.AddrShiftAmount = 26;
8802292SN/A                        } else if ((newEntry.Mask & 0x30000) == 0x30000) {
8812292SN/A                            newEntry.AddrShiftAmount = 28;
8822292SN/A                        } else {
8832292SN/A                            fatal("Invalid Mask Pattern Detected!\n");
8842847Sksewell@umich.edu                        }
8855362Sksewell@umich.edu                        newEntry.OffsetMask =
8862292SN/A                            (1 << newEntry.AddrShiftAmount) - 1;
8872292SN/A
8882292SN/A                        auto ptr = dynamic_cast<MipsISA::TLB *>(
8892292SN/A                            xc->tcBase()->getITBPtr());
8902292SN/A                        Config3Reg config3 = Config3;
8912292SN/A                        PageGrainReg pageGrain = PageGrain;
8922847Sksewell@umich.edu                        int SP = 0;
8938138SAli.Saidi@ARM.com                        if (bits(config3, config3.sp) == 1 &&
8948138SAli.Saidi@ARM.com                            bits(pageGrain, pageGrain.esp) == 1) {
8958138SAli.Saidi@ARM.com                            SP = 1;
8962292SN/A                        }
8972935Sksewell@umich.edu                        ptr->insertAt(newEntry, Random, SP);
8982875Sksewell@umich.edu                    }});
8995363Sksewell@umich.edu
9002935Sksewell@umich.edu                    0x08: tlbp({{
9012292SN/A                        Config3Reg config3 = Config3;
9025362Sksewell@umich.edu                        PageGrainReg pageGrain = PageGrain;
9035362Sksewell@umich.edu                        EntryHiReg entryHi = EntryHi;
9042292SN/A                        int tlbIndex;
9052292SN/A                        Addr vpn;
9062847Sksewell@umich.edu                        if (pageGrain.esp == 1 && config3.sp ==1) {
9073229Sktlim@umich.edu                            vpn = EntryHi >> 11;
9083229Sktlim@umich.edu                        } else {
9093229Sktlim@umich.edu                            // Mask off lower 2 bits
9103229Sktlim@umich.edu                            vpn = ((EntryHi >> 11) & 0xFFFFFFFC);
9113229Sktlim@umich.edu                        }
9123229Sktlim@umich.edu                        tlbIndex = dynamic_cast<MipsISA::TLB *>(
9132292SN/A                            xc->tcBase()->getITBPtr())->
9142292SN/A                            probeEntry(vpn, entryHi.asid);
9152292SN/A                        // Check TLB for entry matching EntryHi
9162292SN/A                        if (tlbIndex != -1) {
9173229Sktlim@umich.edu                            Index = tlbIndex;
9182292SN/A                        } else {
9192292SN/A                            // else, set Index = 1 << 31
9202292SN/A                            Index = (1 << 31);
9212292SN/A                        }
9222292SN/A                    }});
9236221Snate@binkert.org                }
9242292SN/A                format CP0Unimpl {
9252733Sktlim@umich.edu                    0x20: wait();
9262292SN/A                }
9272292SN/A                default: CP0Unimpl::unknown();
9282292SN/A            }
9292292SN/A        }
9302292SN/A
9312292SN/A        //Table A-13 MIPS32 COP1 Encoding of rs Field
9322733Sktlim@umich.edu        0x1: decode RS_MSB {
9332292SN/A            0x0: decode RS_HI {
9342292SN/A                0x0: decode RS_LO {
9352292SN/A                    format CP1Control {
9362292SN/A                        0x0: mfc1 ({{ Rt = Fs_uw; }});
9372733Sktlim@umich.edu
9382292SN/A                        0x2: cfc1({{
9392292SN/A                            switch (FS) {
9402292SN/A                              case 0:
9412292SN/A                                Rt = FIR;
9422292SN/A                                break;
9432733Sktlim@umich.edu                              case 25:
9442292SN/A                                Rt = (FCSR & 0xFE000000) >> 24 |
9452292SN/A                                     (FCSR & 0x00800000) >> 23;
9462292SN/A                                break;
9472292SN/A                              case 26:
9482292SN/A                                Rt = (FCSR & 0x0003F07C);
9492733Sktlim@umich.edu                                break;
9502292SN/A                              case 28:
9512292SN/A                                Rt = (FCSR & 0x00000F80) |
9522292SN/A                                     (FCSR & 0x01000000) >> 21 |
9532292SN/A                                     (FCSR & 0x00000003);
9542292SN/A                                break;
9552733Sktlim@umich.edu                              case 31:
9562292SN/A                                Rt = FCSR;
9572292SN/A                                break;
9582292SN/A                              default:
9592292SN/A                                warn("FP Control Value (%d) Not Valid");
9602292SN/A                            }
9612292SN/A                        }});
9622292SN/A
9632292SN/A                        0x3: mfhc1({{ Rt = Fs_ud<63:32>; }});
9642292SN/A
9652292SN/A                        0x4: mtc1({{ Fs_uw = Rt; }});
9662292SN/A
9672292SN/A                        0x6: ctc1({{
9682292SN/A                            switch (FS) {
9692292SN/A                              case 25:
9702292SN/A                                FCSR = (Rt<7:1> << 25) |  // move 31-25
9712292SN/A                                       (FCSR & 0x01000000) | // bit 24
9722292SN/A                                       (FCSR & 0x004FFFFF);  // bit 22-0
9732875Sksewell@umich.edu                                break;
9742292SN/A                              case 26:
9752292SN/A                                FCSR = (FCSR & 0xFFFC0000) | // move 31-18
9761060SN/A                                       Rt<17:12> << 12 |  // bit 17-12
9771060SN/A                                       (FCSR & 0x00000F80) << 7 | // bit 11-7
9781060SN/A                                       Rt<6:2> << 2 |     // bit 6-2
9794192Sktlim@umich.edu                                       (FCSR & 0x00000002);  // bit 1-0
9805595Sgblack@eecs.umich.edu                                break;
9816221Snate@binkert.org                              case 28:
9825702Ssaidi@eecs.umich.edu                                FCSR = (FCSR & 0xFE000000) | // move 31-25
9835702Ssaidi@eecs.umich.edu                                       Rt<2:2> << 24 |    // bit 24
9845702Ssaidi@eecs.umich.edu                                       (FCSR & 0x00FFF000) << 23 | // bit 23-12
9855702Ssaidi@eecs.umich.edu                                       Rt<11:7> << 7 |    // bit 24
9865702Ssaidi@eecs.umich.edu                                       (FCSR & 0x000007E) |
9875702Ssaidi@eecs.umich.edu                                       Rt<1:0>;           // bit 22-0
9885702Ssaidi@eecs.umich.edu                                break;
9895702Ssaidi@eecs.umich.edu                              case 31:
9905702Ssaidi@eecs.umich.edu                                FCSR = Rt;
9915702Ssaidi@eecs.umich.edu                                break;
9925702Ssaidi@eecs.umich.edu
9935702Ssaidi@eecs.umich.edu                              default:
9945702Ssaidi@eecs.umich.edu                                panic("FP Control Value (%d) "
9955702Ssaidi@eecs.umich.edu                                        "Not Available. Ignoring Access "
9966221Snate@binkert.org                                        "to Floating Control Status "
9975702Ssaidi@eecs.umich.edu                                        "Register", FS);
9985702Ssaidi@eecs.umich.edu                            }
9995702Ssaidi@eecs.umich.edu                        }});
10005702Ssaidi@eecs.umich.edu
10015702Ssaidi@eecs.umich.edu                        0x7: mthc1({{
10025702Ssaidi@eecs.umich.edu                             uint64_t fs_hi = Rt;
10035702Ssaidi@eecs.umich.edu                             uint64_t fs_lo = Fs_ud & 0x0FFFFFFFF;
10045702Ssaidi@eecs.umich.edu                             Fs_ud = (fs_hi << 32) | fs_lo;
10055702Ssaidi@eecs.umich.edu                        }});
10065702Ssaidi@eecs.umich.edu
10075702Ssaidi@eecs.umich.edu                    }
10085702Ssaidi@eecs.umich.edu                    format CP1Unimpl {
10095702Ssaidi@eecs.umich.edu                      0x1: dmfc1();
10105702Ssaidi@eecs.umich.edu                      0x5: dmtc1();
10115702Ssaidi@eecs.umich.edu                    }
10125702Ssaidi@eecs.umich.edu                }
10135702Ssaidi@eecs.umich.edu
10145702Ssaidi@eecs.umich.edu                0x1: decode RS_LO {
10155702Ssaidi@eecs.umich.edu                    0x0: decode ND {
10165702Ssaidi@eecs.umich.edu                        format Branch {
10175702Ssaidi@eecs.umich.edu                            0x0: decode TF {
10185702Ssaidi@eecs.umich.edu                                0x0: bc1f({{
10195702Ssaidi@eecs.umich.edu                                    cond = getCondCode(FCSR, BRANCH_CC) == 0;
10205702Ssaidi@eecs.umich.edu                                }});
10215702Ssaidi@eecs.umich.edu                                0x1: bc1t({{
10225595Sgblack@eecs.umich.edu                                    cond = getCondCode(FCSR, BRANCH_CC) == 1;
10235595Sgblack@eecs.umich.edu                                }});
10245595Sgblack@eecs.umich.edu                            }
10255647Sgblack@eecs.umich.edu                            0x1: decode TF {
10265595Sgblack@eecs.umich.edu                                0x0: bc1fl({{
10275595Sgblack@eecs.umich.edu                                    cond = getCondCode(FCSR, BRANCH_CC) == 0;
10285595Sgblack@eecs.umich.edu                                }}, Likely);
10295595Sgblack@eecs.umich.edu                                0x1: bc1tl({{
10305595Sgblack@eecs.umich.edu                                    cond = getCondCode(FCSR, BRANCH_CC) == 1;
10315595Sgblack@eecs.umich.edu                                }}, Likely);
10325595Sgblack@eecs.umich.edu                            }
10335595Sgblack@eecs.umich.edu                        }
10345595Sgblack@eecs.umich.edu                    }
10355595Sgblack@eecs.umich.edu                    format CP1Unimpl {
10365595Sgblack@eecs.umich.edu                        0x1: bc1any2();
10375595Sgblack@eecs.umich.edu                        0x2: bc1any4();
10385595Sgblack@eecs.umich.edu                        default: unknown();
10395647Sgblack@eecs.umich.edu                    }
10405595Sgblack@eecs.umich.edu                }
10415595Sgblack@eecs.umich.edu            }
10427684Sgblack@eecs.umich.edu
10435595Sgblack@eecs.umich.edu            0x1: decode RS_HI {
10445595Sgblack@eecs.umich.edu                0x2: decode RS_LO {
10451060SN/A                    //Table A-14 MIPS32 COP1 Encoding of Function Field When
10462852Sktlim@umich.edu                    //rs=S (( single-precision floating point))
10477684Sgblack@eecs.umich.edu                    0x0: decode FUNCTION_HI {
10485595Sgblack@eecs.umich.edu                        0x0: decode FUNCTION_LO {
10495595Sgblack@eecs.umich.edu                            format FloatOp {
10507684Sgblack@eecs.umich.edu                                0x0: add_s({{ Fd_sf = Fs_sf + Ft_sf; }});
10515595Sgblack@eecs.umich.edu                                0x1: sub_s({{ Fd_sf = Fs_sf - Ft_sf; }});
10525595Sgblack@eecs.umich.edu                                0x2: mul_s({{ Fd_sf = Fs_sf * Ft_sf; }});
10535595Sgblack@eecs.umich.edu                                0x3: div_s({{ Fd_sf = Fs_sf / Ft_sf; }});
10545595Sgblack@eecs.umich.edu                                0x4: sqrt_s({{ Fd_sf = sqrt(Fs_sf); }});
10556221Snate@binkert.org                                0x5: abs_s({{ Fd_sf = fabs(Fs_sf); }});
10565595Sgblack@eecs.umich.edu                                0x7: neg_s({{ Fd_sf = -Fs_sf; }});
10575595Sgblack@eecs.umich.edu                            }
10585595Sgblack@eecs.umich.edu                            0x6: BasicOp::mov_s({{ Fd_sf = Fs_sf; }});
10595595Sgblack@eecs.umich.edu                        }
10605595Sgblack@eecs.umich.edu                        0x1: decode FUNCTION_LO {
10615595Sgblack@eecs.umich.edu                            format FloatConvertOp {
10625595Sgblack@eecs.umich.edu                                0x0: round_l_s({{ val = Fs_sf; }},
10635595Sgblack@eecs.umich.edu                                               ToLong, Round);
10645595Sgblack@eecs.umich.edu                                0x1: trunc_l_s({{ val = Fs_sf; }},
10655595Sgblack@eecs.umich.edu                                               ToLong, Trunc);
10665595Sgblack@eecs.umich.edu                                0x2: ceil_l_s({{ val = Fs_sf;}},
10675595Sgblack@eecs.umich.edu                                              ToLong, Ceil);
10685595Sgblack@eecs.umich.edu                                0x3: floor_l_s({{ val = Fs_sf; }},
10695595Sgblack@eecs.umich.edu                                               ToLong, Floor);
10705595Sgblack@eecs.umich.edu                                0x4: round_w_s({{ val = Fs_sf; }},
10715595Sgblack@eecs.umich.edu                                               ToWord, Round);
10725595Sgblack@eecs.umich.edu                                0x5: trunc_w_s({{ val = Fs_sf; }},
10735595Sgblack@eecs.umich.edu                                               ToWord, Trunc);
10745595Sgblack@eecs.umich.edu                                0x6: ceil_w_s({{ val = Fs_sf; }},
10752864Sktlim@umich.edu                                              ToWord, Ceil);
10762864Sktlim@umich.edu                                0x7: floor_w_s({{ val = Fs_sf; }},
10772918Sktlim@umich.edu                                               ToWord, Floor);
10782918Sktlim@umich.edu                            }
10792864Sktlim@umich.edu                        }
10802864Sktlim@umich.edu
10812864Sktlim@umich.edu                        0x2: decode FUNCTION_LO {
10822864Sktlim@umich.edu                            0x1: decode MOVCF {
10832864Sktlim@umich.edu                                format BasicOp {
10842864Sktlim@umich.edu                                    0x0: movf_s({{
10852864Sktlim@umich.edu                                        Fd = (getCondCode(FCSR,CC) == 0) ?
10862864Sktlim@umich.edu                                             Fs : Fd;
10872864Sktlim@umich.edu                                    }});
10886221Snate@binkert.org                                    0x1: movt_s({{
10896221Snate@binkert.org                                        Fd = (getCondCode(FCSR,CC) == 1) ?
10902864Sktlim@umich.edu                                             Fs : Fd;
10912864Sktlim@umich.edu                                    }});
10922864Sktlim@umich.edu                                }
10932864Sktlim@umich.edu                            }
10942864Sktlim@umich.edu
10952864Sktlim@umich.edu                            format BasicOp {
10962864Sktlim@umich.edu                                0x2: movz_s({{ Fd = (Rt == 0) ? Fs : Fd; }});
10972864Sktlim@umich.edu                                0x3: movn_s({{ Fd = (Rt != 0) ? Fs : Fd; }});
10982864Sktlim@umich.edu                            }
10992864Sktlim@umich.edu
11002918Sktlim@umich.edu                            format FloatOp {
11012918Sktlim@umich.edu                                0x5: recip_s({{ Fd = 1 / Fs; }});
11022864Sktlim@umich.edu                                0x6: rsqrt_s({{ Fd = 1 / sqrt(Fs); }});
11032864Sktlim@umich.edu                            }
11042864Sktlim@umich.edu                            format CP1Unimpl {
11052864Sktlim@umich.edu                                default: unknown();
11062864Sktlim@umich.edu                            }
11072864Sktlim@umich.edu                        }
11082864Sktlim@umich.edu                        0x3: CP1Unimpl::unknown();
11092864Sktlim@umich.edu
11106221Snate@binkert.org                        0x4: decode FUNCTION_LO {
11116221Snate@binkert.org                            format FloatConvertOp {
11122864Sktlim@umich.edu                                0x1: cvt_d_s({{ val = Fs_sf; }}, ToDouble);
11132864Sktlim@umich.edu                                0x4: cvt_w_s({{ val = Fs_sf; }}, ToWord);
11142864Sktlim@umich.edu                                0x5: cvt_l_s({{ val = Fs_sf; }}, ToLong);
11152864Sktlim@umich.edu                            }
11162864Sktlim@umich.edu
11172864Sktlim@umich.edu                            0x6: FloatOp::cvt_ps_s({{
11182864Sktlim@umich.edu                                Fd_ud = (uint64_t)Fs_uw << 32 |
11192905Sktlim@umich.edu                                        (uint64_t)Ft_uw;
11202843Sktlim@umich.edu                            }});
11211060SN/A                            format CP1Unimpl {
11223125Sktlim@umich.edu                                default: unknown();
11233512Sktlim@umich.edu                            }
11243512Sktlim@umich.edu                        }
11259152Satgutier@umich.edu                        0x5: CP1Unimpl::unknown();
11263512Sktlim@umich.edu
11273512Sktlim@umich.edu                        0x6: decode FUNCTION_LO {
11282843Sktlim@umich.edu                            format FloatCompareOp {
11292843Sktlim@umich.edu                                0x0: c_f_s({{ cond = 0; }},
11302843Sktlim@umich.edu                                           SinglePrecision, UnorderedFalse);
11312843Sktlim@umich.edu                                0x1: c_un_s({{ cond = 0; }},
11322843Sktlim@umich.edu                                            SinglePrecision, UnorderedTrue);
11332843Sktlim@umich.edu                                0x2: c_eq_s({{ cond = (Fs_sf == Ft_sf); }},
11342325SN/A                                            UnorderedFalse);
11352325SN/A                                0x3: c_ueq_s({{ cond = (Fs_sf == Ft_sf); }},
11362863Sktlim@umich.edu                                             UnorderedTrue);
11372905Sktlim@umich.edu                                0x4: c_olt_s({{ cond = (Fs_sf < Ft_sf); }},
11382864Sktlim@umich.edu                                             UnorderedFalse);
11392864Sktlim@umich.edu                                0x5: c_ult_s({{ cond = (Fs_sf < Ft_sf); }},
11402864Sktlim@umich.edu                                             UnorderedTrue);
11412864Sktlim@umich.edu                                0x6: c_ole_s({{ cond = (Fs_sf <= Ft_sf); }},
11422864Sktlim@umich.edu                                             UnorderedFalse);
11432843Sktlim@umich.edu                                0x7: c_ule_s({{ cond = (Fs_sf <= Ft_sf); }},
11442863Sktlim@umich.edu                                             UnorderedTrue);
11452863Sktlim@umich.edu                            }
11462852Sktlim@umich.edu                        }
11479152Satgutier@umich.edu
11489152Satgutier@umich.edu                        0x7: decode FUNCTION_LO {
11492905Sktlim@umich.edu                            format FloatCompareOp {
11502863Sktlim@umich.edu                                0x0: c_sf_s({{ cond = 0; }}, SinglePrecision,
11512905Sktlim@umich.edu                                            UnorderedFalse, QnanException);
11522863Sktlim@umich.edu                                0x1: c_ngle_s({{ cond = 0; }}, SinglePrecision,
11532316SN/A                                              UnorderedTrue, QnanException);
11542310SN/A                                0x2: c_seq_s({{ cond = (Fs_sf == Ft_sf); }},
11552316SN/A                                             UnorderedFalse, QnanException);
11562316SN/A                                0x3: c_ngl_s({{ cond = (Fs_sf == Ft_sf); }},
11572843Sktlim@umich.edu                                             UnorderedTrue, QnanException);
11582316SN/A                                0x4: c_lt_s({{ cond = (Fs_sf < Ft_sf); }},
11592843Sktlim@umich.edu                                            UnorderedFalse, QnanException);
11602843Sktlim@umich.edu                                0x5: c_nge_s({{ cond = (Fs_sf < Ft_sf); }},
11612843Sktlim@umich.edu                                             UnorderedTrue, QnanException);
11622843Sktlim@umich.edu                                0x6: c_le_s({{ cond = (Fs_sf <= Ft_sf); }},
11632843Sktlim@umich.edu                                            UnorderedFalse, QnanException);
11642316SN/A                                0x7: c_ngt_s({{ cond = (Fs_sf <= Ft_sf); }},
11652905Sktlim@umich.edu                                             UnorderedTrue, QnanException);
11662905Sktlim@umich.edu                            }
11679152Satgutier@umich.edu                        }
11682864Sktlim@umich.edu                    }
11692864Sktlim@umich.edu
11704762Snate@binkert.org                    //Table A-15 MIPS32 COP1 Encoding of Function Field When
11713319Shsul@eecs.umich.edu                    //rs=D
11722843Sktlim@umich.edu                    0x1: decode FUNCTION_HI {
11735606Snate@binkert.org                        0x0: decode FUNCTION_LO {
11742843Sktlim@umich.edu                            format FloatOp {
11752843Sktlim@umich.edu                                0x0: add_d({{ Fd_df = Fs_df + Ft_df; }});
11762316SN/A                                0x1: sub_d({{ Fd_df = Fs_df - Ft_df; }});
11772843Sktlim@umich.edu                                0x2: mul_d({{ Fd_df = Fs_df * Ft_df; }});
11782843Sktlim@umich.edu                                0x3: div_d({{ Fd_df = Fs_df / Ft_df; }});
11792843Sktlim@umich.edu                                0x4: sqrt_d({{ Fd_df = sqrt(Fs_df); }});
11802843Sktlim@umich.edu                                0x5: abs_d({{ Fd_df = fabs(Fs_df); }});
11812843Sktlim@umich.edu                                0x7: neg_d({{ Fd_df = -1 * Fs_df; }});
11822316SN/A                            }
11832316SN/A                            0x6: BasicOp::mov_d({{ Fd_df = Fs_df; }});
11842863Sktlim@umich.edu                        }
11852905Sktlim@umich.edu
11862863Sktlim@umich.edu                        0x1: decode FUNCTION_LO {
11873126Sktlim@umich.edu                            format FloatConvertOp {
11883126Sktlim@umich.edu                                0x0: round_l_d({{ val = Fs_df; }},
11892863Sktlim@umich.edu                                               ToLong, Round);
11909152Satgutier@umich.edu                                0x1: trunc_l_d({{ val = Fs_df; }},
11912863Sktlim@umich.edu                                               ToLong, Trunc);
11922863Sktlim@umich.edu                                0x2: ceil_l_d({{ val = Fs_df; }},
11932863Sktlim@umich.edu                                              ToLong, Ceil);
11942310SN/A                                0x3: floor_l_d({{ val = Fs_df; }},
11952843Sktlim@umich.edu                                               ToLong, Floor);
11962843Sktlim@umich.edu                                0x4: round_w_d({{ val = Fs_df; }},
11972843Sktlim@umich.edu                                               ToWord, Round);
11982843Sktlim@umich.edu                                0x5: trunc_w_d({{ val = Fs_df; }},
11992843Sktlim@umich.edu                                               ToWord, Trunc);
12002843Sktlim@umich.edu                                0x6: ceil_w_d({{ val = Fs_df; }},
12012843Sktlim@umich.edu                                              ToWord, Ceil);
12022843Sktlim@umich.edu                                0x7: floor_w_d({{ val = Fs_df; }},
12032843Sktlim@umich.edu                                               ToWord, Floor);
12042325SN/A                            }
12052843Sktlim@umich.edu                        }
12062843Sktlim@umich.edu
12072843Sktlim@umich.edu                        0x2: decode FUNCTION_LO {
12082843Sktlim@umich.edu                            0x1: decode MOVCF {
12092843Sktlim@umich.edu                                format BasicOp {
12102843Sktlim@umich.edu                                    0x0: movf_d({{
12112843Sktlim@umich.edu                                        Fd_df = (getCondCode(FCSR,CC) == 0) ?
12128887Sgeoffrey.blake@arm.com                                                       Fs_df : Fd_df;
12132843Sktlim@umich.edu                                    }});
12142843Sktlim@umich.edu                                    0x1: movt_d({{
12158887Sgeoffrey.blake@arm.com                                        Fd_df = (getCondCode(FCSR,CC) == 1) ?
12163126Sktlim@umich.edu                                                       Fs_df : Fd_df;
12173126Sktlim@umich.edu                                    }});
12181060SN/A                                }
12191060SN/A                            }
12201060SN/A
12211060SN/A                            format BasicOp {
12221755SN/A                                0x2: movz_d({{
12231060SN/A                                    Fd_df = (Rt == 0) ? Fs_df : Fd_df;
12242325SN/A                                }});
12252873Sktlim@umich.edu                                0x3: movn_d({{
12262307SN/A                                    Fd_df = (Rt != 0) ? Fs_df : Fd_df;
12272307SN/A                                }});
12282307SN/A                            }
12292307SN/A
12302307SN/A                            format FloatOp {
12312307SN/A                                0x5: recip_d({{ Fd_df = 1 / Fs_df; }});
12322307SN/A                                0x6: rsqrt_d({{ Fd_df = 1 / sqrt(Fs_df); }});
12332325SN/A                            }
12342307SN/A                            format CP1Unimpl {
12358737Skoansin.tan@gmail.com                                default: unknown();
12361060SN/A                            }
12372307SN/A
12382307SN/A                        }
12392307SN/A                        0x4: decode FUNCTION_LO {
12402307SN/A                            format FloatConvertOp {
12412307SN/A                                0x0: cvt_s_d({{ val = Fs_df; }}, ToSingle);
12422307SN/A                                0x4: cvt_w_d({{ val = Fs_df; }}, ToWord);
12437507Stjones1@inf.ed.ac.uk                                0x5: cvt_l_d({{ val = Fs_df; }}, ToLong);
12441060SN/A                            }
12459152Satgutier@umich.edu                            default: CP1Unimpl::unknown();
12469152Satgutier@umich.edu                        }
12479152Satgutier@umich.edu
12489152Satgutier@umich.edu                        0x6: decode FUNCTION_LO {
12492325SN/A                            format FloatCompareOp {
12502325SN/A                                0x0: c_f_d({{ cond = 0; }},
12516221Snate@binkert.org                                           DoublePrecision, UnorderedFalse);
12522307SN/A                                0x1: c_un_d({{ cond = 0; }},
12536221Snate@binkert.org                                            DoublePrecision, UnorderedTrue);
12545314Sstever@gmail.com                                0x2: c_eq_d({{ cond = (Fs_df == Ft_df); }},
12552307SN/A                                            UnorderedFalse);
12562307SN/A                                0x3: c_ueq_d({{ cond = (Fs_df == Ft_df); }},
12572325SN/A                                             UnorderedTrue);
12582325SN/A                                0x4: c_olt_d({{ cond = (Fs_df < Ft_df); }},
12592733Sktlim@umich.edu                                             UnorderedFalse);
12602307SN/A                                0x5: c_ult_d({{ cond = (Fs_df < Ft_df); }},
12612307SN/A                                             UnorderedTrue);
12622307SN/A                                0x6: c_ole_d({{ cond = (Fs_df <= Ft_df); }},
12632307SN/A                                             UnorderedFalse);
12642307SN/A                                0x7: c_ule_d({{ cond = (Fs_df <= Ft_df); }},
12652325SN/A                                             UnorderedTrue);
12662307SN/A                            }
12676221Snate@binkert.org                        }
12686221Snate@binkert.org
12692680Sktlim@umich.edu                        0x7: decode FUNCTION_LO {
12702680Sktlim@umich.edu                            format FloatCompareOp {
12711681SN/A                                0x0: c_sf_d({{ cond = 0; }}, DoublePrecision,
12727507Stjones1@inf.ed.ac.uk                                            UnorderedFalse, QnanException);
12731681SN/A                                0x1: c_ngle_d({{ cond = 0; }}, DoublePrecision,
12741060SN/A                                              UnorderedTrue, QnanException);
12752307SN/A                                0x2: c_seq_d({{ cond = (Fs_df == Ft_df); }},
12765606Snate@binkert.org                                             UnorderedFalse, QnanException);
12778627SAli.Saidi@ARM.com                                0x3: c_ngl_d({{ cond = (Fs_df == Ft_df); }},
12788627SAli.Saidi@ARM.com                                             UnorderedTrue, QnanException);
12791060SN/A                                0x4: c_lt_d({{ cond = (Fs_df < Ft_df); }},
12801060SN/A                                            UnorderedFalse, QnanException);
12811060SN/A                                0x5: c_nge_d({{ cond = (Fs_df < Ft_df); }},
12825595Sgblack@eecs.umich.edu                                             UnorderedTrue, QnanException);
12836221Snate@binkert.org                                0x6: c_le_d({{ cond = (Fs_df <= Ft_df); }},
12845595Sgblack@eecs.umich.edu                                            UnorderedFalse, QnanException);
12856313Sgblack@eecs.umich.edu                                0x7: c_ngt_d({{ cond = (Fs_df <= Ft_df); }},
12865595Sgblack@eecs.umich.edu                                             UnorderedTrue, QnanException);
12875595Sgblack@eecs.umich.edu                            }
12885595Sgblack@eecs.umich.edu                        }
12895595Sgblack@eecs.umich.edu                        default: CP1Unimpl::unknown();
12906221Snate@binkert.org                    }
12915595Sgblack@eecs.umich.edu                    0x2: CP1Unimpl::unknown();
12927897Shestness@cs.utexas.edu                    0x3: CP1Unimpl::unknown();
12936313Sgblack@eecs.umich.edu                    0x7: CP1Unimpl::unknown();
12945595Sgblack@eecs.umich.edu
12955595Sgblack@eecs.umich.edu                    //Table A-16 MIPS32 COP1 Encoding of Function
12965595Sgblack@eecs.umich.edu                    //Field When rs=W
12975595Sgblack@eecs.umich.edu                    0x4: decode FUNCTION {
12985595Sgblack@eecs.umich.edu                        format FloatConvertOp {
12996221Snate@binkert.org                            0x20: cvt_s_w({{ val = Fs_sw; }}, ToSingle);
13005595Sgblack@eecs.umich.edu                            0x21: cvt_d_w({{ val = Fs_sw; }}, ToDouble);
13016313Sgblack@eecs.umich.edu                            0x26: CP1Unimpl::cvt_ps_w();
13025595Sgblack@eecs.umich.edu                        }
13035595Sgblack@eecs.umich.edu                        default: CP1Unimpl::unknown();
13045595Sgblack@eecs.umich.edu                    }
13055595Sgblack@eecs.umich.edu
13065595Sgblack@eecs.umich.edu                    //Table A-16 MIPS32 COP1 Encoding of Function Field
13076221Snate@binkert.org                    //When rs=L1
13085595Sgblack@eecs.umich.edu                    //Note: "1. Format type L is legal only if 64-bit
13097897Shestness@cs.utexas.edu                    //floating point operations are enabled."
13106313Sgblack@eecs.umich.edu                    0x5: decode FUNCTION {
13115595Sgblack@eecs.umich.edu                        format FloatConvertOp {
13125595Sgblack@eecs.umich.edu                            0x20: cvt_s_l({{ val = Fs_sd; }}, ToSingle);
13135595Sgblack@eecs.umich.edu                            0x21: cvt_d_l({{ val = Fs_sd; }}, ToDouble);
13141060SN/A                            0x26: CP1Unimpl::cvt_ps_l();
13151755SN/A                        }
13161060SN/A                        default: CP1Unimpl::unknown();
13177897Shestness@cs.utexas.edu                    }
13181060SN/A
13191060SN/A                    //Table A-17 MIPS64 COP1 Encoding of Function Field
13201060SN/A                    //When rs=PS1
13211060SN/A                    //Note: "1. Format type PS is legal only if 64-bit
13222455SN/A                    //floating point operations are enabled. "
13232455SN/A                    0x6: decode FUNCTION_HI {
13241060SN/A                        0x0: decode FUNCTION_LO {
13257897Shestness@cs.utexas.edu                            format Float64Op {
13262455SN/A                                0x0: add_ps({{
13271060SN/A                                    Fd1_sf = Fs1_sf + Ft2_sf;
13281060SN/A                                    Fd2_sf = Fs2_sf + Ft2_sf;
13291060SN/A                                }});
13302455SN/A                                0x1: sub_ps({{
13312455SN/A                                    Fd1_sf = Fs1_sf - Ft2_sf;
13322455SN/A                                    Fd2_sf = Fs2_sf - Ft2_sf;
13337897Shestness@cs.utexas.edu                                }});
13342455SN/A                                0x2: mul_ps({{
13351060SN/A                                    Fd1_sf = Fs1_sf * Ft2_sf;
13361060SN/A                                    Fd2_sf = Fs2_sf * Ft2_sf;
13371060SN/A                                }});
13381060SN/A                                0x5: abs_ps({{
13391755SN/A                                    Fd1_sf = fabs(Fs1_sf);
13401060SN/A                                    Fd2_sf = fabs(Fs2_sf);
13417897Shestness@cs.utexas.edu                                }});
13421060SN/A                                0x6: mov_ps({{
13431060SN/A                                    Fd1_sf = Fs1_sf;
13441060SN/A                                    Fd2_sf = Fs2_sf;
13451060SN/A                                }});
13461060SN/A                                0x7: neg_ps({{
13472455SN/A                                    Fd1_sf = -(Fs1_sf);
13481060SN/A                                    Fd2_sf = -(Fs2_sf);
13497897Shestness@cs.utexas.edu                                }});
13502455SN/A                                default: CP1Unimpl::unknown();
13511060SN/A                            }
13521060SN/A                        }
13531060SN/A                        0x1: CP1Unimpl::unknown();
13541060SN/A                        0x2: decode FUNCTION_LO {
13552455SN/A                            0x1: decode MOVCF {
13562455SN/A                                format Float64Op {
13577897Shestness@cs.utexas.edu                                    0x0: movf_ps({{
13582455SN/A                                        Fd1 = (getCondCode(FCSR, CC) == 0) ?
13591060SN/A                                            Fs1 : Fd1;
13601060SN/A                                        Fd2 = (getCondCode(FCSR, CC+1) == 0) ?
13611060SN/A                                            Fs2 : Fd2;
13621060SN/A                                    }});
13636221Snate@binkert.org                                    0x1: movt_ps({{
13641060SN/A                                        Fd2 = (getCondCode(FCSR, CC) == 1) ?
13657897Shestness@cs.utexas.edu                                            Fs1 : Fd1;
13662292SN/A                                        Fd2 = (getCondCode(FCSR, CC+1) == 1) ?
13672292SN/A                                            Fs2 : Fd2;
13682292SN/A                                    }});
13692292SN/A                                }
13702292SN/A                            }
13712292SN/A
13722292SN/A                            format Float64Op {
13736314Sgblack@eecs.umich.edu                                0x2: movz_ps({{
13742292SN/A                                    Fd1 = (getCondCode(FCSR, CC) == 0) ?
13757897Shestness@cs.utexas.edu                                        Fs1 : Fd1;
13766032Ssteve.reinhardt@amd.com                                    Fd2 = (getCondCode(FCSR, CC) == 0) ?
13772307SN/A                                        Fs2 : Fd2;
13782292SN/A                                }});
13792669Sktlim@umich.edu                                0x3: movn_ps({{
13802292SN/A                                    Fd1 = (getCondCode(FCSR, CC) == 1) ?
13812292SN/A                                        Fs1 : Fd1;
13822292SN/A                                    Fd2 = (getCondCode(FCSR, CC) == 1) ?
13832292SN/A                                        Fs2 : Fd2;
13846221Snate@binkert.org                                }});
13852292SN/A                            }
13867897Shestness@cs.utexas.edu                            default: CP1Unimpl::unknown();
13876032Ssteve.reinhardt@amd.com                        }
13882307SN/A                        0x3: CP1Unimpl::unknown();
13892292SN/A                        0x4: decode FUNCTION_LO {
13902669Sktlim@umich.edu                            0x0: FloatOp::cvt_s_pu({{ Fd_sf = Fs2_sf; }});
13911060SN/A                            default: CP1Unimpl::unknown();
13921060SN/A                        }
13931060SN/A
13941060SN/A                        0x5: decode FUNCTION_LO {
13956221Snate@binkert.org                            0x0: FloatOp::cvt_s_pl({{ Fd_sf = Fs1_sf; }});
13961060SN/A                            format Float64Op {
13977897Shestness@cs.utexas.edu                                0x4: pll({{
13982292SN/A                                    Fd_ud = (uint64_t)Fs1_uw << 32 | Ft1_uw;
13992292SN/A                                }});
14002292SN/A                                0x5: plu({{
14011060SN/A                                    Fd_ud = (uint64_t)Fs1_uw << 32 | Ft2_uw;
14021060SN/A                                }});
14031060SN/A                                0x6: pul({{
14041060SN/A                                    Fd_ud = (uint64_t)Fs2_uw << 32 | Ft1_uw;
14056314Sgblack@eecs.umich.edu                                }});
14061060SN/A                                0x7: puu({{
14077897Shestness@cs.utexas.edu                                    Fd_ud = (uint64_t)Fs2_uw << 32 | Ft2_uw;
14086032Ssteve.reinhardt@amd.com                                }});
14092918Sktlim@umich.edu                            }
14102292SN/A                            default: CP1Unimpl::unknown();
14112669Sktlim@umich.edu                        }
14121060SN/A
14131060SN/A                        0x6: decode FUNCTION_LO {
14141060SN/A                            format FloatPSCompareOp {
14151060SN/A                                0x0: c_f_ps({{ cond1 = 0; }}, {{ cond2 = 0; }},
14166221Snate@binkert.org                                            UnorderedFalse);
14171060SN/A                                0x1: c_un_ps({{ cond1 = 0; }}, {{ cond2 = 0; }},
14187897Shestness@cs.utexas.edu                                             UnorderedTrue);
14196032Ssteve.reinhardt@amd.com                                0x2: c_eq_ps({{ cond1 = (Fs1_sf == Ft1_sf); }},
14202918Sktlim@umich.edu                                             {{ cond2 = (Fs2_sf == Ft2_sf); }},
14211060SN/A                                             UnorderedFalse);
14222669Sktlim@umich.edu                                0x3: c_ueq_ps({{ cond1 = (Fs1_sf == Ft1_sf); }},
14232292SN/A                                              {{ cond2 = (Fs2_sf == Ft2_sf); }},
14242292SN/A                                              UnorderedTrue);
14252292SN/A                                0x4: c_olt_ps({{ cond1 = (Fs1_sf < Ft1_sf); }},
14267720Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf < Ft2_sf); }},
14277720Sgblack@eecs.umich.edu                                              UnorderedFalse);
14282292SN/A                                0x5: c_ult_ps({{ cond1 = (Fs_sf < Ft_sf); }},
14297720Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf < Ft2_sf); }},
14301060SN/A                                              UnorderedTrue);
14311060SN/A                                0x6: c_ole_ps({{ cond1 = (Fs_sf <= Ft_sf); }},
14321060SN/A                                              {{ cond2 = (Fs2_sf <= Ft2_sf); }},
14331060SN/A                                              UnorderedFalse);
14347720Sgblack@eecs.umich.edu                                0x7: c_ule_ps({{ cond1 = (Fs1_sf <= Ft1_sf); }},
14351060SN/A                                              {{ cond2 = (Fs2_sf <= Ft2_sf); }},
14367720Sgblack@eecs.umich.edu                                              UnorderedTrue);
14372292SN/A                            }
14381060SN/A                        }
14392292SN/A
14407720Sgblack@eecs.umich.edu                        0x7: decode FUNCTION_LO {
14417720Sgblack@eecs.umich.edu                            format FloatPSCompareOp {
14424636Sgblack@eecs.umich.edu                                0x0: c_sf_ps({{ cond1 = 0; }}, {{ cond2 = 0; }},
14437720Sgblack@eecs.umich.edu                                             UnorderedFalse, QnanException);
14444636Sgblack@eecs.umich.edu                                0x1: c_ngle_ps({{ cond1 = 0; }},
14454636Sgblack@eecs.umich.edu                                               {{ cond2 = 0; }},
14464636Sgblack@eecs.umich.edu                                               UnorderedTrue, QnanException);
14477720Sgblack@eecs.umich.edu                                0x2: c_seq_ps({{ cond1 = (Fs1_sf == Ft1_sf); }},
14487720Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf == Ft2_sf); }},
14494636Sgblack@eecs.umich.edu                                              UnorderedFalse, QnanException);
14507720Sgblack@eecs.umich.edu                                0x3: c_ngl_ps({{ cond1 = (Fs1_sf == Ft1_sf); }},
14514636Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf == Ft2_sf); }},
14524636Sgblack@eecs.umich.edu                                              UnorderedTrue, QnanException);
14534636Sgblack@eecs.umich.edu                                0x4: c_lt_ps({{ cond1 = (Fs1_sf < Ft1_sf); }},
14547720Sgblack@eecs.umich.edu                                             {{ cond2 = (Fs2_sf < Ft2_sf); }},
14557720Sgblack@eecs.umich.edu                                             UnorderedFalse, QnanException);
14562292SN/A                                0x5: c_nge_ps({{ cond1 = (Fs1_sf < Ft1_sf); }},
14577720Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf < Ft2_sf); }},
14584636Sgblack@eecs.umich.edu                                              UnorderedTrue, QnanException);
14594636Sgblack@eecs.umich.edu                                0x6: c_le_ps({{ cond1 = (Fs1_sf <= Ft1_sf); }},
14604636Sgblack@eecs.umich.edu                                             {{ cond2 = (Fs2_sf <= Ft2_sf); }},
14615595Sgblack@eecs.umich.edu                                             UnorderedFalse, QnanException);
14626221Snate@binkert.org                                0x7: c_ngt_ps({{ cond1 = (Fs1_sf <= Ft1_sf); }},
14635595Sgblack@eecs.umich.edu                                              {{ cond2 = (Fs2_sf <= Ft2_sf); }},
14645595Sgblack@eecs.umich.edu                                              UnorderedTrue, QnanException);
14655595Sgblack@eecs.umich.edu                            }
14665595Sgblack@eecs.umich.edu                        }
14675595Sgblack@eecs.umich.edu                    }
14685595Sgblack@eecs.umich.edu                }
14692292SN/A                default: CP1Unimpl::unknown();
14702292SN/A            }
14712292SN/A        }
14722292SN/A
14731060SN/A        //Table A-19 MIPS32 COP2 Encoding of rs Field
14742292SN/A        0x2: decode RS_MSB {
14752292SN/A            format CP2Unimpl {
14761060SN/A                0x0: decode RS_HI {
14772292SN/A                    0x0: decode RS_LO {
14782292SN/A                        0x0: mfc2();
14798834Satgutier@umich.edu                        0x2: cfc2();
14802292SN/A                        0x3: mfhc2();
14812292SN/A                        0x4: mtc2();
14828834Satgutier@umich.edu                        0x6: ctc2();
14838834Satgutier@umich.edu                        0x7: mftc2();
14848834Satgutier@umich.edu                        default: unknown();
14858834Satgutier@umich.edu                    }
14868834Satgutier@umich.edu
14878834Satgutier@umich.edu                    0x1: decode ND {
14888834Satgutier@umich.edu                        0x0: decode TF {
14898834Satgutier@umich.edu                            0x0: bc2f();
14908834Satgutier@umich.edu                            0x1: bc2t();
14918834Satgutier@umich.edu                            default: unknown();
14927897Shestness@cs.utexas.edu                        }
14932292SN/A
14942292SN/A                        0x1: decode TF {
14957897Shestness@cs.utexas.edu                            0x0: bc2fl();
14962292SN/A                            0x1: bc2tl();
14972292SN/A                            default: unknown();
14982292SN/A                        }
14992292SN/A                        default: unknown();
15001755SN/A
15011060SN/A                    }
15027720Sgblack@eecs.umich.edu                    default: unknown();
15032292SN/A                }
15047720Sgblack@eecs.umich.edu                default: unknown();
15051060SN/A            }
15062292SN/A        }
15071060SN/A
15081060SN/A        //Table A-20 MIPS64 COP1X Encoding of Function Field 1
15092292SN/A        //Note: "COP1X instructions are legal only if 64-bit floating point
15101060SN/A        //operations are enabled."
15111060SN/A        0x3: decode FUNCTION_HI {
15121060SN/A            0x0: decode FUNCTION_LO {
15131060SN/A                format LoadIndexedMemory {
15146221Snate@binkert.org                    0x0: lwxc1({{ Fd_uw = Mem; }});
15151060SN/A                    0x1: ldxc1({{ Fd_ud = Mem_ud; }});
15162733Sktlim@umich.edu                    0x5: luxc1({{ Fd_ud = Mem_ud; }},
15172292SN/A                               {{ EA = (Rs + Rt) & ~7; }});
15181060SN/A                }
15192292SN/A            }
15201060SN/A
15212292SN/A            0x1: decode FUNCTION_LO {
15222292SN/A                format StoreIndexedMemory {
15232292SN/A                    0x0: swxc1({{ Mem = Fs_uw; }});
15242292SN/A                    0x1: sdxc1({{ Mem_ud = Fs_ud; }});
15252292SN/A                    0x5: suxc1({{ Mem_ud = Fs_ud; }},
15262733Sktlim@umich.edu                               {{ EA = (Rs + Rt) & ~7; }});
15272292SN/A                }
15282292SN/A                0x7: Prefetch::prefx({{ EA = Rs + Rt; }});
15292292SN/A            }
15302292SN/A
15312733Sktlim@umich.edu            0x3: decode FUNCTION_LO {
15322292SN/A                0x6: Float64Op::alnv_ps({{
15332292SN/A                    if (Rs<2:0> == 0) {
15342292SN/A                        Fd_ud = Fs_ud;
15352292SN/A                    } else if (Rs<2:0> == 4) {
15362292SN/A                        if (GuestByteOrder == BigEndianByteOrder)
15372292SN/A                            Fd_ud = Fs_ud<31:0> << 32 | Ft_ud<63:32>;
15382292SN/A                        else
15392292SN/A                            Fd_ud = Ft_ud<31:0> << 32 | Fs_ud<63:32>;
15402292SN/A                    } else {
15412292SN/A                        Fd_ud = Fd_ud;
15422292SN/A                    }
15432292SN/A                }});
15442292SN/A            }
15452292SN/A
15462292SN/A            format FloatAccOp {
15472292SN/A                0x4: decode FUNCTION_LO {
15482292SN/A                    0x0: madd_s({{ Fd_sf = (Fs_sf * Ft_sf) + Fr_sf; }});
15492292SN/A                    0x1: madd_d({{ Fd_df = (Fs_df * Ft_df) + Fr_df; }});
15502292SN/A                    0x6: madd_ps({{
15512292SN/A                        Fd1_sf = (Fs1_df * Ft1_df) + Fr1_df;
15522292SN/A                        Fd2_sf = (Fs2_df * Ft2_df) + Fr2_df;
15532292SN/A                    }});
15542292SN/A                }
15551060SN/A
15561060SN/A                0x5: decode FUNCTION_LO {
15571060SN/A                    0x0: msub_s({{ Fd_sf = (Fs_sf * Ft_sf) - Fr_sf; }});
15581060SN/A                    0x1: msub_d({{ Fd_df = (Fs_df * Ft_df) - Fr_df; }});
15596221Snate@binkert.org                    0x6: msub_ps({{
15601062SN/A                        Fd1_sf = (Fs1_df * Ft1_df) - Fr1_df;
15612292SN/A                        Fd2_sf = (Fs2_df * Ft2_df) - Fr2_df;
15622292SN/A                    }});
15632292SN/A                }
15642292SN/A
15652292SN/A                0x6: decode FUNCTION_LO {
15662292SN/A                    0x0: nmadd_s({{ Fd_sf = (-1 * Fs_sf * Ft_sf) - Fr_sf; }});
15672292SN/A                    0x1: nmadd_d({{ Fd_df = (-1 * Fs_df * Ft_df) - Fr_df; }});
15682292SN/A                    0x6: nmadd_ps({{
15692733Sktlim@umich.edu                        Fd1_sf = -((Fs1_df * Ft1_df) + Fr1_df);
15702292SN/A                        Fd2_sf = -((Fs2_df * Ft2_df) + Fr2_df);
15712292SN/A                    }});
15721062SN/A                }
15732292SN/A
15741062SN/A                0x7: decode FUNCTION_LO {
15752292SN/A                    0x0: nmsub_s({{ Fd_sf = (-1 * Fs_sf * Ft_sf) + Fr_sf; }});
15761062SN/A                    0x1: nmsub_d({{ Fd_df = (-1 * Fs_df * Ft_df) + Fr_df; }});
15772292SN/A                    0x6: nmsub_ps({{
15781062SN/A                        Fd1_sf = -((Fs1_df * Ft1_df) - Fr1_df);
15792292SN/A                        Fd2_sf = -((Fs2_df * Ft2_df) - Fr2_df);
15801062SN/A                    }});
15812292SN/A                }
15822292SN/A            }
15832292SN/A        }
15842292SN/A
15852292SN/A        format Branch {
15862292SN/A            0x4: beql({{ cond = (Rs_sw == Rt_sw); }}, Likely);
15872292SN/A            0x5: bnel({{ cond = (Rs_sw != Rt_sw); }}, Likely);
15886221Snate@binkert.org            0x6: blezl({{ cond = (Rs_sw <= 0); }}, Likely);
15892292SN/A            0x7: bgtzl({{ cond = (Rs_sw > 0); }}, Likely);
15902292SN/A        }
15912733Sktlim@umich.edu    }
15927720Sgblack@eecs.umich.edu
15932292SN/A    0x3: decode OPCODE_LO {
15942292SN/A        //Table A-5 MIPS32 SPECIAL2 Encoding of Function Field
15957720Sgblack@eecs.umich.edu        0x4: decode FUNCTION_HI {
15961062SN/A            0x0: decode FUNCTION_LO {
15971062SN/A                0x2: IntOp::mul({{
15982292SN/A                    int64_t temp1 = Rs_sd * Rt_sd;
15992292SN/A                    Rd = temp1<31:0>;
16002325SN/A                }}, IntMultOp);
16012325SN/A
16022292SN/A                format HiLoRdSelValOp {
16032292SN/A                    0x0: madd({{
16042292SN/A                        val = ((int64_t)HI_RD_SEL << 32 | LO_RD_SEL) +
16052292SN/A                              (Rs_sd * Rt_sd);
16062292SN/A                    }}, IntMultOp);
16072292SN/A                    0x1: maddu({{
16082292SN/A                        val = ((uint64_t)HI_RD_SEL << 32 | LO_RD_SEL) +
16092292SN/A                              (Rs_ud * Rt_ud);
16102292SN/A                    }}, IntMultOp);
16112292SN/A                    0x4: msub({{
16122733Sktlim@umich.edu                        val = ((int64_t)HI_RD_SEL << 32 | LO_RD_SEL) -
16137720Sgblack@eecs.umich.edu                              (Rs_sd * Rt_sd);
16142292SN/A                    }}, IntMultOp);
16152292SN/A                    0x5: msubu({{
16167720Sgblack@eecs.umich.edu                        val = ((uint64_t)HI_RD_SEL << 32 | LO_RD_SEL) -
16172292SN/A                              (Rs_ud * Rt_ud);
16182292SN/A                    }}, IntMultOp);
16192292SN/A                }
16202292SN/A            }
16211062SN/A
16221062SN/A            0x4: decode FUNCTION_LO {
16232292SN/A                format BasicOp {
16241062SN/A                    0x0: clz({{
16252325SN/A                        int cnt = 32;
16261062SN/A                        for (int idx = 31; idx >= 0; idx--) {
16271062SN/A                            if (Rs<idx:idx> == 1) {
16281755SN/A                                cnt = 31 - idx;
16291060SN/A                                break;
16301060SN/A                            }
16311060SN/A                        }
16322325SN/A                        Rd = cnt;
16331060SN/A                    }});
16341060SN/A                    0x1: clo({{
16351755SN/A                        int cnt = 32;
16361060SN/A                        for (int idx = 31; idx >= 0; idx--) {
16371060SN/A                            if (Rs<idx:idx> == 0) {
16381060SN/A                                cnt = 31 - idx;
16392292SN/A                                break;
16402292SN/A                            }
16412292SN/A                        }
16422292SN/A                        Rd = cnt;
16432292SN/A                    }});
16442292SN/A                }
16452292SN/A            }
16467720Sgblack@eecs.umich.edu
16472292SN/A            0x7: decode FUNCTION_LO {
16482292SN/A                0x7: FailUnimpl::sdbbp();
16491060SN/A            }
16501060SN/A        }
16511060SN/A
16521060SN/A        //Table A-6 MIPS32 SPECIAL3 Encoding of Function Field for Release 2
16532325SN/A        //of the Architecture
16541060SN/A        0x7: decode FUNCTION_HI {
16551060SN/A            0x0: decode FUNCTION_LO {
16561755SN/A                format BasicOp {
16571060SN/A                    0x0: ext({{ Rt = bits(Rs, MSB + LSB, LSB); }});
16581060SN/A                    0x4: ins({{
16591060SN/A                        Rt = bits(Rt, 31, MSB + 1) << (MSB + 1) |
16602325SN/A                             bits(Rs, MSB - LSB, 0) << LSB |
16612292SN/A                             bits(Rt, LSB - 1, 0);
16622292SN/A                    }});
16632292SN/A                }
16642292SN/A            }
16652325SN/A
16662325SN/A            0x1: decode FUNCTION_LO {
16672292SN/A                format MT_Control {
16682292SN/A                    0x0: fork({{
16692292SN/A                        forkThread(xc->tcBase(), fault, RD, Rs, Rt);
16702325SN/A                    }}, UserMode);
16712325SN/A                    0x1: yield({{
16727823Ssteve.reinhardt@amd.com                        Rd = yieldThread(xc->tcBase(), fault, Rs_sw,
16737823Ssteve.reinhardt@amd.com                                            YQMask);
16742292SN/A                    }}, UserMode);
16755606Snate@binkert.org                }
16762292SN/A
16772292SN/A                //Table 5-9 MIPS32 LX Encoding of the op Field (DSP ASE MANUAL)
16785807Snate@binkert.org                0x2: decode OP_HI {
16795807Snate@binkert.org                    0x0: decode OP_LO {
16805807Snate@binkert.org                        format LoadIndexedMemory {
16815807Snate@binkert.org                            0x0: lwx({{ Rd = Mem; }});
16825807Snate@binkert.org                            0x4: lhx({{ Rd = Mem_sh; }});
16835807Snate@binkert.org                            0x6: lbux({{ Rd = Mem_ub; }});
16845807Snate@binkert.org                        }
16855807Snate@binkert.org                    }
16865807Snate@binkert.org                }
16875807Snate@binkert.org                0x4: DspIntOp::insv({{
16885807Snate@binkert.org                    int pos = dspctl<5:0>;
16895807Snate@binkert.org                    int size = dspctl<12:7> - 1;
16905807Snate@binkert.org                    Rt = insertBits(Rt, pos + size, pos, Rs<size:0>);
16912292SN/A                }});
16926221Snate@binkert.org            }
16932292SN/A
16942292SN/A            0x2: decode FUNCTION_LO {
16956221Snate@binkert.org
16966221Snate@binkert.org                //Table 5-5 MIPS32 ADDU.QB Encoding of the op Field
16976221Snate@binkert.org                //(DSP ASE MANUAL)
16986221Snate@binkert.org                0x0: decode OP_HI {
16992292SN/A                    0x0: decode OP_LO {
17002292SN/A                        format DspIntOp {
17012292SN/A                            0x0: addu_qb({{
17026221Snate@binkert.org                                Rd = dspAdd(Rs, Rt, SIMD_FMT_QB,
17032292SN/A                                            NOSATURATE, UNSIGNED, &dspctl);
17042292SN/A                            }});
17052292SN/A                            0x1: subu_qb({{
17062292SN/A                                Rd = dspSub(Rs, Rt, SIMD_FMT_QB,
17072292SN/A                                            NOSATURATE, UNSIGNED, &dspctl);
17082292SN/A                            }});
17092292SN/A                            0x4: addu_s_qb({{
17102292SN/A                                Rd = dspAdd(Rs, Rt, SIMD_FMT_QB,
17112292SN/A                                            SATURATE, UNSIGNED, &dspctl);
17122292SN/A                            }});
17136221Snate@binkert.org                            0x5: subu_s_qb({{
17146221Snate@binkert.org                                Rd = dspSub(Rs, Rt, SIMD_FMT_QB,
17152292SN/A                                            SATURATE, UNSIGNED, &dspctl);
17162292SN/A                            }});
17172292SN/A                            0x6: muleu_s_ph_qbl({{
17182292SN/A                                Rd = dspMuleu(Rs, Rt, MODE_L, &dspctl);
17192292SN/A                            }}, IntMultOp);
17202292SN/A                            0x7: muleu_s_ph_qbr({{
17212292SN/A                                Rd = dspMuleu(Rs, Rt, MODE_R, &dspctl);
17222292SN/A                            }}, IntMultOp);
17232292SN/A                        }
17242292SN/A                    }
17252292SN/A                    0x1: decode OP_LO {
17262292SN/A                        format DspIntOp {
17276221Snate@binkert.org                            0x0: addu_ph({{
17282292SN/A                                Rd = dspAdd(Rs, Rt, SIMD_FMT_PH,
17292292SN/A                                            NOSATURATE, UNSIGNED, &dspctl);
17306221Snate@binkert.org                            }});
17312292SN/A                            0x1: subu_ph({{
17322292SN/A                                Rd = dspSub(Rs, Rt, SIMD_FMT_PH,
17332292SN/A                                            NOSATURATE, UNSIGNED, &dspctl);
17342292SN/A                            }});
17352292SN/A                            0x2: addq_ph({{
17362292SN/A                                Rd = dspAdd(Rs, Rt, SIMD_FMT_PH,
17372292SN/A                                            NOSATURATE, SIGNED, &dspctl);
17382292SN/A                            }});
17391060SN/A                            0x3: subq_ph({{
17401755SN/A                                Rd = dspSub(Rs, Rt, SIMD_FMT_PH,
17412818Sksewell@umich.edu                                            NOSATURATE, SIGNED, &dspctl);
1742                            }});
1743                            0x4: addu_s_ph({{
1744                                Rd = dspAdd(Rs, Rt, SIMD_FMT_PH,
1745                                            SATURATE, UNSIGNED, &dspctl);
1746                            }});
1747                            0x5: subu_s_ph({{
1748                                Rd = dspSub(Rs, Rt, SIMD_FMT_PH,
1749                                            SATURATE, UNSIGNED, &dspctl);
1750                            }});
1751                            0x6: addq_s_ph({{
1752                                Rd = dspAdd(Rs, Rt, SIMD_FMT_PH,
1753                                            SATURATE, SIGNED, &dspctl);
1754                            }});
1755                            0x7: subq_s_ph({{
1756                                Rd = dspSub(Rs, Rt, SIMD_FMT_PH,
1757                                            SATURATE, SIGNED, &dspctl);
1758                            }});
1759                        }
1760                    }
1761                    0x2: decode OP_LO {
1762                        format DspIntOp {
1763                            0x0: addsc({{
1764                                int64_t dresult;
1765                                dresult = Rs_ud + Rt_ud;
1766                                Rd = dresult<31:0>;
1767                                dspctl = insertBits(dspctl, 13, 13,
1768                                                    dresult<32:32>);
1769                            }});
1770                            0x1: addwc({{
1771                                int64_t dresult;
1772                                dresult = Rs_sd + Rt_sd + dspctl<13:13>;
1773                                Rd = dresult<31:0>;
1774                                if (dresult<32:32> != dresult<31:31>)
1775                                    dspctl = insertBits(dspctl, 20, 20, 1);
1776                            }});
1777                            0x2: modsub({{
1778                                Rd = (Rs_sw == 0) ? Rt_sw<23:8> :
1779                                                       Rs_sw - Rt_sw<7:0>;
1780                            }});
1781                            0x4: raddu_w_qb({{
1782                                Rd = Rs<31:24> + Rs<23:16> +
1783                                     Rs<15:8> + Rs<7:0>;
1784                            }});
1785                            0x6: addq_s_w({{
1786                                Rd = dspAdd(Rs_sw, Rt_sw, SIMD_FMT_W,
1787                                               SATURATE, SIGNED, &dspctl);
1788                            }});
1789                            0x7: subq_s_w({{
1790                                Rd = dspSub(Rs_sw, Rt_sw, SIMD_FMT_W,
1791                                               SATURATE, SIGNED, &dspctl);
1792                            }});
1793                        }
1794                    }
1795                    0x3: decode OP_LO {
1796                        format DspIntOp {
1797                            0x4: muleq_s_w_phl({{
1798                                Rd = dspMuleq(Rs_sw, Rt_sw,
1799                                                 MODE_L, &dspctl);
1800                            }}, IntMultOp);
1801                            0x5: muleq_s_w_phr({{
1802                                Rd = dspMuleq(Rs_sw, Rt_sw,
1803                                                 MODE_R, &dspctl);
1804                            }}, IntMultOp);
1805                            0x6: mulq_s_ph({{
1806                                Rd = dspMulq(Rs_sw, Rt_sw, SIMD_FMT_PH,
1807                                                SATURATE, NOROUND, &dspctl);
1808                            }}, IntMultOp);
1809                            0x7: mulq_rs_ph({{
1810                                Rd = dspMulq(Rs_sw, Rt_sw, SIMD_FMT_PH,
1811                                                SATURATE, ROUND, &dspctl);
1812                            }}, IntMultOp);
1813                        }
1814                    }
1815                }
1816
1817                //Table 5-6 MIPS32 CMPU_EQ_QB Encoding of the op Field
1818                //(DSP ASE MANUAL)
1819                0x1: decode OP_HI {
1820                    0x0: decode OP_LO {
1821                        format DspIntOp {
1822                            0x0: cmpu_eq_qb({{
1823                                dspCmp(Rs, Rt, SIMD_FMT_QB,
1824                                       UNSIGNED, CMP_EQ, &dspctl);
1825                            }});
1826                            0x1: cmpu_lt_qb({{
1827                                dspCmp(Rs, Rt, SIMD_FMT_QB,
1828                                       UNSIGNED, CMP_LT, &dspctl);
1829                            }});
1830                            0x2: cmpu_le_qb({{
1831                                dspCmp(Rs, Rt, SIMD_FMT_QB,
1832                                       UNSIGNED, CMP_LE, &dspctl);
1833                            }});
1834                            0x3: pick_qb({{
1835                                Rd = dspPick(Rs, Rt, SIMD_FMT_QB, &dspctl);
1836                            }});
1837                            0x4: cmpgu_eq_qb({{
1838                                Rd = dspCmpg(Rs, Rt, SIMD_FMT_QB,
1839                                             UNSIGNED, CMP_EQ );
1840                            }});
1841                            0x5: cmpgu_lt_qb({{
1842                                Rd = dspCmpg(Rs, Rt, SIMD_FMT_QB,
1843                                             UNSIGNED, CMP_LT);
1844                            }});
1845                            0x6: cmpgu_le_qb({{
1846                                Rd = dspCmpg(Rs, Rt, SIMD_FMT_QB,
1847                                             UNSIGNED, CMP_LE);
1848                            }});
1849                        }
1850                    }
1851                    0x1: decode OP_LO {
1852                        format DspIntOp {
1853                            0x0: cmp_eq_ph({{
1854                                dspCmp(Rs, Rt, SIMD_FMT_PH,
1855                                       SIGNED, CMP_EQ, &dspctl);
1856                            }});
1857                            0x1: cmp_lt_ph({{
1858                                dspCmp(Rs, Rt, SIMD_FMT_PH,
1859                                       SIGNED, CMP_LT, &dspctl);
1860                            }});
1861                            0x2: cmp_le_ph({{
1862                                dspCmp(Rs, Rt, SIMD_FMT_PH,
1863                                       SIGNED, CMP_LE, &dspctl);
1864                            }});
1865                            0x3: pick_ph({{
1866                                Rd = dspPick(Rs, Rt, SIMD_FMT_PH, &dspctl);
1867                            }});
1868                            0x4: precrq_qb_ph({{
1869                                Rd = Rs<31:24> << 24 | Rs<15:8> << 16 |
1870                                     Rt<31:24> << 8 | Rt<15:8>;
1871                            }});
1872                            0x5: precr_qb_ph({{
1873                                Rd = Rs<23:16> << 24 | Rs<7:0> << 16 |
1874                                     Rt<23:16> << 8 | Rt<7:0>;
1875                            }});
1876                            0x6: packrl_ph({{
1877                                Rd = dspPack(Rs, Rt, SIMD_FMT_PH);
1878                            }});
1879                            0x7: precrqu_s_qb_ph({{
1880                                Rd = dspPrecrqu(Rs, Rt, &dspctl);
1881                            }});
1882                        }
1883                    }
1884                    0x2: decode OP_LO {
1885                        format DspIntOp {
1886                            0x4: precrq_ph_w({{
1887                                Rd = Rs<31:16> << 16 | Rt<31:16>;
1888                            }});
1889                            0x5: precrq_rs_ph_w({{
1890                                Rd = dspPrecrq(Rs, Rt, SIMD_FMT_W, &dspctl);
1891                            }});
1892                        }
1893                    }
1894                    0x3: decode OP_LO {
1895                        format DspIntOp {
1896                            0x0: cmpgdu_eq_qb({{
1897                                Rd = dspCmpgd(Rs, Rt, SIMD_FMT_QB,
1898                                              UNSIGNED, CMP_EQ, &dspctl);
1899                            }});
1900                            0x1: cmpgdu_lt_qb({{
1901                                Rd = dspCmpgd(Rs, Rt, SIMD_FMT_QB,
1902                                              UNSIGNED, CMP_LT, &dspctl);
1903                            }});
1904                            0x2: cmpgdu_le_qb({{
1905                                Rd = dspCmpgd(Rs, Rt, SIMD_FMT_QB,
1906                                              UNSIGNED, CMP_LE, &dspctl);
1907                            }});
1908                            0x6: precr_sra_ph_w({{
1909                                Rt = dspPrecrSra(Rt, Rs, RD,
1910                                                 SIMD_FMT_W, NOROUND);
1911                            }});
1912                            0x7: precr_sra_r_ph_w({{
1913                                Rt = dspPrecrSra(Rt, Rs, RD,
1914                                                 SIMD_FMT_W, ROUND);
1915                            }});
1916                        }
1917                    }
1918                }
1919
1920                //Table 5-7 MIPS32 ABSQ_S.PH Encoding of the op Field
1921                //(DSP ASE MANUAL)
1922                0x2: decode OP_HI {
1923                    0x0: decode OP_LO {
1924                        format DspIntOp {
1925                            0x1: absq_s_qb({{
1926                                Rd = dspAbs(Rt_sw, SIMD_FMT_QB, &dspctl);
1927                            }});
1928                            0x2: repl_qb({{
1929                                Rd = RS_RT<7:0> << 24 | RS_RT<7:0> << 16 |
1930                                     RS_RT<7:0> << 8 | RS_RT<7:0>;
1931                            }});
1932                            0x3: replv_qb({{
1933                                Rd = Rt<7:0> << 24 | Rt<7:0> << 16 |
1934                                     Rt<7:0> << 8 | Rt<7:0>;
1935                            }});
1936                            0x4: precequ_ph_qbl({{
1937                                Rd = dspPrece(Rt, SIMD_FMT_QB, UNSIGNED,
1938                                              SIMD_FMT_PH, SIGNED, MODE_L);
1939                            }});
1940                            0x5: precequ_ph_qbr({{
1941                                Rd = dspPrece(Rt, SIMD_FMT_QB, UNSIGNED,
1942                                              SIMD_FMT_PH, SIGNED, MODE_R);
1943                            }});
1944                            0x6: precequ_ph_qbla({{
1945                                Rd = dspPrece(Rt, SIMD_FMT_QB, UNSIGNED,
1946                                              SIMD_FMT_PH, SIGNED, MODE_LA);
1947                            }});
1948                            0x7: precequ_ph_qbra({{
1949                                Rd = dspPrece(Rt, SIMD_FMT_QB, UNSIGNED,
1950                                              SIMD_FMT_PH, SIGNED, MODE_RA);
1951                            }});
1952                        }
1953                    }
1954                    0x1: decode OP_LO {
1955                        format DspIntOp {
1956                            0x1: absq_s_ph({{
1957                                Rd = dspAbs(Rt_sw, SIMD_FMT_PH, &dspctl);
1958                            }});
1959                            0x2: repl_ph({{
1960                                Rd = (sext<10>(RS_RT))<15:0> << 16 |
1961                                        (sext<10>(RS_RT))<15:0>;
1962                            }});
1963                            0x3: replv_ph({{
1964                                Rd = Rt<15:0> << 16 | Rt<15:0>;
1965                            }});
1966                            0x4: preceq_w_phl({{
1967                                Rd = dspPrece(Rt, SIMD_FMT_PH, SIGNED,
1968                                              SIMD_FMT_W, SIGNED, MODE_L);
1969                            }});
1970                            0x5: preceq_w_phr({{
1971                                Rd = dspPrece(Rt, SIMD_FMT_PH, SIGNED,
1972                                              SIMD_FMT_W, SIGNED, MODE_R);
1973                            }});
1974                        }
1975                    }
1976                    0x2: decode OP_LO {
1977                        format DspIntOp {
1978                            0x1: absq_s_w({{
1979                                Rd = dspAbs(Rt_sw, SIMD_FMT_W, &dspctl);
1980                            }});
1981                        }
1982                    }
1983                    0x3: decode OP_LO {
1984                        0x3: IntOp::bitrev({{
1985                            Rd = bitrev(Rt<15:0>);
1986                        }});
1987                        format DspIntOp {
1988                            0x4: preceu_ph_qbl({{
1989                                Rd = dspPrece(Rt, SIMD_FMT_QB,
1990                                              UNSIGNED, SIMD_FMT_PH,
1991                                                 UNSIGNED, MODE_L);
1992                            }});
1993                            0x5: preceu_ph_qbr({{
1994                                Rd = dspPrece(Rt, SIMD_FMT_QB,
1995                                              UNSIGNED, SIMD_FMT_PH,
1996                                                 UNSIGNED, MODE_R );
1997                            }});
1998                            0x6: preceu_ph_qbla({{
1999                                Rd = dspPrece(Rt, SIMD_FMT_QB,
2000                                              UNSIGNED, SIMD_FMT_PH,
2001                                              UNSIGNED, MODE_LA );
2002                            }});
2003                            0x7: preceu_ph_qbra({{
2004                                Rd = dspPrece(Rt, SIMD_FMT_QB,
2005                                              UNSIGNED, SIMD_FMT_PH,
2006                                                 UNSIGNED, MODE_RA);
2007                            }});
2008                        }
2009                    }
2010                }
2011
2012                //Table 5-8 MIPS32 SHLL.QB Encoding of the op Field
2013                //(DSP ASE MANUAL)
2014                0x3: decode OP_HI {
2015                    0x0: decode OP_LO {
2016                        format DspIntOp {
2017                            0x0: shll_qb({{
2018                                Rd = dspShll(Rt_sw, RS, SIMD_FMT_QB,
2019                                             NOSATURATE, UNSIGNED, &dspctl);
2020                            }});
2021                            0x1: shrl_qb({{
2022                                Rd = dspShrl(Rt_sw, RS, SIMD_FMT_QB,
2023                                             UNSIGNED);
2024                            }});
2025                            0x2: shllv_qb({{
2026                                Rd = dspShll(Rt_sw, Rs_sw, SIMD_FMT_QB,
2027                                             NOSATURATE, UNSIGNED, &dspctl);
2028                            }});
2029                            0x3: shrlv_qb({{
2030                                Rd = dspShrl(Rt_sw, Rs_sw, SIMD_FMT_QB,
2031                                             UNSIGNED);
2032                            }});
2033                            0x4: shra_qb({{
2034                                Rd = dspShra(Rt_sw, RS, SIMD_FMT_QB,
2035                                             NOROUND, SIGNED, &dspctl);
2036                            }});
2037                            0x5: shra_r_qb({{
2038                                Rd = dspShra(Rt_sw, RS, SIMD_FMT_QB,
2039                                             ROUND, SIGNED, &dspctl);
2040                            }});
2041                            0x6: shrav_qb({{
2042                                Rd = dspShra(Rt_sw, Rs_sw, SIMD_FMT_QB,
2043                                             NOROUND, SIGNED, &dspctl);
2044                            }});
2045                            0x7: shrav_r_qb({{
2046                                Rd = dspShra(Rt_sw, Rs_sw, SIMD_FMT_QB,
2047                                             ROUND, SIGNED, &dspctl);
2048                            }});
2049                        }
2050                    }
2051                    0x1: decode OP_LO {
2052                        format DspIntOp {
2053                            0x0: shll_ph({{
2054                                Rd = dspShll(Rt, RS, SIMD_FMT_PH,
2055                                             NOSATURATE, SIGNED, &dspctl);
2056                            }});
2057                            0x1: shra_ph({{
2058                                Rd = dspShra(Rt_sw, RS, SIMD_FMT_PH,
2059                                             NOROUND, SIGNED, &dspctl);
2060                            }});
2061                            0x2: shllv_ph({{
2062                                Rd = dspShll(Rt_sw, Rs_sw, SIMD_FMT_PH,
2063                                             NOSATURATE, SIGNED, &dspctl);
2064                            }});
2065                            0x3: shrav_ph({{
2066                                Rd = dspShra(Rt_sw, Rs_sw, SIMD_FMT_PH,
2067                                             NOROUND, SIGNED, &dspctl);
2068                            }});
2069                            0x4: shll_s_ph({{
2070                                Rd = dspShll(Rt_sw, RS, SIMD_FMT_PH,
2071                                             SATURATE, SIGNED, &dspctl);
2072                            }});
2073                            0x5: shra_r_ph({{
2074                                Rd = dspShra(Rt_sw, RS, SIMD_FMT_PH,
2075                                             ROUND, SIGNED, &dspctl);
2076                            }});
2077                            0x6: shllv_s_ph({{
2078                                Rd = dspShll(Rt_sw, Rs_sw, SIMD_FMT_PH,
2079                                             SATURATE, SIGNED, &dspctl);
2080                            }});
2081                            0x7: shrav_r_ph({{
2082                                Rd = dspShra(Rt_sw, Rs_sw, SIMD_FMT_PH,
2083                                             ROUND, SIGNED, &dspctl);
2084                            }});
2085                        }
2086                    }
2087                    0x2: decode OP_LO {
2088                        format DspIntOp {
2089                            0x4: shll_s_w({{
2090                                Rd = dspShll(Rt_sw, RS, SIMD_FMT_W,
2091                                             SATURATE, SIGNED, &dspctl);
2092                            }});
2093                            0x5: shra_r_w({{
2094                                Rd = dspShra(Rt_sw, RS, SIMD_FMT_W,
2095                                             ROUND, SIGNED, &dspctl);
2096                            }});
2097                            0x6: shllv_s_w({{
2098                                Rd = dspShll(Rt_sw, Rs_sw, SIMD_FMT_W,
2099                                             SATURATE, SIGNED, &dspctl);
2100                            }});
2101                            0x7: shrav_r_w({{
2102                                Rd = dspShra(Rt_sw, Rs_sw, SIMD_FMT_W,
2103                                             ROUND, SIGNED, &dspctl);
2104                            }});
2105                        }
2106                    }
2107                    0x3: decode OP_LO {
2108                        format DspIntOp {
2109                            0x1: shrl_ph({{
2110                                Rd = dspShrl(Rt_sw, RS, SIMD_FMT_PH,
2111                                             UNSIGNED);
2112                            }});
2113                            0x3: shrlv_ph({{
2114                                Rd = dspShrl(Rt_sw, Rs_sw, SIMD_FMT_PH,
2115                                             UNSIGNED);
2116                            }});
2117                        }
2118                    }
2119                }
2120            }
2121
2122            0x3: decode FUNCTION_LO {
2123
2124                //Table 3.12 MIPS32 ADDUH.QB Encoding of the op Field
2125                //(DSP ASE Rev2 Manual)
2126                0x0: decode OP_HI {
2127                    0x0: decode OP_LO {
2128                        format DspIntOp {
2129                            0x0: adduh_qb({{
2130                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_QB,
2131                                             NOROUND, UNSIGNED);
2132                            }});
2133                            0x1: subuh_qb({{
2134                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_QB,
2135                                             NOROUND, UNSIGNED);
2136                            }});
2137                            0x2: adduh_r_qb({{
2138                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_QB,
2139                                             ROUND, UNSIGNED);
2140                            }});
2141                            0x3: subuh_r_qb({{
2142                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_QB,
2143                                             ROUND, UNSIGNED);
2144                            }});
2145                        }
2146                    }
2147                    0x1: decode OP_LO {
2148                        format DspIntOp {
2149                            0x0: addqh_ph({{
2150                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_PH,
2151                                             NOROUND, SIGNED);
2152                            }});
2153                            0x1: subqh_ph({{
2154                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_PH,
2155                                             NOROUND, SIGNED);
2156                            }});
2157                            0x2: addqh_r_ph({{
2158                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_PH,
2159                                             ROUND, SIGNED);
2160                            }});
2161                            0x3: subqh_r_ph({{
2162                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_PH,
2163                                             ROUND, SIGNED);
2164                            }});
2165                            0x4: mul_ph({{
2166                                Rd = dspMul(Rs_sw, Rt_sw, SIMD_FMT_PH,
2167                                            NOSATURATE, &dspctl);
2168                            }}, IntMultOp);
2169                            0x6: mul_s_ph({{
2170                                Rd = dspMul(Rs_sw, Rt_sw, SIMD_FMT_PH,
2171                                            SATURATE, &dspctl);
2172                            }}, IntMultOp);
2173                        }
2174                    }
2175                    0x2: decode OP_LO {
2176                        format DspIntOp {
2177                            0x0: addqh_w({{
2178                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_W,
2179                                             NOROUND, SIGNED);
2180                            }});
2181                            0x1: subqh_w({{
2182                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_W,
2183                                             NOROUND, SIGNED);
2184                            }});
2185                            0x2: addqh_r_w({{
2186                                Rd = dspAddh(Rs_sw, Rt_sw, SIMD_FMT_W,
2187                                             ROUND, SIGNED);
2188                            }});
2189                            0x3: subqh_r_w({{
2190                                Rd = dspSubh(Rs_sw, Rt_sw, SIMD_FMT_W,
2191                                             ROUND, SIGNED);
2192                            }});
2193                            0x6: mulq_s_w({{
2194                                Rd = dspMulq(Rs_sw, Rt_sw, SIMD_FMT_W,
2195                                             SATURATE, NOROUND, &dspctl);
2196                            }}, IntMultOp);
2197                            0x7: mulq_rs_w({{
2198                                Rd = dspMulq(Rs_sw, Rt_sw, SIMD_FMT_W,
2199                                             SATURATE, ROUND, &dspctl);
2200                            }}, IntMultOp);
2201                        }
2202                    }
2203                }
2204            }
2205
2206            //Table A-10 MIPS32 BSHFL Encoding of sa Field
2207            0x4: decode SA {
2208                format BasicOp {
2209                    0x02: wsbh({{
2210                        Rd = Rt<23:16> << 24 | Rt<31:24> << 16 |
2211                             Rt<7:0> << 8 | Rt<15:8>;
2212                    }});
2213                    0x10: seb({{ Rd = Rt_sb; }});
2214                    0x18: seh({{ Rd = Rt_sh; }});
2215                }
2216            }
2217
2218            0x6: decode FUNCTION_LO {
2219
2220                //Table 5-10 MIPS32 DPAQ.W.PH Encoding of the op Field
2221                //(DSP ASE MANUAL)
2222                0x0: decode OP_HI {
2223                    0x0: decode OP_LO {
2224                        format DspHiLoOp {
2225                            0x0: dpa_w_ph({{
2226                                dspac = dspDpa(dspac, Rs_sw, Rt_sw, ACDST,
2227                                               SIMD_FMT_PH, SIGNED, MODE_L);
2228                            }}, IntMultOp);
2229                            0x1: dps_w_ph({{
2230                                dspac = dspDps(dspac, Rs_sw, Rt_sw, ACDST,
2231                                               SIMD_FMT_PH, SIGNED, MODE_L);
2232                            }}, IntMultOp);
2233                            0x2: mulsa_w_ph({{
2234                                dspac = dspMulsa(dspac, Rs_sw, Rt_sw,
2235                                                 ACDST, SIMD_FMT_PH );
2236                            }}, IntMultOp);
2237                            0x3: dpau_h_qbl({{
2238                                dspac = dspDpa(dspac, Rs_sw, Rt_sw, ACDST,
2239                                               SIMD_FMT_QB, UNSIGNED, MODE_L);
2240                            }}, IntMultOp);
2241                            0x4: dpaq_s_w_ph({{
2242                                dspac = dspDpaq(dspac, Rs_sw, Rt_sw,
2243                                                ACDST, SIMD_FMT_PH,
2244                                                SIMD_FMT_W, NOSATURATE,
2245                                                MODE_L, &dspctl);
2246                            }}, IntMultOp);
2247                            0x5: dpsq_s_w_ph({{
2248                                dspac = dspDpsq(dspac, Rs_sw, Rt_sw,
2249                                                ACDST, SIMD_FMT_PH,
2250                                                SIMD_FMT_W, NOSATURATE,
2251                                                MODE_L, &dspctl);
2252                            }}, IntMultOp);
2253                            0x6: mulsaq_s_w_ph({{
2254                                dspac = dspMulsaq(dspac, Rs_sw, Rt_sw,
2255                                                  ACDST, SIMD_FMT_PH,
2256                                                  &dspctl);
2257                            }}, IntMultOp);
2258                            0x7: dpau_h_qbr({{
2259                                dspac = dspDpa(dspac, Rs_sw, Rt_sw, ACDST,
2260                                               SIMD_FMT_QB, UNSIGNED, MODE_R);
2261                            }}, IntMultOp);
2262                        }
2263                    }
2264                    0x1: decode OP_LO {
2265                        format DspHiLoOp {
2266                            0x0: dpax_w_ph({{
2267                                dspac = dspDpa(dspac, Rs_sw, Rt_sw, ACDST,
2268                                               SIMD_FMT_PH, SIGNED, MODE_X);
2269                            }}, IntMultOp);
2270                            0x1: dpsx_w_ph({{
2271                                dspac = dspDps(dspac, Rs_sw, Rt_sw, ACDST,
2272                                               SIMD_FMT_PH, SIGNED, MODE_X);
2273                            }}, IntMultOp);
2274                            0x3: dpsu_h_qbl({{
2275                                dspac = dspDps(dspac, Rs_sw, Rt_sw, ACDST,
2276                                               SIMD_FMT_QB, UNSIGNED, MODE_L);
2277                            }}, IntMultOp);
2278                            0x4: dpaq_sa_l_w({{
2279                                dspac = dspDpaq(dspac, Rs_sw, Rt_sw,
2280                                                ACDST, SIMD_FMT_W,
2281                                                SIMD_FMT_L, SATURATE,
2282                                                MODE_L, &dspctl);
2283                            }}, IntMultOp);
2284                            0x5: dpsq_sa_l_w({{
2285                                dspac = dspDpsq(dspac, Rs_sw, Rt_sw,
2286                                                ACDST, SIMD_FMT_W,
2287                                                SIMD_FMT_L, SATURATE,
2288                                                MODE_L, &dspctl);
2289                            }}, IntMultOp);
2290                            0x7: dpsu_h_qbr({{
2291                                dspac = dspDps(dspac, Rs_sw, Rt_sw, ACDST,
2292                                               SIMD_FMT_QB, UNSIGNED, MODE_R);
2293                            }}, IntMultOp);
2294                        }
2295                    }
2296                    0x2: decode OP_LO {
2297                        format DspHiLoOp {
2298                            0x0: maq_sa_w_phl({{
2299                                dspac = dspMaq(dspac, Rs, Rt,
2300                                               ACDST, SIMD_FMT_PH,
2301                                               MODE_L, SATURATE, &dspctl);
2302                            }}, IntMultOp);
2303                            0x2: maq_sa_w_phr({{
2304                                dspac = dspMaq(dspac, Rs, Rt,
2305                                               ACDST, SIMD_FMT_PH,
2306                                               MODE_R, SATURATE, &dspctl);
2307                            }}, IntMultOp);
2308                            0x4: maq_s_w_phl({{
2309                                dspac = dspMaq(dspac, Rs, Rt,
2310                                               ACDST, SIMD_FMT_PH,
2311                                               MODE_L, NOSATURATE, &dspctl);
2312                            }}, IntMultOp);
2313                            0x6: maq_s_w_phr({{
2314                                dspac = dspMaq(dspac, Rs, Rt,
2315                                               ACDST, SIMD_FMT_PH,
2316                                               MODE_R, NOSATURATE, &dspctl);
2317                            }}, IntMultOp);
2318                        }
2319                    }
2320                    0x3: decode OP_LO {
2321                        format DspHiLoOp {
2322                            0x0: dpaqx_s_w_ph({{
2323                                dspac = dspDpaq(dspac, Rs_sw, Rt_sw,
2324                                                ACDST, SIMD_FMT_PH,
2325                                                SIMD_FMT_W, NOSATURATE,
2326                                                MODE_X, &dspctl);
2327                            }}, IntMultOp);
2328                            0x1: dpsqx_s_w_ph({{
2329                                dspac = dspDpsq(dspac, Rs_sw, Rt_sw,
2330                                                ACDST, SIMD_FMT_PH,
2331                                                SIMD_FMT_W, NOSATURATE,
2332                                                MODE_X, &dspctl);
2333                            }}, IntMultOp);
2334                            0x2: dpaqx_sa_w_ph({{
2335                                dspac = dspDpaq(dspac, Rs_sw, Rt_sw,
2336                                                ACDST, SIMD_FMT_PH,
2337                                                SIMD_FMT_W, SATURATE,
2338                                                MODE_X, &dspctl);
2339                            }}, IntMultOp);
2340                            0x3: dpsqx_sa_w_ph({{
2341                                dspac = dspDpsq(dspac, Rs_sw, Rt_sw,
2342                                                ACDST, SIMD_FMT_PH,
2343                                                SIMD_FMT_W, SATURATE,
2344                                                MODE_X, &dspctl);
2345                            }}, IntMultOp);
2346                        }
2347                    }
2348                }
2349
2350                //Table 3.3 MIPS32 APPEND Encoding of the op Field
2351                0x1: decode OP_HI {
2352                    0x0: decode OP_LO {
2353                        format IntOp {
2354                            0x0: append({{
2355                                Rt = (Rt << RD) | bits(Rs, RD - 1, 0);
2356                                }});
2357                            0x1: prepend({{
2358                                Rt = (Rt >> RD) |
2359                                        (bits(Rs, RD - 1, 0) << (32 - RD));
2360                            }});
2361                        }
2362                    }
2363                    0x2: decode OP_LO {
2364                        format IntOp {
2365                            0x0: balign({{
2366                                Rt = (Rt << (8 * BP)) | (Rs >> (8 * (4 - BP)));
2367                            }});
2368                        }
2369                    }
2370                }
2371
2372            }
2373            0x7: decode FUNCTION_LO {
2374
2375                //Table 5-11 MIPS32 EXTR.W Encoding of the op Field
2376                //(DSP ASE MANUAL)
2377                0x0: decode OP_HI {
2378                    0x0: decode OP_LO {
2379                        format DspHiLoOp {
2380                            0x0: extr_w({{
2381                                Rt = dspExtr(dspac, SIMD_FMT_W, RS,
2382                                             NOROUND, NOSATURATE, &dspctl);
2383                            }});
2384                            0x1: extrv_w({{
2385                                Rt = dspExtr(dspac, SIMD_FMT_W, Rs,
2386                                             NOROUND, NOSATURATE, &dspctl);
2387                            }});
2388                            0x2: extp({{
2389                                Rt = dspExtp(dspac, RS, &dspctl);
2390                            }});
2391                            0x3: extpv({{
2392                                Rt = dspExtp(dspac, Rs, &dspctl);
2393                            }});
2394                            0x4: extr_r_w({{
2395                                Rt = dspExtr(dspac, SIMD_FMT_W, RS,
2396                                             ROUND, NOSATURATE, &dspctl);
2397                            }});
2398                            0x5: extrv_r_w({{
2399                                Rt = dspExtr(dspac, SIMD_FMT_W, Rs,
2400                                             ROUND, NOSATURATE, &dspctl);
2401                            }});
2402                            0x6: extr_rs_w({{
2403                                Rt = dspExtr(dspac, SIMD_FMT_W, RS,
2404                                             ROUND, SATURATE, &dspctl);
2405                            }});
2406                            0x7: extrv_rs_w({{
2407                                Rt = dspExtr(dspac, SIMD_FMT_W, Rs,
2408                                             ROUND, SATURATE, &dspctl);
2409                            }});
2410                        }
2411                    }
2412                    0x1: decode OP_LO {
2413                        format DspHiLoOp {
2414                            0x2: extpdp({{
2415                                Rt = dspExtpd(dspac, RS, &dspctl);
2416                            }});
2417                            0x3: extpdpv({{
2418                                Rt = dspExtpd(dspac, Rs, &dspctl);
2419                            }});
2420                            0x6: extr_s_h({{
2421                                Rt = dspExtr(dspac, SIMD_FMT_PH, RS,
2422                                             NOROUND, SATURATE, &dspctl);
2423                            }});
2424                            0x7: extrv_s_h({{
2425                                Rt = dspExtr(dspac, SIMD_FMT_PH, Rs,
2426                                             NOROUND, SATURATE, &dspctl);
2427                            }});
2428                        }
2429                    }
2430                    0x2: decode OP_LO {
2431                        format DspIntOp {
2432                            0x2: rddsp({{
2433                                Rd = readDSPControl(&dspctl, RDDSPMASK);
2434                            }});
2435                            0x3: wrdsp({{
2436                                writeDSPControl(&dspctl, Rs, WRDSPMASK);
2437                            }});
2438                        }
2439                    }
2440                    0x3: decode OP_LO {
2441                        format DspHiLoOp {
2442                            0x2: shilo({{
2443                                        if ((int64_t)sext<6>(HILOSA) < 0) {
2444                                    dspac = (uint64_t)dspac <<
2445                                                -sext<6>(HILOSA);
2446                                } else {
2447                                    dspac = (uint64_t)dspac >>
2448                                                sext<6>(HILOSA);
2449                                }
2450                            }});
2451                            0x3: shilov({{
2452                                        if ((int64_t)sext<6>(Rs_sw<5:0>) < 0) {
2453                                    dspac = (uint64_t)dspac <<
2454                                                -sext<6>(Rs_sw<5:0>);
2455                                } else {
2456                                    dspac = (uint64_t)dspac >>
2457                                                sext<6>(Rs_sw<5:0>);
2458                                }
2459                            }});
2460                            0x7: mthlip({{
2461                                dspac = dspac << 32;
2462                                dspac |= Rs;
2463                                dspctl = insertBits(dspctl, 5, 0,
2464                                                    dspctl<5:0> + 32);
2465                            }});
2466                        }
2467                    }
2468                }
2469                0x3: decode OP default FailUnimpl::rdhwr() {
2470                    0x0: decode FullSystemInt {
2471                        0: decode RD {
2472                            29: BasicOp::rdhwr_se({{ Rt = TpValue; }});
2473                        }
2474                    }
2475                }
2476            }
2477        }
2478    }
2479
2480    0x4: decode OPCODE_LO {
2481        format LoadMemory {
2482          0x0: lb({{ Rt = Mem_sb; }});
2483          0x1: lh({{ Rt = Mem_sh; }});
2484            0x3: lw({{ Rt = Mem_sw; }});
2485            0x4: lbu({{ Rt = Mem_ub;}});
2486            0x5: lhu({{ Rt = Mem_uh; }});
2487        }
2488
2489        format LoadUnalignedMemory {
2490            0x2: lwl({{
2491                uint32_t mem_shift = 24 - (8 * byte_offset);
2492                Rt = mem_word << mem_shift | (Rt & mask(mem_shift));
2493            }});
2494            0x6: lwr({{
2495                uint32_t mem_shift = 8 * byte_offset;
2496                Rt = (Rt & (mask(mem_shift) << (32 - mem_shift))) |
2497                        (mem_word >> mem_shift);
2498            }});
2499        }
2500    }
2501
2502    0x5: decode OPCODE_LO {
2503        format StoreMemory {
2504            0x0: sb({{ Mem_ub = Rt<7:0>; }});
2505            0x1: sh({{ Mem_uh = Rt<15:0>; }});
2506            0x3: sw({{ Mem = Rt<31:0>; }});
2507        }
2508
2509        format StoreUnalignedMemory {
2510            0x2: swl({{
2511                uint32_t reg_shift = 24 - (8 * byte_offset);
2512                uint32_t mem_shift = 32 - reg_shift;
2513                mem_word = (mem_word & (mask(reg_shift) << mem_shift)) |
2514                           (Rt >> reg_shift);
2515                }});
2516            0x6: swr({{
2517                uint32_t reg_shift = 8 * byte_offset;
2518                mem_word = Rt << reg_shift |
2519                           (mem_word & (mask(reg_shift)));
2520            }});
2521        }
2522        format CP0Control {
2523            0x7: cache({{
2524                //Addr CacheEA = Rs + OFFSET;
2525                //fault = xc->CacheOp((uint8_t)CACHE_OP,(Addr) CacheEA);
2526            }});
2527        }
2528    }
2529
2530    0x6: decode OPCODE_LO {
2531        format LoadMemory {
2532            0x0: ll({{ Rt = Mem; }}, mem_flags=LLSC);
2533            0x1: lwc1({{ Ft_uw = Mem; }});
2534            0x5: ldc1({{ Ft_ud = Mem_ud; }});
2535        }
2536        0x2: CP2Unimpl::lwc2();
2537        0x6: CP2Unimpl::ldc2();
2538        0x3: Prefetch::pref();
2539    }
2540
2541
2542    0x7: decode OPCODE_LO {
2543        0x0: StoreCond::sc({{ Mem = Rt; }},
2544                           {{ uint64_t tmp = write_result;
2545                              Rt = (tmp == 0 || tmp == 1) ? tmp : Rt;
2546                           }}, mem_flags=LLSC,
2547                               inst_flags = IsStoreConditional);
2548        format StoreMemory {
2549            0x1: swc1({{ Mem = Ft_uw; }});
2550            0x5: sdc1({{ Mem_ud = Ft_ud; }});
2551        }
2552        0x2: CP2Unimpl::swc2();
2553        0x6: CP2Unimpl::sdc2();
2554    }
2555}
2556
2557
2558