blob: 2eb454ded21bb3d8daef5c2ac686d9cc24647155 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- X86InstrExtension.td - Sign and Zero Extensions ----*- tablegen -*-===//
2//
Chris Lattner89497a92010-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 Liub22310f2012-02-18 12:03:15 +00007//
Chris Lattner89497a92010-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 Trick6eb65282012-02-29 19:44:41 +000040
Chris Lattner89497a92010-10-05 06:52:35 +000041// Sign/Zero extenders
Craig Topperefd97042012-07-30 07:14:07 +000042let neverHasSideEffects = 1 in {
Stuart Hastings91f1d242011-05-20 19:04:40 +000043def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +000044 "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_R8>,
45 TB, OpSize;
Craig Topperefd97042012-07-30 07:14:07 +000046let mayLoad = 1 in
Stuart Hastings91f1d242011-05-20 19:04:40 +000047def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +000048 "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_M8>,
49 TB, OpSize;
Craig Topperefd97042012-07-30 07:14:07 +000050} // neverHasSideEffects = 1
Stuart Hastings91f1d242011-05-20 19:04:40 +000051def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8:$src),
Chris Lattner89497a92010-10-05 06:52:35 +000052 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000053 [(set GR32:$dst, (sext GR8:$src))], IIC_MOVSX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000054def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
55 "movs{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000056 [(set GR32:$dst, (sextloadi32i8 addr:$src))], IIC_MOVSX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000057def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
58 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000059 [(set GR32:$dst, (sext GR16:$src))], IIC_MOVSX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000060def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
61 "movs{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000062 [(set GR32:$dst, (sextloadi32i16 addr:$src))], IIC_MOVSX>,
63 TB;
Chris Lattner89497a92010-10-05 06:52:35 +000064
Craig Topperefd97042012-07-30 07:14:07 +000065let neverHasSideEffects = 1 in {
Stuart Hastings91f1d242011-05-20 19:04:40 +000066def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +000067 "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_R8>,
68 TB, OpSize;
Craig Topperefd97042012-07-30 07:14:07 +000069let mayLoad = 1 in
Stuart Hastings91f1d242011-05-20 19:04:40 +000070def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +000071 "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_M8>,
72 TB, OpSize;
Craig Topperefd97042012-07-30 07:14:07 +000073} // neverHasSideEffects = 1
Chris Lattner89497a92010-10-05 06:52:35 +000074def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
75 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000076 [(set GR32:$dst, (zext GR8:$src))], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000077def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
78 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000079 [(set GR32:$dst, (zextloadi32i8 addr:$src))], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000080def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
81 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000082 [(set GR32:$dst, (zext GR16:$src))], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000083def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
84 "movz{wl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000085 [(set GR32:$dst, (zextloadi32i16 addr:$src))], IIC_MOVZX>,
86 TB;
Chris Lattner89497a92010-10-05 06:52:35 +000087
88// These are the same as the regular MOVZX32rr8 and MOVZX32rm8
89// except that they use GR32_NOREX for the output operand register class
90// instead of GR32. This allows them to operate on h registers on x86-64.
Craig Topperc6b7ef62012-07-30 06:48:11 +000091let neverHasSideEffects = 1, isCodeGenOnly = 1 in {
Chris Lattner89497a92010-10-05 06:52:35 +000092def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
Jakob Stoklund Olesen464fcc02011-10-07 20:15:54 +000093 (outs GR32_NOREX:$dst), (ins GR8_NOREX:$src),
Chris Lattner178f4bb2010-11-01 04:44:29 +000094 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +000095 [], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +000096let mayLoad = 1 in
97def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
Jakob Stoklund Olesen464fcc02011-10-07 20:15:54 +000098 (outs GR32_NOREX:$dst), (ins i8mem_NOREX:$src),
Chris Lattner178f4bb2010-11-01 04:44:29 +000099 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000100 [], IIC_MOVZX>, TB;
Craig Topperc6b7ef62012-07-30 06:48:11 +0000101}
Chris Lattner89497a92010-10-05 06:52:35 +0000102
103// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
104// operand, which makes it a rare instruction with an 8-bit register
105// operand that can never access an h register. If support for h registers
106// were generalized, this would require a special register class.
107def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
108 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000109 [(set GR64:$dst, (sext GR8:$src))], IIC_MOVSX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000110def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
111 "movs{bq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000112 [(set GR64:$dst, (sextloadi64i8 addr:$src))], IIC_MOVSX>,
113 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000114def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
115 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000116 [(set GR64:$dst, (sext GR16:$src))], IIC_MOVSX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000117def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
118 "movs{wq|x}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000119 [(set GR64:$dst, (sextloadi64i16 addr:$src))], IIC_MOVSX>,
120 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000121def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
122 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000123 [(set GR64:$dst, (sext GR32:$src))], IIC_MOVSX>;
Chris Lattner89497a92010-10-05 06:52:35 +0000124def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
125 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
Andrew Trick6eb65282012-02-29 19:44:41 +0000126 [(set GR64:$dst, (sextloadi64i32 addr:$src))], IIC_MOVSX>;
Chris Lattner89497a92010-10-05 06:52:35 +0000127
128// movzbq and movzwq encodings for the disassembler
129def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000130 "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
131 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000132def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000133 "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
134 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000135def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000136 "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
137 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000138def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000139 "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
140 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000141
Chris Lattner9492c172010-10-31 19:15:18 +0000142// FIXME: These should be Pat patterns.
143let isCodeGenOnly = 1 in {
144
Chris Lattner89497a92010-10-05 06:52:35 +0000145// Use movzbl instead of movzbq when the destination is a register; it's
146// equivalent due to implicit zero-extending, and it has a smaller encoding.
147def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000148 "", [(set GR64:$dst, (zext GR8:$src))], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000149def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000150 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))], IIC_MOVZX>,
151 TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000152// Use movzwl instead of movzwq when the destination is a register; it's
153// equivalent due to implicit zero-extending, and it has a smaller encoding.
154def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000155 "", [(set GR64:$dst, (zext GR16:$src))], IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000156def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000157 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))],
158 IIC_MOVZX>, TB;
Chris Lattner89497a92010-10-05 06:52:35 +0000159
160// There's no movzlq instruction, but movl can be used for this purpose, using
161// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
162// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
163// zero-extension, however this isn't possible when the 32-bit value is
164// defined by a truncate or is copied from something where the high bits aren't
165// necessarily all zero. In such cases, we fall back to these explicit zext
166// instructions.
167def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000168 "", [(set GR64:$dst, (zext GR32:$src))], IIC_MOVZX>;
Chris Lattner89497a92010-10-05 06:52:35 +0000169def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
Andrew Trick6eb65282012-02-29 19:44:41 +0000170 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))],
171 IIC_MOVZX>;
Chris Lattner9492c172010-10-31 19:15:18 +0000172}
Chris Lattner89497a92010-10-05 06:52:35 +0000173