blob: 0d5490ad9cc1f3b4dc568456112d89d651816309 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- X86InstrExtension.td - Sign and Zero Extensions ----*- tablegen -*-===//
2//
Chris Lattner2c065e12010-10-05 06:52:35 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jia Liu31d157a2012-02-18 12:03:15 +00007//
Chris Lattner2c065e12010-10-05 06:52:35 +00008//===----------------------------------------------------------------------===//
9//
10// This file describes the sign and zero extension operations.
11//
12//===----------------------------------------------------------------------===//
13
14let neverHasSideEffects = 1 in {
15 let Defs = [AX], Uses = [AL] in
16 def CBW : I<0x98, RawFrm, (outs), (ins),
17 "{cbtw|cbw}", []>, OpSize; // AX = signext(AL)
18 let Defs = [EAX], Uses = [AX] in
19 def CWDE : I<0x98, RawFrm, (outs), (ins),
20 "{cwtl|cwde}", []>; // EAX = signext(AX)
21
22 let Defs = [AX,DX], Uses = [AX] in
23 def CWD : I<0x99, RawFrm, (outs), (ins),
24 "{cwtd|cwd}", []>, OpSize; // DX:AX = signext(AX)
25 let Defs = [EAX,EDX], Uses = [EAX] in
26 def CDQ : I<0x99, RawFrm, (outs), (ins),
27 "{cltd|cdq}", []>; // EDX:EAX = signext(EAX)
28
29
30 let Defs = [RAX], Uses = [EAX] in
31 def CDQE : RI<0x98, RawFrm, (outs), (ins),
32 "{cltq|cdqe}", []>; // RAX = signext(EAX)
33
34 let Defs = [RAX,RDX], Uses = [RAX] in
35 def CQO : RI<0x99, RawFrm, (outs), (ins),
36 "{cqto|cqo}", []>; // RDX:RAX = signext(RAX)
37}
38
39
Andrew Trick9fd58f02012-02-29 19:44:41 +000040
Chris Lattner2c065e12010-10-05 06:52:35 +000041// Sign/Zero extenders
Stuart Hastings0e29ed02011-05-20 19:04:40 +000042def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +000043 "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_R8>,
44 TB, OpSize;
Stuart Hastings0e29ed02011-05-20 19:04:40 +000045def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +000046 "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_M8>,
47 TB, OpSize;
Stuart Hastings0e29ed02011-05-20 19:04:40 +000048def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8:$src),
Chris Lattner2c065e12010-10-05 06:52:35 +000049 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000050 [(set GR32:$dst, (sext GR8:$src))], IIC_MOVSX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000051def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
52 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000053 [(set GR32:$dst, (sextloadi32i8 addr:$src))], IIC_MOVSX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000054def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
55 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000056 [(set GR32:$dst, (sext GR16:$src))], IIC_MOVSX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000057def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
58 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000059 [(set GR32:$dst, (sextloadi32i16 addr:$src))], IIC_MOVSX>,
60 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000061
Stuart Hastings0e29ed02011-05-20 19:04:40 +000062def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +000063 "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_R8>,
64 TB, OpSize;
Stuart Hastings0e29ed02011-05-20 19:04:40 +000065def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +000066 "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_M8>,
67 TB, OpSize;
Chris Lattner2c065e12010-10-05 06:52:35 +000068def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
69 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000070 [(set GR32:$dst, (zext GR8:$src))], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000071def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
72 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000073 [(set GR32:$dst, (zextloadi32i8 addr:$src))], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000074def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
75 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000076 [(set GR32:$dst, (zext GR16:$src))], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000077def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
78 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000079 [(set GR32:$dst, (zextloadi32i16 addr:$src))], IIC_MOVZX>,
80 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000081
82// These are the same as the regular MOVZX32rr8 and MOVZX32rm8
83// except that they use GR32_NOREX for the output operand register class
84// instead of GR32. This allows them to operate on h registers on x86-64.
85def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
Jakob Stoklund Olesenb66f1842011-10-07 20:15:54 +000086 (outs GR32_NOREX:$dst), (ins GR8_NOREX:$src),
Chris Lattner4164f6b2010-11-01 04:44:29 +000087 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000088 [], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000089let mayLoad = 1 in
90def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
Jakob Stoklund Olesenb66f1842011-10-07 20:15:54 +000091 (outs GR32_NOREX:$dst), (ins i8mem_NOREX:$src),
Chris Lattner4164f6b2010-11-01 04:44:29 +000092 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +000093 [], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000094
95// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
96// operand, which makes it a rare instruction with an 8-bit register
97// operand that can never access an h register. If support for h registers
98// were generalized, this would require a special register class.
99def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
100 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000101 [(set GR64:$dst, (sext GR8:$src))], IIC_MOVSX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000102def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
103 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000104 [(set GR64:$dst, (sextloadi64i8 addr:$src))], IIC_MOVSX>,
105 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000106def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
107 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000108 [(set GR64:$dst, (sext GR16:$src))], IIC_MOVSX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000109def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
110 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000111 [(set GR64:$dst, (sextloadi64i16 addr:$src))], IIC_MOVSX>,
112 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000113def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
114 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000115 [(set GR64:$dst, (sext GR32:$src))], IIC_MOVSX>;
Chris Lattner2c065e12010-10-05 06:52:35 +0000116def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
117 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Andrew Trick9fd58f02012-02-29 19:44:41 +0000118 [(set GR64:$dst, (sextloadi64i32 addr:$src))], IIC_MOVSX>;
Chris Lattner2c065e12010-10-05 06:52:35 +0000119
120// movzbq and movzwq encodings for the disassembler
121def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000122 "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
123 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000124def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000125 "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
126 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000127def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000128 "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
129 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000130def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000131 "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
132 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000133
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000134// FIXME: These should be Pat patterns.
135let isCodeGenOnly = 1 in {
136
Chris Lattner2c065e12010-10-05 06:52:35 +0000137// Use movzbl instead of movzbq when the destination is a register; it's
138// equivalent due to implicit zero-extending, and it has a smaller encoding.
139def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000140 "", [(set GR64:$dst, (zext GR8:$src))], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000141def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000142 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))], IIC_MOVZX>,
143 TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000144// Use movzwl instead of movzwq when the destination is a register; it's
145// equivalent due to implicit zero-extending, and it has a smaller encoding.
146def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000147 "", [(set GR64:$dst, (zext GR16:$src))], IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000148def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000149 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))],
150 IIC_MOVZX>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +0000151
152// There's no movzlq instruction, but movl can be used for this purpose, using
153// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
154// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
155// zero-extension, however this isn't possible when the 32-bit value is
156// defined by a truncate or is copied from something where the high bits aren't
157// necessarily all zero. In such cases, we fall back to these explicit zext
158// instructions.
159def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000160 "", [(set GR64:$dst, (zext GR32:$src))], IIC_MOVZX>;
Chris Lattner2c065e12010-10-05 06:52:35 +0000161def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Andrew Trick9fd58f02012-02-29 19:44:41 +0000162 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))],
163 IIC_MOVZX>;
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000164}
Chris Lattner2c065e12010-10-05 06:52:35 +0000165