two_byte_opcodes.isa revision 5292
1// Copyright (c) 2007 The Hewlett-Packard Development Company
2// All rights reserved.
3//
4// Redistribution and use of this software in source and binary forms,
5// with or without modification, are permitted provided that the
6// following conditions are met:
7//
8// The software must be used only for Non-Commercial Use which means any
9// use which is NOT directed to receiving any direct monetary
10// compensation for, or commercial advantage from such use.  Illustrative
11// examples of non-commercial use are academic research, personal study,
12// teaching, education and corporate research & development.
13// Illustrative examples of commercial use are distributing products for
14// commercial advantage and providing services using the software for
15// commercial advantage.
16//
17// If you wish to use this software or functionality therein that may be
18// covered by patents for commercial use, please contact:
19//     Director of Intellectual Property Licensing
20//     Office of Strategy and Technology
21//     Hewlett-Packard Company
22//     1501 Page Mill Road
23//     Palo Alto, California  94304
24//
25// Redistributions of source code must retain the above copyright notice,
26// this list of conditions and the following disclaimer.  Redistributions
27// in binary form must reproduce the above copyright notice, this list of
28// conditions and the following disclaimer in the documentation and/or
29// other materials provided with the distribution.  Neither the name of
30// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31// contributors may be used to endorse or promote products derived from
32// this software without specific prior written permission.  No right of
33// sublicense is granted herewith.  Derivatives of the software and
34// output created using the software may be prepared, but only for
35// Non-Commercial Uses.  Derivatives of the software may be shared with
36// others provided: (i) the others agree to abide by the list of
37// conditions herein which includes the Non-Commercial Use restrictions;
38// and (ii) such Derivatives of the software include the above copyright
39// notice to acknowledge the contribution from this software where
40// applicable, this list of conditions and the disclaimer below.
41//
42// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53//
54// Authors: Gabe Black
55
56////////////////////////////////////////////////////////////////////
57//
58// Decode the two byte opcodes
59//
600x2: decode OPCODE_PREFIXA {
61    0x0F: decode OPCODE_OP_TOP5 {
62        format WarnUnimpl {
63            0x00: decode OPCODE_OP_BOTTOM3 {
64                //0x00: group6();
65                0x00: decode MODRM_REG {
66                    0x0: sldt_Mw_or_Rv();
67                    0x1: str_Mw_or_Rv();
68                    0x2: lldt_Mw_or_Rv();
69                    0x3: ltr_Mw_or_Rv();
70                    0x4: verr_Mw_or_Rv();
71                    0x5: verw_Mw_or_Rv();
72                    //0x6: jmpe_Ev(); // IA-64
73                    default: Inst::UD2();
74                }
75                //0x01: group7(); // Ugly, ugly, ugly...
76                0x01: decode MODRM_MOD {
77                    0x3: decode MODRM_REG {
78                        0x0: decode MODRM_RM {
79                            0x1: vmcall();
80                            0x2: vmlaunch();
81                            0x3: vmresume();
82                            0x4: vmxoff();
83                            default: Inst::UD2();
84                        }
85                        0x1: decode MODRM_RM {
86                            0x0: monitor();
87                            0x1: mwait();
88                            default: Inst::UD2();
89                        }
90                        0x3: decode MODRM_RM {
91                            0x0: vmrun();
92                            0x1: vmmcall();
93                            0x2: vmload();
94                            0x3: vmsave();
95                            0x4: stgi();
96                            0x5: clgi();
97                            0x6: skinit();
98                            0x7: invlpga();
99                        }
100                        0x4: smsw_Rv();
101                        0x6: lmsw_Rv();
102                        0x7: decode MODRM_RM {
103                            0x0: swapgs();
104                            0x1: rdtscp();
105                            default: Inst::UD2();
106                        }
107                        default: Inst::UD2();
108                    }
109                    default: decode MODRM_REG {
110                        0x0: sgdt_Ms();
111                        0x1: sidt_Ms();
112                        0x2: decode MODE_SUBMODE {
113                            0x0: Inst::LGDT(M);
114                            default: decode OPSIZE {
115                                // 16 bit operand sizes are special, but only
116                                // in legacy and compatability modes.
117                                0x2: Inst::LGDT_16(M);
118                                default: Inst::LGDT(M);
119                            }
120                        }
121                        0x3: decode MODE_SUBMODE {
122                            0x0: Inst::LIDT(M);
123                            default: decode OPSIZE {
124                                // 16 bit operand sizes are special, but only
125                                // in legacy and compatability modes.
126                                0x2: Inst::LIDT_16(M);
127                                default: Inst::LIDT(M);
128                            }
129                        }
130                        0x4: smsw_Mw();
131                        0x6: lmsw_Mw();
132                        0x7: invlpg_M();
133                        default: Inst::UD2();
134                    }
135                }
136                0x02: lar_Gv_Ew();
137                0x03: lsl_Gv_Ew();
138                //sandpile.org doesn't seem to know what this is... ?
139                0x04: loadall_or_reset_or_hang();
140#if FULL_SYSTEM
141                0x05: syscall();
142#else
143                0x05: SyscallInst::syscall('xc->syscall(rax)', IsSyscall);
144#endif
145                0x06: clts();
146                //sandpile.org says (AMD) after sysret, so I might want to check
147                //if that means amd64 or AMD machines
148                0x07: loadall_or_sysret();
149            }
150            0x01: decode OPCODE_OP_BOTTOM3 {
151                0x0: invd();
152                0x1: wbinvd();
153                0x2: Inst::UD2();
154                0x3: Inst::UD2();
155                0x4: Inst::UD2();
156                0x5: threednow();
157                0x6: threednow();
158                0x7: threednow();
159            }
160            0x02: decode LEGACY_DECODEVAL {
161                // no prefix
162                0x0: decode OPCODE_OP_BOTTOM3 {
163                    0x0: movups_Vo_Wo();
164                    0x1: movups_Wo_Vo();
165                    0x2: decode MODRM_MOD {
166                        0x3: movhlps_Vq_VRq();
167                        default: movlps_Vq_Mq();
168                    }
169                    0x3: movlps_Mq_Vq();
170                    0x4: unpcklps();
171                    0x5: unpckhps();
172                    0x6: decode MODRM_MOD {
173                        0x3: movlhps_Vq_VRq();
174                        default: movhps_Vq_Mq();
175                    }
176                    0x7: movhps_Mq_Vq();
177                }
178                // repe (0xF3)
179                0x4: decode OPCODE_OP_BOTTOM3 {
180                    0x0: movss_Vd_Wd();
181                    0x1: movss_Wd_Vd();
182                    0x2: movsldup_Vo_Wo();
183                    0x6: movshdup_Vo_Wo();
184                    default: Inst::UD2();
185                }
186                // operand size (0x66)
187                0x1: decode OPCODE_OP_BOTTOM3 {
188                    0x0: movupd_Vo_Wo();
189                    0x1: movupd_Wo_Vo();
190                    0x2: Inst::MOVLPD(Vq,Mq);
191                    0x3: Inst::MOVLPD(Mq,Vq);
192                    0x4: unpcklpd_Vo_Wq();
193                    0x5: unpckhpd_Vo_Wo();
194                    0x6: movhpd_Vq_Mq();
195                    0x7: movhpd_Mq_Vq();
196                }
197                // repne (0xF2)
198                0x8: decode OPCODE_OP_BOTTOM3 {
199                    0x0: Inst::MOVSD(Vq,Wq);
200                    0x1: Inst::MOVSD(Wq,Vq);
201                    0x2: movddup_Vo_Wq();
202                    default: Inst::UD2();
203                }
204                default: Inst::UD2();
205            }
206            0x03: decode OPCODE_OP_BOTTOM3 {
207                0x0: group17();
208                0x1: group17();
209                0x2: group17();
210                0x3: group17();
211                0x4: group17();
212                0x5: group17();
213                0x6: group17();
214                0x7: group17();
215            }
216            0x04: decode LEGACY_DECODEVAL {
217                // no prefix
218                0x0: decode OPCODE_OP_BOTTOM3 {
219                    0x0: mov_Rd_Cd();
220                    0x1: mov_Rd_Dd();
221                    0x2: Inst::MOV(Cd,Rd);
222                    0x3: mov_Dd_Rd();
223                    0x4: mov_Rd_Td();
224                    0x6: mov_Td_Rd();
225                    default: Inst::UD2();
226                }
227                // lock prefix (0xF0)
228                0x2: decode OPCODE_OP_BOTTOM3 {
229                    0x0: mov_Rd_CR8D();
230                    0x2: mov_CR8D_Rd();
231                }
232                default: Inst::UD2();
233            }
234            0x05: decode LEGACY_DECODEVAL {
235                // no prefix
236                0x0: decode OPCODE_OP_BOTTOM3 {
237                    //These moves should really use size o (octword), but
238                    //because they are split in two, they use q (quadword).
239                    0x0: Inst::MOVAPS(Vq,Wq);
240                    0x1: Inst::MOVAPS(Wq,Vq);
241                    0x2: decode MODRM_MOD {
242                        0x3: cvtpi2pS_Vq_Pq();
243                        default: cvtpi2ps_Vq_Mq();
244                    }
245                    0x3: movntps_Mo_Vo();
246                    0x4: cvttps2pi_Pq_Wq();
247                    0x5: cvtpS2pi_Pq_Wq();
248                    0x6: ucomiss_Vd_Wd();
249                    0x7: comiss_Vd_Wd();
250                }
251                // repe (0xF3)
252                0x4: decode OPCODE_OP_BOTTOM3 {
253                    0x2: cvtsi2ss_Vd_Ed();
254                    0x4: cvttss2si_Gd_Wd();
255                    0x5: cvtss2si_Gd_Wd();
256                    default: Inst::UD2();
257                }
258                // operand size (0x66)
259                0x1: decode OPCODE_OP_BOTTOM3 {
260                    0x0: movapd_Vo_Wo();
261                    0x1: movapd_Wo_Vo();
262                    0x2: decode MODRM_MOD {
263                        0x3: cvtpi2pd_Vo_Pq();
264                        default: cvtpi2pd_Vo_Mq();
265                    }
266                    0x3: movntpd_Mo_Vo();
267                    0x4: cvttpd2pi_Pq_Wo();
268                    0x5: cvtpd2pi_Pq_Wo();
269                    0x6: Inst::UCOMISD(Vq,Wq);
270                    0x7: comisd_Vq_Wq();
271                }
272                // repne (0xF2)
273                0x8: decode OPCODE_OP_BOTTOM3 {
274                    // The size of the V operand should be q, not dp
275                    0x2: Inst::CVTSI2SD(Vdp,Edp);
276                    // The size of the W operand should be q, not dp
277                    0x4: Inst::CVTTSD2SI(Gdp,Wdp);
278                    0x5: cvtsd2si_Gd_Wq();
279                    default: Inst::UD2();
280                }
281                default: Inst::UD2();
282            }
283            0x06: decode OPCODE_OP_BOTTOM3 {
284                0x0: Inst::WRMSR();
285                0x1: rdtsc();
286                0x2: Inst::RDMSR();
287                0x3: rdpmc();
288                0x4: sysenter();
289                0x5: sysexit();
290                0x6: Inst::UD2();
291                0x7: getsec();
292            }
293            0x07: decode OPCODE_OP_BOTTOM3 {
294                0x0: three_byte_opcode();
295                0x1: three_byte_opcode();
296                0x2: three_byte_opcode();
297                0x3: three_byte_opcode();
298                0x4: three_byte_opcode();
299                0x5: three_byte_opcode();
300                0x6: three_byte_opcode();
301                0x7: three_byte_opcode();
302            }
303            format Inst {
304                0x08: decode OPCODE_OP_BOTTOM3 {
305                    0x0: CMOVO(Gv,Ev);
306                    0x1: CMOVNO(Gv,Ev);
307                    0x2: CMOVB(Gv,Ev);
308                    0x3: CMOVNB(Gv,Ev);
309                    0x4: CMOVZ(Gv,Ev);
310                    0x5: CMOVNZ(Gv,Ev);
311                    0x6: CMOVBE(Gv,Ev);
312                    0x7: CMOVNBE(Gv,Ev);
313                }
314                0x09: decode OPCODE_OP_BOTTOM3 {
315                    0x0: CMOVS(Gv,Ev);
316                    0x1: CMOVNS(Gv,Ev);
317                    0x2: CMOVP(Gv,Ev);
318                    0x3: CMOVNP(Gv,Ev);
319                    0x4: CMOVL(Gv,Ev);
320                    0x5: CMOVNL(Gv,Ev);
321                    0x6: CMOVLE(Gv,Ev);
322                    0x7: CMOVNLE(Gv,Ev);
323                }
324            }
325            0x0A: decode LEGACY_DECODEVAL {
326                // no prefix
327                0x0: decode OPCODE_OP_BOTTOM3 {
328                    0x0: movmskps_Gd_VRo();
329                    0x1: sqrtps_Vo_Wo();
330                    0x2: rqsrtps_Vo_Wo();
331                    0x3: rcpps_Vo_Wo();
332                    0x4: andps_Vo_Wo();
333                    0x5: andnps_Vo_Wo();
334                    0x6: orps_Vo_Wo();
335                    0x7: xorps_Vo_Wo();
336                }
337                // repe (0xF3)
338                0x4: decode OPCODE_OP_BOTTOM3 {
339                    0x1: sqrtss_Vd_Wd();
340                    0x2: rsqrtss_Vd_Wd();
341                    0x3: rcpss_Vd_Wd();
342                    default: Inst::UD2();
343                }
344                // operand size (0x66)
345                0x1: decode OPCODE_OP_BOTTOM3 {
346                    0x0: movmskpd_Gd_VRo();
347                    0x1: sqrtpd_Vo_Wo();
348                    0x4: andpd_Vo_Wo();
349                    0x5: andnpd_Vo_Wo();
350                    0x6: orpd_Vo_Wo();
351                    //This really should be type o, but it works on q sized
352                    //chunks at a time.
353                    0x7: Inst::XORPD(Vq,Wq);
354                    default: Inst::UD2();
355                }
356                format Inst {
357                    // repne (0xF2)
358                    0x8: decode OPCODE_OP_BOTTOM3 {
359                        0x1: SQRTSD(Vq,Wq);
360                        default: UD2();
361                    }
362                    default: UD2();
363                }
364            }
365            0x0B: decode LEGACY_DECODEVAL {
366                // no prefix
367                0x0: decode OPCODE_OP_BOTTOM3 {
368                    0x0: addps_Vo_Wo();
369                    0x1: mulps_Vo_Wo();
370                    0x2: cvtps2pd_Vo_Wq();
371                    0x3: cvtdq2ps_Vo_Wo();
372                    0x4: subps_Vo_Wo();
373                    0x5: minps_Vo_Wo();
374                    0x6: divps_Vo_Wo();
375                    0x7: maxps_Vo_Wo();
376                }
377                // repe (0xF3)
378                0x4: decode OPCODE_OP_BOTTOM3 {
379                    0x0: addss_Vd_Wd();
380                    0x1: mulss_Vd_Wd();
381                    0x2: cvtss2sd_Vq_Wd();
382                    0x3: cvttps2dq_Vo_Wo();
383                    0x4: subss_Vd_Wd();
384                    0x5: minss_Vd_Wd();
385                    0x6: divss_Vd_Wd();
386                    0x7: maxss_Vd_Wd();
387                }
388                // operand size (0x66)
389                0x1: decode OPCODE_OP_BOTTOM3 {
390                    0x0: addpd_Vo_Wo();
391                    0x1: mulpd_Vo_Wo();
392                    0x2: cvtpd2ps_Vo_Wo();
393                    0x3: cvtps2dq_Vo_Wo();
394                    0x4: subpd_Vo_Wo();
395                    0x5: minpd_Vo_Wo();
396                    0x6: divpd_Vo_Wo();
397                    0x7: maxpd_Vo_Wo();
398                }
399                // repne (0xF2)
400                0x8: decode OPCODE_OP_BOTTOM3 {
401                    0x0: Inst::ADDSD(Vq,Wq);
402                    0x1: Inst::MULSD(Vq,Wq);
403                    0x2: cvtsd2ss_Vd_Wq();
404                    0x4: Inst::SUBSD(Vq,Wq);
405                    0x5: minsd_Vq_Wq();
406                    0x6: Inst::DIVSD(Vq,Wq);
407                    0x7: maxsd_Vq_Wq();
408                    default: Inst::UD2();
409                }
410                default: Inst::UD2();
411            }
412            0x0C: decode LEGACY_DECODEVAL {
413                // no prefix
414                0x0: decode OPCODE_OP_BOTTOM3 {
415                    0x0: punpcklbw_Pq_Qd();
416                    0x1: punpcklwd_Pq_Qd();
417                    0x2: punpckldq_Pq_Qd();
418                    0x3: packsswb_Pq_Qq();
419                    0x4: pcmpgtb_Pq_Qq();
420                    0x5: pcmpgtw_Pq_Qq();
421                    0x6: pcmpgtd_Pq_Qq();
422                    0x7: packuswb_Pq_Qq();
423                }
424                // operand size (0x66)
425                0x1: decode OPCODE_OP_BOTTOM3 {
426                    0x0: punpcklbw_Vo_Wq();
427                    0x1: punpcklwd_Vo_Wq();
428                    0x2: punpckldq_Vo_Wq();
429                    0x3: packsswb_Vo_Wo();
430                    0x4: pcmpgtb_Vo_Wo();
431                    0x5: pcmpgtw_Vo_Wo();
432                    0x6: pcmpgtd_Vo_Wo();
433                    0x7: packuswb_Vo_Wo();
434                }
435                default: Inst::UD2();
436            }
437            0x0D: decode LEGACY_DECODEVAL {
438                // no prefix
439                0x0: decode OPCODE_OP_BOTTOM3 {
440                    0x0: punpckhbw_Pq_Qq();
441                    0x1: punpckhwd_Pq_Qq();
442                    0x2: punpckhdq_Pq_Qq();
443                    0x3: packssdw_Pq_Qq();
444                    0x6: movd_Pq_Ed();
445                    0x7: movq_Pq_Qq();
446                    default: Inst::UD2();
447                }
448                // repe (0xF3)
449                0x4: decode OPCODE_OP_BOTTOM3 {
450                    0x7: movdqu_Vo_Wo();
451                    default: Inst::UD2();
452                }
453                // operand size (0x66)
454                0x1: decode OPCODE_OP_BOTTOM3 {
455                    0x0: punpckhbw_Vo_Wo();
456                    0x1: punpckhwd_Vo_Wo();
457                    0x2: punpckhdq_Vo_Wo();
458                    0x3: packssdw_Vo_Wo();
459                    0x4: punpcklqdq_Vo_Wq();
460                    0x5: punpcklqdq_Vo_Wq();
461                    0x6: movd_Vo_Ed();
462                    0x7: movdqa_Vo_Wo();
463                }
464                default: Inst::UD2();
465            }
466            0x0E: decode LEGACY_DECODEVAL {
467                // no prefix
468                0x0: decode OPCODE_OP_BOTTOM3 {
469                    0x0: pshufw_Pq_Qq_Ib();
470                    //0x1: group13_pshimw();
471                    0x1: decode MODRM_REG {
472                        0x2: decode LEGACY_OP {
473                            0x0: psrlw_PRq_Ib();
474                            0x1: psrlw_VRo_Ib();
475                        }
476                        0x4: decode LEGACY_OP {
477                            0x0: psraw_PRq_Ib();
478                            0x1: psraw_VRo_Ib();
479                        }
480                        0x6: decode LEGACY_OP {
481                            0x0: psllw_PRq_Ib();
482                            0x1: psllw_VRo_Ib();
483                        }
484                        default: Inst::UD2();
485                    }
486                    //0x2: group14_pshimd();
487                    0x2: decode MODRM_REG {
488                        0x2: decode LEGACY_OP {
489                            0x0: psrld_PRq_Ib();
490                            0x1: psrld_VRo_Ib();
491                        }
492                        0x4: decode LEGACY_OP {
493                            0x0: psrad_PRq_Ib();
494                            0x1: psrad_VRo_Ib();
495                        }
496                        0x6: decode LEGACY_OP {
497                            0x0: pslld_PRq_Ib();
498                            0x1: pslld_VRo_Ib();
499                        }
500                        default: Inst::UD2();
501                    }
502                    //0x3: group15_pshimq();
503                    0x3: decode MODRM_REG {
504                        0x2: decode LEGACY_OP {
505                            0x0: psrlq_PRq_Ib();
506                            0x1: psrlq_VRo_Ib();
507                        }
508                        0x3: decode LEGACY_OP {
509                            0x0: Inst::UD2();
510                            0x1: psrldq_VRo_Ib();
511                        }
512                        0x6: decode LEGACY_OP {
513                            0x0: psllq_PRq_Ib();
514                            0x1: psllq_VRo_Ib();
515                        }
516                        0x7: decode LEGACY_OP {
517                            0x0: Inst::UD2();
518                            0x1: pslldq_VRo_Ib();
519                        }
520                        default: Inst::UD2();
521                    }
522                    0x4: pcmpeqb_Pq_Qq();
523                    0x5: pcmpeqw_Pq_Qq();
524                    0x6: pcmpeqd_Pq_Qq();
525                    0x7: emms();
526                }
527                // repe (0xF3)
528                0x4: decode OPCODE_OP_BOTTOM3 {
529                    0x0: pshufhw_Vo_Wo_Ib();
530                    default: Inst::UD2();
531                }
532                // operand size (0x66)
533                0x1: decode OPCODE_OP_BOTTOM3 {
534                    0x0: pshufd_Vo_Wo_Ib();
535                    //0x1: group13_pshimw();
536                    0x1: decode MODRM_REG {
537                        0x2: decode LEGACY_OP {
538                            0x0: psrlw_PRq_Ib();
539                            0x1: psrlw_VRo_Ib();
540                        }
541                        0x4: decode LEGACY_OP {
542                            0x0: psraw_PRq_Ib();
543                            0x1: psraw_VRo_Ib();
544                        }
545                        0x6: decode LEGACY_OP {
546                            0x0: psllw_PRq_Ib();
547                            0x1: psllw_VRo_Ib();
548                        }
549                        default: Inst::UD2();
550                    }
551                    //0x2: group14_pshimd();
552                    0x2: decode MODRM_REG {
553                        0x2: decode LEGACY_OP {
554                            0x0: psrld_PRq_Ib();
555                            0x1: psrld_VRo_Ib();
556                        }
557                        0x4: decode LEGACY_OP {
558                            0x0: psrad_PRq_Ib();
559                            0x1: psrad_VRo_Ib();
560                        }
561                        0x6: decode LEGACY_OP {
562                            0x0: pslld_PRq_Ib();
563                            0x1: pslld_VRo_Ib();
564                        }
565                        default: Inst::UD2();
566                    }
567                    //0x3: group15_pshimq();
568                    0x3: decode MODRM_REG {
569                        0x2: decode LEGACY_OP {
570                            0x0: psrlq_PRq_Ib();
571                            0x1: psrlq_VRo_Ib();
572                        }
573                        0x3: decode LEGACY_OP {
574                            0x0: Inst::UD2();
575                            0x1: psrldq_VRo_Ib();
576                        }
577                        0x6: decode LEGACY_OP {
578                            0x0: psllq_PRq_Ib();
579                            0x1: psllq_VRo_Ib();
580                        }
581                        0x7: decode LEGACY_OP {
582                            0x0: Inst::UD2();
583                            0x1: pslldq_VRo_Ib();
584                        }
585                        default: Inst::UD2();
586                    }
587                    0x4: pcmpeqb_Vo_Wo();
588                    0x5: pcmpeqw_Vo_Wo();
589                    0x6: pcmpeqd_Vo_Wo();
590                    default: Inst::UD2();
591                }
592                // repne (0xF2)
593                0x8: decode OPCODE_OP_BOTTOM3 {
594                    0x0: pshuflw_Vo_Wo_Ib();
595                    default: Inst::UD2();
596                }
597                default: Inst::UD2();
598            }
599            0x0F: decode LEGACY_DECODEVAL {
600                // no prefix
601                0x0: decode OPCODE_OP_BOTTOM3 {
602                    0x0: vmread_Ed_or_Eq_Gd_or_Gq();
603                    0x1: vmwrite_Gd_or_Gq_Ed_or_Eq();
604                    0x6: mov_Ed_Pd();
605                    0x7: mov_Qq_Pq();
606                    default: Inst::UD2();
607                }
608                // repe (0xF3)
609                0x4: decode OPCODE_OP_BOTTOM3 {
610                    0x6: movq_Vo_Mq_or_Vq_Vq();
611                    0x7: movdqu_Wo_Vo();
612                    default: Inst::UD2();
613                }
614                // operand size (0x66)
615                0x1: decode OPCODE_OP_BOTTOM3 {
616                    0x4: haddpd_Vo_Wo();
617                    0x5: hsubpd_Vo_Wo();
618                    0x6: movd_Ed_Vd();
619                    0x7: movdqa_Wo_Vo();
620                    default: Inst::UD2();
621                }
622                // repne (0xF2)
623                0x8: decode OPCODE_OP_BOTTOM3 {
624                    0x4: haddps_Vo_Wo();
625                    0x5: hsubps_Vo_Wo();
626                    default: Inst::UD2();
627                }
628                default: Inst::UD2();
629            }
630            format Inst {
631                0x10: decode OPCODE_OP_BOTTOM3 {
632                    0x0: JO(Jz);
633                    0x1: JNO(Jz);
634                    0x2: JB(Jz);
635                    0x3: JNB(Jz);
636                    0x4: JZ(Jz);
637                    0x5: JNZ(Jz);
638                    0x6: JBE(Jz);
639                    0x7: JNBE(Jz);
640                }
641                0x11: decode OPCODE_OP_BOTTOM3 {
642                    0x0: JS(Jz);
643                    0x1: JNS(Jz);
644                    0x2: JP(Jz);
645                    0x3: JNP(Jz);
646                    0x4: JL(Jz);
647                    0x5: JNL(Jz);
648                    0x6: JLE(Jz);
649                    0x7: JNLE(Jz);
650                }
651                0x12: decode OPCODE_OP_BOTTOM3 {
652                    0x0: SETO(Eb);
653                    0x1: SETNO(Eb);
654                    0x2: SETB(Eb);
655                    0x3: SETNB(Eb);
656                    0x4: SETZ(Eb);
657                    0x5: SETNZ(Eb);
658                    0x6: SETBE(Eb);
659                    0x7: SETNBE(Eb);
660                }
661                0x13: decode OPCODE_OP_BOTTOM3 {
662                    0x0: SETS(Eb);
663                    0x1: SETNS(Eb);
664                    0x2: SETP(Eb);
665                    0x3: SETNP(Eb);
666                    0x4: SETL(Eb);
667                    0x5: SETNL(Eb);
668                    0x6: SETLE(Eb);
669                    0x7: SETNLE(Eb);
670                }
671            }
672            0x14: decode OPCODE_OP_BOTTOM3 {
673                0x0: push_fs();
674                0x1: pop_fs();
675                0x2: Inst::CPUID(rAd);
676                0x3: Inst::BT(Ev,Gv);
677                0x4: shld_Ev_Gv_Ib();
678                0x5: shld_Ev_Gv_rCl();
679                0x6: xbts_and_cmpxchg();
680                0x7: ibts_and_cmpxchg();
681            }
682            0x15: decode OPCODE_OP_BOTTOM3 {
683                0x0: push_gs();
684                0x1: pop_gs();
685                0x2: rsm_smm();
686                0x3: Inst::BTS(Ev,Gv);
687                0x4: shrd_Ev_Gv_Ib();
688                0x5: shrd_Ev_Gv_rCl();
689                //0x6: group16();
690                0x6: decode MODRM_MOD {
691                    0x3: decode MODRM_REG {
692                        0x5: lfence();
693                        0x6: mfence();
694                        0x7: sfence();
695                        default: Inst::UD2();
696                    }
697                    default: decode MODRM_REG {
698                        0x0: fxsave();
699                        0x1: fxrstor();
700                        0x7: clflush();
701                        default: Inst::UD2();
702                    }
703                }
704                0x7: Inst::IMUL(Gv,Ev);
705            }
706            0x16: decode OPCODE_OP_BOTTOM3 {
707                0x0: Inst::CMPXCHG(Eb,Gb);
708                0x1: Inst::CMPXCHG(Ev,Gv);
709                0x2: lss_Gz_Mp();
710                0x3: Inst::BTR(Ev,Gv);
711                0x4: lfs_Gz_Mp();
712                0x5: lgs_Gz_Mp();
713                //The size of the second operand in these instructions should
714                //really be "b" or "w", but it's set to v in order to have a
715                //consistent register size. This shouldn't affect behavior.
716                0x6: Inst::MOVZX_B(Gv,Ev);
717                0x7: Inst::MOVZX_W(Gv,Ev);
718            }
719            0x17: decode OPCODE_OP_BOTTOM3 {
720                0x0: jmpe_Jz(); // IA-64?
721                format Inst {
722                    //0x1: group11_UD2();
723                    0x1: UD2();
724                    //0x2: group8_Ev_Ib();
725                    0x2: decode MODRM_REG {
726                        0x4: BT(Ev,Ib);
727                        0x5: BTS(Ev,Ib);
728                        0x6: BTR(Ev,Ib);
729                        0x7: BTC(Ev,Ib);
730                        default: UD2();
731                    }
732                    0x3: BTC(Ev,Gv);
733                }
734                0x4: bsf_Gv_Ev();
735                0x5: bsr_Gv_Ev();
736                //The size of the second operand in these instructions should
737                //really be "b" or "w", but it's set to v in order to have a
738                //consistent register size. This shouldn't affect behavior.
739                0x6: Inst::MOVSX_B(Gv,Ev);
740                0x7: Inst::MOVSX_W(Gv,Ev);
741            }
742            0x18: decode OPCODE_OP_BOTTOM3 {
743                0x0: xadd_Eb_Gb();
744                0x1: xadd_Ev_Gv();
745                //0x7: group9();
746                0x7: decode MODRM_REG {
747                    0x1: cmpxchg_Mq();
748                    0x6: decode LEGACY_OP {
749                        0x1: vmclear_Mq();
750                        default: decode LEGACY_REP {
751                            0x1: vmxon_Mq();
752                            0x0: vmptrld_Mq();
753                        }
754                    }
755                    0x7: vmptrst_Mq();
756                    default: Inst::UD2();
757                }
758                default: decode LEGACY_DECODEVAL {
759                    // no prefix
760                    0x0: decode OPCODE_OP_BOTTOM3 {
761                        0x2: cmpccps_Vo_Wo_Ib();
762                        0x3: cvtdq2ps_Vo_Wo();
763                        0x4: subps_Vo_Wo();
764                        0x5: minps_Vo_Wo();
765                        0x6: divps_Vo_Wo();
766                    }
767                    // repe (0xF3)
768                    0x4: decode OPCODE_OP_BOTTOM3 {
769                        0x2: cmpccss_Vd_Wd_Ib();
770                        default: Inst::UD2();
771                    }
772                    // operand size (0x66)
773                    0x1: decode OPCODE_OP_BOTTOM3 {
774                        0x2: cmpccpd_Vo_Wo_Ib();
775                        0x4: subpd_Vo_Wo();
776                        0x5: minpd_Vo_Wo();
777                        0x6: divpd_Vo_Wo();
778                        default: Inst::UD2();
779                    }
780                    // repne (0xF2)
781                    0x8: decode OPCODE_OP_BOTTOM3 {
782                        0x2: cmpccsd_Vq_Wq_Ib();
783                        default: Inst::UD2();
784                    }
785                    default: Inst::UD2();
786                }
787            }
788            0x19: bswap_B();
789            0x1A: decode LEGACY_DECODEVAL {
790                // no prefix
791                0x0: decode OPCODE_OP_BOTTOM3 {
792                    0x1: psrlw_Pq_Qq();
793                    0x2: psrld_Pq_Qq();
794                    0x3: psrlq_Pq_Qq();
795                    0x4: paddq_Pq_Qq();
796                    0x5: pmullw_Pq_Qq();
797                    0x7: pmovmskb_Gd_PRq();
798                    default: Inst::UD2();
799                }
800                // repe (0xF3)
801                0x4: decode OPCODE_OP_BOTTOM3 {
802                    0x6: movq2dq_Vo_PRq();
803                    default: Inst::UD2();
804                }
805                // operand size (0x66)
806                0x1: decode OPCODE_OP_BOTTOM3 {
807                    0x0: addsubpd_Vo_Wo();
808                    0x1: psrlw_Vo_Wo();
809                    0x2: psrld_Vo_Wo();
810                    0x3: psrlq_Vo_Wo();
811                    0x4: paddq_Vo_Wo();
812                    0x5: pmullw_Vo_Wo();
813                    0x6: decode MODRM_MOD {
814                        0x3: movq_Vq_Vq();
815                        default: movq_Mq_Vq();
816                    }
817                    0x7: pmovmskb_Gd_VRo();
818                }
819                // repne (0xF2)
820                0x8: decode OPCODE_OP_BOTTOM3 {
821                    0x0: addsubps_Vo_Wo();
822                    0x6: movdq2q_Pq_VRq();
823                    default: Inst::UD2();
824                }
825                default: Inst::UD2();
826            }
827            0x1B: decode LEGACY_DECODEVAL {
828                // no prefix
829                0x0: decode OPCODE_OP_BOTTOM3 {
830                    0x0: psubusb_Pq_Qq();
831                    0x1: psubusw_Pq_Qq();
832                    0x2: pminub_Pq_Qq();
833                    0x3: pand_Pq_Qq();
834                    0x4: paddusb_Pq_Qq();
835                    0x5: paddusw_Pq_Qq();
836                    0x6: pmaxub_Pq_Qq();
837                    0x7: pandn_Pq_Qq();
838                }
839                // operand size (0x66)
840                0x1: decode OPCODE_OP_BOTTOM3 {
841                    0x0: psubusb_Vo_Wo();
842                    0x1: psubusw_Vo_Wo();
843                    0x2: pminub_Vo_Wo();
844                    0x3: pand_Vo_Wo();
845                    0x4: paddusb_Vo_Wo();
846                    0x5: paddusw_Vo_Wo();
847                    0x6: pmaxub_Vo_Wo();
848                    0x7: pandn_Vo_Wo();
849                }
850                default: Inst::UD2();
851            }
852            0x1C: decode LEGACY_DECODEVAL {
853                // no prefix
854                0x0: decode OPCODE_OP_BOTTOM3 {
855                    0x0: pavgb_Pq_Qq();
856                    0x1: psraw_Pq_Qq();
857                    0x2: psrad_Pq_Qq();
858                    0x3: pavgw_Pq_Qq();
859                    0x4: pmulhuw_Pq_Qq();
860                    0x5: pmulhw_Pq_Qq();
861                    0x7: movntq_Mq_Pq();
862                    default: Inst::UD2();
863                }
864                // repe (0xF3)
865                0x4: decode OPCODE_OP_BOTTOM3 {
866                    0x6: cvtdq2pd_Vo_Wq();
867                    default: Inst::UD2();
868                }
869                // operand size (0x66)
870                0x1: decode OPCODE_OP_BOTTOM3 {
871                    0x0: pavgb_Vo_Wo();
872                    0x1: psraw_Vo_Wo();
873                    0x2: psrad_Vo_Wo();
874                    0x3: pavgw_Vo_Wo();
875                    0x4: pmulhuw_Vo_Wo();
876                    0x5: pmulhw_Vo_Wo();
877                    0x6: cvttpd2dq_Vo_Wo();
878                    0x7: movntdq_Mo_Vo();
879                }
880                // repne (0xF2)
881                0x8: decode OPCODE_OP_BOTTOM3 {
882                    0x6: cvtpd2dq_Vo_Wo();
883                    default: Inst::UD2();
884                }
885                default: Inst::UD2();
886            }
887            0x1D: decode LEGACY_DECODEVAL {
888                // no prefix
889                0x0: decode OPCODE_OP_BOTTOM3 {
890                    0x0: psubsb_Pq_Qq();
891                    0x1: psubsw_Pq_Qq();
892                    0x2: pminsw_Pq_Qq();
893                    0x3: por_Pq_Qq();
894                    0x4: paddsb_Pq_Qq();
895                    0x5: paddsw_Pq_Qq();
896                    0x6: pmaxsw_Pq_Qq();
897                    0x7: pxor_Pq_Qq();
898                }
899                // operand size (0x66)
900                0x1: decode OPCODE_OP_BOTTOM3 {
901                    0x0: psubsb_Vo_Wo();
902                    0x1: psubsw_Vo_Wo();
903                    0x2: pminsw_Vo_Wo();
904                    0x3: por_Vo_Wo();
905                    0x4: paddsb_Vo_Wo();
906                    0x5: paddsw_Vo_Wo();
907                    0x6: pmaxsw_Vo_Wo();
908                    0x7: pxor_Vo_Wo();
909                }
910                default: Inst::UD2();
911            }
912            0x1E: decode OPCODE_OP_BOTTOM3 {
913                // no prefix
914                0x0: decode OPCODE_OP_BOTTOM3 {
915                    0x1: psllw_Pq_Qq();
916                    0x2: pslld_Pq_Qq();
917                    0x3: psllq_Pq_Qq();
918                    0x4: pmuludq_Pq_Qq();
919                    0x5: pmaddwd_Pq_Qq();
920                    0x6: psadbw_Pq_Qq();
921                    0x7: maskmovq_Pq_PRq();
922                    default: Inst::UD2();
923                }
924                // operand size (0x66)
925                0x1: decode OPCODE_OP_BOTTOM3 {
926                    0x1: psllw_Vo_Wo();
927                    0x2: pslld_Vo_Wo();
928                    0x3: psllq_Vo_Wo();
929                    0x4: pmuludq_Vo_Wo();
930                    0x5: pmaddwd_Vo_Wo();
931                    0x6: psadbw_Vo_Wo();
932                    0x7: maskmovdqu_Vo_VRo();
933                    default: Inst::UD2();
934                }
935                // repne (0xF2)
936                0x8: decode OPCODE_OP_BOTTOM3 {
937                    0x0: lddqu_Vo_Mo();
938                    default: Inst::UD2();
939                }
940                default: Inst::UD2();
941            }
942            0x1F: decode LEGACY_DECODEVAL {
943                // no prefix
944                0x0: decode OPCODE_OP_BOTTOM3 {
945                    0x0: psubb_Pq_Qq();
946                    0x1: psubw_Pq_Qq();
947                    0x2: psubd_Pq_Qq();
948                    0x3: psubq_Pq_Qq();
949                    0x4: paddb_Pq_Qq();
950                    0x5: paddw_Pq_Qq();
951                    0x6: paddd_Pq_Qq();
952                    0x7: Inst::UD2();
953                }
954                // operand size (0x66)
955                0x1: decode OPCODE_OP_BOTTOM3 {
956                    0x0: psubb_Vo_Wo();
957                    0x1: psubw_Vo_Wo();
958                    0x2: psubd_Vo_Wo();
959                    0x3: psubq_Vo_Wo();
960                    0x4: paddb_Vo_Wo();
961                    0x5: paddw_Vo_Wo();
962                    0x6: paddd_Vo_Wo();
963                    0x7: Inst::UD2();
964                }
965                default: Inst::UD2();
966            }
967            default: FailUnimpl::twoByteOps();
968        }
969    }
970    default: M5InternalError::error(
971        {{"Unexpected first opcode byte in two byte opcode!"}});
972}
973