blob: b061654c2ad26fc7ed48739ab136ba0fe79f950b [file] [log] [blame]
Chris Lattner2c065e12010-10-05 06:52:35 +00001//===- X86InstrExtension.td - Sign and Zero Extensions -----*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
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
40// Sign/Zero extenders
41// Use movsbl intead of movsbw; we don't care about the high 16 bits
42// of the register here. This has a smaller encoding and avoids a
43// partial-register update. Actual movsbw included for the disassembler.
44def MOVSX16rr8W : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
45 "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
46def MOVSX16rm8W : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
47 "movs{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
48def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
Stuart Hastingsb6dcf3c2011-05-19 16:59:50 +000049 "movs{bl|x}\t{$src, $dst|$dst, $src}",
50 [(set GR16:$dst, (sext GR8:$src))]>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000051def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
Stuart Hastingsb6dcf3c2011-05-19 16:59:50 +000052 "movs{bl|x}\t{$src, $dst|$dst, $src}",
53 [(set GR16:$dst, (sextloadi16i8 addr:$src))]>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000054def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
55 "movs{bl|x}\t{$src, $dst|$dst, $src}",
56 [(set GR32:$dst, (sext GR8:$src))]>, TB;
57def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
58 "movs{bl|x}\t{$src, $dst|$dst, $src}",
59 [(set GR32:$dst, (sextloadi32i8 addr:$src))]>, TB;
60def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
61 "movs{wl|x}\t{$src, $dst|$dst, $src}",
62 [(set GR32:$dst, (sext GR16:$src))]>, TB;
63def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
64 "movs{wl|x}\t{$src, $dst|$dst, $src}",
65 [(set GR32:$dst, (sextloadi32i16 addr:$src))]>, TB;
66
67// Use movzbl intead of movzbw; we don't care about the high 16 bits
68// of the register here. This has a smaller encoding and avoids a
69// partial-register update. Actual movzbw included for the disassembler.
70def MOVZX16rr8W : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
71 "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
72def MOVZX16rm8W : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
73 "movz{bw|x}\t{$src, $dst|$dst, $src}", []>, TB, OpSize;
74def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8 :$src),
Stuart Hastingsb6dcf3c2011-05-19 16:59:50 +000075 "movz{bl|x}\t{$src, $dst|$dst, $src}",
76 [(set GR16:$dst, (zext GR8:$src))]>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000077def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem :$src),
Stuart Hastingsb6dcf3c2011-05-19 16:59:50 +000078 "movz{bl|x}\t{$src, $dst|$dst, $src}",
79 [(set GR16:$dst, (zextloadi16i8 addr:$src))]>, TB;
Chris Lattner2c065e12010-10-05 06:52:35 +000080def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
81 "movz{bl|x}\t{$src, $dst|$dst, $src}",
82 [(set GR32:$dst, (zext GR8:$src))]>, TB;
83def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
84 "movz{bl|x}\t{$src, $dst|$dst, $src}",
85 [(set GR32:$dst, (zextloadi32i8 addr:$src))]>, TB;
86def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
87 "movz{wl|x}\t{$src, $dst|$dst, $src}",
88 [(set GR32:$dst, (zext GR16:$src))]>, TB;
89def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
90 "movz{wl|x}\t{$src, $dst|$dst, $src}",
91 [(set GR32:$dst, (zextloadi32i16 addr:$src))]>, TB;
92
93// These are the same as the regular MOVZX32rr8 and MOVZX32rm8
94// except that they use GR32_NOREX for the output operand register class
95// instead of GR32. This allows them to operate on h registers on x86-64.
96def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
97 (outs GR32_NOREX:$dst), (ins GR8:$src),
Chris Lattner4164f6b2010-11-01 04:44:29 +000098 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Chris Lattner2c065e12010-10-05 06:52:35 +000099 []>, TB;
100let mayLoad = 1 in
101def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
102 (outs GR32_NOREX:$dst), (ins i8mem:$src),
Chris Lattner4164f6b2010-11-01 04:44:29 +0000103 "movz{bl|x}\t{$src, $dst|$dst, $src}",
Chris Lattner2c065e12010-10-05 06:52:35 +0000104 []>, TB;
105
106// MOVSX64rr8 always has a REX prefix and it has an 8-bit register
107// operand, which makes it a rare instruction with an 8-bit register
108// operand that can never access an h register. If support for h registers
109// were generalized, this would require a special register class.
110def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
111 "movs{bq|x}\t{$src, $dst|$dst, $src}",
112 [(set GR64:$dst, (sext GR8:$src))]>, TB;
113def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
114 "movs{bq|x}\t{$src, $dst|$dst, $src}",
115 [(set GR64:$dst, (sextloadi64i8 addr:$src))]>, TB;
116def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
117 "movs{wq|x}\t{$src, $dst|$dst, $src}",
118 [(set GR64:$dst, (sext GR16:$src))]>, TB;
119def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
120 "movs{wq|x}\t{$src, $dst|$dst, $src}",
121 [(set GR64:$dst, (sextloadi64i16 addr:$src))]>, TB;
122def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
123 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
124 [(set GR64:$dst, (sext GR32:$src))]>;
125def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
126 "movs{lq|xd}\t{$src, $dst|$dst, $src}",
127 [(set GR64:$dst, (sextloadi64i32 addr:$src))]>;
128
129// movzbq and movzwq encodings for the disassembler
130def MOVZX64rr8_Q : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
131 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
132def MOVZX64rm8_Q : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
133 "movz{bq|x}\t{$src, $dst|$dst, $src}", []>, TB;
134def MOVZX64rr16_Q : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
135 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
136def MOVZX64rm16_Q : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
137 "movz{wq|x}\t{$src, $dst|$dst, $src}", []>, TB;
138
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000139// FIXME: These should be Pat patterns.
140let isCodeGenOnly = 1 in {
141
Chris Lattner2c065e12010-10-05 06:52:35 +0000142// Use movzbl instead of movzbq when the destination is a register; it's
143// equivalent due to implicit zero-extending, and it has a smaller encoding.
144def MOVZX64rr8 : I<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
145 "", [(set GR64:$dst, (zext GR8:$src))]>, TB;
146def MOVZX64rm8 : I<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
147 "", [(set GR64:$dst, (zextloadi64i8 addr:$src))]>, TB;
148// Use movzwl instead of movzwq when the destination is a register; it's
149// equivalent due to implicit zero-extending, and it has a smaller encoding.
150def MOVZX64rr16: I<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
151 "", [(set GR64:$dst, (zext GR16:$src))]>, TB;
152def MOVZX64rm16: I<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
153 "", [(set GR64:$dst, (zextloadi64i16 addr:$src))]>, TB;
154
155// There's no movzlq instruction, but movl can be used for this purpose, using
156// implicit zero-extension. The preferred way to do 32-bit-to-64-bit zero
157// extension on x86-64 is to use a SUBREG_TO_REG to utilize implicit
158// zero-extension, however this isn't possible when the 32-bit value is
159// defined by a truncate or is copied from something where the high bits aren't
160// necessarily all zero. In such cases, we fall back to these explicit zext
161// instructions.
162def MOVZX64rr32 : I<0x89, MRMDestReg, (outs GR64:$dst), (ins GR32:$src),
163 "", [(set GR64:$dst, (zext GR32:$src))]>;
164def MOVZX64rm32 : I<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
165 "", [(set GR64:$dst, (zextloadi64i32 addr:$src))]>;
166
167
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000168}
Chris Lattner2c065e12010-10-05 06:52:35 +0000169