two_byte_opcodes.isa revision 10593:a39de7b8d2c9
1// Copyright (c) 2007-2008 The Hewlett-Packard Development Company
2// All rights reserved.
3//
4// The license below extends only to copyright in the software and shall
5// not be construed as granting a license to any other intellectual
6// property including but not limited to intellectual property relating
7// to a hardware implementation of the functionality of the software
8// licensed hereunder.  You may use the software subject to the license
9// terms below provided that you ensure that this notice is replicated
10// unmodified and in its entirety in all distributions of the software,
11// modified or unmodified, in source code or in binary form.
12//
13// Copyright (c) 2008 The Regents of The University of Michigan
14// All rights reserved.
15//
16// Redistribution and use in source and binary forms, with or without
17// modification, are permitted provided that the following conditions are
18// met: redistributions of source code must retain the above copyright
19// notice, this list of conditions and the following disclaimer;
20// redistributions in binary form must reproduce the above copyright
21// notice, this list of conditions and the following disclaimer in the
22// documentation and/or other materials provided with the distribution;
23// neither the name of the copyright holders nor the names of its
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Authors: Gabe Black
40
41////////////////////////////////////////////////////////////////////
42//
43// Decode the two byte opcodes
44//
45'X86ISA::TwoByteOpcode': decode OPCODE_OP_TOP5 {
46    format WarnUnimpl {
47        0x00: decode OPCODE_OP_BOTTOM3 {
48            //0x00: group6();
49            0x00: decode MODRM_REG {
50                0x0: sldt_Mw_or_Rv();
51                0x1: str_Mw_or_Rv();
52                0x2: Inst::LLDT(Ew);
53                0x3: Inst::LTR(Ew);
54                0x4: verr_Mw_or_Rv();
55                0x5: verw_Mw_or_Rv();
56                //0x6: jmpe_Ev(); // IA-64
57                default: Inst::UD2();
58            }
59            //0x01: group7(); // Ugly, ugly, ugly...
60            0x01: decode MODRM_REG {
61                0x0: decode MODRM_MOD {
62                    0x3: decode MODRM_RM {
63                        0x1: vmcall();
64                        0x2: vmlaunch();
65                        0x3: vmresume();
66                        0x4: vmxoff();
67                        default: Inst::UD2();
68                    }
69                    default: sgdt_Ms();
70                }
71                0x1: decode MODRM_MOD {
72                    0x3: decode MODRM_RM {
73                        0x0: MonitorInst::monitor({{
74                           xc->armMonitor(Rax);
75                        }});
76                        0x1: MwaitInst::mwait({{
77                           uint64_t m = 0;          //mem
78                           unsigned s = 0x8;        //size
79                           unsigned f = 0;          //flags
80                           readMemAtomic(xc, traceData,
81                                         xc->getAddrMonitor()->vAddr,
82                                         m, s, f);
83                           xc->mwaitAtomic(xc->tcBase());
84                           MicroHalt hltObj(machInst, mnemonic, 0x0);
85                           hltObj.execute(xc, traceData);
86                        }});
87                        default: Inst::UD2();
88                    }
89                    default: sidt_Ms();
90                }
91                0x2: decode MODRM_MOD {
92                    0x3: decode MODRM_RM {
93                        0x0: xgetbv();
94                        0x1: xsetbv();
95                    }
96                    default: decode MODE_SUBMODE {
97                        0x0: Inst::LGDT(M);
98                        default: decode OPSIZE {
99                            // 16 bit operand sizes are special, but only
100                            // in legacy and compatability modes.
101                            0x2: Inst::LGDT_16(M);
102                            default: Inst::LGDT(M);
103                        }
104                    }
105                }
106                0x3: decode MODRM_MOD {
107                    0x3: decode MODRM_RM {
108                        0x0: vmrun();
109                        0x1: vmmcall();
110                        0x2: vmload();
111                        0x3: vmsave();
112                        0x4: stgi();
113                        0x5: clgi();
114                        0x6: skinit();
115                        0x7: invlpga();
116                    }
117                    default: decode MODE_SUBMODE {
118                        0x0: Inst::LIDT(M);
119                        default: decode OPSIZE {
120                            // 16 bit operand sizes are special, but only
121                            // in legacy and compatability modes.
122                            0x2: Inst::LIDT_16(M);
123                            default: Inst::LIDT(M);
124                        }
125                    }
126                }
127                0x4: decode MODRM_MOD {
128                    0x3: Inst::SMSW(Rv);
129                    default: Inst::SMSW(Mw);
130                }
131                0x6: Inst::LMSW(Ew);
132                0x7: decode MODRM_MOD {
133                    0x3: decode MODRM_RM {
134                        0x0: Inst::SWAPGS();
135                        0x1: rdtscp();
136                        default: Inst::UD2();
137                    }
138                    default: Inst::INVLPG(M);
139                }
140            }
141            0x02: lar_Gv_Ew();
142            0x03: lsl_Gv_Ew();
143            // sandpile.org doesn't seem to know what this is...? We'll
144            // use it for pseudo instructions. We've got 16 bits of space
145            // to play with so there can be quite a few pseudo
146            // instructions.
147            //0x04: loadall_or_reset_or_hang();
148            0x4: decode IMMEDIATE {
149                format BasicOperate {
150                    0x00: m5arm({{
151                        PseudoInst::arm(xc->tcBase());
152                    }}, IsNonSpeculative);
153                    0x01: m5quiesce({{
154                        PseudoInst::quiesce(xc->tcBase());
155                    }}, IsNonSpeculative, IsQuiesce);
156                    0x02: m5quiesceNs({{
157                        PseudoInst::quiesceNs(xc->tcBase(), Rdi);
158                    }}, IsNonSpeculative, IsQuiesce);
159                    0x03: m5quiesceCycle({{
160                        PseudoInst::quiesceCycles(xc->tcBase(), Rdi);
161                    }}, IsNonSpeculative, IsQuiesce);
162                    0x04: m5quiesceTime({{
163                        Rax = PseudoInst::quiesceTime(xc->tcBase());
164                    }}, IsNonSpeculative);
165                    0x07: m5rpns({{
166                        Rax = PseudoInst::rpns(xc->tcBase());
167                    }}, IsNonSpeculative);
168                    0x21: m5exit({{
169                        PseudoInst::m5exit(xc->tcBase(), Rdi);
170                    }}, IsNonSpeculative);
171                    0x22: m5fail({{
172                        PseudoInst::m5fail(xc->tcBase(), Rdi, Rsi);
173                    }}, IsNonSpeculative);
174                    0x30: m5initparam({{
175                        Rax = PseudoInst::initParam(xc->tcBase());
176                    }}, IsNonSpeculative);
177                    0x31: m5loadsymbol({{
178                        PseudoInst::loadsymbol(xc->tcBase());
179                    }}, IsNonSpeculative);
180                    0x40: m5resetstats({{
181                        PseudoInst::resetstats(xc->tcBase(), Rdi, Rsi);
182                    }}, IsNonSpeculative);
183                    0x41: m5dumpstats({{
184                        PseudoInst::dumpstats(xc->tcBase(), Rdi, Rsi);
185                    }}, IsNonSpeculative);
186                    0x42: m5dumpresetstats({{
187                        PseudoInst::dumpresetstats(xc->tcBase(), Rdi, Rsi);
188                    }}, IsNonSpeculative);
189                    0x43: m5checkpoint({{
190                        PseudoInst::m5checkpoint(xc->tcBase(), Rdi, Rsi);
191                    }}, IsNonSpeculative);
192                    0x50: m5readfile({{
193                        Rax = PseudoInst::readfile(
194                            xc->tcBase(), Rdi, Rsi, Rdx);
195                    }}, IsNonSpeculative);
196                    0x51: m5debugbreak({{
197                        PseudoInst::debugbreak(xc->tcBase());
198                    }}, IsNonSpeculative);
199                    0x52: m5switchcpu({{
200                        PseudoInst::switchcpu(xc->tcBase());
201                    }}, IsNonSpeculative);
202                    0x53: m5addsymbol({{
203                        PseudoInst::addsymbol(xc->tcBase(), Rdi, Rsi);
204                    }}, IsNonSpeculative);
205                    0x54: m5panic({{
206                        panic("M5 panic instruction called at pc = %#x.\n",
207                              RIP);
208                    }}, IsNonSpeculative);
209                    0x55: m5reserved1({{
210                        warn("M5 reserved opcode 1 ignored.\n");
211                    }}, IsNonSpeculative);
212                    0x56: m5reserved2({{
213                        warn("M5 reserved opcode 2 ignored.\n");
214                    }}, IsNonSpeculative);
215                    0x57: m5reserved3({{
216                        warn("M5 reserved opcode 3 ignored.\n");
217                    }}, IsNonSpeculative);
218                    0x58: m5reserved4({{
219                        warn("M5 reserved opcode 4 ignored.\n");
220                    }}, IsNonSpeculative);
221                    0x59: m5reserved5({{
222                        warn("M5 reserved opcode 5 ignored.\n");
223                    }}, IsNonSpeculative);
224                    0x5a: m5_work_begin({{
225                        PseudoInst::workbegin(xc->tcBase(), Rdi, Rsi);
226                    }}, IsNonSpeculative);
227                    0x5b: m5_work_end({{
228                        PseudoInst::workend(xc->tcBase(), Rdi, Rsi);
229                    }}, IsNonSpeculative);
230                    default: Inst::UD2();
231                }
232            }
233            0x05: decode FullSystemInt {
234                0: SyscallInst::syscall('xc->syscall(Rax)',
235                        IsSyscall, IsNonSpeculative, IsSerializeAfter);
236                default: decode MODE_MODE {
237                    0x0: decode MODE_SUBMODE {
238                        0x0: Inst::SYSCALL_64();
239                        0x1: Inst::SYSCALL_COMPAT();
240                    }
241                    0x1: Inst::SYSCALL_LEGACY();
242                }
243            }
244            0x06: Inst::CLTS();
245            0x07: decode MODE_SUBMODE {
246                0x0: decode OPSIZE {
247                    // Return to 64 bit mode.
248                    0x8: Inst::SYSRET_TO_64();
249                    // Return to compatibility mode.
250                    default: Inst::SYSRET_TO_COMPAT();
251                }
252                default: Inst::SYSRET_NON_64();
253            }
254        }
255        0x01: decode OPCODE_OP_BOTTOM3 {
256            0x0: invd();
257            0x1: wbinvd();
258            0x2: Inst::UD2();
259            0x3: Inst::UD2();
260            0x4: Inst::UD2();
261            0x5: Inst::PREFETCH(Mb);
262            0x6: FailUnimpl::femms();
263            0x7: decode IMMEDIATE {
264                0x0C: pi2fw_Pq_Qq();
265                0x0D: pi2fd_Pq_Qq();
266                0x1C: pf2iw_Pq_Qq();
267                0x1D: pf2id_Pq_Qq();
268                0x8A: pfnacc_Pq_Qq();
269                0x8E: pfpnacc_Pq_Qq();
270                0x90: pfcmpge_Pq_Qq();
271                0x94: pfmin_Pq_Qq();
272                0x96: pfrcp_Pq_Qq();
273                0x97: pfrsqrt_Pq_Qq();
274                0x9A: Inst::PFSUB(Pq,Qq);
275                0x9E: pfadd_Pq_Qq();
276                0xA0: pfcmpgt_Pq_Qq();
277                0xA4: pfmax_Pq_Qq();
278                0xA6: pfrcpit1_Pq_Qq();
279                0xA7: pfrsqit1_Pq_Qq();
280                0xAA: Inst::PFSUBR(Pq,Qq);
281                0xAE: pfacc_Pq_Qq();
282                0xB0: pfcmpeq_Pq_Qq();
283                0xB4: Inst::PFMUL(Pq,Qq);
284                0xB6: pfrcpit2_Pq_Qq();
285                0xB7: Inst::PMULHRW(Pq,Qq);
286                0xBB: pswapd_Pq_Qq();
287                0xBF: pavgusb_Pq_Qq();
288                default: Inst::UD2();
289            }
290        }
291        format Inst{
292            0x02: decode LEGACY_DECODEVAL {
293                // no prefix
294                0x0: decode OPCODE_OP_BOTTOM3 {
295                    0x0: MOVUPS(Vo,Wo);
296                    0x1: MOVUPS(Wo,Vo);
297                    0x2: decode MODRM_MOD {
298                        0x3: MOVHLPS(Vps,VRq);
299                        default: MOVLPS(Vps,Mq);
300                    }
301                    0x3: MOVLPS(Mq,Vps);
302                    0x4: UNPCKLPS(Vps,Wq);
303                    0x5: UNPCKHPS(Vps,Wq);
304                    0x6: decode MODRM_MOD {
305                        0x3: MOVLHPS(Vps,VRq);
306                        default: MOVHPS(Vps,Mq);
307                    }
308                    0x7: MOVHPS(Mq,Vq);
309                }
310                // repe (0xF3)
311                0x4: decode OPCODE_OP_BOTTOM3 {
312                    0x0: MOVSS(Vd,Wd);
313                    0x1: MOVSS(Wd,Vd);
314                    0x2: WarnUnimpl::movsldup_Vo_Wo();
315                    0x6: WarnUnimpl::movshdup_Vo_Wo();
316                    default: UD2();
317                }
318                // operand size (0x66)
319                0x1: decode OPCODE_OP_BOTTOM3 {
320                    0x0: MOVUPD(Vo,Wo);
321                    0x1: MOVUPD(Wo,Vo);
322                    0x2: MOVLPD(Vq,Mq);
323                    0x3: MOVLPD(Mq,Vq);
324                    0x4: UNPCKLPD(Vo,Wq);
325                    0x5: UNPCKHPD(Vo,Wo);
326                    0x6: MOVHPD(Vq,Mq);
327                    0x7: MOVHPD(Mq,Vq);
328            }
329                // repne (0xF2)
330                0x8: decode OPCODE_OP_BOTTOM3 {
331                    0x0: MOVSD(Vq,Wq);
332                    0x1: MOVSD(Wq,Vq);
333                    0x2: MOVDDUP(Vo,Wq);
334                    default: UD2();
335                }
336                default: UD2();
337            }
338            0x03: decode OPCODE_OP_BOTTOM3 {
339                //group16();
340                0x0: decode MODRM_REG {
341                    0x0: WarnUnimpl::prefetch_nta();
342                    0x1: PREFETCH_T0(Mb);
343                    0x2: WarnUnimpl::prefetch_t1();
344                    0x3: WarnUnimpl::prefetch_t2();
345                    default: HINT_NOP();
346                }
347                0x1: HINT_NOP();
348                0x2: HINT_NOP();
349                0x3: HINT_NOP();
350                0x4: HINT_NOP();
351                0x5: HINT_NOP();
352                0x6: HINT_NOP();
353                0x7: HINT_NOP();
354            }
355            0x04: decode LEGACY_DECODEVAL {
356                // no prefix
357                0x0: decode OPCODE_OP_BOTTOM3 {
358                    0x0: MOV(Rd,Cd);
359                    0x1: MOV(Rd,Dd);
360                    0x2: MOV(Cd,Rd);
361                    0x3: MOV(Dd,Rd);
362                    default: UD2();
363                }
364                default: UD2();
365            }
366            0x05: decode LEGACY_DECODEVAL {
367                // no prefix
368                0x0: decode OPCODE_OP_BOTTOM3 {
369                    //These moves should really use size o (octword), but
370                    //because they are split in two, they use q (quadword).
371                    0x0: MOVAPS(Vq,Wq);
372                    0x1: MOVAPS(Wq,Vq);
373                    0x2: CVTPI2PS(Vq,Qq);
374                    0x3: WarnUnimpl::movntps_Mo_Vo();
375                    0x4: CVTTPS2PI(Pq,Wq);
376                    0x5: CVTPS2PI(Pq,Wq);
377                    0x6: UCOMISS(Vd,Wd);
378                    0x7: COMISS(Vd,Wd);
379                }
380                // repe (0xF3)
381                0x4: decode OPCODE_OP_BOTTOM3 {
382                    0x2: CVTSI2SS(Vd,Ed);
383                    0x4: CVTTSS2SI(Gd,Wd);
384                    0x5: CVTSS2SI(Gd,Wd);
385                    default: UD2();
386                }
387                // operand size (0x66)
388                0x1: decode OPCODE_OP_BOTTOM3 {
389                    0x0: MOVAPD(Vo,Wo);
390                    0x1: MOVAPD(Wo,Vo);
391                    0x2: CVTPI2PD(Vo,Qq);
392                    0x3: WarnUnimpl::movntpd_Mo_Vo();
393                    0x4: CVTTPD2PI(Pq,Wo);
394                    0x5: CVTPD2PI(Pq,Wo);
395                    0x6: UCOMISD(Vq,Wq);
396                    0x7: COMISD(Vq,Wq);
397                }
398                // repne (0xF2)
399                0x8: decode OPCODE_OP_BOTTOM3 {
400                    // The size of the V operand should be q, not dp
401                    0x2: CVTSI2SD(Vdp,Edp);
402                    // The size of the W operand should be q, not dp
403                    0x4: CVTTSD2SI(Gdp,Wdp);
404                    0x5: CVTSD2SI(Gd,Wq);
405                    default: UD2();
406                }
407                default: UD2();
408            }
409        }
410        0x06: decode OPCODE_OP_BOTTOM3 {
411            0x0: Inst::WRMSR();
412            0x1: Inst::RDTSC();
413            0x2: Inst::RDMSR();
414            0x3: rdpmc();
415            0x4: decode FullSystemInt {
416                0: SyscallInst::sysenter('xc->syscall(Rax)',
417                        IsSyscall, IsNonSpeculative, IsSerializeAfter);
418                default: sysenter();
419            }
420            0x5: sysexit();
421            0x6: Inst::UD2();
422            0x7: getsec();
423        }
424        0x07: decode OPCODE_OP_BOTTOM3 {
425            0x0: M5InternalError::error(
426                {{"Three byte opcode shouldn't be handled by "
427                  "two_byte_opcodes.isa!"}});
428            0x2: M5InternalError::error(
429                {{"Three byte opcode shouldn't be handled by "
430                  "two_byte_opcodes.isa!"}});
431            default: UD2();
432        }
433        format Inst {
434            0x08: decode OPCODE_OP_BOTTOM3 {
435                0x0: CMOVO(Gv,Ev);
436                0x1: CMOVNO(Gv,Ev);
437                0x2: CMOVB(Gv,Ev);
438                0x3: CMOVNB(Gv,Ev);
439                0x4: CMOVZ(Gv,Ev);
440                0x5: CMOVNZ(Gv,Ev);
441                0x6: CMOVBE(Gv,Ev);
442                0x7: CMOVNBE(Gv,Ev);
443            }
444            0x09: decode OPCODE_OP_BOTTOM3 {
445                0x0: CMOVS(Gv,Ev);
446                0x1: CMOVNS(Gv,Ev);
447                0x2: CMOVP(Gv,Ev);
448                0x3: CMOVNP(Gv,Ev);
449                0x4: CMOVL(Gv,Ev);
450                0x5: CMOVNL(Gv,Ev);
451                0x6: CMOVLE(Gv,Ev);
452                0x7: CMOVNLE(Gv,Ev);
453            }
454            0x0A: decode LEGACY_DECODEVAL {
455                // no prefix
456                0x0: decode OPCODE_OP_BOTTOM3 {
457                    0x0: MOVMSKPS(Gd,VRo);
458                    0x1: SQRTPS(Vo,Wo);
459                    0x2: WarnUnimpl::rqsrtps_Vo_Wo();
460                    0x3: WarnUnimpl::rcpps_Vo_Wo();
461                    0x4: ANDPS(Vo,Wo);
462                    0x5: ANDNPS(Vo,Wo);
463                    0x6: ORPS(Vo,Wo);
464                    0x7: XORPS(Vo,Wo);
465                }
466                // repe (0xF3)
467                0x4: decode OPCODE_OP_BOTTOM3 {
468                    0x1: SQRTSS(Vd,Wd);
469                    0x2: WarnUnimpl::rsqrtss_Vd_Wd();
470                    0x3: WarnUnimpl::rcpss_Vd_Wd();
471                    default: UD2();
472                }
473                // operand size (0x66)
474                0x1: decode OPCODE_OP_BOTTOM3 {
475                    0x0: MOVMSKPD(Gd,VRo);
476                    0x1: SQRTPD(Vo,Wo);
477                    0x4: ANDPD(Vo,Wo);
478                    0x5: ANDNPD(Vo,Wo);
479                    0x6: ORPD(Vo,Wo);
480                    0x7: XORPD(Vo,Wo);
481                    default: UD2();
482                }
483                // repne (0xF2)
484                0x8: decode OPCODE_OP_BOTTOM3 {
485                    0x1: SQRTSD(Vq,Wq);
486                    default: UD2();
487                }
488                default: UD2();
489            }
490            0x0B: decode LEGACY_DECODEVAL {
491                // no prefix
492                0x0: decode OPCODE_OP_BOTTOM3 {
493                    0x0: ADDPS(Vo,Wo);
494                    0x1: MULPS(Vo,Wo);
495                    0x2: CVTPS2PD(Vo,Wq);
496                    0x3: CVTDQ2PS(Vo,Wo);
497                    0x4: SUBPS(Vo,Wo);
498                    0x5: MINPS(Vo,Wo);
499                    0x6: DIVPS(Vo,Wo);
500                    0x7: MAXPS(Vo,Wo);
501                }
502                // repe (0xF3)
503                0x4: decode OPCODE_OP_BOTTOM3 {
504                    0x0: ADDSS(Vd,Wd);
505                    0x1: MULSS(Vd,Wd);
506                    0x2: CVTSS2SD(Vq,Wd);
507                    0x3: CVTTPS2DQ(Vo,Wo);
508                    0x4: SUBSS(Vd,Wd);
509                    0x5: MINSS(Vd,Wd);
510                    0x6: DIVSS(Vd,Wd);
511                    0x7: MAXSS(Vd,Wd);
512                }
513                // operand size (0x66)
514                0x1: decode OPCODE_OP_BOTTOM3 {
515                    0x0: ADDPD(Vo,Wo);
516                    0x1: MULPD(Vo,Wo);
517                    0x2: CVTPD2PS(Vo,Wo);
518                    0x3: CVTPS2DQ(Vo,Wo);
519                    0x4: SUBPD(Vo,Wo);
520                    0x5: MINPD(Vo,Wo);
521                    0x6: DIVPD(Vo,Wo);
522                    0x7: MAXPD(Vo,Wo);
523                }
524                // repne (0xF2)
525                0x8: decode OPCODE_OP_BOTTOM3 {
526                    0x0: ADDSD(Vq,Wq);
527                    0x1: MULSD(Vq,Wq);
528                    0x2: CVTSD2SS(Vd,Wq);
529                    0x4: SUBSD(Vq,Wq);
530                    0x5: MINSD(Vq,Wq);
531                    0x6: DIVSD(Vq,Wq);
532                    0x7: MAXSD(Vq,Wq);
533                    default: UD2();
534                }
535                default: UD2();
536            }
537            0x0C: decode LEGACY_DECODEVAL {
538                // no prefix
539                0x0: decode OPCODE_OP_BOTTOM3 {
540                    0x0: PUNPCKLBW(Pq,Qd);
541                    0x1: PUNPCKLWD(Pq,Qd);
542                    0x2: PUNPCKLDQ(Pq,Qd);
543                    0x3: PACKSSWB(Pq,Qq);
544                    0x4: PCMPGTB(Pq,Qq);
545                    0x5: PCMPGTW(Pq,Qq);
546                    0x6: PCMPGTD(Pq,Qq);
547                    0x7: PACKUSWB(Pq,Qq);
548                }
549                // operand size (0x66)
550                0x1: decode OPCODE_OP_BOTTOM3 {
551                    0x0: PUNPCKLBW(Vo,Wq);
552                    0x1: PUNPCKLWD(Vo,Wq);
553                    0x2: PUNPCKLDQ(Vo,Wq);
554                    0x3: PACKSSWB(Vo,Wo);
555                    0x4: PCMPGTB(Vo,Wo);
556                    0x5: PCMPGTW(Vo,Wo);
557                    0x6: PCMPGTD(Vo,Wo);
558                    0x7: PACKUSWB(Vo,Wo);
559                }
560                default: UD2();
561            }
562            0x0D: decode LEGACY_DECODEVAL {
563                // no prefix
564                0x0: decode OPCODE_OP_BOTTOM3 {
565                    0x0: PUNPCKHBW(Pq,Qq);
566                    0x1: PUNPCKHWD(Pq,Qq);
567                    0x2: PUNPCKHDQ(Pq,Qq);
568                    0x3: PACKSSDW(Pq,Qq);
569                    0x6: MOVD(Pq,Edp);
570                    0x7: MOVQ(Pq,Qq);
571                    default: UD2();
572                }
573                // repe (0xF3)
574                0x4: decode OPCODE_OP_BOTTOM3 {
575                    0x7: MOVDQU(Vo,Wo);
576                    default: UD2();
577                }
578                // operand size (0x66)
579                0x1: decode OPCODE_OP_BOTTOM3 {
580                    0x0: PUNPCKHBW(Vo,Wo);
581                    0x1: PUNPCKHWD(Vo,Wo);
582                    0x2: PUNPCKHDQ(Vo,Wo);
583                    0x3: PACKSSDW(Vo,Wo);
584                    0x4: PUNPCKLQDQ(Vo,Wq);
585                    0x5: PUNPCKHQDQ(Vo,Wq);
586                    0x6: MOVD(Vo,Edp);
587                    0x7: MOVDQA(Vo,Wo);
588                }
589                default: UD2();
590            }
591            0x0E: decode LEGACY_DECODEVAL {
592                // no prefix
593                0x0: decode OPCODE_OP_BOTTOM3 {
594                    0x0: PSHUFW(Pq,Qq,Ib);
595                    //0x1: group12_pshimw();
596                    0x1: decode MODRM_REG {
597                        0x2: PSRLW(PRq,Ib);
598                        0x4: PSRAW(PRq,Ib);
599                        0x6: PSLLW(PRq,Ib);
600                        default: UD2();
601                    }
602                    //0x2: group13_pshimd();
603                    0x2: decode MODRM_REG {
604                        0x2: PSRLD(PRq,Ib);
605                        0x4: PSRAD(PRq,Ib);
606                        0x6: PSLLD(PRq,Ib);
607                        default: UD2();
608                    }
609                    //0x3: group14_pshimq();
610                    0x3: decode MODRM_REG {
611                        0x2: PSRLQ(PRq,Ib);
612                        0x6: PSLLQ(PRq,Ib);
613                        default: Inst::UD2();
614                    }
615                    0x4: Inst::PCMPEQB(Pq,Qq);
616                    0x5: Inst::PCMPEQW(Pq,Qq);
617                    0x6: Inst::PCMPEQD(Pq,Qq);
618                    0x7: Inst::EMMS();
619                }
620                // repe (0xF3)
621                0x4: decode OPCODE_OP_BOTTOM3 {
622                    0x0: PSHUFHW(Vo,Wo,Ib);
623                    default: UD2();
624                }
625                // operand size (0x66)
626                0x1: decode OPCODE_OP_BOTTOM3 {
627                    0x0: PSHUFD(Vo,Wo,Ib);
628                    //0x1: group12_pshimw();
629                    0x1: decode MODRM_REG {
630                        0x2: PSRLW(VRo,Ib);
631                        0x4: PSRAW(VRo,Ib);
632                        0x6: PSLLW(VRo,Ib);
633                    }
634                    //0x2: group13_pshimd();
635                    0x2: decode MODRM_REG {
636                        0x2: PSRLD(VRo,Ib);
637                        0x4: PSRAD(VRo,Ib);
638                        0x6: PSLLD(VRo,Ib);
639                        default: UD2();
640                    }
641                    //0x3: group14_pshimq();
642                    0x3: decode MODRM_REG {
643                        0x2: PSRLQ(VRo,Ib);
644                        0x3: PSRLDQ(VRo,Ib);
645                        0x6: PSLLQ(VRo,Ib);
646                        0x7: PSLLDQ(VRo,Ib);
647                        default: UD2();
648                    }
649                    0x4: PCMPEQB(Vo,Wo);
650                    0x5: PCMPEQW(Vo,Wo);
651                    0x6: PCMPEQD(Vo,Wo);
652                    default: UD2();
653                }
654                // repne (0xF2)
655                0x8: decode OPCODE_OP_BOTTOM3 {
656                    0x0: PSHUFLW(Vo,Wo,Ib);
657                    default: UD2();
658                }
659                default: UD2();
660            }
661            0x0F: decode LEGACY_DECODEVAL {
662                // no prefix
663                0x0: decode OPCODE_OP_BOTTOM3 {
664                    0x0: WarnUnimpl::vmread_Edp_Gdp();
665                    0x1: WarnUnimpl::vmwrite_Gdp_Edp();
666                    0x6: MOVD(Edp,Pdp);
667                    0x7: MOVQ(Qq,Pq);
668                    default: UD2();
669                }
670                // repe (0xF3)
671                0x4: decode OPCODE_OP_BOTTOM3 {
672                    0x6: MOVQ(Vq,Wq);
673                    0x7: MOVDQU(Wo,Vo);
674                    default: UD2();
675                }
676                // operand size (0x66)
677                0x1: decode OPCODE_OP_BOTTOM3 {
678                    0x4: HADDPD(Vo,Wo);
679                    0x5: WarnUnimpl::hsubpd_Vo_Wo();
680                    0x6: MOVD(Edp,Vd);
681                    0x7: MOVDQA(Wo,Vo);
682                    default: UD2();
683                }
684                // repne (0xF2)
685                0x8: decode OPCODE_OP_BOTTOM3 {
686                    0x4: HADDPS(Vo,Wo);
687                    0x5: WarnUnimpl::hsubps_Vo_Wo();
688                    default: UD2();
689                }
690                default: UD2();
691            }
692            0x10: decode OPCODE_OP_BOTTOM3 {
693                0x0: JO(Jz);
694                0x1: JNO(Jz);
695                0x2: JB(Jz);
696                0x3: JNB(Jz);
697                0x4: JZ(Jz);
698                0x5: JNZ(Jz);
699                0x6: JBE(Jz);
700                0x7: JNBE(Jz);
701            }
702            0x11: decode OPCODE_OP_BOTTOM3 {
703                0x0: JS(Jz);
704                0x1: JNS(Jz);
705                0x2: JP(Jz);
706                0x3: JNP(Jz);
707                0x4: JL(Jz);
708                0x5: JNL(Jz);
709                0x6: JLE(Jz);
710                0x7: JNLE(Jz);
711            }
712            0x12: decode OPCODE_OP_BOTTOM3 {
713                0x0: SETO(Eb);
714                0x1: SETNO(Eb);
715                0x2: SETB(Eb);
716                0x3: SETNB(Eb);
717                0x4: SETZ(Eb);
718                0x5: SETNZ(Eb);
719                0x6: SETBE(Eb);
720                0x7: SETNBE(Eb);
721            }
722            0x13: decode OPCODE_OP_BOTTOM3 {
723                0x0: SETS(Eb);
724                0x1: SETNS(Eb);
725                0x2: SETP(Eb);
726                0x3: SETNP(Eb);
727                0x4: SETL(Eb);
728                0x5: SETNL(Eb);
729                0x6: SETLE(Eb);
730                0x7: SETNLE(Eb);
731            }
732        }
733        0x14: decode OPCODE_OP_BOTTOM3 {
734            0x0: push_fs();
735            0x1: pop_fs();
736            0x2: CPUIDInst::CPUID({{
737                CpuidResult result;
738                bool success = doCpuid(xc->tcBase(), bits(Rax, 31, 0),
739                    bits(Rcx, 31, 0), result);
740                if (success) {
741                    Rax = result.rax;
742                    Rbx = result.rbx;
743                    Rcx = result.rcx;
744                    Rdx = result.rdx;
745                } else {
746                    Rax = Rax;
747                    Rbx = Rbx;
748                    Rcx = Rcx;
749                    Rdx = Rdx;
750                }
751                }});
752            0x3: Inst::BT(Ev,Gv);
753            0x4: Inst::SHLD(Ev,Gv,Ib);
754            0x5: Inst::SHLD(Ev,Gv);
755            default: Inst::UD2();
756        }
757        0x15: decode OPCODE_OP_BOTTOM3 {
758            0x0: push_gs();
759            0x1: pop_gs();
760            0x2: rsm_smm();
761            0x3: Inst::BTS(Ev,Gv);
762            0x4: Inst::SHRD(Ev,Gv,Ib);
763            0x5: Inst::SHRD(Ev,Gv);
764            //0x6: group15();
765            0x6: decode MODRM_MOD {
766                0x3: decode MODRM_REG {
767                    0x5: BasicOperate::LFENCE(
768                                 {{/*Nothing*/}}, IsReadBarrier);
769                    0x6: BasicOperate::MFENCE(
770                                 {{/*Nothing*/}}, IsMemBarrier);
771                    0x7: BasicOperate::SFENCE(
772                                 {{/*Nothing*/}}, IsWriteBarrier);
773                    default: Inst::UD2();
774                }
775                default: decode MODRM_REG {
776                    0x0: decode OPSIZE {
777                        4: Inst::FXSAVE(M);
778                        8: Inst::FXSAVE64(M);
779                        default: fxsave();
780                    }
781                    0x1: decode OPSIZE {
782                        4: Inst::FXRSTOR(M);
783                        8: Inst::FXRSTOR64(M);
784                        default: fxrstor();
785                    }
786                    0x2: Inst::LDMXCSR(Md);
787                    0x3: Inst::STMXCSR(Md);
788                    0x4: xsave();
789                    0x5: xrstor();
790                    0x6: Inst::UD2();
791                    0x7: clflush();
792                }
793            }
794            0x7: Inst::IMUL(Gv,Ev);
795        }
796        format Inst {
797            0x16: decode OPCODE_OP_BOTTOM3 {
798                0x0: CMPXCHG(Eb,Gb);
799                0x1: CMPXCHG(Ev,Gv);
800                0x2: WarnUnimpl::lss_Gz_Mp();
801                0x3: BTR(Ev,Gv);
802                0x4: WarnUnimpl::lfs_Gz_Mp();
803                0x5: WarnUnimpl::lgs_Gz_Mp();
804                //The size of the second operand in these instructions
805                //should really be "b" or "w", but it's set to v in order
806                //to have a consistent register size. This shouldn't
807                //affect behavior.
808                0x6: MOVZX_B(Gv,Ev);
809                0x7: MOVZX_W(Gv,Ev);
810            }
811            0x17: decode OPCODE_OP_BOTTOM3 {
812                0x0: decode LEGACY_REP {
813                    0x0: WarnUnimpl::jmpe_Jz();
814                    0x1: WarnUnimpl::popcnt_Gv_Ev();
815                }
816                //0x1: group10_UD2();
817                0x1: UD2();
818                //0x2: group8_Ev_Ib();
819                0x2: decode MODRM_REG {
820                    0x4: BT(Ev,Ib);
821                    0x5: BTS(Ev,Ib);
822                    0x6: BTR(Ev,Ib);
823                    0x7: BTC(Ev,Ib);
824                    default: UD2();
825                }
826                0x3: BTC(Ev,Gv);
827                0x4: BSF(Gv,Ev);
828                0x5: BSR(Gv,Ev);
829                //The size of the second operand in these instructions
830                //should really be "b" or "w", but it's set to v in order
831                //to have a consistent register size. This shouldn't
832                //affect behavior.
833                0x6: MOVSX_B(Gv,Ev);
834                0x7: MOVSX_W(Gv,Ev);
835            }
836            0x18: decode OPCODE_OP_BOTTOM3 {
837                0x0: XADD(Eb,Gb);
838                0x1: XADD(Ev,Gv);
839                //0x7: group9();
840                0x7: decode MODRM_REG {
841                    //Also CMPXCHG16B
842                    0x1: CMPXCHG8B(Mdp);
843                    0x6: decode LEGACY_OP {
844                        0x1: WarnUnimpl::vmclear_Mq();
845                        default: decode LEGACY_REP {
846                            0x1: WarnUnimpl::vmxon_Mq();
847                            0x0: WarnUnimpl::vmptrld_Mq();
848                        }
849                    }
850                    0x7: WarnUnimpl::vmptrst_Mq();
851                    default: UD2();
852                }
853                default: decode LEGACY_DECODEVAL {
854                    // no prefix
855                    0x0: decode OPCODE_OP_BOTTOM3 {
856                        0x2: CMPPS(Vo,Wo,Ib);
857                        0x3: MOVNTI(Mdp,Gdp);
858                        0x4: PINSRW(Pq,Ew,Ib);
859                        0x5: PEXTRW(Gd,PRq,Ib);
860                        0x6: SHUFPS(Vps,Wps,Ib);
861                    }
862                    // repe (0xF3)
863                    0x4: decode OPCODE_OP_BOTTOM3 {
864                        0x2: CMPSS(Vd,Wd,Ib);
865                        default: UD2();
866                    }
867                    // operand size (0x66)
868                    0x1: decode OPCODE_OP_BOTTOM3 {
869                        0x2: CMPPD(Vo,Wo,Ib);
870                        0x4: PINSRW(Vdw,Ew,Ib);
871                        0x5: PEXTRW(Gd,VRdq,Ib);
872                        0x6: SHUFPD(Vpd,Wpd,Ib);
873                        default: UD2();
874                    }
875                    // repne (0xF2)
876                    0x8: decode OPCODE_OP_BOTTOM3 {
877                        0x2: CMPSD(Vq,Wq,Ib);
878                        default: UD2();
879                    }
880                    default: UD2();
881                }
882            }
883            0x19: decode OPSIZE {
884                4: BSWAP_D(Bd);
885                8: BSWAP_Q(Bq);
886                default: UD2();
887            }
888            0x1A: decode LEGACY_DECODEVAL {
889                // no prefix
890                0x0: decode OPCODE_OP_BOTTOM3 {
891                    0x1: PSRLW(Pq,Qq);
892                    0x2: PSRLD(Pq,Qq);
893                    0x3: PSRLQ(Pq,Qq);
894                    0x4: PADDQ(Pq,Qq);
895                    0x5: PMULLW(Pq,Qq);
896                    0x7: PMOVMSKB(Gd,PRq);
897                    default: UD2();
898                }
899                // repe (0xF3)
900                0x4: decode OPCODE_OP_BOTTOM3 {
901                    0x6: MOVQ2DQ(Vo,PRq);
902                    default: UD2();
903                }
904                // operand size (0x66)
905                0x1: decode OPCODE_OP_BOTTOM3 {
906                    0x0: WarnUnimpl::addsubpd_Vo_Wo();
907                    0x1: PSRLW(Vo,Wo);
908                    0x2: PSRLD(Vo,Wo);
909                    0x3: PSRLQ(Vo,Wo);
910                    0x4: PADDQ(Vo,Wo);
911                    0x5: PMULLW(Vo,Wo);
912                    0x6: MOVQ(Wq,Vq);
913                    0x7: PMOVMSKB(Gd,VRo);
914                }
915                // repne (0xF2)
916                0x8: decode OPCODE_OP_BOTTOM3 {
917                    0x0: WarnUnimpl::addsubps_Vo_Wo();
918                    0x6: MOVDQ2Q(Pq,VRq);
919                    default: UD2();
920                }
921                default: UD2();
922            }
923            0x1B: decode LEGACY_DECODEVAL {
924                // no prefix
925                0x0: decode OPCODE_OP_BOTTOM3 {
926                    0x0: PSUBUSB(Pq,Qq);
927                    0x1: PSUBUSW(Pq,Qq);
928                    0x2: PMINUB(Pq,Qq);
929                    0x3: PAND(Pq,Qq);
930                    0x4: PADDUSB(Pq,Qq);
931                    0x5: PADDUSW(Pq,Qq);
932                    0x6: PMAXUB(Pq,Qq);
933                    0x7: PANDN(Pq,Qq);
934                }
935                // operand size (0x66)
936                0x1: decode OPCODE_OP_BOTTOM3 {
937                    0x0: PSUBUSB(Vo,Wo);
938                    0x1: PSUBUSW(Vo,Wo);
939                    0x2: PMINUB(Vo,Wo);
940                    0x3: PAND(Vo,Wo);
941                    0x4: PADDUSB(Vo,Wo);
942                    0x5: PADDUSW(Vo,Wo);
943                    0x6: PMAXUB(Vo,Wo);
944                    0x7: PANDN(Vo,Wo);
945                }
946                default: UD2();
947            }
948            0x1C: decode LEGACY_DECODEVAL {
949                // no prefix
950                0x0: decode OPCODE_OP_BOTTOM3 {
951                    0x0: PAVGB(Pq,Qq);
952                    0x1: PSRAW(Pq,Qq);
953                    0x2: PSRAD(Pq,Qq);
954                    0x3: PAVGW(Pq,Qq);
955                    0x4: PMULHUW(Pq,Qq);
956                    0x5: PMULHW(Pq,Qq);
957                    0x7: WarnUnimpl::movntq_Mq_Pq();
958                    default: UD2();
959                }
960                // repe (0xF3)
961                0x4: decode OPCODE_OP_BOTTOM3 {
962                    0x6: CVTDQ2PD(Vo,Wq);
963                    default: UD2();
964                }
965                // operand size (0x66)
966                0x1: decode OPCODE_OP_BOTTOM3 {
967                    0x0: PAVGB(Vo,Wo);
968                    0x1: PSRAW(Vo,Wo);
969                    0x2: PSRAD(Vo,Wo);
970                    0x3: PAVGW(Vo,Wo);
971                    0x4: PMULHUW(Vo,Wo);
972                    0x5: PMULHW(Vo,Wo);
973                    0x6: CVTTPD2DQ(Vo,Wo);
974                    0x7: WarnUnimpl::movntdq_Mo_Vo();
975                }
976                // repne (0xF2)
977                0x8: decode OPCODE_OP_BOTTOM3 {
978                    0x6: CVTPD2DQ(Vo,Wo);
979                    default: UD2();
980                }
981                default: UD2();
982            }
983            0x1D: decode LEGACY_DECODEVAL {
984                // no prefix
985                0x0: decode OPCODE_OP_BOTTOM3 {
986                    0x0: PSUBSB(Pq,Qq);
987                    0x1: PSUBSW(Pq,Qq);
988                    0x2: PMINSW(Pq,Qq);
989                    0x3: POR(Pq,Qq);
990                    0x4: PADDSB(Pq,Qq);
991                    0x5: PADDSW(Pq,Qq);
992                    0x6: PMAXSW(Pq,Qq);
993                    0x7: PXOR(Pq,Qq);
994                }
995                // operand size (0x66)
996                0x1: decode OPCODE_OP_BOTTOM3 {
997                    0x0: PSUBSB(Vo,Wo);
998                    0x1: PSUBSW(Vo,Wo);
999                    0x2: PMINSW(Vo,Wo);
1000                    0x3: POR(Vo,Wo);
1001                    0x4: PADDSB(Vo,Wo);
1002                    0x5: PADDSW(Vo,Wo);
1003                    0x6: PMAXSW(Vo,Wo);
1004                    0x7: PXOR(Vo,Wo);
1005                }
1006                default: UD2();
1007            }
1008            0x1E: decode LEGACY_DECODEVAL {
1009                // no prefix
1010                0x0: decode OPCODE_OP_BOTTOM3 {
1011                    0x1: PSLLW(Pq,Qq);
1012                    0x2: PSLLD(Pq,Qq);
1013                    0x3: PSLLQ(Pq,Qq);
1014                    0x4: PMULUDQ(Pq,Qq);
1015                    0x5: PMADDWD(Pq,Qq);
1016                    0x6: PSADBW(Pq,Qq);
1017                    0x7: MASKMOVQ(Pq,PRq);
1018                    default: UD2();
1019                }
1020                // operand size (0x66)
1021                0x1: decode OPCODE_OP_BOTTOM3 {
1022                    0x1: PSLLW(Vo,Wo);
1023                    0x2: PSLLD(Vo,Wo);
1024                    0x3: PSLLQ(Vo,Wo);
1025                    0x4: PMULUDQ(Vo,Wo);
1026                    0x5: PMADDWD(Vo,Wo);
1027                    0x6: PSADBW(Vo,Wo);
1028                    0x7: MASKMOVDQU(Vo,VRo);
1029                    default: UD2();
1030                }
1031                // repne (0xF2)
1032                0x8: decode OPCODE_OP_BOTTOM3 {
1033                    0x0: WarnUnimpl::lddqu_Vo_Mo();
1034                    default: UD2();
1035                }
1036                default: UD2();
1037            }
1038            0x1F: decode LEGACY_DECODEVAL {
1039                // no prefix
1040                0x0: decode OPCODE_OP_BOTTOM3 {
1041                    0x0: PSUBB(Pq,Qq);
1042                    0x1: PSUBW(Pq,Qq);
1043                    0x2: PSUBD(Pq,Qq);
1044                    0x3: PSUBQ(Pq,Qq);
1045                    0x4: PADDB(Pq,Qq);
1046                    0x5: PADDW(Pq,Qq);
1047                    0x6: PADDD(Pq,Qq);
1048                    0x7: UD2();
1049                }
1050                // operand size (0x66)
1051                0x1: decode OPCODE_OP_BOTTOM3 {
1052                    0x0: PSUBB(Vo,Wo);
1053                    0x1: PSUBW(Vo,Wo);
1054                    0x2: PSUBD(Vo,Wo);
1055                    0x3: PSUBQ(Vo,Wo);
1056                    0x4: PADDB(Vo,Wo);
1057                    0x5: PADDW(Vo,Wo);
1058                    0x6: PADDD(Vo,Wo);
1059                    0x7: UD2();
1060                }
1061                default: UD2();
1062            }
1063        }
1064        default: FailUnimpl::twoByteOps();
1065    }
1066}
1067