blob: c8a588b03668a1d7cc9976a66fde00f30495de7c [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- X86InstrInfo.td - Main X86 Instruction Definition --*- tablegen -*-===//
Michael J. Spencer6e56b182010-10-20 23:40:27 +00002//
John Criswell856ba762003-10-21 15:17:13 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer6e56b182010-10-20 23:40:27 +00007//
John Criswell856ba762003-10-21 15:17:13 +00008//===----------------------------------------------------------------------===//
Chris Lattner1cca5e32003-08-03 21:54:21 +00009//
10// This file describes the X86 instruction set, defining the instructions, and
11// properties of the instructions which are needed for code generation, machine
12// code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
Evan Chengaed7c722005-12-17 01:24:02 +000016//===----------------------------------------------------------------------===//
17// X86 specific DAG Nodes.
18//
19
Evan Chenge3413162006-01-09 18:33:28 +000020def SDTIntShiftDOp: SDTypeProfile<1, 3,
21 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
22 SDTCisInt<0>, SDTCisInt<3>]>;
23
Chris Lattnere3486a42010-03-19 00:01:11 +000024def SDTX86CmpTest : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisSameAs<1, 2>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000025
Stuart Hastings865f0932011-06-03 23:53:54 +000026def SDTX86Cmpsd : SDTypeProfile<1, 3, [SDTCisVT<0, f64>, SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>;
27def SDTX86Cmpss : SDTypeProfile<1, 3, [SDTCisVT<0, f32>, SDTCisSameAs<1, 2>, SDTCisVT<3, i8>]>;
28
Evan Chenge5f62042007-09-29 00:00:36 +000029def SDTX86Cmov : SDTypeProfile<1, 4,
Evan Cheng0488db92007-09-25 01:57:46 +000030 [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
31 SDTCisVT<3, i8>, SDTCisVT<4, i32>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000032
Dan Gohman076aee32009-03-04 19:44:21 +000033// Unary and binary operator instructions that set EFLAGS as a side-effect.
Chris Lattner74c8d672010-03-24 00:47:47 +000034def SDTUnaryArithWithFlags : SDTypeProfile<2, 1,
35 [SDTCisInt<0>, SDTCisVT<1, i32>]>;
36
Chris Lattner1aec4d72010-03-24 00:49:29 +000037def SDTBinaryArithWithFlags : SDTypeProfile<2, 2,
38 [SDTCisSameAs<0, 2>,
39 SDTCisSameAs<0, 3>,
40 SDTCisInt<0>, SDTCisVT<1, i32>]>;
Chris Lattner5b856542010-12-20 00:59:46 +000041
NAKAMURA Takumie5fffe92011-01-26 02:03:37 +000042// SDTBinaryArithWithFlagsInOut - RES1, EFLAGS = op LHS, RHS, EFLAGS
Chris Lattner5b856542010-12-20 00:59:46 +000043def SDTBinaryArithWithFlagsInOut : SDTypeProfile<2, 3,
44 [SDTCisSameAs<0, 2>,
45 SDTCisSameAs<0, 3>,
46 SDTCisInt<0>,
47 SDTCisVT<1, i32>,
48 SDTCisVT<4, i32>]>;
Chris Lattnerb20e0b12010-12-05 07:30:36 +000049// RES1, RES2, FLAGS = op LHS, RHS
50def SDT2ResultBinaryArithWithFlags : SDTypeProfile<3, 2,
51 [SDTCisSameAs<0, 1>,
52 SDTCisSameAs<0, 2>,
53 SDTCisSameAs<0, 3>,
54 SDTCisInt<0>, SDTCisVT<1, i32>]>;
Evan Chenge5f62042007-09-29 00:00:36 +000055def SDTX86BrCond : SDTypeProfile<0, 3,
Evan Cheng0488db92007-09-25 01:57:46 +000056 [SDTCisVT<0, OtherVT>,
57 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Chengaed7c722005-12-17 01:24:02 +000058
Evan Chenge5f62042007-09-29 00:00:36 +000059def SDTX86SetCC : SDTypeProfile<1, 2,
Evan Cheng0488db92007-09-25 01:57:46 +000060 [SDTCisVT<0, i8>,
61 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Cheng2e489c42009-12-16 00:53:11 +000062def SDTX86SetCC_C : SDTypeProfile<1, 2,
63 [SDTCisInt<0>,
64 SDTCisVT<1, i8>, SDTCisVT<2, i32>]>;
Evan Chengd5781fc2005-12-21 20:21:51 +000065
Benjamin Kramer17c836c2012-04-27 12:07:43 +000066def SDTX86sahf : SDTypeProfile<1, 1, [SDTCisVT<0, i32>, SDTCisVT<1, i8>]>;
67
Benjamin Kramerb9bee042012-07-12 09:31:43 +000068def SDTX86rdrand : SDTypeProfile<2, 0, [SDTCisInt<0>, SDTCisVT<1, i32>]>;
69
Michael J. Spencer6e56b182010-10-20 23:40:27 +000070def SDTX86cas : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisInt<1>,
Andrew Lenharth26ed8692008-03-01 21:52:34 +000071 SDTCisVT<2, i8>]>;
Eli Friedman43f51ae2011-08-26 21:21:21 +000072def SDTX86caspair : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
Andrew Lenharth26ed8692008-03-01 21:52:34 +000073
Dale Johannesen48c1bc22008-10-02 18:53:47 +000074def SDTX86atomicBinary : SDTypeProfile<2, 3, [SDTCisInt<0>, SDTCisInt<1>,
75 SDTCisPtrTy<2>, SDTCisInt<3>,SDTCisInt<4>]>;
Chris Lattner447ff682008-03-11 03:23:40 +000076def SDTX86Ret : SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>;
Evan Cheng898101c2005-12-19 23:12:38 +000077
Sean Callanan1c97ceb2009-06-23 23:25:37 +000078def SDT_X86CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
79def SDT_X86CallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>,
80 SDTCisVT<1, i32>]>;
Evan Chenge3413162006-01-09 18:33:28 +000081
Dan Gohmand35121a2008-05-29 19:57:41 +000082def SDT_X86Call : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
Evan Chenge3413162006-01-09 18:33:28 +000083
Dan Gohmand6708ea2009-08-15 01:38:56 +000084def SDT_X86VASTART_SAVE_XMM_REGS : SDTypeProfile<0, -1, [SDTCisVT<0, i8>,
85 SDTCisVT<1, iPTR>,
86 SDTCisVT<2, iPTR>]>;
87
Dan Gohman320afb82010-10-12 18:00:49 +000088def SDT_X86VAARG_64 : SDTypeProfile<1, -1, [SDTCisPtrTy<0>,
89 SDTCisPtrTy<1>,
90 SDTCisVT<2, i32>,
91 SDTCisVT<3, i8>,
92 SDTCisVT<4, i32>]>;
93
Chris Lattnered52c8f2010-03-28 07:38:39 +000094def SDTX86RepStr : SDTypeProfile<0, 1, [SDTCisVT<0, OtherVT>]>;
95
Anton Korobeynikov043f3c22010-03-06 19:32:29 +000096def SDTX86Void : SDTypeProfile<0, 0, []>;
Evan Chengd90eb7f2006-01-05 00:27:02 +000097
Evan Cheng71fb8342006-02-25 10:02:21 +000098def SDTX86Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
99
Rafael Espindola2ee3db32009-04-17 14:35:58 +0000100def SDT_X86TLSADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000101
Hans Wennborgf0234fc2012-06-01 16:27:21 +0000102def SDT_X86TLSBASEADDR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
103
Eric Christopherd8c05362010-12-09 06:25:53 +0000104def SDT_X86TLSCALL : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
Eric Christopher30ef0e52010-06-03 04:07:48 +0000105
Rafael Espindolad07b7ec2011-08-30 19:43:21 +0000106def SDT_X86SEG_ALLOCA : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
107
Michael J. Spencer1a2d0612012-02-24 19:01:22 +0000108def SDT_X86WIN_FTOL : SDTypeProfile<0, 1, [SDTCisFP<0>]>;
109
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000110def SDT_X86EHRET : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
111
Arnold Schwaighoferc85e1712007-10-11 19:40:01 +0000112def SDT_X86TCRET : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
113
Eric Christopher9a9d2752010-07-22 02:48:34 +0000114def SDT_X86MEMBARRIER : SDTypeProfile<0, 0, []>;
Eric Christopher9a9d2752010-07-22 02:48:34 +0000115
116def X86MemBarrier : SDNode<"X86ISD::MEMBARRIER", SDT_X86MEMBARRIER,
Jakob Stoklund Olesencfe8a962012-08-24 00:31:10 +0000117 [SDNPHasChain,SDNPSideEffect]>;
Eric Christopher9a9d2752010-07-22 02:48:34 +0000118def X86MFence : SDNode<"X86ISD::MFENCE", SDT_X86MEMBARRIER,
119 [SDNPHasChain]>;
120def X86SFence : SDNode<"X86ISD::SFENCE", SDT_X86MEMBARRIER,
121 [SDNPHasChain]>;
122def X86LFence : SDNode<"X86ISD::LFENCE", SDT_X86MEMBARRIER,
123 [SDNPHasChain]>;
124
125
Chris Lattnerd486d772010-03-28 05:07:17 +0000126def X86bsf : SDNode<"X86ISD::BSF", SDTUnaryArithWithFlags>;
127def X86bsr : SDNode<"X86ISD::BSR", SDTUnaryArithWithFlags>;
Evan Chenge3413162006-01-09 18:33:28 +0000128def X86shld : SDNode<"X86ISD::SHLD", SDTIntShiftDOp>;
129def X86shrd : SDNode<"X86ISD::SHRD", SDTIntShiftDOp>;
Evan Chengb077b842005-12-21 02:39:21 +0000130
Evan Chenge5f62042007-09-29 00:00:36 +0000131def X86cmp : SDNode<"X86ISD::CMP" , SDTX86CmpTest>;
Dan Gohmanc7a37d42008-12-23 22:45:23 +0000132def X86bt : SDNode<"X86ISD::BT", SDTX86CmpTest>;
133
Evan Chenge5f62042007-09-29 00:00:36 +0000134def X86cmov : SDNode<"X86ISD::CMOV", SDTX86Cmov>;
Evan Chenge3413162006-01-09 18:33:28 +0000135def X86brcond : SDNode<"X86ISD::BRCOND", SDTX86BrCond,
Evan Cheng0488db92007-09-25 01:57:46 +0000136 [SDNPHasChain]>;
Evan Chenge5f62042007-09-29 00:00:36 +0000137def X86setcc : SDNode<"X86ISD::SETCC", SDTX86SetCC>;
Evan Cheng2e489c42009-12-16 00:53:11 +0000138def X86setcc_c : SDNode<"X86ISD::SETCC_CARRY", SDTX86SetCC_C>;
Evan Chengb077b842005-12-21 02:39:21 +0000139
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000140def X86sahf : SDNode<"X86ISD::SAHF", SDTX86sahf>;
141
Benjamin Kramerfeae00a2012-07-12 18:14:57 +0000142def X86rdrand : SDNode<"X86ISD::RDRAND", SDTX86rdrand,
143 [SDNPHasChain, SDNPSideEffect]>;
Benjamin Kramerb9bee042012-07-12 09:31:43 +0000144
Andrew Lenharth26ed8692008-03-01 21:52:34 +0000145def X86cas : SDNode<"X86ISD::LCMPXCHG_DAG", SDTX86cas,
Chris Lattner036609b2010-12-23 18:28:41 +0000146 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore,
Chris Lattner88641552010-09-22 00:34:38 +0000147 SDNPMayLoad, SDNPMemOperand]>;
Eli Friedman43f51ae2011-08-26 21:21:21 +0000148def X86cas8 : SDNode<"X86ISD::LCMPXCHG8_DAG", SDTX86caspair,
Chris Lattner036609b2010-12-23 18:28:41 +0000149 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore,
Chris Lattner88641552010-09-22 00:34:38 +0000150 SDNPMayLoad, SDNPMemOperand]>;
Eli Friedman43f51ae2011-08-26 21:21:21 +0000151def X86cas16 : SDNode<"X86ISD::LCMPXCHG16_DAG", SDTX86caspair,
152 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore,
153 SDNPMayLoad, SDNPMemOperand]>;
154
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000155def X86AtomAdd64 : SDNode<"X86ISD::ATOMADD64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000156 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000157 SDNPMayLoad, SDNPMemOperand]>;
158def X86AtomSub64 : SDNode<"X86ISD::ATOMSUB64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000159 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000160 SDNPMayLoad, SDNPMemOperand]>;
161def X86AtomOr64 : SDNode<"X86ISD::ATOMOR64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000162 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000163 SDNPMayLoad, SDNPMemOperand]>;
164def X86AtomXor64 : SDNode<"X86ISD::ATOMXOR64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000165 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000166 SDNPMayLoad, SDNPMemOperand]>;
167def X86AtomAnd64 : SDNode<"X86ISD::ATOMAND64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000168 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000169 SDNPMayLoad, SDNPMemOperand]>;
170def X86AtomNand64 : SDNode<"X86ISD::ATOMNAND64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000171 [SDNPHasChain, SDNPMayStore,
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000172 SDNPMayLoad, SDNPMemOperand]>;
Dale Johannesen880ae362008-10-03 22:25:52 +0000173def X86AtomSwap64 : SDNode<"X86ISD::ATOMSWAP64_DAG", SDTX86atomicBinary,
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000174 [SDNPHasChain, SDNPMayStore,
Dale Johannesen880ae362008-10-03 22:25:52 +0000175 SDNPMayLoad, SDNPMemOperand]>;
Evan Chenge3413162006-01-09 18:33:28 +0000176def X86retflag : SDNode<"X86ISD::RET_FLAG", SDTX86Ret,
Chris Lattner036609b2010-12-23 18:28:41 +0000177 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
Evan Chengb077b842005-12-21 02:39:21 +0000178
Dan Gohmand6708ea2009-08-15 01:38:56 +0000179def X86vastart_save_xmm_regs :
180 SDNode<"X86ISD::VASTART_SAVE_XMM_REGS",
181 SDT_X86VASTART_SAVE_XMM_REGS,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000182 [SDNPHasChain, SDNPVariadic]>;
Dan Gohman320afb82010-10-12 18:00:49 +0000183def X86vaarg64 :
184 SDNode<"X86ISD::VAARG_64", SDT_X86VAARG_64,
185 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
186 SDNPMemOperand]>;
Evan Chenge3413162006-01-09 18:33:28 +0000187def X86callseq_start :
188 SDNode<"ISD::CALLSEQ_START", SDT_X86CallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +0000189 [SDNPHasChain, SDNPOutGlue]>;
Evan Chenge3413162006-01-09 18:33:28 +0000190def X86callseq_end :
191 SDNode<"ISD::CALLSEQ_END", SDT_X86CallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +0000192 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Evan Chengb077b842005-12-21 02:39:21 +0000193
Evan Chenge3413162006-01-09 18:33:28 +0000194def X86call : SDNode<"X86ISD::CALL", SDT_X86Call,
Chris Lattner036609b2010-12-23 18:28:41 +0000195 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattnere8cabf32010-03-19 05:07:09 +0000196 SDNPVariadic]>;
Evan Chengaed7c722005-12-17 01:24:02 +0000197
Chris Lattnered52c8f2010-03-28 07:38:39 +0000198def X86rep_stos: SDNode<"X86ISD::REP_STOS", SDTX86RepStr,
Chris Lattner036609b2010-12-23 18:28:41 +0000199 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore]>;
Chris Lattnered52c8f2010-03-28 07:38:39 +0000200def X86rep_movs: SDNode<"X86ISD::REP_MOVS", SDTX86RepStr,
Chris Lattner036609b2010-12-23 18:28:41 +0000201 [SDNPHasChain, SDNPInGlue, SDNPOutGlue, SDNPMayStore,
Chris Lattner9b37aaf2008-01-10 05:12:37 +0000202 SDNPMayLoad]>;
Evan Cheng67f92a72006-01-11 22:15:48 +0000203
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000204def X86rdtsc : SDNode<"X86ISD::RDTSC_DAG", SDTX86Void,
Chris Lattner036609b2010-12-23 18:28:41 +0000205 [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>;
Evan Chengd90eb7f2006-01-05 00:27:02 +0000206
Evan Cheng0085a282006-11-30 21:55:46 +0000207def X86Wrapper : SDNode<"X86ISD::Wrapper", SDTX86Wrapper>;
208def X86WrapperRIP : SDNode<"X86ISD::WrapperRIP", SDTX86Wrapper>;
Evan Cheng71fb8342006-02-25 10:02:21 +0000209
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000210def X86tlsaddr : SDNode<"X86ISD::TLSADDR", SDT_X86TLSADDR,
Chris Lattner036609b2010-12-23 18:28:41 +0000211 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000212
Hans Wennborgf0234fc2012-06-01 16:27:21 +0000213def X86tlsbaseaddr : SDNode<"X86ISD::TLSBASEADDR", SDT_X86TLSBASEADDR,
214 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
215
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000216def X86ehret : SDNode<"X86ISD::EH_RETURN", SDT_X86EHRET,
217 [SDNPHasChain]>;
218
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000219def X86tcret : SDNode<"X86ISD::TC_RETURN", SDT_X86TCRET,
Chris Lattner036609b2010-12-23 18:28:41 +0000220 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000221
Dan Gohman43ffe672010-01-04 20:51:05 +0000222def X86add_flag : SDNode<"X86ISD::ADD", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000223 [SDNPCommutative]>;
Dan Gohman076aee32009-03-04 19:44:21 +0000224def X86sub_flag : SDNode<"X86ISD::SUB", SDTBinaryArithWithFlags>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000225def X86smul_flag : SDNode<"X86ISD::SMUL", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000226 [SDNPCommutative]>;
Chris Lattnerb20e0b12010-12-05 07:30:36 +0000227def X86umul_flag : SDNode<"X86ISD::UMUL", SDT2ResultBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000228 [SDNPCommutative]>;
Chris Lattner5b856542010-12-20 00:59:46 +0000229def X86adc_flag : SDNode<"X86ISD::ADC", SDTBinaryArithWithFlagsInOut>;
230def X86sbb_flag : SDNode<"X86ISD::SBB", SDTBinaryArithWithFlagsInOut>;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000231
Dan Gohman076aee32009-03-04 19:44:21 +0000232def X86inc_flag : SDNode<"X86ISD::INC", SDTUnaryArithWithFlags>;
233def X86dec_flag : SDNode<"X86ISD::DEC", SDTUnaryArithWithFlags>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000234def X86or_flag : SDNode<"X86ISD::OR", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000235 [SDNPCommutative]>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000236def X86xor_flag : SDNode<"X86ISD::XOR", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000237 [SDNPCommutative]>;
Dan Gohman43ffe672010-01-04 20:51:05 +0000238def X86and_flag : SDNode<"X86ISD::AND", SDTBinaryArithWithFlags,
Dan Gohman4361bbf2010-01-05 00:44:20 +0000239 [SDNPCommutative]>;
Craig Topper54a11172011-10-14 07:06:56 +0000240def X86andn_flag : SDNode<"X86ISD::ANDN", SDTBinaryArithWithFlags>;
Bill Wendlingab55ebd2008-12-12 00:56:36 +0000241
Craig Topperb4c94572011-10-21 06:55:01 +0000242def X86blsi_flag : SDNode<"X86ISD::BLSI", SDTUnaryArithWithFlags>;
243def X86blsmsk_flag : SDNode<"X86ISD::BLSMSK", SDTUnaryArithWithFlags>;
244def X86blsr_flag : SDNode<"X86ISD::BLSR", SDTUnaryArithWithFlags>;
245
Evan Cheng73f24c92009-03-30 21:36:47 +0000246def X86mul_imm : SDNode<"X86ISD::MUL_IMM", SDTIntBinOp>;
247
Michael J. Spencere9c253e2010-10-21 01:41:01 +0000248def X86WinAlloca : SDNode<"X86ISD::WIN_ALLOCA", SDTX86Void,
Chris Lattner036609b2010-12-23 18:28:41 +0000249 [SDNPHasChain, SDNPInGlue, SDNPOutGlue]>;
Michael J. Spencere9c253e2010-10-21 01:41:01 +0000250
Rafael Espindolad07b7ec2011-08-30 19:43:21 +0000251def X86SegAlloca : SDNode<"X86ISD::SEG_ALLOCA", SDT_X86SEG_ALLOCA,
252 [SDNPHasChain]>;
253
Eric Christopher30ef0e52010-06-03 04:07:48 +0000254def X86TLSCall : SDNode<"X86ISD::TLSCALL", SDT_X86TLSCALL,
Chris Lattner036609b2010-12-23 18:28:41 +0000255 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Anton Korobeynikov043f3c22010-03-06 19:32:29 +0000256
Michael J. Spencer1a2d0612012-02-24 19:01:22 +0000257def X86WinFTOL : SDNode<"X86ISD::WIN_FTOL", SDT_X86WIN_FTOL,
258 [SDNPHasChain, SDNPOutGlue]>;
259
Evan Chengaed7c722005-12-17 01:24:02 +0000260//===----------------------------------------------------------------------===//
261// X86 Operand Definitions.
262//
263
Dan Gohmana4714e02009-07-30 01:56:29 +0000264// A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
265// the index operand of an address, to conform to x86 encoding restrictions.
266def ptr_rc_nosp : PointerLikeRegClass<1>;
Chris Lattner7680e732009-06-20 19:34:09 +0000267
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000268// *mem - Operand definitions for the funky X86 addressing mode operands.
269//
Devang Patelc59d9df2012-01-12 01:51:42 +0000270def X86MemAsmOperand : AsmOperandClass {
271 let Name = "Mem"; let PredicateMethod = "isMem";
Daniel Dunbar338825c2009-08-10 18:41:10 +0000272}
Devang Patelc59d9df2012-01-12 01:51:42 +0000273def X86Mem8AsmOperand : AsmOperandClass {
274 let Name = "Mem8"; let PredicateMethod = "isMem8";
275}
276def X86Mem16AsmOperand : AsmOperandClass {
277 let Name = "Mem16"; let PredicateMethod = "isMem16";
278}
279def X86Mem32AsmOperand : AsmOperandClass {
280 let Name = "Mem32"; let PredicateMethod = "isMem32";
281}
282def X86Mem64AsmOperand : AsmOperandClass {
283 let Name = "Mem64"; let PredicateMethod = "isMem64";
284}
285def X86Mem80AsmOperand : AsmOperandClass {
286 let Name = "Mem80"; let PredicateMethod = "isMem80";
287}
288def X86Mem128AsmOperand : AsmOperandClass {
289 let Name = "Mem128"; let PredicateMethod = "isMem128";
290}
291def X86Mem256AsmOperand : AsmOperandClass {
292 let Name = "Mem256"; let PredicateMethod = "isMem256";
293}
294
Craig Topper75dc33a2012-07-18 04:11:12 +0000295// Gather mem operands
296def X86MemVX32Operand : AsmOperandClass {
297 let Name = "MemVX32"; let PredicateMethod = "isMemVX32";
298}
299def X86MemVY32Operand : AsmOperandClass {
300 let Name = "MemVY32"; let PredicateMethod = "isMemVY32";
301}
302def X86MemVX64Operand : AsmOperandClass {
303 let Name = "MemVX64"; let PredicateMethod = "isMemVX64";
304}
305def X86MemVY64Operand : AsmOperandClass {
306 let Name = "MemVY64"; let PredicateMethod = "isMemVY64";
307}
308
Daniel Dunbarc26ae5a2010-05-06 22:39:14 +0000309def X86AbsMemAsmOperand : AsmOperandClass {
310 let Name = "AbsMem";
Chris Lattner599b5312010-07-08 23:46:44 +0000311 let SuperClasses = [X86MemAsmOperand];
Daniel Dunbarc26ae5a2010-05-06 22:39:14 +0000312}
Evan Chengaf78ef52006-05-17 21:21:41 +0000313class X86MemOperand<string printMethod> : Operand<iPTR> {
Nate Begeman391c5d22005-11-30 18:54:35 +0000314 let PrintMethod = printMethod;
Dan Gohmana4714e02009-07-30 01:56:29 +0000315 let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, i8imm);
Daniel Dunbar338825c2009-08-10 18:41:10 +0000316 let ParserMatchClass = X86MemAsmOperand;
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000317}
Nate Begeman391c5d22005-11-30 18:54:35 +0000318
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000319let OperandType = "OPERAND_MEMORY" in {
Sean Callanan9947bbb2009-09-03 00:04:47 +0000320def opaque32mem : X86MemOperand<"printopaquemem">;
321def opaque48mem : X86MemOperand<"printopaquemem">;
322def opaque80mem : X86MemOperand<"printopaquemem">;
Sean Callanan108934c2009-12-18 00:01:26 +0000323def opaque512mem : X86MemOperand<"printopaquemem">;
324
Devang Patelc59d9df2012-01-12 01:51:42 +0000325def i8mem : X86MemOperand<"printi8mem"> {
326 let ParserMatchClass = X86Mem8AsmOperand; }
327def i16mem : X86MemOperand<"printi16mem"> {
328 let ParserMatchClass = X86Mem16AsmOperand; }
329def i32mem : X86MemOperand<"printi32mem"> {
330 let ParserMatchClass = X86Mem32AsmOperand; }
331def i64mem : X86MemOperand<"printi64mem"> {
332 let ParserMatchClass = X86Mem64AsmOperand; }
333def i128mem : X86MemOperand<"printi128mem"> {
334 let ParserMatchClass = X86Mem128AsmOperand; }
335def i256mem : X86MemOperand<"printi256mem"> {
336 let ParserMatchClass = X86Mem256AsmOperand; }
337def f32mem : X86MemOperand<"printf32mem"> {
338 let ParserMatchClass = X86Mem32AsmOperand; }
339def f64mem : X86MemOperand<"printf64mem"> {
340 let ParserMatchClass = X86Mem64AsmOperand; }
341def f80mem : X86MemOperand<"printf80mem"> {
342 let ParserMatchClass = X86Mem80AsmOperand; }
343def f128mem : X86MemOperand<"printf128mem"> {
344 let ParserMatchClass = X86Mem128AsmOperand; }
345def f256mem : X86MemOperand<"printf256mem">{
346 let ParserMatchClass = X86Mem256AsmOperand; }
Craig Topper75dc33a2012-07-18 04:11:12 +0000347
348// Gather mem operands
349def vx32mem : X86MemOperand<"printi32mem">{
Manman Ren1f7a1b62012-06-26 19:47:59 +0000350 let MIOperandInfo = (ops ptr_rc, i8imm, VR128, i32imm, i8imm);
Craig Topper75dc33a2012-07-18 04:11:12 +0000351 let ParserMatchClass = X86MemVX32Operand; }
352def vy32mem : X86MemOperand<"printi32mem">{
Manman Ren1f7a1b62012-06-26 19:47:59 +0000353 let MIOperandInfo = (ops ptr_rc, i8imm, VR256, i32imm, i8imm);
Craig Topper75dc33a2012-07-18 04:11:12 +0000354 let ParserMatchClass = X86MemVY32Operand; }
355def vx64mem : X86MemOperand<"printi64mem">{
356 let MIOperandInfo = (ops ptr_rc, i8imm, VR128, i32imm, i8imm);
357 let ParserMatchClass = X86MemVX64Operand; }
358def vy64mem : X86MemOperand<"printi64mem">{
359 let MIOperandInfo = (ops ptr_rc, i8imm, VR256, i32imm, i8imm);
360 let ParserMatchClass = X86MemVY64Operand; }
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000361}
Nate Begeman391c5d22005-11-30 18:54:35 +0000362
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000363// A version of i8mem for use on x86-64 that uses GR64_NOREX instead of
364// plain GR64, so that it doesn't potentially require a REX prefix.
365def i8mem_NOREX : Operand<i64> {
366 let PrintMethod = "printi8mem";
Dan Gohmana4714e02009-07-30 01:56:29 +0000367 let MIOperandInfo = (ops GR64_NOREX, i8imm, GR64_NOREX_NOSP, i32imm, i8imm);
Devang Patel2f8af1d2012-01-17 21:48:03 +0000368 let ParserMatchClass = X86Mem8AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000369 let OperandType = "OPERAND_MEMORY";
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000370}
371
NAKAMURA Takumi7754f852011-01-26 02:04:09 +0000372// GPRs available for tailcall.
Jakob Stoklund Olesencf661a02012-05-09 01:50:09 +0000373// It represents GR32_TC, GR64_TC or GR64_TCW64.
NAKAMURA Takumi7754f852011-01-26 02:04:09 +0000374def ptr_rc_tailcall : PointerLikeRegClass<2>;
375
Evan Chengf48ef032010-03-14 03:48:46 +0000376// Special i32mem for addresses of load folding tail calls. These are not
377// allowed to use callee-saved registers since they must be scheduled
378// after callee-saved register are popped.
379def i32mem_TC : Operand<i32> {
380 let PrintMethod = "printi32mem";
Jakob Stoklund Olesencf661a02012-05-09 01:50:09 +0000381 let MIOperandInfo = (ops ptr_rc_tailcall, i8imm, ptr_rc_tailcall,
382 i32imm, i8imm);
Devang Patel2f8af1d2012-01-17 21:48:03 +0000383 let ParserMatchClass = X86Mem32AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000384 let OperandType = "OPERAND_MEMORY";
Evan Chengf48ef032010-03-14 03:48:46 +0000385}
386
Chris Lattner41efbfa2010-10-05 06:37:31 +0000387// Special i64mem for addresses of load folding tail calls. These are not
388// allowed to use callee-saved registers since they must be scheduled
389// after callee-saved register are popped.
390def i64mem_TC : Operand<i64> {
391 let PrintMethod = "printi64mem";
NAKAMURA Takumi7754f852011-01-26 02:04:09 +0000392 let MIOperandInfo = (ops ptr_rc_tailcall, i8imm,
393 ptr_rc_tailcall, i32imm, i8imm);
Devang Patel2f8af1d2012-01-17 21:48:03 +0000394 let ParserMatchClass = X86Mem64AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000395 let OperandType = "OPERAND_MEMORY";
Chris Lattner41efbfa2010-10-05 06:37:31 +0000396}
Evan Cheng25ab6902006-09-08 06:48:29 +0000397
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000398let OperandType = "OPERAND_PCREL",
399 ParserMatchClass = X86AbsMemAsmOperand,
Daniel Dunbarb834f5d2010-01-30 01:02:48 +0000400 PrintMethod = "print_pcrel_imm" in {
Daniel Dunbar728e5eb2010-01-30 00:24:12 +0000401def i32imm_pcrel : Operand<i32>;
Chris Lattner9fc05222010-07-07 22:27:31 +0000402def i16imm_pcrel : Operand<i16>;
Daniel Dunbar728e5eb2010-01-30 00:24:12 +0000403
404def offset8 : Operand<i64>;
405def offset16 : Operand<i64>;
406def offset32 : Operand<i64>;
407def offset64 : Operand<i64>;
408
409// Branch targets have OtherVT type and print as pc-relative values.
410def brtarget : Operand<OtherVT>;
411def brtarget8 : Operand<OtherVT>;
412
413}
414
Nate Begeman16b04f32005-07-15 00:38:55 +0000415def SSECC : Operand<i8> {
416 let PrintMethod = "printSSECC";
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000417 let OperandType = "OPERAND_IMMEDIATE";
Nate Begeman16b04f32005-07-15 00:38:55 +0000418}
Chris Lattner66fa1dc2004-08-11 02:25:00 +0000419
Craig Topper769bbfd2012-04-03 05:20:24 +0000420def AVXCC : Operand<i8> {
421 let PrintMethod = "printSSECC";
422 let OperandType = "OPERAND_IMMEDIATE";
423}
424
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000425class ImmSExtAsmOperandClass : AsmOperandClass {
Daniel Dunbar54ddf3d2010-05-22 21:02:29 +0000426 let SuperClasses = [ImmAsmOperand];
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000427 let RenderMethod = "addImmOperands";
Daniel Dunbar1fe591d2010-05-20 20:20:39 +0000428}
429
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000430class ImmZExtAsmOperandClass : AsmOperandClass {
431 let SuperClasses = [ImmAsmOperand];
432 let RenderMethod = "addImmOperands";
433}
434
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000435// Sign-extended immediate classes. We don't need to define the full lattice
436// here because there is no instruction with an ambiguity between ImmSExti64i32
437// and ImmSExti32i8.
438//
439// The strange ranges come from the fact that the assembler always works with
440// 64-bit immediates, but for a 16-bit target value we want to accept both "-1"
441// (which will be a -1ULL), and "0xFF" (-1 in 16-bits).
442
Chris Lattner599b5312010-07-08 23:46:44 +0000443// [0, 0x7FFFFFFF] |
444// [0xFFFFFFFF80000000, 0xFFFFFFFFFFFFFFFF]
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000445def ImmSExti64i32AsmOperand : ImmSExtAsmOperandClass {
446 let Name = "ImmSExti64i32";
447}
448
Chris Lattner599b5312010-07-08 23:46:44 +0000449// [0, 0x0000007F] | [0x000000000000FF80, 0x000000000000FFFF] |
450// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000451def ImmSExti16i8AsmOperand : ImmSExtAsmOperandClass {
452 let Name = "ImmSExti16i8";
453 let SuperClasses = [ImmSExti64i32AsmOperand];
454}
455
Chris Lattner599b5312010-07-08 23:46:44 +0000456// [0, 0x0000007F] | [0x00000000FFFFFF80, 0x00000000FFFFFFFF] |
457// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000458def ImmSExti32i8AsmOperand : ImmSExtAsmOperandClass {
459 let Name = "ImmSExti32i8";
460}
461
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000462// [0, 0x000000FF]
463def ImmZExtu32u8AsmOperand : ImmZExtAsmOperandClass {
464 let Name = "ImmZExtu32u8";
465}
466
467
Chris Lattner599b5312010-07-08 23:46:44 +0000468// [0, 0x0000007F] |
469// [0xFFFFFFFFFFFFFF80, 0xFFFFFFFFFFFFFFFF]
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000470def ImmSExti64i8AsmOperand : ImmSExtAsmOperandClass {
471 let Name = "ImmSExti64i8";
Chris Lattner599b5312010-07-08 23:46:44 +0000472 let SuperClasses = [ImmSExti16i8AsmOperand, ImmSExti32i8AsmOperand,
473 ImmSExti64i32AsmOperand];
Daniel Dunbar338825c2009-08-10 18:41:10 +0000474}
475
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000476// A couple of more descriptive operand definitions.
477// 16-bits but only 8 bits are significant.
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000478def i16i8imm : Operand<i16> {
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000479 let ParserMatchClass = ImmSExti16i8AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000480 let OperandType = "OPERAND_IMMEDIATE";
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000481}
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000482// 32-bits but only 8 bits are significant.
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000483def i32i8imm : Operand<i32> {
Daniel Dunbar62e4c672010-05-22 21:02:33 +0000484 let ParserMatchClass = ImmSExti32i8AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000485 let OperandType = "OPERAND_IMMEDIATE";
Daniel Dunbar5fe63382009-08-09 07:20:21 +0000486}
Kevin Enderbyc37d4bb2011-07-27 23:01:50 +0000487// 32-bits but only 8 bits are significant, and those 8 bits are unsigned.
488def u32u8imm : Operand<i32> {
489 let ParserMatchClass = ImmZExtu32u8AsmOperand;
490 let OperandType = "OPERAND_IMMEDIATE";
491}
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000492
Chris Lattner41efbfa2010-10-05 06:37:31 +0000493// 64-bits but only 32 bits are significant.
494def i64i32imm : Operand<i64> {
495 let ParserMatchClass = ImmSExti64i32AsmOperand;
Benjamin Kramer3be41b72011-07-14 21:47:22 +0000496 let OperandType = "OPERAND_IMMEDIATE";
Chris Lattner41efbfa2010-10-05 06:37:31 +0000497}
498
499// 64-bits but only 32 bits are significant, and those bits are treated as being
500// pc relative.
501def i64i32imm_pcrel : Operand<i64> {
502 let PrintMethod = "print_pcrel_imm";
503 let ParserMatchClass = X86AbsMemAsmOperand;
Benjamin Kramer3c1fece2011-08-22 22:55:32 +0000504 let OperandType = "OPERAND_PCREL";
Chris Lattner41efbfa2010-10-05 06:37:31 +0000505}
506
507// 64-bits but only 8 bits are significant.
508def i64i8imm : Operand<i64> {
509 let ParserMatchClass = ImmSExti64i8AsmOperand;
Benjamin Kramer3c1fece2011-08-22 22:55:32 +0000510 let OperandType = "OPERAND_IMMEDIATE";
Chris Lattner41efbfa2010-10-05 06:37:31 +0000511}
512
513def lea64_32mem : Operand<i32> {
514 let PrintMethod = "printi32mem";
515 let AsmOperandLowerMethod = "lower_lea64_32mem";
516 let MIOperandInfo = (ops GR32, i8imm, GR32_NOSP, i32imm, i8imm);
517 let ParserMatchClass = X86MemAsmOperand;
518}
519
520
Evan Chengaed7c722005-12-17 01:24:02 +0000521//===----------------------------------------------------------------------===//
522// X86 Complex Pattern Definitions.
523//
524
Evan Chengec693f72005-12-08 02:01:35 +0000525// Define X86 specific addressing mode.
Chris Lattnerb86faa12010-09-21 22:07:31 +0000526def addr : ComplexPattern<iPTR, 5, "SelectAddr", [], [SDNPWantParent]>;
Chris Lattner599b5312010-07-08 23:46:44 +0000527def lea32addr : ComplexPattern<i32, 5, "SelectLEAAddr",
Dan Gohmana98634b2009-08-02 16:09:17 +0000528 [add, sub, mul, X86mul_imm, shl, or, frameindex],
529 []>;
Chris Lattner599b5312010-07-08 23:46:44 +0000530def tls32addr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
Chris Lattner5c0b16d2009-06-20 20:38:48 +0000531 [tglobaltlsaddr], []>;
Evan Chengec693f72005-12-08 02:01:35 +0000532
Hans Wennborgf0234fc2012-06-01 16:27:21 +0000533def tls32baseaddr : ComplexPattern<i32, 5, "SelectTLSADDRAddr",
534 [tglobaltlsaddr], []>;
535
Chris Lattner41efbfa2010-10-05 06:37:31 +0000536def lea64addr : ComplexPattern<i64, 5, "SelectLEAAddr",
537 [add, sub, mul, X86mul_imm, shl, or, frameindex,
538 X86WrapperRIP], []>;
539
540def tls64addr : ComplexPattern<i64, 5, "SelectTLSADDRAddr",
541 [tglobaltlsaddr], []>;
542
Hans Wennborgf0234fc2012-06-01 16:27:21 +0000543def tls64baseaddr : ComplexPattern<i64, 5, "SelectTLSADDRAddr",
544 [tglobaltlsaddr], []>;
545
Evan Chengaed7c722005-12-17 01:24:02 +0000546//===----------------------------------------------------------------------===//
Evan Chengbbc8ddb2005-12-20 22:59:51 +0000547// X86 Instruction Predicate Definitions.
Chris Lattner314a1132010-03-14 18:31:44 +0000548def HasCMov : Predicate<"Subtarget->hasCMov()">;
549def NoCMov : Predicate<"!Subtarget->hasCMov()">;
Nate Begeman5812b102010-12-03 22:29:15 +0000550
Nate Begeman2ea8ee72010-12-10 00:26:57 +0000551def HasMMX : Predicate<"Subtarget->hasMMX()">;
Chris Lattner548abfc2010-10-03 18:08:05 +0000552def Has3DNow : Predicate<"Subtarget->has3DNow()">;
553def Has3DNowA : Predicate<"Subtarget->has3DNowA()">;
Nate Begeman2ea8ee72010-12-10 00:26:57 +0000554def HasSSE1 : Predicate<"Subtarget->hasSSE1()">;
555def HasSSE2 : Predicate<"Subtarget->hasSSE2()">;
556def HasSSE3 : Predicate<"Subtarget->hasSSE3()">;
557def HasSSSE3 : Predicate<"Subtarget->hasSSSE3()">;
558def HasSSE41 : Predicate<"Subtarget->hasSSE41()">;
559def HasSSE42 : Predicate<"Subtarget->hasSSE42()">;
560def HasSSE4A : Predicate<"Subtarget->hasSSE4A()">;
David Greene343dadb2009-06-26 22:46:54 +0000561def HasAVX : Predicate<"Subtarget->hasAVX()">;
Craig Toppere7b05502011-10-30 19:57:21 +0000562def HasAVX2 : Predicate<"Subtarget->hasAVX2()">;
Craig Topper3a1683f2012-08-27 06:08:57 +0000563def HasAVX1Only : Predicate<"Subtarget->hasAVX() && !Subtarget->hasAVX2()">;
Nate Begeman2ea8ee72010-12-10 00:26:57 +0000564
Craig Topperc48b3012011-10-11 07:13:09 +0000565def HasPOPCNT : Predicate<"Subtarget->hasPOPCNT()">;
Nate Begeman2ea8ee72010-12-10 00:26:57 +0000566def HasAES : Predicate<"Subtarget->hasAES()">;
Benjamin Kramerc8e340d2012-05-31 14:34:17 +0000567def HasPCLMUL : Predicate<"Subtarget->hasPCLMUL()">;
Craig Toppera15f9d52012-06-03 18:58:46 +0000568def HasFMA : Predicate<"Subtarget->hasFMA()">;
David Greene343dadb2009-06-26 22:46:54 +0000569def HasFMA4 : Predicate<"Subtarget->hasFMA4()">;
Jan Sjödin37e7ecf2011-12-12 19:37:49 +0000570def HasXOP : Predicate<"Subtarget->hasXOP()">;
Craig Topper581fe822011-10-03 17:28:23 +0000571def HasMOVBE : Predicate<"Subtarget->hasMOVBE()">;
572def HasRDRAND : Predicate<"Subtarget->hasRDRAND()">;
Craig Topperda394042011-10-09 07:31:39 +0000573def HasF16C : Predicate<"Subtarget->hasF16C()">;
Craig Toppere7b05502011-10-30 19:57:21 +0000574def HasFSGSBase : Predicate<"Subtarget->hasFSGSBase()">;
Craig Topper37f21672011-10-11 06:44:02 +0000575def HasLZCNT : Predicate<"Subtarget->hasLZCNT()">;
Craig Topper909652f2011-10-14 03:21:46 +0000576def HasBMI : Predicate<"Subtarget->hasBMI()">;
Craig Topperb53fa8b2011-10-16 07:55:05 +0000577def HasBMI2 : Predicate<"Subtarget->hasBMI2()">;
Craig Topperc6d59952012-01-10 06:30:56 +0000578def FPStackf32 : Predicate<"!Subtarget->hasSSE1()">;
579def FPStackf64 : Predicate<"!Subtarget->hasSSE2()">;
Eli Friedman43f51ae2011-08-26 21:21:21 +0000580def HasCmpxchg16b: Predicate<"Subtarget->hasCmpxchg16b()">;
Evan Chengebdeeab2011-07-08 01:53:10 +0000581def In32BitMode : Predicate<"!Subtarget->is64Bit()">,
582 AssemblerPredicate<"!Mode64Bit">;
583def In64BitMode : Predicate<"Subtarget->is64Bit()">,
584 AssemblerPredicate<"Mode64Bit">;
Anton Korobeynikovcf6b7392009-08-03 08:12:53 +0000585def IsWin64 : Predicate<"Subtarget->isTargetWin64()">;
David Meyer928698b2011-10-18 05:29:23 +0000586def IsNaCl : Predicate<"Subtarget->isTargetNaCl()">;
587def NotNaCl : Predicate<"!Subtarget->isTargetNaCl()">;
Anton Korobeynikovd7697d02009-08-06 11:23:24 +0000588def SmallCode : Predicate<"TM.getCodeModel() == CodeModel::Small">;
589def KernelCode : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
590def FarData : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
Anton Korobeynikov186fa1d2009-08-06 09:11:19 +0000591 "TM.getCodeModel() != CodeModel::Kernel">;
Anton Korobeynikovd7697d02009-08-06 11:23:24 +0000592def NearData : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
593 "TM.getCodeModel() == CodeModel::Kernel">;
Evan Cheng28b514392006-12-05 19:50:18 +0000594def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
Evan Chengcb0f06e2010-03-25 00:10:31 +0000595def IsNotPIC : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
Evan Chengb1f49812009-12-22 17:47:23 +0000596def OptForSize : Predicate<"OptForSize">;
Evan Chengb7a75a52008-09-26 23:41:32 +0000597def OptForSpeed : Predicate<"!OptForSize">;
Evan Chengccb69762009-01-02 05:35:45 +0000598def FastBTMem : Predicate<"!Subtarget->isBTMemSlow()">;
Evan Chengd7f666a2009-05-20 04:53:57 +0000599def CallImmAddr : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
Evan Chengbbc8ddb2005-12-20 22:59:51 +0000600
601//===----------------------------------------------------------------------===//
Evan Chengc64a1a92007-07-31 08:04:03 +0000602// X86 Instruction Format Definitions.
Evan Chengaed7c722005-12-17 01:24:02 +0000603//
604
Evan Chengc64a1a92007-07-31 08:04:03 +0000605include "X86InstrFormats.td"
Chris Lattner1cca5e32003-08-03 21:54:21 +0000606
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +0000607//===----------------------------------------------------------------------===//
Chris Lattner54379062011-04-17 21:38:24 +0000608// Pattern fragments.
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000609//
Evan Chengd9558e02006-01-06 00:43:03 +0000610
611// X86 specific condition code. These correspond to CondCode in
Nate Begeman9a225302007-05-06 04:00:55 +0000612// X86InstrInfo.h. They must be kept in synch.
Dan Gohman653456c2009-01-07 00:15:08 +0000613def X86_COND_A : PatLeaf<(i8 0)>; // alt. COND_NBE
614def X86_COND_AE : PatLeaf<(i8 1)>; // alt. COND_NC
615def X86_COND_B : PatLeaf<(i8 2)>; // alt. COND_C
616def X86_COND_BE : PatLeaf<(i8 3)>; // alt. COND_NA
617def X86_COND_E : PatLeaf<(i8 4)>; // alt. COND_Z
618def X86_COND_G : PatLeaf<(i8 5)>; // alt. COND_NLE
619def X86_COND_GE : PatLeaf<(i8 6)>; // alt. COND_NL
620def X86_COND_L : PatLeaf<(i8 7)>; // alt. COND_NGE
621def X86_COND_LE : PatLeaf<(i8 8)>; // alt. COND_NG
622def X86_COND_NE : PatLeaf<(i8 9)>; // alt. COND_NZ
Evan Chengd9558e02006-01-06 00:43:03 +0000623def X86_COND_NO : PatLeaf<(i8 10)>;
Dan Gohman653456c2009-01-07 00:15:08 +0000624def X86_COND_NP : PatLeaf<(i8 11)>; // alt. COND_PO
Evan Chengd9558e02006-01-06 00:43:03 +0000625def X86_COND_NS : PatLeaf<(i8 12)>;
Dan Gohman653456c2009-01-07 00:15:08 +0000626def X86_COND_O : PatLeaf<(i8 13)>;
627def X86_COND_P : PatLeaf<(i8 14)>; // alt. COND_PE
628def X86_COND_S : PatLeaf<(i8 15)>;
Evan Chengd9558e02006-01-06 00:43:03 +0000629
Chris Lattner202a7a12011-04-18 06:36:55 +0000630let FastIselShouldIgnore = 1 in { // FastIsel should ignore all simm8 instrs.
Nick Lewycky52a83992011-04-20 03:19:42 +0000631 def i16immSExt8 : ImmLeaf<i16, [{ return Imm == (int8_t)Imm; }]>;
632 def i32immSExt8 : ImmLeaf<i32, [{ return Imm == (int8_t)Imm; }]>;
633 def i64immSExt8 : ImmLeaf<i64, [{ return Imm == (int8_t)Imm; }]>;
Chris Lattner202a7a12011-04-18 06:36:55 +0000634}
635
Chris Lattner5662bc92011-04-17 22:12:55 +0000636def i64immSExt32 : ImmLeaf<i64, [{ return Imm == (int32_t)Imm; }]>;
Chris Lattner7ed13912011-04-17 22:05:17 +0000637
638
Chris Lattner5662bc92011-04-17 22:12:55 +0000639// i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
640// unsigned field.
641def i64immZExt32 : ImmLeaf<i64, [{ return (uint64_t)Imm == (uint32_t)Imm; }]>;
Chris Lattner7ed13912011-04-17 22:05:17 +0000642
Chris Lattner5662bc92011-04-17 22:12:55 +0000643def i64immZExt32SExt8 : ImmLeaf<i64, [{
644 return (uint64_t)Imm == (uint32_t)Imm && (int32_t)Imm == (int8_t)Imm;
Rafael Espindoladba81cf2010-10-13 13:31:20 +0000645}]>;
646
Evan Cheng605c4152005-12-13 01:57:51 +0000647// Helper fragments for loads.
Evan Chengb6564432008-05-13 18:59:59 +0000648// It's always safe to treat a anyext i16 load as a i32 load if the i16 is
649// known to be 32-bit aligned or better. Ditto for i8 to i16.
Dan Gohman33586292008-10-15 06:50:19 +0000650def loadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
Dan Gohman67ca6be2008-08-20 15:24:22 +0000651 LoadSDNode *LD = cast<LoadSDNode>(N);
Dan Gohman67ca6be2008-08-20 15:24:22 +0000652 ISD::LoadExtType ExtType = LD->getExtensionType();
653 if (ExtType == ISD::NON_EXTLOAD)
654 return true;
655 if (ExtType == ISD::EXTLOAD)
656 return LD->getAlignment() >= 2 && !LD->isVolatile();
Evan Chengfa7fd332008-05-13 00:54:02 +0000657 return false;
658}]>;
659
Chris Lattnerf85eff72010-03-03 01:52:59 +0000660def loadi16_anyext : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)),[{
Evan Chengca57f782008-09-24 23:27:55 +0000661 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengca57f782008-09-24 23:27:55 +0000662 ISD::LoadExtType ExtType = LD->getExtensionType();
663 if (ExtType == ISD::EXTLOAD)
664 return LD->getAlignment() >= 2 && !LD->isVolatile();
665 return false;
666}]>;
667
Dan Gohman33586292008-10-15 06:50:19 +0000668def loadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
Dan Gohman67ca6be2008-08-20 15:24:22 +0000669 LoadSDNode *LD = cast<LoadSDNode>(N);
Dan Gohman67ca6be2008-08-20 15:24:22 +0000670 ISD::LoadExtType ExtType = LD->getExtensionType();
671 if (ExtType == ISD::NON_EXTLOAD)
672 return true;
673 if (ExtType == ISD::EXTLOAD)
674 return LD->getAlignment() >= 4 && !LD->isVolatile();
Evan Chengfa7fd332008-05-13 00:54:02 +0000675 return false;
676}]>;
677
Chris Lattnerb86faa12010-09-21 22:07:31 +0000678def loadi8 : PatFrag<(ops node:$ptr), (i8 (load node:$ptr))>;
679def loadi64 : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;
680def loadf32 : PatFrag<(ops node:$ptr), (f32 (load node:$ptr))>;
681def loadf64 : PatFrag<(ops node:$ptr), (f64 (load node:$ptr))>;
682def loadf80 : PatFrag<(ops node:$ptr), (f80 (load node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000683
Evan Cheng466685d2006-10-09 20:57:25 +0000684def sextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
685def sextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
686def sextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
Chris Lattner41efbfa2010-10-05 06:37:31 +0000687def sextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (sextloadi8 node:$ptr))>;
688def sextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (sextloadi16 node:$ptr))>;
689def sextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (sextloadi32 node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000690
Evan Cheng466685d2006-10-09 20:57:25 +0000691def zextloadi8i1 : PatFrag<(ops node:$ptr), (i8 (zextloadi1 node:$ptr))>;
692def zextloadi16i1 : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
693def zextloadi32i1 : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
694def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
695def zextloadi32i8 : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
696def zextloadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
Chris Lattner41efbfa2010-10-05 06:37:31 +0000697def zextloadi64i1 : PatFrag<(ops node:$ptr), (i64 (zextloadi1 node:$ptr))>;
698def zextloadi64i8 : PatFrag<(ops node:$ptr), (i64 (zextloadi8 node:$ptr))>;
699def zextloadi64i16 : PatFrag<(ops node:$ptr), (i64 (zextloadi16 node:$ptr))>;
700def zextloadi64i32 : PatFrag<(ops node:$ptr), (i64 (zextloadi32 node:$ptr))>;
Evan Cheng7a7e8372005-12-14 02:22:27 +0000701
Evan Cheng466685d2006-10-09 20:57:25 +0000702def extloadi8i1 : PatFrag<(ops node:$ptr), (i8 (extloadi1 node:$ptr))>;
703def extloadi16i1 : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
704def extloadi32i1 : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
705def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
706def extloadi32i8 : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
707def extloadi32i16 : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
Chris Lattner41efbfa2010-10-05 06:37:31 +0000708def extloadi64i1 : PatFrag<(ops node:$ptr), (i64 (extloadi1 node:$ptr))>;
709def extloadi64i8 : PatFrag<(ops node:$ptr), (i64 (extloadi8 node:$ptr))>;
710def extloadi64i16 : PatFrag<(ops node:$ptr), (i64 (extloadi16 node:$ptr))>;
711def extloadi64i32 : PatFrag<(ops node:$ptr), (i64 (extloadi32 node:$ptr))>;
Evan Cheng747a90d2006-02-21 02:24:38 +0000712
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000713
714// An 'and' node with a single use.
715def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
Evan Cheng07b7ea12008-03-04 00:40:35 +0000716 return N->hasOneUse();
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000717}]>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +0000718// An 'srl' node with a single use.
719def srl_su : PatFrag<(ops node:$lhs, node:$rhs), (srl node:$lhs, node:$rhs), [{
720 return N->hasOneUse();
721}]>;
722// An 'trunc' node with a single use.
723def trunc_su : PatFrag<(ops node:$src), (trunc node:$src), [{
724 return N->hasOneUse();
725}]>;
Chris Lattnerce2bcc82008-02-19 17:37:35 +0000726
Chris Lattnerf124d5e2005-11-18 01:04:42 +0000727//===----------------------------------------------------------------------===//
Chris Lattner434c7cb2010-10-05 05:32:15 +0000728// Instruction list.
Chris Lattner1cca5e32003-08-03 21:54:21 +0000729//
730
Evan Cheng4a460802006-01-11 00:33:36 +0000731// Nop
Sean Callanan74e52102009-07-23 23:39:34 +0000732let neverHasSideEffects = 1 in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000733 def NOOP : I<0x90, RawFrm, (outs), (ins), "nop", [], IIC_NOP>;
Sean Callanan108934c2009-12-18 00:01:26 +0000734 def NOOPW : I<0x1f, MRM0m, (outs), (ins i16mem:$zero),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000735 "nop{w}\t$zero", [], IIC_NOP>, TB, OpSize;
Sean Callanan74e52102009-07-23 23:39:34 +0000736 def NOOPL : I<0x1f, MRM0m, (outs), (ins i32mem:$zero),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000737 "nop{l}\t$zero", [], IIC_NOP>, TB;
Sean Callanan74e52102009-07-23 23:39:34 +0000738}
Evan Cheng4a460802006-01-11 00:33:36 +0000739
Chris Lattner1cca5e32003-08-03 21:54:21 +0000740
Sean Callanan8d708542009-09-16 02:57:13 +0000741// Constructing a stack frame.
Chris Lattner40cc3f82010-09-17 18:02:29 +0000742def ENTER : Ii16<0xC8, RawFrmImm8, (outs), (ins i16imm:$len, i8imm:$lvl),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000743 "enter\t$len, $lvl", [], IIC_ENTER>;
Sean Callanan8d708542009-09-16 02:57:13 +0000744
Chris Lattnerba7e7562008-01-10 07:59:24 +0000745let Defs = [EBP, ESP], Uses = [EBP, ESP], mayLoad = 1, neverHasSideEffects=1 in
Chris Lattner30bf2d82004-08-10 20:17:41 +0000746def LEAVE : I<0xC9, RawFrm,
Preston Gurddeaa3f32012-05-10 21:58:35 +0000747 (outs), (ins), "leave", [], IIC_LEAVE>,
748 Requires<[In32BitMode]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000749
Chris Lattner5673e1d2010-10-05 06:41:40 +0000750let Defs = [RBP,RSP], Uses = [RBP,RSP], mayLoad = 1, neverHasSideEffects = 1 in
751def LEAVE64 : I<0xC9, RawFrm,
Preston Gurddeaa3f32012-05-10 21:58:35 +0000752 (outs), (ins), "leave", [], IIC_LEAVE>,
753 Requires<[In64BitMode]>;
Chris Lattner5673e1d2010-10-05 06:41:40 +0000754
Chris Lattner87be16a2010-10-05 06:04:14 +0000755//===----------------------------------------------------------------------===//
Chris Lattner5673e1d2010-10-05 06:41:40 +0000756// Miscellaneous Instructions.
Chris Lattner87be16a2010-10-05 06:04:14 +0000757//
Sean Callanan108934c2009-12-18 00:01:26 +0000758
Chris Lattnerba7e7562008-01-10 07:59:24 +0000759let Defs = [ESP], Uses = [ESP], neverHasSideEffects=1 in {
Sean Callanan1f24e012009-09-10 18:29:13 +0000760let mayLoad = 1 in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000761def POP16r : I<0x58, AddRegFrm, (outs GR16:$reg), (ins), "pop{w}\t$reg", [],
762 IIC_POP_REG16>, OpSize;
763def POP32r : I<0x58, AddRegFrm, (outs GR32:$reg), (ins), "pop{l}\t$reg", [],
764 IIC_POP_REG>;
765def POP16rmr: I<0x8F, MRM0r, (outs GR16:$reg), (ins), "pop{w}\t$reg", [],
766 IIC_POP_REG>, OpSize;
767def POP16rmm: I<0x8F, MRM0m, (outs i16mem:$dst), (ins), "pop{w}\t$dst", [],
768 IIC_POP_MEM>, OpSize;
769def POP32rmr: I<0x8F, MRM0r, (outs GR32:$reg), (ins), "pop{l}\t$reg", [],
770 IIC_POP_REG>;
771def POP32rmm: I<0x8F, MRM0m, (outs i32mem:$dst), (ins), "pop{l}\t$dst", [],
772 IIC_POP_MEM>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000773
Preston Gurddeaa3f32012-05-10 21:58:35 +0000774def POPF16 : I<0x9D, RawFrm, (outs), (ins), "popf{w}", [], IIC_POP_F>, OpSize;
775def POPF32 : I<0x9D, RawFrm, (outs), (ins), "popf{l|d}", [], IIC_POP_FD>,
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000776 Requires<[In32BitMode]>;
Sean Callanan1f24e012009-09-10 18:29:13 +0000777}
Chris Lattner1cca5e32003-08-03 21:54:21 +0000778
Sean Callanan1f24e012009-09-10 18:29:13 +0000779let mayStore = 1 in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000780def PUSH16r : I<0x50, AddRegFrm, (outs), (ins GR16:$reg), "push{w}\t$reg",[],
781 IIC_PUSH_REG>, OpSize;
782def PUSH32r : I<0x50, AddRegFrm, (outs), (ins GR32:$reg), "push{l}\t$reg",[],
783 IIC_PUSH_REG>;
784def PUSH16rmr: I<0xFF, MRM6r, (outs), (ins GR16:$reg), "push{w}\t$reg",[],
785 IIC_PUSH_REG>, OpSize;
786def PUSH16rmm: I<0xFF, MRM6m, (outs), (ins i16mem:$src), "push{w}\t$src",[],
787 IIC_PUSH_MEM>,
Sean Callanan1f24e012009-09-10 18:29:13 +0000788 OpSize;
Preston Gurddeaa3f32012-05-10 21:58:35 +0000789def PUSH32rmr: I<0xFF, MRM6r, (outs), (ins GR32:$reg), "push{l}\t$reg",[],
790 IIC_PUSH_REG>;
791def PUSH32rmm: I<0xFF, MRM6m, (outs), (ins i32mem:$src), "push{l}\t$src",[],
792 IIC_PUSH_MEM>;
Anton Korobeynikov57fc00d2007-04-17 09:20:00 +0000793
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000794def PUSHi8 : Ii8<0x6a, RawFrm, (outs), (ins i32i8imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000795 "push{l}\t$imm", [], IIC_PUSH_IMM>;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000796def PUSHi16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000797 "push{w}\t$imm", [], IIC_PUSH_IMM>, OpSize;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000798def PUSHi32 : Ii32<0x68, RawFrm, (outs), (ins i32imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000799 "push{l}\t$imm", [], IIC_PUSH_IMM>;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000800
Preston Gurddeaa3f32012-05-10 21:58:35 +0000801def PUSHF16 : I<0x9C, RawFrm, (outs), (ins), "pushf{w}", [], IIC_PUSH_F>,
802 OpSize;
803def PUSHF32 : I<0x9C, RawFrm, (outs), (ins), "pushf{l|d}", [], IIC_PUSH_F>,
Dan Gohmane5e4ff92010-05-20 16:16:00 +0000804 Requires<[In32BitMode]>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000805
Sean Callanan108934c2009-12-18 00:01:26 +0000806}
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000807}
808
809let Defs = [RSP], Uses = [RSP], neverHasSideEffects=1 in {
810let mayLoad = 1 in {
811def POP64r : I<0x58, AddRegFrm,
Preston Gurddeaa3f32012-05-10 21:58:35 +0000812 (outs GR64:$reg), (ins), "pop{q}\t$reg", [], IIC_POP_REG>;
813def POP64rmr: I<0x8F, MRM0r, (outs GR64:$reg), (ins), "pop{q}\t$reg", [],
814 IIC_POP_REG>;
815def POP64rmm: I<0x8F, MRM0m, (outs i64mem:$dst), (ins), "pop{q}\t$dst", [],
816 IIC_POP_MEM>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000817}
818let mayStore = 1 in {
819def PUSH64r : I<0x50, AddRegFrm,
Preston Gurddeaa3f32012-05-10 21:58:35 +0000820 (outs), (ins GR64:$reg), "push{q}\t$reg", [], IIC_PUSH_REG>;
821def PUSH64rmr: I<0xFF, MRM6r, (outs), (ins GR64:$reg), "push{q}\t$reg", [],
822 IIC_PUSH_REG>;
823def PUSH64rmm: I<0xFF, MRM6m, (outs), (ins i64mem:$src), "push{q}\t$src", [],
824 IIC_PUSH_MEM>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000825}
826}
827
828let Defs = [RSP], Uses = [RSP], neverHasSideEffects = 1, mayStore = 1 in {
Kevin Enderbyd521f2d2011-07-06 17:23:46 +0000829def PUSH64i8 : Ii8<0x6a, RawFrm, (outs), (ins i64i8imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000830 "push{q}\t$imm", [], IIC_PUSH_IMM>;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000831def PUSH64i16 : Ii16<0x68, RawFrm, (outs), (ins i16imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000832 "push{q}\t$imm", [], IIC_PUSH_IMM>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000833def PUSH64i32 : Ii32<0x68, RawFrm, (outs), (ins i64i32imm:$imm),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000834 "push{q}\t$imm", [], IIC_PUSH_IMM>;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000835}
836
837let Defs = [RSP, EFLAGS], Uses = [RSP], mayLoad = 1, neverHasSideEffects=1 in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000838def POPF64 : I<0x9D, RawFrm, (outs), (ins), "popfq", [], IIC_POP_FD>,
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000839 Requires<[In64BitMode]>;
840let Defs = [RSP], Uses = [RSP, EFLAGS], mayStore = 1, neverHasSideEffects=1 in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000841def PUSHF64 : I<0x9C, RawFrm, (outs), (ins), "pushfq", [], IIC_PUSH_F>,
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000842 Requires<[In64BitMode]>;
843
844
Evan Cheng2f245ba2007-09-26 01:29:06 +0000845
Nico Weber50b9efc2010-06-23 20:00:58 +0000846let Defs = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP], Uses = [ESP],
847 mayLoad=1, neverHasSideEffects=1 in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000848def POPA32 : I<0x61, RawFrm, (outs), (ins), "popa{l}", [], IIC_POP_A>,
Nico Weber50b9efc2010-06-23 20:00:58 +0000849 Requires<[In32BitMode]>;
850}
851let Defs = [ESP], Uses = [EDI, ESI, EBP, EBX, EDX, ECX, EAX, ESP],
852 mayStore=1, neverHasSideEffects=1 in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000853def PUSHA32 : I<0x60, RawFrm, (outs), (ins), "pusha{l}", [], IIC_PUSH_A>,
Nico Weber50b9efc2010-06-23 20:00:58 +0000854 Requires<[In32BitMode]>;
855}
856
Chris Lattner8917cd32010-10-05 06:52:26 +0000857let Constraints = "$src = $dst" in { // GR32 = bswap GR32
858def BSWAP32r : I<0xC8, AddRegFrm,
859 (outs GR32:$dst), (ins GR32:$src),
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000860 "bswap{l}\t$dst",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000861 [(set GR32:$dst, (bswap GR32:$src))], IIC_BSWAP>, TB;
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000862
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000863def BSWAP64r : RI<0xC8, AddRegFrm, (outs GR64:$dst), (ins GR64:$src),
Michael J. Spencer6e56b182010-10-20 23:40:27 +0000864 "bswap{q}\t$dst",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000865 [(set GR64:$dst, (bswap GR64:$src))], IIC_BSWAP>, TB;
Chris Lattner8917cd32010-10-05 06:52:26 +0000866} // Constraints = "$src = $dst"
Chris Lattner1cca5e32003-08-03 21:54:21 +0000867
Evan Cheng18efe262007-12-14 02:13:44 +0000868// Bit scan instructions.
869let Defs = [EFLAGS] in {
Evan Chengfd9e4732007-12-14 18:49:43 +0000870def BSF16rr : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000871 "bsf{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000872 [(set GR16:$dst, EFLAGS, (X86bsf GR16:$src))],
873 IIC_BSF>, TB, OpSize;
Evan Cheng18efe262007-12-14 02:13:44 +0000874def BSF16rm : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000875 "bsf{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000876 [(set GR16:$dst, EFLAGS, (X86bsf (loadi16 addr:$src)))],
877 IIC_BSF>, TB, OpSize;
Evan Chengfd9e4732007-12-14 18:49:43 +0000878def BSF32rr : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000879 "bsf{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000880 [(set GR32:$dst, EFLAGS, (X86bsf GR32:$src))], IIC_BSF>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000881def BSF32rm : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000882 "bsf{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000883 [(set GR32:$dst, EFLAGS, (X86bsf (loadi32 addr:$src)))],
884 IIC_BSF>, TB;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000885def BSF64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
886 "bsf{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000887 [(set GR64:$dst, EFLAGS, (X86bsf GR64:$src))],
888 IIC_BSF>, TB;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000889def BSF64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
890 "bsf{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000891 [(set GR64:$dst, EFLAGS, (X86bsf (loadi64 addr:$src)))],
892 IIC_BSF>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000893
Evan Chengfd9e4732007-12-14 18:49:43 +0000894def BSR16rr : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000895 "bsr{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000896 [(set GR16:$dst, EFLAGS, (X86bsr GR16:$src))], IIC_BSR>,
897 TB, OpSize;
Evan Cheng18efe262007-12-14 02:13:44 +0000898def BSR16rm : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000899 "bsr{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000900 [(set GR16:$dst, EFLAGS, (X86bsr (loadi16 addr:$src)))],
901 IIC_BSR>, TB,
Kevin Enderby9ac72822010-04-28 23:20:40 +0000902 OpSize;
Evan Chengfd9e4732007-12-14 18:49:43 +0000903def BSR32rr : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000904 "bsr{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000905 [(set GR32:$dst, EFLAGS, (X86bsr GR32:$src))], IIC_BSR>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000906def BSR32rm : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohman1a8001e2007-12-14 15:10:00 +0000907 "bsr{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000908 [(set GR32:$dst, EFLAGS, (X86bsr (loadi32 addr:$src)))],
909 IIC_BSR>, TB;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000910def BSR64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
911 "bsr{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000912 [(set GR64:$dst, EFLAGS, (X86bsr GR64:$src))], IIC_BSR>, TB;
Chris Lattnerd8cc2722010-10-05 06:47:35 +0000913def BSR64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
914 "bsr{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000915 [(set GR64:$dst, EFLAGS, (X86bsr (loadi64 addr:$src)))],
916 IIC_BSR>, TB;
Evan Cheng18efe262007-12-14 02:13:44 +0000917} // Defs = [EFLAGS]
918
Chris Lattner915e5e52004-02-12 17:53:22 +0000919
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000920// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
921let Defs = [EDI,ESI], Uses = [EDI,ESI,EFLAGS] in {
Preston Gurddeaa3f32012-05-10 21:58:35 +0000922def MOVSB : I<0xA4, RawFrm, (outs), (ins), "movsb", [], IIC_MOVS>;
923def MOVSW : I<0xA5, RawFrm, (outs), (ins), "movsw", [], IIC_MOVS>, OpSize;
924def MOVSD : I<0xA5, RawFrm, (outs), (ins), "movs{l|d}", [], IIC_MOVS>;
925def MOVSQ : RI<0xA5, RawFrm, (outs), (ins), "movsq", [], IIC_MOVS>;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000926}
927
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000928// These uses the DF flag in the EFLAGS register to inc or dec EDI and ESI
929let Defs = [EDI], Uses = [AL,EDI,EFLAGS] in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000930def STOSB : I<0xAA, RawFrm, (outs), (ins), "stosb", [], IIC_STOS>;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000931let Defs = [EDI], Uses = [AX,EDI,EFLAGS] in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000932def STOSW : I<0xAB, RawFrm, (outs), (ins), "stosw", [], IIC_STOS>, OpSize;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000933let Defs = [EDI], Uses = [EAX,EDI,EFLAGS] in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000934def STOSD : I<0xAB, RawFrm, (outs), (ins), "stos{l|d}", [], IIC_STOS>;
Chris Lattnerd3f033d2010-10-05 06:27:48 +0000935let Defs = [RCX,RDI], Uses = [RAX,RCX,RDI,EFLAGS] in
Preston Gurddeaa3f32012-05-10 21:58:35 +0000936def STOSQ : RI<0xAB, RawFrm, (outs), (ins), "stosq", [], IIC_STOS>;
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000937
Preston Gurddeaa3f32012-05-10 21:58:35 +0000938def SCAS8 : I<0xAE, RawFrm, (outs), (ins), "scasb", [], IIC_SCAS>;
939def SCAS16 : I<0xAF, RawFrm, (outs), (ins), "scasw", [], IIC_SCAS>, OpSize;
940def SCAS32 : I<0xAF, RawFrm, (outs), (ins), "scas{l|d}", [], IIC_SCAS>;
941def SCAS64 : RI<0xAF, RawFrm, (outs), (ins), "scasq", [], IIC_SCAS>;
Sean Callanana82e4652009-09-12 00:37:19 +0000942
Preston Gurddeaa3f32012-05-10 21:58:35 +0000943def CMPS8 : I<0xA6, RawFrm, (outs), (ins), "cmpsb", [], IIC_CMPS>;
944def CMPS16 : I<0xA7, RawFrm, (outs), (ins), "cmpsw", [], IIC_CMPS>, OpSize;
945def CMPS32 : I<0xA7, RawFrm, (outs), (ins), "cmps{l|d}", [], IIC_CMPS>;
946def CMPS64 : RI<0xA7, RawFrm, (outs), (ins), "cmpsq", [], IIC_CMPS>;
Sean Callanan6f8f4622009-09-12 02:25:20 +0000947
Chris Lattner02552de2009-08-11 16:58:39 +0000948
Chris Lattner1cca5e32003-08-03 21:54:21 +0000949//===----------------------------------------------------------------------===//
Chris Lattner434c7cb2010-10-05 05:32:15 +0000950// Move Instructions.
Chris Lattner1cca5e32003-08-03 21:54:21 +0000951//
Chris Lattner748a2fe2010-10-05 20:49:15 +0000952
Chris Lattnerba7e7562008-01-10 07:59:24 +0000953let neverHasSideEffects = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000954def MOV8rr : I<0x88, MRMDestReg, (outs GR8 :$dst), (ins GR8 :$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000955 "mov{b}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000956def MOV16rr : I<0x89, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000957 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +0000958def MOV32rr : I<0x89, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000959 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Chris Lattner748a2fe2010-10-05 20:49:15 +0000960def MOV64rr : RI<0x89, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000961 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000962}
Evan Cheng359e9372008-06-18 08:13:07 +0000963let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000964def MOV8ri : Ii8 <0xB0, AddRegFrm, (outs GR8 :$dst), (ins i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000965 "mov{b}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000966 [(set GR8:$dst, imm:$src)], IIC_MOV>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000967def MOV16ri : Ii16<0xB8, AddRegFrm, (outs GR16:$dst), (ins i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000968 "mov{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000969 [(set GR16:$dst, imm:$src)], IIC_MOV>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +0000970def MOV32ri : Ii32<0xB8, AddRegFrm, (outs GR32:$dst), (ins i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000971 "mov{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000972 [(set GR32:$dst, imm:$src)], IIC_MOV>;
Chris Lattner748a2fe2010-10-05 20:49:15 +0000973def MOV64ri : RIi64<0xB8, AddRegFrm, (outs GR64:$dst), (ins i64imm:$src),
974 "movabs{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000975 [(set GR64:$dst, imm:$src)], IIC_MOV>;
Chris Lattner748a2fe2010-10-05 20:49:15 +0000976def MOV64ri32 : RIi32<0xC7, MRM0r, (outs GR64:$dst), (ins i64i32imm:$src),
977 "mov{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000978 [(set GR64:$dst, i64immSExt32:$src)], IIC_MOV>;
Dan Gohmand45eddd2007-06-26 00:48:07 +0000979}
Kevin Enderby12ce0de2010-02-03 21:04:42 +0000980
Evan Cheng64d80e32007-07-19 01:14:50 +0000981def MOV8mi : Ii8 <0xC6, MRM0m, (outs), (ins i8mem :$dst, i8imm :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000982 "mov{b}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000983 [(store (i8 imm:$src), addr:$dst)], IIC_MOV_MEM>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000984def MOV16mi : Ii16<0xC7, MRM0m, (outs), (ins i16mem:$dst, i16imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000985 "mov{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000986 [(store (i16 imm:$src), addr:$dst)], IIC_MOV_MEM>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +0000987def MOV32mi : Ii32<0xC7, MRM0m, (outs), (ins i32mem:$dst, i32imm:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +0000988 "mov{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000989 [(store (i32 imm:$src), addr:$dst)], IIC_MOV_MEM>;
Chris Lattner748a2fe2010-10-05 20:49:15 +0000990def MOV64mi32 : RIi32<0xC7, MRM0m, (outs), (ins i64mem:$dst, i64i32imm:$src),
991 "mov{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +0000992 [(store i64immSExt32:$src, addr:$dst)], IIC_MOV_MEM>;
Chris Lattner1cca5e32003-08-03 21:54:21 +0000993
Chris Lattnerb5505d02010-05-13 00:02:47 +0000994/// moffs8, moffs16 and moffs32 versions of moves. The immediate is a
995/// 32-bit offset from the PC. These are only valid in x86-32 mode.
Chris Lattner2745f6e2010-05-12 22:48:24 +0000996def MOV8o8a : Ii32 <0xA0, RawFrm, (outs), (ins offset8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +0000997 "mov{b}\t{$src, %al|AL, $src}", [], IIC_MOV_MEM>,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +0000998 Requires<[In32BitMode]>;
Chris Lattner2745f6e2010-05-12 22:48:24 +0000999def MOV16o16a : Ii32 <0xA1, RawFrm, (outs), (ins offset16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001000 "mov{w}\t{$src, %ax|AL, $src}", [], IIC_MOV_MEM>, OpSize,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +00001001 Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001002def MOV32o32a : Ii32 <0xA1, RawFrm, (outs), (ins offset32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001003 "mov{l}\t{$src, %eax|EAX, $src}", [], IIC_MOV_MEM>,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +00001004 Requires<[In32BitMode]>;
Chris Lattner2745f6e2010-05-12 22:48:24 +00001005def MOV8ao8 : Ii32 <0xA2, RawFrm, (outs offset8:$dst), (ins),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001006 "mov{b}\t{%al, $dst|$dst, AL}", [], IIC_MOV_MEM>,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +00001007 Requires<[In32BitMode]>;
Chris Lattner2745f6e2010-05-12 22:48:24 +00001008def MOV16ao16 : Ii32 <0xA3, RawFrm, (outs offset16:$dst), (ins),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001009 "mov{w}\t{%ax, $dst|$dst, AL}", [], IIC_MOV_MEM>, OpSize,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +00001010 Requires<[In32BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +00001011def MOV32ao32 : Ii32 <0xA3, RawFrm, (outs offset32:$dst), (ins),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001012 "mov{l}\t{%eax, $dst|$dst, EAX}", [], IIC_MOV_MEM>,
Daniel Dunbar6c2c9a22010-07-19 06:14:44 +00001013 Requires<[In32BitMode]>;
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001014
Chris Lattner748a2fe2010-10-05 20:49:15 +00001015// FIXME: These definitions are utterly broken
1016// Just leave them commented out for now because they're useless outside
1017// of the large code model, and most compilers won't generate the instructions
1018// in question.
1019/*
1020def MOV64o8a : RIi8<0xA0, RawFrm, (outs), (ins offset8:$src),
Craig Topper82f131a2011-10-02 21:08:12 +00001021 "mov{q}\t{$src, %rax|RAX, $src}", []>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001022def MOV64o64a : RIi32<0xA1, RawFrm, (outs), (ins offset64:$src),
Craig Topper82f131a2011-10-02 21:08:12 +00001023 "mov{q}\t{$src, %rax|RAX, $src}", []>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001024def MOV64ao8 : RIi8<0xA2, RawFrm, (outs offset8:$dst), (ins),
Craig Topper82f131a2011-10-02 21:08:12 +00001025 "mov{q}\t{%rax, $dst|$dst, RAX}", []>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001026def MOV64ao64 : RIi32<0xA3, RawFrm, (outs offset64:$dst), (ins),
Craig Topper82f131a2011-10-02 21:08:12 +00001027 "mov{q}\t{%rax, $dst|$dst, RAX}", []>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001028*/
1029
Sean Callanan38fee0e2009-09-15 18:47:29 +00001030
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001031let isCodeGenOnly = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001032def MOV8rr_REV : I<0x8A, MRMSrcReg, (outs GR8:$dst), (ins GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001033 "mov{b}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Sean Callanan108934c2009-12-18 00:01:26 +00001034def MOV16rr_REV : I<0x8B, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001035 "mov{w}\t{$src, $dst|$dst, $src}", [], IIC_MOV>, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001036def MOV32rr_REV : I<0x8B, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001037 "mov{l}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001038def MOV64rr_REV : RI<0x8B, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001039 "mov{q}\t{$src, $dst|$dst, $src}", [], IIC_MOV>;
Daniel Dunbardcbab9c2010-05-26 22:21:28 +00001040}
Sean Callanan108934c2009-12-18 00:01:26 +00001041
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001042let canFoldAsLoad = 1, isReMaterializable = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +00001043def MOV8rm : I<0x8A, MRMSrcMem, (outs GR8 :$dst), (ins i8mem :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001044 "mov{b}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001045 [(set GR8:$dst, (loadi8 addr:$src))], IIC_MOV_MEM>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001046def MOV16rm : I<0x8B, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001047 "mov{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001048 [(set GR16:$dst, (loadi16 addr:$src))], IIC_MOV_MEM>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001049def MOV32rm : I<0x8B, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001050 "mov{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001051 [(set GR32:$dst, (loadi32 addr:$src))], IIC_MOV_MEM>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001052def MOV64rm : RI<0x8B, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1053 "mov{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001054 [(set GR64:$dst, (load addr:$src))], IIC_MOV_MEM>;
Evan Cheng2f394262007-08-30 05:49:43 +00001055}
Chris Lattner1cca5e32003-08-03 21:54:21 +00001056
Evan Cheng64d80e32007-07-19 01:14:50 +00001057def MOV8mr : I<0x88, MRMDestMem, (outs), (ins i8mem :$dst, GR8 :$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001058 "mov{b}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001059 [(store GR8:$src, addr:$dst)], IIC_MOV_MEM>;
Evan Cheng64d80e32007-07-19 01:14:50 +00001060def MOV16mr : I<0x89, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001061 "mov{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001062 [(store GR16:$src, addr:$dst)], IIC_MOV_MEM>, OpSize;
Evan Cheng64d80e32007-07-19 01:14:50 +00001063def MOV32mr : I<0x89, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Dan Gohmanb1576f52007-07-31 20:11:57 +00001064 "mov{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001065 [(store GR32:$src, addr:$dst)], IIC_MOV_MEM>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001066def MOV64mr : RI<0x89, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
1067 "mov{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001068 [(store GR64:$src, addr:$dst)], IIC_MOV_MEM>;
Dan Gohman21e3dfb2009-04-13 16:09:41 +00001069
Dan Gohman4af325d2009-04-27 16:41:36 +00001070// Versions of MOV8rr, MOV8mr, and MOV8rm that use i8mem_NOREX and GR8_NOREX so
1071// that they can be used for copying and storing h registers, which can't be
1072// encoded when a REX prefix is present.
Daniel Dunbarcf246b72010-07-19 06:14:49 +00001073let isCodeGenOnly = 1 in {
Dan Gohman6d9305c2009-04-15 00:04:23 +00001074let neverHasSideEffects = 1 in
Dan Gohmandf7dfc72009-04-15 19:48:57 +00001075def MOV8rr_NOREX : I<0x88, MRMDestReg,
1076 (outs GR8_NOREX:$dst), (ins GR8_NOREX:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001077 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [], IIC_MOV>;
Evan Cheng8c147402009-04-30 00:58:57 +00001078let mayStore = 1 in
Dan Gohman6d9305c2009-04-15 00:04:23 +00001079def MOV8mr_NOREX : I<0x88, MRMDestMem,
1080 (outs), (ins i8mem_NOREX:$dst, GR8_NOREX:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001081 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [],
1082 IIC_MOV_MEM>;
Jakob Stoklund Olesenccbe6032011-10-14 01:00:49 +00001083let mayLoad = 1, neverHasSideEffects = 1,
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001084 canFoldAsLoad = 1, isReMaterializable = 1 in
Dan Gohman4af325d2009-04-27 16:41:36 +00001085def MOV8rm_NOREX : I<0x8A, MRMSrcMem,
1086 (outs GR8_NOREX:$dst), (ins i8mem_NOREX:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001087 "mov{b}\t{$src, $dst|$dst, $src} # NOREX", [],
1088 IIC_MOV_MEM>;
Daniel Dunbarcf246b72010-07-19 06:14:49 +00001089}
Dan Gohman21e3dfb2009-04-13 16:09:41 +00001090
Evan Cheng0488db92007-09-25 01:57:46 +00001091
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001092// Condition code ops, incl. set if equal/not equal/...
Benjamin Kramer17c836c2012-04-27 12:07:43 +00001093let Defs = [EFLAGS], Uses = [AH] in
1094def SAHF : I<0x9E, RawFrm, (outs), (ins), "sahf",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001095 [(set EFLAGS, (X86sahf AH))], IIC_AHF>;
Chris Lattnerba7e7562008-01-10 07:59:24 +00001096let Defs = [AH], Uses = [EFLAGS], neverHasSideEffects = 1 in
Preston Gurddeaa3f32012-05-10 21:58:35 +00001097def LAHF : I<0x9F, RawFrm, (outs), (ins), "lahf", [],
1098 IIC_AHF>; // AH = flags
Alkis Evlogimenos5ab29b52004-02-28 22:02:05 +00001099
Sean Callanana09caa52009-09-02 00:55:49 +00001100
Chris Lattner748a2fe2010-10-05 20:49:15 +00001101//===----------------------------------------------------------------------===//
1102// Bit tests instructions: BT, BTS, BTR, BTC.
Daniel Dunbar1e8ee892010-03-09 22:50:40 +00001103
Dan Gohmanc7a37d42008-12-23 22:45:23 +00001104let Defs = [EFLAGS] in {
Dan Gohman0c89b7e2009-01-13 20:32:45 +00001105def BT16rr : I<0xA3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
Dan Gohmanc7a37d42008-12-23 22:45:23 +00001106 "bt{w}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001107 [(set EFLAGS, (X86bt GR16:$src1, GR16:$src2))], IIC_BT_RR>,
1108 OpSize, TB;
Dan Gohman0c89b7e2009-01-13 20:32:45 +00001109def BT32rr : I<0xA3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
Dan Gohmanc7a37d42008-12-23 22:45:23 +00001110 "bt{l}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001111 [(set EFLAGS, (X86bt GR32:$src1, GR32:$src2))], IIC_BT_RR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001112def BT64rr : RI<0xA3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1113 "bt{q}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001114 [(set EFLAGS, (X86bt GR64:$src1, GR64:$src2))], IIC_BT_RR>, TB;
Dan Gohmanf31408d2009-01-13 23:23:30 +00001115
1116// Unlike with the register+register form, the memory+register form of the
1117// bt instruction does not ignore the high bits of the index. From ISel's
Sean Callanan108934c2009-12-18 00:01:26 +00001118// perspective, this is pretty bizarre. Make these instructions disassembly
1119// only for now.
1120
1121def BT16mr : I<0xA3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001122 "bt{w}\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf31408d2009-01-13 23:23:30 +00001123// [(X86bt (loadi16 addr:$src1), GR16:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001124// (implicit EFLAGS)]
Preston Gurddeaa3f32012-05-10 21:58:35 +00001125 [], IIC_BT_MR
Sean Callanan108934c2009-12-18 00:01:26 +00001126 >, OpSize, TB, Requires<[FastBTMem]>;
1127def BT32mr : I<0xA3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001128 "bt{l}\t{$src2, $src1|$src1, $src2}",
Dan Gohmanf31408d2009-01-13 23:23:30 +00001129// [(X86bt (loadi32 addr:$src1), GR32:$src2),
Sean Callanan108934c2009-12-18 00:01:26 +00001130// (implicit EFLAGS)]
Preston Gurddeaa3f32012-05-10 21:58:35 +00001131 [], IIC_BT_MR
Sean Callanan108934c2009-12-18 00:01:26 +00001132 >, TB, Requires<[FastBTMem]>;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001133def BT64mr : RI<0xA3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
1134 "bt{q}\t{$src2, $src1|$src1, $src2}",
1135// [(X86bt (loadi64 addr:$src1), GR64:$src2),
1136// (implicit EFLAGS)]
Preston Gurddeaa3f32012-05-10 21:58:35 +00001137 [], IIC_BT_MR
Chris Lattner748a2fe2010-10-05 20:49:15 +00001138 >, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00001139
1140def BT16ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR16:$src1, i16i8imm:$src2),
1141 "bt{w}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001142 [(set EFLAGS, (X86bt GR16:$src1, i16immSExt8:$src2))],
1143 IIC_BT_RI>, OpSize, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00001144def BT32ri8 : Ii8<0xBA, MRM4r, (outs), (ins GR32:$src1, i32i8imm:$src2),
1145 "bt{l}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001146 [(set EFLAGS, (X86bt GR32:$src1, i32immSExt8:$src2))],
1147 IIC_BT_RI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001148def BT64ri8 : RIi8<0xBA, MRM4r, (outs), (ins GR64:$src1, i64i8imm:$src2),
1149 "bt{q}\t{$src2, $src1|$src1, $src2}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001150 [(set EFLAGS, (X86bt GR64:$src1, i64immSExt8:$src2))],
1151 IIC_BT_RI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001152
Dan Gohman4afe15b2009-01-13 20:33:23 +00001153// Note that these instructions don't need FastBTMem because that
1154// only applies when the other operand is in a register. When it's
1155// an immediate, bt is still fast.
1156def BT16mi8 : Ii8<0xBA, MRM4m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
1157 "bt{w}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001158 [(set EFLAGS, (X86bt (loadi16 addr:$src1), i16immSExt8:$src2))
Preston Gurddeaa3f32012-05-10 21:58:35 +00001159 ], IIC_BT_MI>, OpSize, TB;
Dan Gohman4afe15b2009-01-13 20:33:23 +00001160def BT32mi8 : Ii8<0xBA, MRM4m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
1161 "bt{l}\t{$src2, $src1|$src1, $src2}",
Chris Lattnere3486a42010-03-19 00:01:11 +00001162 [(set EFLAGS, (X86bt (loadi32 addr:$src1), i32immSExt8:$src2))
Preston Gurddeaa3f32012-05-10 21:58:35 +00001163 ], IIC_BT_MI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001164def BT64mi8 : RIi8<0xBA, MRM4m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
1165 "bt{q}\t{$src2, $src1|$src1, $src2}",
1166 [(set EFLAGS, (X86bt (loadi64 addr:$src1),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001167 i64immSExt8:$src2))], IIC_BT_MI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001168
Sean Callanan108934c2009-12-18 00:01:26 +00001169
1170def BTC16rr : I<0xBB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001171 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>,
1172 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001173def BTC32rr : I<0xBB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001174 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001175def BTC64rr : RI<0xBB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001176 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001177def BTC16mr : I<0xBB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001178 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>,
1179 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001180def BTC32mr : I<0xBB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001181 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001182def BTC64mr : RI<0xBB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001183 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001184def BTC16ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR16:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001185 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>,
1186 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001187def BTC32ri8 : Ii8<0xBA, MRM7r, (outs), (ins GR32:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001188 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001189def BTC64ri8 : RIi8<0xBA, MRM7r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001190 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001191def BTC16mi8 : Ii8<0xBA, MRM7m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001192 "btc{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>,
1193 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001194def BTC32mi8 : Ii8<0xBA, MRM7m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001195 "btc{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001196def BTC64mi8 : RIi8<0xBA, MRM7m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001197 "btc{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001198
1199def BTR16rr : I<0xB3, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001200 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>,
1201 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001202def BTR32rr : I<0xB3, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001203 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001204def BTR64rr : RI<0xB3, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
1205 "btr{q}\t{$src2, $src1|$src1, $src2}", []>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001206def BTR16mr : I<0xB3, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001207 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>,
1208 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001209def BTR32mr : I<0xB3, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001210 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001211def BTR64mr : RI<0xB3, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001212 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001213def BTR16ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR16:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001214 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>,
1215 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001216def BTR32ri8 : Ii8<0xBA, MRM6r, (outs), (ins GR32:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001217 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001218def BTR64ri8 : RIi8<0xBA, MRM6r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001219 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001220def BTR16mi8 : Ii8<0xBA, MRM6m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001221 "btr{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>,
1222 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001223def BTR32mi8 : Ii8<0xBA, MRM6m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001224 "btr{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001225def BTR64mi8 : RIi8<0xBA, MRM6m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001226 "btr{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001227
1228def BTS16rr : I<0xAB, MRMDestReg, (outs), (ins GR16:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001229 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>,
1230 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001231def BTS32rr : I<0xAB, MRMDestReg, (outs), (ins GR32:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001232 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001233def BTS64rr : RI<0xAB, MRMDestReg, (outs), (ins GR64:$src1, GR64:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001234 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RR>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001235def BTS16mr : I<0xAB, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001236 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>,
1237 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001238def BTS32mr : I<0xAB, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001239 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001240def BTS64mr : RI<0xAB, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001241 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MR>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001242def BTS16ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR16:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001243 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>,
1244 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001245def BTS32ri8 : Ii8<0xBA, MRM5r, (outs), (ins GR32:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001246 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001247def BTS64ri8 : RIi8<0xBA, MRM5r, (outs), (ins GR64:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001248 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_RI>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001249def BTS16mi8 : Ii8<0xBA, MRM5m, (outs), (ins i16mem:$src1, i16i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001250 "bts{w}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>,
1251 OpSize, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001252def BTS32mi8 : Ii8<0xBA, MRM5m, (outs), (ins i32mem:$src1, i32i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001253 "bts{l}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Chris Lattner748a2fe2010-10-05 20:49:15 +00001254def BTS64mi8 : RIi8<0xBA, MRM5m, (outs), (ins i64mem:$src1, i64i8imm:$src2),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001255 "bts{q}\t{$src2, $src1|$src1, $src2}", [], IIC_BTX_MI>, TB;
Dan Gohmanc7a37d42008-12-23 22:45:23 +00001256} // Defs = [EFLAGS]
1257
Anton Korobeynikov2365f512007-07-14 14:06:15 +00001258
1259//===----------------------------------------------------------------------===//
Andrew Lenharthab0b9492008-02-21 06:45:13 +00001260// Atomic support
1261//
Andrew Lenharthea7da502008-03-01 13:37:02 +00001262
Eric Christopher9a9d2752010-07-22 02:48:34 +00001263
Evan Chengbb6939d2008-04-19 01:20:30 +00001264// Atomic swap. These are just normal xchg instructions. But since a memory
1265// operand is referenced, the atomicity is ensured.
Dan Gohman165660e2008-08-06 15:52:50 +00001266let Constraints = "$val = $dst" in {
Chris Lattner010496c2010-10-05 06:22:35 +00001267def XCHG8rm : I<0x86, MRMSrcMem, (outs GR8:$dst), (ins GR8:$val, i8mem:$ptr),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001268 "xchg{b}\t{$val, $ptr|$ptr, $val}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001269 [(set GR8:$dst, (atomic_swap_8 addr:$ptr, GR8:$val))],
1270 IIC_XCHG_MEM>;
Chris Lattner5bde7342010-11-06 08:20:59 +00001271def XCHG16rm : I<0x87, MRMSrcMem, (outs GR16:$dst),(ins GR16:$val, i16mem:$ptr),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001272 "xchg{w}\t{$val, $ptr|$ptr, $val}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001273 [(set GR16:$dst, (atomic_swap_16 addr:$ptr, GR16:$val))],
1274 IIC_XCHG_MEM>,
Evan Chengbb6939d2008-04-19 01:20:30 +00001275 OpSize;
Chris Lattner5bde7342010-11-06 08:20:59 +00001276def XCHG32rm : I<0x87, MRMSrcMem, (outs GR32:$dst),(ins GR32:$val, i32mem:$ptr),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001277 "xchg{l}\t{$val, $ptr|$ptr, $val}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001278 [(set GR32:$dst, (atomic_swap_32 addr:$ptr, GR32:$val))],
1279 IIC_XCHG_MEM>;
Chris Lattner5bde7342010-11-06 08:20:59 +00001280def XCHG64rm : RI<0x87, MRMSrcMem, (outs GR64:$dst),(ins GR64:$val,i64mem:$ptr),
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001281 "xchg{q}\t{$val, $ptr|$ptr, $val}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001282 [(set GR64:$dst, (atomic_swap_64 addr:$ptr, GR64:$val))],
1283 IIC_XCHG_MEM>;
Sean Callanan108934c2009-12-18 00:01:26 +00001284
Sean Callanan108934c2009-12-18 00:01:26 +00001285def XCHG8rr : I<0x86, MRMSrcReg, (outs GR8:$dst), (ins GR8:$val, GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001286 "xchg{b}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>;
Chris Lattner010496c2010-10-05 06:22:35 +00001287def XCHG16rr : I<0x87, MRMSrcReg, (outs GR16:$dst), (ins GR16:$val, GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001288 "xchg{w}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>, OpSize;
Chris Lattner010496c2010-10-05 06:22:35 +00001289def XCHG32rr : I<0x87, MRMSrcReg, (outs GR32:$dst), (ins GR32:$val, GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001290 "xchg{l}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>;
Chris Lattner010496c2010-10-05 06:22:35 +00001291def XCHG64rr : RI<0x87, MRMSrcReg, (outs GR64:$dst), (ins GR64:$val,GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001292 "xchg{q}\t{$val, $src|$src, $val}", [], IIC_XCHG_REG>;
Evan Chengbb6939d2008-04-19 01:20:30 +00001293}
1294
Craig Topper25f6dfd2011-10-07 05:35:38 +00001295def XCHG16ar : I<0x90, AddRegFrm, (outs), (ins GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001296 "xchg{w}\t{$src, %ax|AX, $src}", [], IIC_XCHG_REG>, OpSize;
Craig Topper25f6dfd2011-10-07 05:35:38 +00001297def XCHG32ar : I<0x90, AddRegFrm, (outs), (ins GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001298 "xchg{l}\t{$src, %eax|EAX, $src}", [], IIC_XCHG_REG>,
1299 Requires<[In32BitMode]>;
Craig Topper25f6dfd2011-10-07 05:35:38 +00001300// Uses GR32_NOAX in 64-bit mode to prevent encoding using the 0x90 NOP encoding.
1301// xchg %eax, %eax needs to clear upper 32-bits of RAX so is not a NOP.
1302def XCHG32ar64 : I<0x90, AddRegFrm, (outs), (ins GR32_NOAX:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001303 "xchg{l}\t{$src, %eax|EAX, $src}", [], IIC_XCHG_REG>,
1304 Requires<[In64BitMode]>;
Craig Topper25f6dfd2011-10-07 05:35:38 +00001305def XCHG64ar : RI<0x90, AddRegFrm, (outs), (ins GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001306 "xchg{q}\t{$src, %rax|RAX, $src}", [], IIC_XCHG_REG>;
Sean Callanan108934c2009-12-18 00:01:26 +00001307
Andrew Lenharth26ed8692008-03-01 21:52:34 +00001308
Andrew Lenharthea7da502008-03-01 13:37:02 +00001309
Sean Callanan108934c2009-12-18 00:01:26 +00001310def XADD8rr : I<0xC0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001311 "xadd{b}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001312def XADD16rr : I<0xC1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001313 "xadd{w}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB,
1314 OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001315def XADD32rr : I<0xC1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001316 "xadd{l}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB;
Chris Lattner010496c2010-10-05 06:22:35 +00001317def XADD64rr : RI<0xC1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001318 "xadd{q}\t{$src, $dst|$dst, $src}", [], IIC_XADD_REG>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001319
Dan Gohman7f357ec2010-05-14 16:34:55 +00001320let mayLoad = 1, mayStore = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001321def XADD8rm : I<0xC0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001322 "xadd{b}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001323def XADD16rm : I<0xC1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001324 "xadd{w}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB,
1325 OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001326def XADD32rm : I<0xC1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001327 "xadd{l}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB;
Chris Lattner010496c2010-10-05 06:22:35 +00001328def XADD64rm : RI<0xC1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001329 "xadd{q}\t{$src, $dst|$dst, $src}", [], IIC_XADD_MEM>, TB;
Chris Lattner010496c2010-10-05 06:22:35 +00001330
Dan Gohman7f357ec2010-05-14 16:34:55 +00001331}
Sean Callanan108934c2009-12-18 00:01:26 +00001332
1333def CMPXCHG8rr : I<0xB0, MRMDestReg, (outs GR8:$dst), (ins GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001334 "cmpxchg{b}\t{$src, $dst|$dst, $src}", [],
1335 IIC_CMPXCHG_REG8>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001336def CMPXCHG16rr : I<0xB1, MRMDestReg, (outs GR16:$dst), (ins GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001337 "cmpxchg{w}\t{$src, $dst|$dst, $src}", [],
1338 IIC_CMPXCHG_REG>, TB, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001339def CMPXCHG32rr : I<0xB1, MRMDestReg, (outs GR32:$dst), (ins GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001340 "cmpxchg{l}\t{$src, $dst|$dst, $src}", [],
1341 IIC_CMPXCHG_REG>, TB;
Chris Lattner010496c2010-10-05 06:22:35 +00001342def CMPXCHG64rr : RI<0xB1, MRMDestReg, (outs GR64:$dst), (ins GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001343 "cmpxchg{q}\t{$src, $dst|$dst, $src}", [],
1344 IIC_CMPXCHG_REG>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001345
Dan Gohman7f357ec2010-05-14 16:34:55 +00001346let mayLoad = 1, mayStore = 1 in {
Sean Callanan108934c2009-12-18 00:01:26 +00001347def CMPXCHG8rm : I<0xB0, MRMDestMem, (outs), (ins i8mem:$dst, GR8:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001348 "cmpxchg{b}\t{$src, $dst|$dst, $src}", [],
1349 IIC_CMPXCHG_MEM8>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001350def CMPXCHG16rm : I<0xB1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001351 "cmpxchg{w}\t{$src, $dst|$dst, $src}", [],
1352 IIC_CMPXCHG_MEM>, TB, OpSize;
Sean Callanan108934c2009-12-18 00:01:26 +00001353def CMPXCHG32rm : I<0xB1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001354 "cmpxchg{l}\t{$src, $dst|$dst, $src}", [],
1355 IIC_CMPXCHG_MEM>, TB;
Chris Lattner010496c2010-10-05 06:22:35 +00001356def CMPXCHG64rm : RI<0xB1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001357 "cmpxchg{q}\t{$src, $dst|$dst, $src}", [],
1358 IIC_CMPXCHG_MEM>, TB;
Dan Gohman7f357ec2010-05-14 16:34:55 +00001359}
Sean Callanan108934c2009-12-18 00:01:26 +00001360
Evan Chengb093bd02010-01-08 01:29:19 +00001361let Defs = [EAX, EDX, EFLAGS], Uses = [EAX, EBX, ECX, EDX] in
Sean Callanan108934c2009-12-18 00:01:26 +00001362def CMPXCHG8B : I<0xC7, MRM1m, (outs), (ins i64mem:$dst),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001363 "cmpxchg8b\t$dst", [], IIC_CMPXCHG_8B>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001364
Chris Lattner010496c2010-10-05 06:22:35 +00001365let Defs = [RAX, RDX, EFLAGS], Uses = [RAX, RBX, RCX, RDX] in
1366def CMPXCHG16B : RI<0xC7, MRM1m, (outs), (ins i128mem:$dst),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001367 "cmpxchg16b\t$dst", [], IIC_CMPXCHG_16B>,
1368 TB, Requires<[HasCmpxchg16b]>;
Evan Cheng37b73872009-07-30 08:33:02 +00001369
Evan Cheng37b73872009-07-30 08:33:02 +00001370
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001371
Kevin Enderby12ce0de2010-02-03 21:04:42 +00001372// Lock instruction prefix
1373def LOCK_PREFIX : I<0xF0, RawFrm, (outs), (ins), "lock", []>;
1374
Rafael Espindolabeb68982010-11-23 11:23:24 +00001375// Rex64 instruction prefix
1376def REX64_PREFIX : I<0x48, RawFrm, (outs), (ins), "rex64", []>;
1377
Rafael Espindolabfd2d262010-11-27 20:29:45 +00001378// Data16 instruction prefix
1379def DATA16_PREFIX : I<0x66, RawFrm, (outs), (ins), "data16", []>;
1380
Kevin Enderby12ce0de2010-02-03 21:04:42 +00001381// Repeat string operation instruction prefixes
1382// These uses the DF flag in the EFLAGS register to inc or dec ECX
1383let Defs = [ECX], Uses = [ECX,EFLAGS] in {
1384// Repeat (used with INS, OUTS, MOVS, LODS and STOS)
1385def REP_PREFIX : I<0xF3, RawFrm, (outs), (ins), "rep", []>;
1386// Repeat while not equal (used with CMPS and SCAS)
1387def REPNE_PREFIX : I<0xF2, RawFrm, (outs), (ins), "repne", []>;
1388}
1389
Kevin Enderby12ce0de2010-02-03 21:04:42 +00001390
Sean Callanan9a86f102009-09-16 22:59:28 +00001391// String manipulation instructions
Preston Gurddeaa3f32012-05-10 21:58:35 +00001392def LODSB : I<0xAC, RawFrm, (outs), (ins), "lodsb", [], IIC_LODS>;
1393def LODSW : I<0xAD, RawFrm, (outs), (ins), "lodsw", [], IIC_LODS>, OpSize;
1394def LODSD : I<0xAD, RawFrm, (outs), (ins), "lods{l|d}", [], IIC_LODS>;
1395def LODSQ : RI<0xAD, RawFrm, (outs), (ins), "lodsq", [], IIC_LODS>;
Sean Callanan108934c2009-12-18 00:01:26 +00001396
Preston Gurddeaa3f32012-05-10 21:58:35 +00001397def OUTSB : I<0x6E, RawFrm, (outs), (ins), "outsb", [], IIC_OUTS>;
1398def OUTSW : I<0x6F, RawFrm, (outs), (ins), "outsw", [], IIC_OUTS>, OpSize;
1399def OUTSD : I<0x6F, RawFrm, (outs), (ins), "outs{l|d}", [], IIC_OUTS>;
Sean Callanan108934c2009-12-18 00:01:26 +00001400
Sean Callanan108934c2009-12-18 00:01:26 +00001401
1402// Flag instructions
Preston Gurddeaa3f32012-05-10 21:58:35 +00001403def CLC : I<0xF8, RawFrm, (outs), (ins), "clc", [], IIC_CLC>;
1404def STC : I<0xF9, RawFrm, (outs), (ins), "stc", [], IIC_STC>;
1405def CLI : I<0xFA, RawFrm, (outs), (ins), "cli", [], IIC_CLI>;
1406def STI : I<0xFB, RawFrm, (outs), (ins), "sti", [], IIC_STI>;
1407def CLD : I<0xFC, RawFrm, (outs), (ins), "cld", [], IIC_CLD>;
1408def STD : I<0xFD, RawFrm, (outs), (ins), "std", [], IIC_STD>;
1409def CMC : I<0xF5, RawFrm, (outs), (ins), "cmc", [], IIC_CMC>;
Sean Callanan108934c2009-12-18 00:01:26 +00001410
Preston Gurddeaa3f32012-05-10 21:58:35 +00001411def CLTS : I<0x06, RawFrm, (outs), (ins), "clts", [], IIC_CLTS>, TB;
Sean Callanan108934c2009-12-18 00:01:26 +00001412
1413// Table lookup instructions
Preston Gurddeaa3f32012-05-10 21:58:35 +00001414def XLAT : I<0xD7, RawFrm, (outs), (ins), "xlatb", [], IIC_XLAT>;
Sean Callanan108934c2009-12-18 00:01:26 +00001415
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001416// ASCII Adjust After Addition
1417// sets AL, AH and CF and AF of EFLAGS and uses AL and AF of EFLAGS
Preston Gurddeaa3f32012-05-10 21:58:35 +00001418def AAA : I<0x37, RawFrm, (outs), (ins), "aaa", [], IIC_AAA>,
1419 Requires<[In32BitMode]>;
Evan Cheng510e4782006-01-09 23:10:28 +00001420
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001421// ASCII Adjust AX Before Division
1422// sets AL, AH and EFLAGS and uses AL and AH
1423def AAD8i8 : Ii8<0xD5, RawFrm, (outs), (ins i8imm:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001424 "aad\t$src", [], IIC_AAD>, Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001425
1426// ASCII Adjust AX After Multiply
1427// sets AL, AH and EFLAGS and uses AL
1428def AAM8i8 : Ii8<0xD4, RawFrm, (outs), (ins i8imm:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001429 "aam\t$src", [], IIC_AAM>, Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001430
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001431// ASCII Adjust AL After Subtraction - sets
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001432// sets AL, AH and CF and AF of EFLAGS and uses AL and AF of EFLAGS
Preston Gurddeaa3f32012-05-10 21:58:35 +00001433def AAS : I<0x3F, RawFrm, (outs), (ins), "aas", [], IIC_AAS>,
1434 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001435
1436// Decimal Adjust AL after Addition
1437// sets AL, CF and AF of EFLAGS and uses AL, CF and AF of EFLAGS
Preston Gurddeaa3f32012-05-10 21:58:35 +00001438def DAA : I<0x27, RawFrm, (outs), (ins), "daa", [], IIC_DAA>,
1439 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001440
1441// Decimal Adjust AL after Subtraction
1442// sets AL, CF and AF of EFLAGS and uses AL, CF and AF of EFLAGS
Preston Gurddeaa3f32012-05-10 21:58:35 +00001443def DAS : I<0x2F, RawFrm, (outs), (ins), "das", [], IIC_DAS>,
1444 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001445
1446// Check Array Index Against Bounds
1447def BOUNDS16rm : I<0x62, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001448 "bound\t{$src, $dst|$dst, $src}", [], IIC_BOUND>, OpSize,
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001449 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001450def BOUNDS32rm : I<0x62, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001451 "bound\t{$src, $dst|$dst, $src}", [], IIC_BOUND>,
Michael J. Spencer6e56b182010-10-20 23:40:27 +00001452 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001453
1454// Adjust RPL Field of Segment Selector
1455def ARPL16rr : I<0x63, MRMDestReg, (outs GR16:$src), (ins GR16:$dst),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001456 "arpl\t{$src, $dst|$dst, $src}", [], IIC_ARPL_REG>,
1457 Requires<[In32BitMode]>;
Kevin Enderby7aef62f2010-10-18 17:04:36 +00001458def ARPL16mr : I<0x63, MRMSrcMem, (outs GR16:$src), (ins i16mem:$dst),
Preston Gurddeaa3f32012-05-10 21:58:35 +00001459 "arpl\t{$src, $dst|$dst, $src}", [], IIC_ARPL_MEM>,
1460 Requires<[In32BitMode]>;
Dan Gohmane220c4b2009-09-18 19:59:53 +00001461
Bill Wendlingd350e022008-12-12 21:15:41 +00001462//===----------------------------------------------------------------------===//
Craig Topper581fe822011-10-03 17:28:23 +00001463// MOVBE Instructions
1464//
1465let Predicates = [HasMOVBE] in {
1466 def MOVBE16rm : I<0xF0, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001467 "movbe{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001468 [(set GR16:$dst, (bswap (loadi16 addr:$src)))], IIC_MOVBE>,
1469 OpSize, T8;
Craig Topper581fe822011-10-03 17:28:23 +00001470 def MOVBE32rm : I<0xF0, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001471 "movbe{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001472 [(set GR32:$dst, (bswap (loadi32 addr:$src)))], IIC_MOVBE>,
1473 T8;
Craig Topper581fe822011-10-03 17:28:23 +00001474 def MOVBE64rm : RI<0xF0, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001475 "movbe{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001476 [(set GR64:$dst, (bswap (loadi64 addr:$src)))], IIC_MOVBE>,
1477 T8;
Craig Topper581fe822011-10-03 17:28:23 +00001478 def MOVBE16mr : I<0xF1, MRMDestMem, (outs), (ins i16mem:$dst, GR16:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001479 "movbe{w}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001480 [(store (bswap GR16:$src), addr:$dst)], IIC_MOVBE>,
1481 OpSize, T8;
Craig Topper581fe822011-10-03 17:28:23 +00001482 def MOVBE32mr : I<0xF1, MRMDestMem, (outs), (ins i32mem:$dst, GR32:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001483 "movbe{l}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001484 [(store (bswap GR32:$src), addr:$dst)], IIC_MOVBE>,
1485 T8;
Craig Topper581fe822011-10-03 17:28:23 +00001486 def MOVBE64mr : RI<0xF1, MRMDestMem, (outs), (ins i64mem:$dst, GR64:$src),
Benjamin Kramera86a5862011-10-10 18:34:56 +00001487 "movbe{q}\t{$src, $dst|$dst, $src}",
Preston Gurddeaa3f32012-05-10 21:58:35 +00001488 [(store (bswap GR64:$src), addr:$dst)], IIC_MOVBE>,
1489 T8;
Craig Topper581fe822011-10-03 17:28:23 +00001490}
1491
1492//===----------------------------------------------------------------------===//
1493// RDRAND Instruction
1494//
1495let Predicates = [HasRDRAND], Defs = [EFLAGS] in {
1496 def RDRAND16r : I<0xC7, MRM6r, (outs GR16:$dst), (ins),
Benjamin Kramerb9bee042012-07-12 09:31:43 +00001497 "rdrand{w}\t$dst",
1498 [(set GR16:$dst, EFLAGS, (X86rdrand))]>, OpSize, TB;
Craig Topper581fe822011-10-03 17:28:23 +00001499 def RDRAND32r : I<0xC7, MRM6r, (outs GR32:$dst), (ins),
Benjamin Kramerb9bee042012-07-12 09:31:43 +00001500 "rdrand{l}\t$dst",
1501 [(set GR32:$dst, EFLAGS, (X86rdrand))]>, TB;
Craig Topper581fe822011-10-03 17:28:23 +00001502 def RDRAND64r : RI<0xC7, MRM6r, (outs GR64:$dst), (ins),
Benjamin Kramerb9bee042012-07-12 09:31:43 +00001503 "rdrand{q}\t$dst",
1504 [(set GR64:$dst, EFLAGS, (X86rdrand))]>, TB;
Craig Topper581fe822011-10-03 17:28:23 +00001505}
1506
1507//===----------------------------------------------------------------------===//
Craig Topper37f21672011-10-11 06:44:02 +00001508// LZCNT Instruction
1509//
1510let Predicates = [HasLZCNT], Defs = [EFLAGS] in {
1511 def LZCNT16rr : I<0xBD, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
1512 "lzcnt{w}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001513 [(set GR16:$dst, (ctlz GR16:$src)), (implicit EFLAGS)]>, XS,
1514 OpSize;
Craig Topper37f21672011-10-11 06:44:02 +00001515 def LZCNT16rm : I<0xBD, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
1516 "lzcnt{w}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001517 [(set GR16:$dst, (ctlz (loadi16 addr:$src))),
1518 (implicit EFLAGS)]>, XS, OpSize;
Craig Topper37f21672011-10-11 06:44:02 +00001519
1520 def LZCNT32rr : I<0xBD, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
1521 "lzcnt{l}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001522 [(set GR32:$dst, (ctlz GR32:$src)), (implicit EFLAGS)]>, XS;
Craig Topper37f21672011-10-11 06:44:02 +00001523 def LZCNT32rm : I<0xBD, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
1524 "lzcnt{l}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001525 [(set GR32:$dst, (ctlz (loadi32 addr:$src))),
1526 (implicit EFLAGS)]>, XS;
Craig Topper37f21672011-10-11 06:44:02 +00001527
1528 def LZCNT64rr : RI<0xBD, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1529 "lzcnt{q}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001530 [(set GR64:$dst, (ctlz GR64:$src)), (implicit EFLAGS)]>,
1531 XS;
Craig Topper37f21672011-10-11 06:44:02 +00001532 def LZCNT64rm : RI<0xBD, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1533 "lzcnt{q}\t{$src, $dst|$dst, $src}",
Craig Topperd501c712011-10-13 06:18:52 +00001534 [(set GR64:$dst, (ctlz (loadi64 addr:$src))),
1535 (implicit EFLAGS)]>, XS;
Craig Topper37f21672011-10-11 06:44:02 +00001536}
1537
1538//===----------------------------------------------------------------------===//
Craig Topper566f2332011-10-15 20:46:47 +00001539// BMI Instructions
Craig Topper909652f2011-10-14 03:21:46 +00001540//
1541let Predicates = [HasBMI], Defs = [EFLAGS] in {
1542 def TZCNT16rr : I<0xBC, MRMSrcReg, (outs GR16:$dst), (ins GR16:$src),
1543 "tzcnt{w}\t{$src, $dst|$dst, $src}",
1544 [(set GR16:$dst, (cttz GR16:$src)), (implicit EFLAGS)]>, XS,
1545 OpSize;
1546 def TZCNT16rm : I<0xBC, MRMSrcMem, (outs GR16:$dst), (ins i16mem:$src),
1547 "tzcnt{w}\t{$src, $dst|$dst, $src}",
1548 [(set GR16:$dst, (cttz (loadi16 addr:$src))),
1549 (implicit EFLAGS)]>, XS, OpSize;
1550
1551 def TZCNT32rr : I<0xBC, MRMSrcReg, (outs GR32:$dst), (ins GR32:$src),
1552 "tzcnt{l}\t{$src, $dst|$dst, $src}",
1553 [(set GR32:$dst, (cttz GR32:$src)), (implicit EFLAGS)]>, XS;
1554 def TZCNT32rm : I<0xBC, MRMSrcMem, (outs GR32:$dst), (ins i32mem:$src),
1555 "tzcnt{l}\t{$src, $dst|$dst, $src}",
1556 [(set GR32:$dst, (cttz (loadi32 addr:$src))),
1557 (implicit EFLAGS)]>, XS;
1558
1559 def TZCNT64rr : RI<0xBC, MRMSrcReg, (outs GR64:$dst), (ins GR64:$src),
1560 "tzcnt{q}\t{$src, $dst|$dst, $src}",
1561 [(set GR64:$dst, (cttz GR64:$src)), (implicit EFLAGS)]>,
1562 XS;
1563 def TZCNT64rm : RI<0xBC, MRMSrcMem, (outs GR64:$dst), (ins i64mem:$src),
1564 "tzcnt{q}\t{$src, $dst|$dst, $src}",
1565 [(set GR64:$dst, (cttz (loadi64 addr:$src))),
1566 (implicit EFLAGS)]>, XS;
1567}
1568
Craig Topper566f2332011-10-15 20:46:47 +00001569multiclass bmi_bls<string mnemonic, Format RegMRM, Format MemMRM,
Craig Topperb4c94572011-10-21 06:55:01 +00001570 RegisterClass RC, X86MemOperand x86memop, SDNode OpNode,
1571 PatFrag ld_frag> {
Craig Topper566f2332011-10-15 20:46:47 +00001572 def rr : I<0xF3, RegMRM, (outs RC:$dst), (ins RC:$src),
Craig Topper717cdb02011-10-19 07:48:35 +00001573 !strconcat(mnemonic, "\t{$src, $dst|$dst, $src}"),
Craig Topperb4c94572011-10-21 06:55:01 +00001574 [(set RC:$dst, EFLAGS, (OpNode RC:$src))]>, T8, VEX_4V;
Craig Topper566f2332011-10-15 20:46:47 +00001575 def rm : I<0xF3, MemMRM, (outs RC:$dst), (ins x86memop:$src),
Craig Topper717cdb02011-10-19 07:48:35 +00001576 !strconcat(mnemonic, "\t{$src, $dst|$dst, $src}"),
Craig Topperb4c94572011-10-21 06:55:01 +00001577 [(set RC:$dst, EFLAGS, (OpNode (ld_frag addr:$src)))]>,
Craig Topper717cdb02011-10-19 07:48:35 +00001578 T8, VEX_4V;
Craig Topper566f2332011-10-15 20:46:47 +00001579}
1580
1581let Predicates = [HasBMI], Defs = [EFLAGS] in {
Craig Topper717cdb02011-10-19 07:48:35 +00001582 defm BLSR32 : bmi_bls<"blsr{l}", MRM1r, MRM1m, GR32, i32mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001583 X86blsr_flag, loadi32>;
Craig Topper717cdb02011-10-19 07:48:35 +00001584 defm BLSR64 : bmi_bls<"blsr{q}", MRM1r, MRM1m, GR64, i64mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001585 X86blsr_flag, loadi64>, VEX_W;
Craig Topper717cdb02011-10-19 07:48:35 +00001586 defm BLSMSK32 : bmi_bls<"blsmsk{l}", MRM2r, MRM2m, GR32, i32mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001587 X86blsmsk_flag, loadi32>;
Craig Topper717cdb02011-10-19 07:48:35 +00001588 defm BLSMSK64 : bmi_bls<"blsmsk{q}", MRM2r, MRM2m, GR64, i64mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001589 X86blsmsk_flag, loadi64>, VEX_W;
Craig Topper717cdb02011-10-19 07:48:35 +00001590 defm BLSI32 : bmi_bls<"blsi{l}", MRM3r, MRM3m, GR32, i32mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001591 X86blsi_flag, loadi32>;
Craig Topper717cdb02011-10-19 07:48:35 +00001592 defm BLSI64 : bmi_bls<"blsi{q}", MRM3r, MRM3m, GR64, i64mem,
Craig Topperb4c94572011-10-21 06:55:01 +00001593 X86blsi_flag, loadi64>, VEX_W;
Craig Topper17730842011-10-16 03:51:13 +00001594}
1595
Craig Topperb53fa8b2011-10-16 07:55:05 +00001596multiclass bmi_bextr_bzhi<bits<8> opc, string mnemonic, RegisterClass RC,
Craig Topper717cdb02011-10-19 07:48:35 +00001597 X86MemOperand x86memop, Intrinsic Int,
1598 PatFrag ld_frag> {
Craig Topperb53fa8b2011-10-16 07:55:05 +00001599 def rr : I<opc, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
Craig Topper17730842011-10-16 03:51:13 +00001600 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Craig Topper717cdb02011-10-19 07:48:35 +00001601 [(set RC:$dst, (Int RC:$src1, RC:$src2)), (implicit EFLAGS)]>,
1602 T8, VEX_4VOp3;
Craig Topperb53fa8b2011-10-16 07:55:05 +00001603 def rm : I<opc, MRMSrcMem, (outs RC:$dst), (ins x86memop:$src1, RC:$src2),
Craig Topper17730842011-10-16 03:51:13 +00001604 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Craig Topper717cdb02011-10-19 07:48:35 +00001605 [(set RC:$dst, (Int (ld_frag addr:$src1), RC:$src2)),
1606 (implicit EFLAGS)]>, T8, VEX_4VOp3;
Craig Topper17730842011-10-16 03:51:13 +00001607}
1608
1609let Predicates = [HasBMI], Defs = [EFLAGS] in {
Craig Topper717cdb02011-10-19 07:48:35 +00001610 defm BEXTR32 : bmi_bextr_bzhi<0xF7, "bextr{l}", GR32, i32mem,
1611 int_x86_bmi_bextr_32, loadi32>;
1612 defm BEXTR64 : bmi_bextr_bzhi<0xF7, "bextr{q}", GR64, i64mem,
1613 int_x86_bmi_bextr_64, loadi64>, VEX_W;
Craig Topperb53fa8b2011-10-16 07:55:05 +00001614}
1615
1616let Predicates = [HasBMI2], Defs = [EFLAGS] in {
Craig Topper717cdb02011-10-19 07:48:35 +00001617 defm BZHI32 : bmi_bextr_bzhi<0xF5, "bzhi{l}", GR32, i32mem,
1618 int_x86_bmi_bzhi_32, loadi32>;
1619 defm BZHI64 : bmi_bextr_bzhi<0xF5, "bzhi{q}", GR64, i64mem,
1620 int_x86_bmi_bzhi_64, loadi64>, VEX_W;
Craig Topper566f2332011-10-15 20:46:47 +00001621}
1622
Craig Topper717cdb02011-10-19 07:48:35 +00001623multiclass bmi_pdep_pext<string mnemonic, RegisterClass RC,
1624 X86MemOperand x86memop, Intrinsic Int,
1625 PatFrag ld_frag> {
Craig Topperee62e4f2011-10-16 16:50:08 +00001626 def rr : I<0xF5, MRMSrcReg, (outs RC:$dst), (ins RC:$src1, RC:$src2),
1627 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Craig Topper717cdb02011-10-19 07:48:35 +00001628 [(set RC:$dst, (Int RC:$src1, RC:$src2))]>,
1629 VEX_4V;
Craig Topperee62e4f2011-10-16 16:50:08 +00001630 def rm : I<0xF5, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
1631 !strconcat(mnemonic, "\t{$src2, $src1, $dst|$dst, $src1, $src2}"),
Craig Topper717cdb02011-10-19 07:48:35 +00001632 [(set RC:$dst, (Int RC:$src1, (ld_frag addr:$src2)))]>, VEX_4V;
Craig Topperee62e4f2011-10-16 16:50:08 +00001633}
1634
1635let Predicates = [HasBMI2] in {
Craig Topper717cdb02011-10-19 07:48:35 +00001636 defm PDEP32 : bmi_pdep_pext<"pdep{l}", GR32, i32mem,
1637 int_x86_bmi_pdep_32, loadi32>, T8XD;
1638 defm PDEP64 : bmi_pdep_pext<"pdep{q}", GR64, i64mem,
1639 int_x86_bmi_pdep_64, loadi64>, T8XD, VEX_W;
1640 defm PEXT32 : bmi_pdep_pext<"pext{l}", GR32, i32mem,
1641 int_x86_bmi_pext_32, loadi32>, T8XS;
1642 defm PEXT64 : bmi_pdep_pext<"pext{q}", GR64, i64mem,
1643 int_x86_bmi_pext_64, loadi64>, T8XS, VEX_W;
Craig Topperee62e4f2011-10-16 16:50:08 +00001644}
1645
Craig Topper909652f2011-10-14 03:21:46 +00001646//===----------------------------------------------------------------------===//
Chris Lattner434c7cb2010-10-05 05:32:15 +00001647// Subsystems.
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001648//===----------------------------------------------------------------------===//
1649
Chris Lattner6367cfc2010-10-05 16:39:12 +00001650include "X86InstrArithmetic.td"
Chris Lattner35649fc2010-10-05 06:33:16 +00001651include "X86InstrCMovSetCC.td"
Chris Lattner8917cd32010-10-05 06:52:26 +00001652include "X86InstrExtension.td"
Chris Lattner87be16a2010-10-05 06:04:14 +00001653include "X86InstrControl.td"
Chris Lattner5f58e842010-10-05 07:00:12 +00001654include "X86InstrShiftRotate.td"
Chris Lattner87be16a2010-10-05 06:04:14 +00001655
Chris Lattner6367cfc2010-10-05 16:39:12 +00001656// X87 Floating Point Stack.
1657include "X86InstrFPStack.td"
1658
David Greene51898d72010-02-09 23:52:19 +00001659// SIMD support (SSE, MMX and AVX)
David Greene51898d72010-02-09 23:52:19 +00001660include "X86InstrFragmentsSIMD.td"
1661
Bruno Cardoso Lopes6b7e9162010-07-23 00:54:35 +00001662// FMA - Fused Multiply-Add support (requires FMA)
Bruno Cardoso Lopes6b7e9162010-07-23 00:54:35 +00001663include "X86InstrFMA.td"
1664
Jan Sjödin37e7ecf2011-12-12 19:37:49 +00001665// XOP
1666include "X86InstrXOP.td"
1667
Chris Lattner434c7cb2010-10-05 05:32:15 +00001668// SSE, MMX and 3DNow! vector support.
Evan Cheng4e4c71e2006-02-21 20:00:20 +00001669include "X86InstrSSE.td"
Evan Cheng80f54042008-04-25 18:19:54 +00001670include "X86InstrMMX.td"
Chris Lattner7330d972010-10-02 23:06:23 +00001671include "X86Instr3DNow.td"
1672
Chris Lattnerd071b832010-10-05 06:06:53 +00001673include "X86InstrVMX.td"
Craig Topper9e3d0b32012-02-18 08:19:49 +00001674include "X86InstrSVM.td"
Chris Lattnerd071b832010-10-05 06:06:53 +00001675
Chris Lattner434c7cb2010-10-05 05:32:15 +00001676// System instructions.
1677include "X86InstrSystem.td"
Chris Lattner87be16a2010-10-05 06:04:14 +00001678
1679// Compiler Pseudo Instructions and Pat Patterns
1680include "X86InstrCompiler.td"
1681
Chris Lattner674c1dc2010-10-30 17:36:36 +00001682//===----------------------------------------------------------------------===//
Chris Lattnerefd8dad2010-11-01 23:07:52 +00001683// Assembler Mnemonic Aliases
Chris Lattner674c1dc2010-10-30 17:36:36 +00001684//===----------------------------------------------------------------------===//
1685
Chris Lattner99f53522010-11-01 21:06:34 +00001686def : MnemonicAlias<"call", "calll">, Requires<[In32BitMode]>;
1687def : MnemonicAlias<"call", "callq">, Requires<[In64BitMode]>;
1688
Chris Lattner674c1dc2010-10-30 17:36:36 +00001689def : MnemonicAlias<"cbw", "cbtw">;
Benjamin Kramer9d399b12011-11-24 12:02:46 +00001690def : MnemonicAlias<"cwde", "cwtl">;
Chris Lattner674c1dc2010-10-30 17:36:36 +00001691def : MnemonicAlias<"cwd", "cwtd">;
1692def : MnemonicAlias<"cdq", "cltd">;
Chris Lattner674c1dc2010-10-30 17:36:36 +00001693def : MnemonicAlias<"cdqe", "cltq">;
Benjamin Kramer9d399b12011-11-24 12:02:46 +00001694def : MnemonicAlias<"cqo", "cqto">;
Chris Lattner8b260a72010-10-30 18:07:17 +00001695
Chris Lattner269f10b2010-11-12 18:54:56 +00001696// lret maps to lretl, it is not ambiguous with lretq.
1697def : MnemonicAlias<"lret", "lretl">;
1698
Joerg Sonnenberger97755a02011-02-17 23:36:39 +00001699def : MnemonicAlias<"leavel", "leave">, Requires<[In32BitMode]>;
1700def : MnemonicAlias<"leaveq", "leave">, Requires<[In64BitMode]>;
1701
Joerg Sonnenbergerd86f4822011-02-22 00:43:07 +00001702def : MnemonicAlias<"loopz", "loope">;
1703def : MnemonicAlias<"loopnz", "loopne">;
1704
Chris Lattner693173f2010-10-30 19:23:13 +00001705def : MnemonicAlias<"pop", "popl">, Requires<[In32BitMode]>;
1706def : MnemonicAlias<"pop", "popq">, Requires<[In64BitMode]>;
1707def : MnemonicAlias<"popf", "popfl">, Requires<[In32BitMode]>;
1708def : MnemonicAlias<"popf", "popfq">, Requires<[In64BitMode]>;
Chris Lattner8b260a72010-10-30 18:07:17 +00001709def : MnemonicAlias<"popfd", "popfl">;
1710
Chris Lattnera33b93f2010-10-31 18:43:46 +00001711// FIXME: This is wrong for "push reg". "push %bx" should turn into pushw in
1712// all modes. However: "push (addr)" and "push $42" should default to
1713// pushl/pushq depending on the current mode. Similar for "pop %bx"
Chris Lattner693173f2010-10-30 19:23:13 +00001714def : MnemonicAlias<"push", "pushl">, Requires<[In32BitMode]>;
1715def : MnemonicAlias<"push", "pushq">, Requires<[In64BitMode]>;
1716def : MnemonicAlias<"pushf", "pushfl">, Requires<[In32BitMode]>;
1717def : MnemonicAlias<"pushf", "pushfq">, Requires<[In64BitMode]>;
1718def : MnemonicAlias<"pushfd", "pushfl">;
1719
Chris Lattner6f96b082010-10-30 18:17:33 +00001720def : MnemonicAlias<"repe", "rep">;
1721def : MnemonicAlias<"repz", "rep">;
1722def : MnemonicAlias<"repnz", "repne">;
1723
Chris Lattner693173f2010-10-30 19:23:13 +00001724def : MnemonicAlias<"retl", "ret">, Requires<[In32BitMode]>;
1725def : MnemonicAlias<"retq", "ret">, Requires<[In64BitMode]>;
1726
Chris Lattnera17a9a02010-10-30 18:14:54 +00001727def : MnemonicAlias<"salb", "shlb">;
1728def : MnemonicAlias<"salw", "shlw">;
1729def : MnemonicAlias<"sall", "shll">;
1730def : MnemonicAlias<"salq", "shlq">;
1731
Chris Lattner674c1dc2010-10-30 17:36:36 +00001732def : MnemonicAlias<"smovb", "movsb">;
1733def : MnemonicAlias<"smovw", "movsw">;
1734def : MnemonicAlias<"smovl", "movsl">;
1735def : MnemonicAlias<"smovq", "movsq">;
1736
Chris Lattner674c1dc2010-10-30 17:36:36 +00001737def : MnemonicAlias<"ud2a", "ud2">;
1738def : MnemonicAlias<"verrw", "verr">;
1739
Chris Lattner99f53522010-11-01 21:06:34 +00001740// System instruction aliases.
1741def : MnemonicAlias<"iret", "iretl">;
1742def : MnemonicAlias<"sysret", "sysretl">;
Kevin Enderby55c41272011-10-27 17:40:41 +00001743def : MnemonicAlias<"sysexit", "sysexitl">;
Chris Lattner99f53522010-11-01 21:06:34 +00001744
1745def : MnemonicAlias<"lgdtl", "lgdt">, Requires<[In32BitMode]>;
1746def : MnemonicAlias<"lgdtq", "lgdt">, Requires<[In64BitMode]>;
1747def : MnemonicAlias<"lidtl", "lidt">, Requires<[In32BitMode]>;
1748def : MnemonicAlias<"lidtq", "lidt">, Requires<[In64BitMode]>;
1749def : MnemonicAlias<"sgdtl", "sgdt">, Requires<[In32BitMode]>;
1750def : MnemonicAlias<"sgdtq", "sgdt">, Requires<[In64BitMode]>;
1751def : MnemonicAlias<"sidtl", "sidt">, Requires<[In32BitMode]>;
1752def : MnemonicAlias<"sidtq", "sidt">, Requires<[In64BitMode]>;
1753
Chris Lattner674c1dc2010-10-30 17:36:36 +00001754
Chris Lattner8b260a72010-10-30 18:07:17 +00001755// Floating point stack aliases.
1756def : MnemonicAlias<"fcmovz", "fcmove">;
1757def : MnemonicAlias<"fcmova", "fcmovnbe">;
1758def : MnemonicAlias<"fcmovnae", "fcmovb">;
1759def : MnemonicAlias<"fcmovna", "fcmovbe">;
1760def : MnemonicAlias<"fcmovae", "fcmovnb">;
Chris Lattnerdb287882010-11-06 21:37:06 +00001761def : MnemonicAlias<"fcomip", "fcompi">;
Chris Lattner8b260a72010-10-30 18:07:17 +00001762def : MnemonicAlias<"fildq", "fildll">;
Chad Rosier77834e72012-02-27 19:43:12 +00001763def : MnemonicAlias<"fistpq", "fistpll">;
1764def : MnemonicAlias<"fisttpq", "fisttpll">;
Chris Lattner8b260a72010-10-30 18:07:17 +00001765def : MnemonicAlias<"fldcww", "fldcw">;
1766def : MnemonicAlias<"fnstcww", "fnstcw">;
1767def : MnemonicAlias<"fnstsww", "fnstsw">;
Chris Lattnerdb287882010-11-06 21:37:06 +00001768def : MnemonicAlias<"fucomip", "fucompi">;
Chris Lattner8b260a72010-10-30 18:07:17 +00001769def : MnemonicAlias<"fwait", "wait">;
1770
1771
Chris Lattner8cb441c2010-10-30 17:56:50 +00001772class CondCodeAlias<string Prefix,string Suffix, string OldCond, string NewCond>
1773 : MnemonicAlias<!strconcat(Prefix, OldCond, Suffix),
1774 !strconcat(Prefix, NewCond, Suffix)>;
Chris Lattnerb69fc282010-10-30 17:51:45 +00001775
1776/// IntegerCondCodeMnemonicAlias - This multiclass defines a bunch of
1777/// MnemonicAlias's that canonicalize the condition code in a mnemonic, for
1778/// example "setz" -> "sete".
Chris Lattner8cb441c2010-10-30 17:56:50 +00001779multiclass IntegerCondCodeMnemonicAlias<string Prefix, string Suffix> {
1780 def C : CondCodeAlias<Prefix, Suffix, "c", "b">; // setc -> setb
1781 def Z : CondCodeAlias<Prefix, Suffix, "z" , "e">; // setz -> sete
1782 def NA : CondCodeAlias<Prefix, Suffix, "na", "be">; // setna -> setbe
1783 def NB : CondCodeAlias<Prefix, Suffix, "nb", "ae">; // setnb -> setae
1784 def NC : CondCodeAlias<Prefix, Suffix, "nc", "ae">; // setnc -> setae
1785 def NG : CondCodeAlias<Prefix, Suffix, "ng", "le">; // setng -> setle
1786 def NL : CondCodeAlias<Prefix, Suffix, "nl", "ge">; // setnl -> setge
1787 def NZ : CondCodeAlias<Prefix, Suffix, "nz", "ne">; // setnz -> setne
1788 def PE : CondCodeAlias<Prefix, Suffix, "pe", "p">; // setpe -> setp
1789 def PO : CondCodeAlias<Prefix, Suffix, "po", "np">; // setpo -> setnp
Chris Lattnerb69fc282010-10-30 17:51:45 +00001790
Chris Lattner8cb441c2010-10-30 17:56:50 +00001791 def NAE : CondCodeAlias<Prefix, Suffix, "nae", "b">; // setnae -> setb
1792 def NBE : CondCodeAlias<Prefix, Suffix, "nbe", "a">; // setnbe -> seta
1793 def NGE : CondCodeAlias<Prefix, Suffix, "nge", "l">; // setnge -> setl
1794 def NLE : CondCodeAlias<Prefix, Suffix, "nle", "g">; // setnle -> setg
Chris Lattnerb69fc282010-10-30 17:51:45 +00001795}
1796
1797// Aliases for set<CC>
Chris Lattner8cb441c2010-10-30 17:56:50 +00001798defm : IntegerCondCodeMnemonicAlias<"set", "">;
Chris Lattnerb69fc282010-10-30 17:51:45 +00001799// Aliases for j<CC>
Chris Lattner8cb441c2010-10-30 17:56:50 +00001800defm : IntegerCondCodeMnemonicAlias<"j", "">;
1801// Aliases for cmov<CC>{w,l,q}
1802defm : IntegerCondCodeMnemonicAlias<"cmov", "w">;
1803defm : IntegerCondCodeMnemonicAlias<"cmov", "l">;
1804defm : IntegerCondCodeMnemonicAlias<"cmov", "q">;
Chris Lattner674c1dc2010-10-30 17:36:36 +00001805
Chris Lattnerefd8dad2010-11-01 23:07:52 +00001806
1807//===----------------------------------------------------------------------===//
1808// Assembler Instruction Aliases
1809//===----------------------------------------------------------------------===//
1810
Chris Lattner98c870f2010-11-06 19:25:43 +00001811// aad/aam default to base 10 if no operand is specified.
1812def : InstAlias<"aad", (AAD8i8 10)>;
1813def : InstAlias<"aam", (AAM8i8 10)>;
1814
Chris Lattner824a9072011-02-19 21:06:36 +00001815// Disambiguate the mem/imm form of bt-without-a-suffix as btl.
1816def : InstAlias<"bt $imm, $mem", (BT32mi8 i32mem:$mem, i32i8imm:$imm)>;
1817
Chris Lattner41409852010-11-06 07:31:43 +00001818// clr aliases.
1819def : InstAlias<"clrb $reg", (XOR8rr GR8 :$reg, GR8 :$reg)>;
1820def : InstAlias<"clrw $reg", (XOR16rr GR16:$reg, GR16:$reg)>;
1821def : InstAlias<"clrl $reg", (XOR32rr GR32:$reg, GR32:$reg)>;
1822def : InstAlias<"clrq $reg", (XOR64rr GR64:$reg, GR64:$reg)>;
1823
Chris Lattner689cf3c2010-11-06 22:41:18 +00001824// div and idiv aliases for explicit A register.
1825def : InstAlias<"divb $src, %al", (DIV8r GR8 :$src)>;
1826def : InstAlias<"divw $src, %ax", (DIV16r GR16:$src)>;
1827def : InstAlias<"divl $src, %eax", (DIV32r GR32:$src)>;
1828def : InstAlias<"divq $src, %rax", (DIV64r GR64:$src)>;
1829def : InstAlias<"divb $src, %al", (DIV8m i8mem :$src)>;
1830def : InstAlias<"divw $src, %ax", (DIV16m i16mem:$src)>;
1831def : InstAlias<"divl $src, %eax", (DIV32m i32mem:$src)>;
1832def : InstAlias<"divq $src, %rax", (DIV64m i64mem:$src)>;
1833def : InstAlias<"idivb $src, %al", (IDIV8r GR8 :$src)>;
1834def : InstAlias<"idivw $src, %ax", (IDIV16r GR16:$src)>;
1835def : InstAlias<"idivl $src, %eax", (IDIV32r GR32:$src)>;
1836def : InstAlias<"idivq $src, %rax", (IDIV64r GR64:$src)>;
1837def : InstAlias<"idivb $src, %al", (IDIV8m i8mem :$src)>;
1838def : InstAlias<"idivw $src, %ax", (IDIV16m i16mem:$src)>;
1839def : InstAlias<"idivl $src, %eax", (IDIV32m i32mem:$src)>;
1840def : InstAlias<"idivq $src, %rax", (IDIV64m i64mem:$src)>;
1841
1842
1843
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001844// Various unary fpstack operations default to operating on on ST1.
1845// For example, "fxch" -> "fxch %st(1)"
Bill Wendlingc6df9882011-04-14 01:11:51 +00001846def : InstAlias<"faddp", (ADD_FPrST0 ST1), 0>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001847def : InstAlias<"fsubp", (SUBR_FPrST0 ST1)>;
1848def : InstAlias<"fsubrp", (SUB_FPrST0 ST1)>;
1849def : InstAlias<"fmulp", (MUL_FPrST0 ST1)>;
1850def : InstAlias<"fdivp", (DIVR_FPrST0 ST1)>;
1851def : InstAlias<"fdivrp", (DIV_FPrST0 ST1)>;
1852def : InstAlias<"fxch", (XCH_F ST1)>;
1853def : InstAlias<"fcomi", (COM_FIr ST1)>;
Chris Lattnerdb287882010-11-06 21:37:06 +00001854def : InstAlias<"fcompi", (COM_FIPr ST1)>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001855def : InstAlias<"fucom", (UCOM_Fr ST1)>;
1856def : InstAlias<"fucomp", (UCOM_FPr ST1)>;
1857def : InstAlias<"fucomi", (UCOM_FIr ST1)>;
Chris Lattnerdb287882010-11-06 21:37:06 +00001858def : InstAlias<"fucompi", (UCOM_FIPr ST1)>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001859
1860// Handle fmul/fadd/fsub/fdiv instructions with explicitly written st(0) op.
1861// For example, "fadd %st(4), %st(0)" -> "fadd %st(4)". We also disambiguate
1862// instructions like "fadd %st(0), %st(0)" as "fadd %st(0)" for consistency with
1863// gas.
Bill Wendlingc6df9882011-04-14 01:11:51 +00001864multiclass FpUnaryAlias<string Mnemonic, Instruction Inst, bit EmitAlias = 1> {
1865 def : InstAlias<!strconcat(Mnemonic, " $op, %st(0)"),
1866 (Inst RST:$op), EmitAlias>;
1867 def : InstAlias<!strconcat(Mnemonic, " %st(0), %st(0)"),
1868 (Inst ST0), EmitAlias>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001869}
1870
1871defm : FpUnaryAlias<"fadd", ADD_FST0r>;
Bill Wendlingc6df9882011-04-14 01:11:51 +00001872defm : FpUnaryAlias<"faddp", ADD_FPrST0, 0>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001873defm : FpUnaryAlias<"fsub", SUB_FST0r>;
1874defm : FpUnaryAlias<"fsubp", SUBR_FPrST0>;
1875defm : FpUnaryAlias<"fsubr", SUBR_FST0r>;
1876defm : FpUnaryAlias<"fsubrp", SUB_FPrST0>;
1877defm : FpUnaryAlias<"fmul", MUL_FST0r>;
1878defm : FpUnaryAlias<"fmulp", MUL_FPrST0>;
1879defm : FpUnaryAlias<"fdiv", DIV_FST0r>;
1880defm : FpUnaryAlias<"fdivp", DIVR_FPrST0>;
1881defm : FpUnaryAlias<"fdivr", DIVR_FST0r>;
1882defm : FpUnaryAlias<"fdivrp", DIV_FPrST0>;
Bill Wendlingc6df9882011-04-14 01:11:51 +00001883defm : FpUnaryAlias<"fcomi", COM_FIr, 0>;
1884defm : FpUnaryAlias<"fucomi", UCOM_FIr, 0>;
Chris Lattnerdb287882010-11-06 21:37:06 +00001885defm : FpUnaryAlias<"fcompi", COM_FIPr>;
1886defm : FpUnaryAlias<"fucompi", UCOM_FIPr>;
Chris Lattner235705b2010-11-06 20:55:09 +00001887
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001888
1889// Handle "f{mulp,addp} st(0), $op" the same as "f{mulp,addp} $op", since they
Nick Lewyckyc00210c2010-12-30 22:10:49 +00001890// commute. We also allow fdiv[r]p/fsubrp even though they don't commute,
1891// solely because gas supports it.
Bill Wendlingc6df9882011-04-14 01:11:51 +00001892def : InstAlias<"faddp %st(0), $op", (ADD_FPrST0 RST:$op), 0>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001893def : InstAlias<"fmulp %st(0), $op", (MUL_FPrST0 RST:$op)>;
Chris Lattner92f920c2011-05-22 22:31:57 +00001894def : InstAlias<"fsubp %st(0), $op", (SUBR_FPrST0 RST:$op)>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001895def : InstAlias<"fsubrp %st(0), $op", (SUB_FPrST0 RST:$op)>;
Nick Lewyckyc00210c2010-12-30 22:10:49 +00001896def : InstAlias<"fdivp %st(0), $op", (DIVR_FPrST0 RST:$op)>;
Chris Lattner3af0e7d2010-11-06 20:47:38 +00001897def : InstAlias<"fdivrp %st(0), $op", (DIV_FPrST0 RST:$op)>;
Chris Lattner90fd7972010-11-06 19:57:21 +00001898
Nick Lewyckyc00210c2010-12-30 22:10:49 +00001899// We accept "fnstsw %eax" even though it only writes %ax.
Benjamin Kramer17c836c2012-04-27 12:07:43 +00001900def : InstAlias<"fnstsw %eax", (FNSTSW16r)>;
1901def : InstAlias<"fnstsw %al" , (FNSTSW16r)>;
1902def : InstAlias<"fnstsw" , (FNSTSW16r)>;
Chris Lattnerdea546b2010-11-06 18:58:32 +00001903
Chris Lattner8caa2902010-11-06 07:48:45 +00001904// lcall and ljmp aliases. This seems to be an odd mapping in 64-bit mode, but
1905// this is compatible with what GAS does.
1906def : InstAlias<"lcall $seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg)>;
1907def : InstAlias<"ljmp $seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg)>;
1908def : InstAlias<"lcall *$dst", (FARCALL32m opaque48mem:$dst)>;
1909def : InstAlias<"ljmp *$dst", (FARJMP32m opaque48mem:$dst)>;
1910
Chris Lattner9c1dbc62010-11-06 18:44:26 +00001911// "imul <imm>, B" is an alias for "imul <imm>, B, B".
1912def : InstAlias<"imulw $imm, $r", (IMUL16rri GR16:$r, GR16:$r, i16imm:$imm)>;
1913def : InstAlias<"imulw $imm, $r", (IMUL16rri8 GR16:$r, GR16:$r, i16i8imm:$imm)>;
1914def : InstAlias<"imull $imm, $r", (IMUL32rri GR32:$r, GR32:$r, i32imm:$imm)>;
1915def : InstAlias<"imull $imm, $r", (IMUL32rri8 GR32:$r, GR32:$r, i32i8imm:$imm)>;
1916def : InstAlias<"imulq $imm, $r",(IMUL64rri32 GR64:$r, GR64:$r,i64i32imm:$imm)>;
1917def : InstAlias<"imulq $imm, $r", (IMUL64rri8 GR64:$r, GR64:$r, i64i8imm:$imm)>;
1918
Chris Lattner7e925cc2010-11-06 18:52:40 +00001919// inb %dx -> inb %al, %dx
1920def : InstAlias<"inb %dx", (IN8rr)>;
1921def : InstAlias<"inw %dx", (IN16rr)>;
1922def : InstAlias<"inl %dx", (IN32rr)>;
1923def : InstAlias<"inb $port", (IN8ri i8imm:$port)>;
Chris Lattnerdea546b2010-11-06 18:58:32 +00001924def : InstAlias<"inw $port", (IN16ri i8imm:$port)>;
Chris Lattner7e925cc2010-11-06 18:52:40 +00001925def : InstAlias<"inl $port", (IN32ri i8imm:$port)>;
1926
Chris Lattner9c1dbc62010-11-06 18:44:26 +00001927
Chris Lattner8caa2902010-11-06 07:48:45 +00001928// jmp and call aliases for lcall and ljmp. jmp $42,$5 -> ljmp
1929def : InstAlias<"call $seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg)>;
1930def : InstAlias<"jmp $seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg)>;
1931def : InstAlias<"callw $seg, $off", (FARCALL16i i16imm:$off, i16imm:$seg)>;
1932def : InstAlias<"jmpw $seg, $off", (FARJMP16i i16imm:$off, i16imm:$seg)>;
1933def : InstAlias<"calll $seg, $off", (FARCALL32i i32imm:$off, i16imm:$seg)>;
1934def : InstAlias<"jmpl $seg, $off", (FARJMP32i i32imm:$off, i16imm:$seg)>;
1935
Chris Lattner04a75ab2010-11-06 22:35:34 +00001936// Force mov without a suffix with a segment and mem to prefer the 'l' form of
1937// the move. All segment/mem forms are equivalent, this has the shortest
1938// encoding.
1939def : InstAlias<"mov $mem, $seg", (MOV32sm SEGMENT_REG:$seg, i32mem:$mem)>;
1940def : InstAlias<"mov $seg, $mem", (MOV32ms i32mem:$mem, SEGMENT_REG:$seg)>;
Chris Lattner8caa2902010-11-06 07:48:45 +00001941
Chris Lattner9c1dbc62010-11-06 18:44:26 +00001942// Match 'movq <largeimm>, <reg>' as an alias for movabsq.
1943def : InstAlias<"movq $imm, $reg", (MOV64ri GR64:$reg, i64imm:$imm)>;
1944
Chris Lattnercbf5d742010-11-21 08:18:57 +00001945// Match 'movq GR64, MMX' as an alias for movd.
Bill Wendlingeef965f2011-04-13 23:36:21 +00001946def : InstAlias<"movq $src, $dst",
Bill Wendlingc6df9882011-04-14 01:11:51 +00001947 (MMX_MOVD64to64rr VR64:$dst, GR64:$src), 0>;
Bill Wendlingeef965f2011-04-13 23:36:21 +00001948def : InstAlias<"movq $src, $dst",
Bill Wendlingc6df9882011-04-14 01:11:51 +00001949 (MMX_MOVD64from64rr GR64:$dst, VR64:$src), 0>;
Chris Lattnercbf5d742010-11-21 08:18:57 +00001950
Chris Lattner8caa2902010-11-06 07:48:45 +00001951// movsd with no operands (as opposed to the SSE scalar move of a double) is an
1952// alias for movsl. (as in rep; movsd)
1953def : InstAlias<"movsd", (MOVSD)>;
1954
Chris Lattnerefd8dad2010-11-01 23:07:52 +00001955// movsx aliases
Stuart Hastings0e29ed02011-05-20 19:04:40 +00001956def : InstAlias<"movsx $src, $dst", (MOVSX16rr8 GR16:$dst, GR8:$src), 0>;
1957def : InstAlias<"movsx $src, $dst", (MOVSX16rm8 GR16:$dst, i8mem:$src), 0>;
Bill Wendlingd336de32011-04-14 01:46:37 +00001958def : InstAlias<"movsx $src, $dst", (MOVSX32rr8 GR32:$dst, GR8:$src), 0>;
1959def : InstAlias<"movsx $src, $dst", (MOVSX32rr16 GR32:$dst, GR16:$src), 0>;
1960def : InstAlias<"movsx $src, $dst", (MOVSX64rr8 GR64:$dst, GR8:$src), 0>;
1961def : InstAlias<"movsx $src, $dst", (MOVSX64rr16 GR64:$dst, GR16:$src), 0>;
1962def : InstAlias<"movsx $src, $dst", (MOVSX64rr32 GR64:$dst, GR32:$src), 0>;
Chris Lattnerefd8dad2010-11-01 23:07:52 +00001963
1964// movzx aliases
Stuart Hastings0e29ed02011-05-20 19:04:40 +00001965def : InstAlias<"movzx $src, $dst", (MOVZX16rr8 GR16:$dst, GR8:$src), 0>;
1966def : InstAlias<"movzx $src, $dst", (MOVZX16rm8 GR16:$dst, i8mem:$src), 0>;
Bill Wendlingd336de32011-04-14 01:46:37 +00001967def : InstAlias<"movzx $src, $dst", (MOVZX32rr8 GR32:$dst, GR8:$src), 0>;
1968def : InstAlias<"movzx $src, $dst", (MOVZX32rr16 GR32:$dst, GR16:$src), 0>;
1969def : InstAlias<"movzx $src, $dst", (MOVZX64rr8_Q GR64:$dst, GR8:$src), 0>;
1970def : InstAlias<"movzx $src, $dst", (MOVZX64rr16_Q GR64:$dst, GR16:$src), 0>;
Chris Lattnerefd8dad2010-11-01 23:07:52 +00001971// Note: No GR32->GR64 movzx form.
1972
Chris Lattner7e925cc2010-11-06 18:52:40 +00001973// outb %dx -> outb %al, %dx
1974def : InstAlias<"outb %dx", (OUT8rr)>;
1975def : InstAlias<"outw %dx", (OUT16rr)>;
1976def : InstAlias<"outl %dx", (OUT32rr)>;
1977def : InstAlias<"outb $port", (OUT8ir i8imm:$port)>;
1978def : InstAlias<"outw $port", (OUT16ir i8imm:$port)>;
1979def : InstAlias<"outl $port", (OUT32ir i8imm:$port)>;
1980
Chris Lattner9c1dbc62010-11-06 18:44:26 +00001981// 'sldt <mem>' can be encoded with either sldtw or sldtq with the same
1982// effect (both store to a 16-bit mem). Force to sldtw to avoid ambiguity
1983// errors, since its encoding is the most compact.
1984def : InstAlias<"sldt $mem", (SLDT16m i16mem:$mem)>;
1985
Eli Friedmanec93b6d2012-03-05 04:31:54 +00001986// shld/shrd op,op -> shld op, op, CL
Eli Friedman54427e52012-03-06 19:58:46 +00001987def : InstAlias<"shldw $r2, $r1", (SHLD16rrCL GR16:$r1, GR16:$r2)>;
1988def : InstAlias<"shldl $r2, $r1", (SHLD32rrCL GR32:$r1, GR32:$r2)>;
1989def : InstAlias<"shldq $r2, $r1", (SHLD64rrCL GR64:$r1, GR64:$r2)>;
1990def : InstAlias<"shrdw $r2, $r1", (SHRD16rrCL GR16:$r1, GR16:$r2)>;
1991def : InstAlias<"shrdl $r2, $r1", (SHRD32rrCL GR32:$r1, GR32:$r2)>;
1992def : InstAlias<"shrdq $r2, $r1", (SHRD64rrCL GR64:$r1, GR64:$r2)>;
Chris Lattnerd5b2f1a2010-11-06 22:25:39 +00001993
Eli Friedman54427e52012-03-06 19:58:46 +00001994def : InstAlias<"shldw $reg, $mem", (SHLD16mrCL i16mem:$mem, GR16:$reg)>;
1995def : InstAlias<"shldl $reg, $mem", (SHLD32mrCL i32mem:$mem, GR32:$reg)>;
1996def : InstAlias<"shldq $reg, $mem", (SHLD64mrCL i64mem:$mem, GR64:$reg)>;
1997def : InstAlias<"shrdw $reg, $mem", (SHRD16mrCL i16mem:$mem, GR16:$reg)>;
1998def : InstAlias<"shrdl $reg, $mem", (SHRD32mrCL i32mem:$mem, GR32:$reg)>;
1999def : InstAlias<"shrdq $reg, $mem", (SHRD64mrCL i64mem:$mem, GR64:$reg)>;
Chris Lattnerd5b2f1a2010-11-06 22:25:39 +00002000
2001/* FIXME: This is disabled because the asm matcher is currently incapable of
2002 * matching a fixed immediate like $1.
Chris Lattner17671512010-11-06 22:05:43 +00002003// "shl X, $1" is an alias for "shl X".
2004multiclass ShiftRotateByOneAlias<string Mnemonic, string Opc> {
Chris Lattner8c24b0c2010-11-06 21:23:40 +00002005 def : InstAlias<!strconcat(Mnemonic, "b $op, $$1"),
2006 (!cast<Instruction>(!strconcat(Opc, "8r1")) GR8:$op)>;
2007 def : InstAlias<!strconcat(Mnemonic, "w $op, $$1"),
2008 (!cast<Instruction>(!strconcat(Opc, "16r1")) GR16:$op)>;
2009 def : InstAlias<!strconcat(Mnemonic, "l $op, $$1"),
2010 (!cast<Instruction>(!strconcat(Opc, "32r1")) GR32:$op)>;
2011 def : InstAlias<!strconcat(Mnemonic, "q $op, $$1"),
2012 (!cast<Instruction>(!strconcat(Opc, "64r1")) GR64:$op)>;
2013 def : InstAlias<!strconcat(Mnemonic, "b $op, $$1"),
2014 (!cast<Instruction>(!strconcat(Opc, "8m1")) i8mem:$op)>;
2015 def : InstAlias<!strconcat(Mnemonic, "w $op, $$1"),
2016 (!cast<Instruction>(!strconcat(Opc, "16m1")) i16mem:$op)>;
2017 def : InstAlias<!strconcat(Mnemonic, "l $op, $$1"),
2018 (!cast<Instruction>(!strconcat(Opc, "32m1")) i32mem:$op)>;
2019 def : InstAlias<!strconcat(Mnemonic, "q $op, $$1"),
2020 (!cast<Instruction>(!strconcat(Opc, "64m1")) i64mem:$op)>;
2021}
2022
Chris Lattner17671512010-11-06 22:05:43 +00002023defm : ShiftRotateByOneAlias<"rcl", "RCL">;
2024defm : ShiftRotateByOneAlias<"rcr", "RCR">;
2025defm : ShiftRotateByOneAlias<"rol", "ROL">;
2026defm : ShiftRotateByOneAlias<"ror", "ROR">;
Chris Lattnerd5b2f1a2010-11-06 22:25:39 +00002027FIXME */
Chris Lattner8c24b0c2010-11-06 21:23:40 +00002028
Chris Lattner5bde7342010-11-06 08:20:59 +00002029// test: We accept "testX <reg>, <mem>" and "testX <mem>, <reg>" as synonyms.
2030def : InstAlias<"testb $val, $mem", (TEST8rm GR8 :$val, i8mem :$mem)>;
2031def : InstAlias<"testw $val, $mem", (TEST16rm GR16:$val, i16mem:$mem)>;
2032def : InstAlias<"testl $val, $mem", (TEST32rm GR32:$val, i32mem:$mem)>;
2033def : InstAlias<"testq $val, $mem", (TEST64rm GR64:$val, i64mem:$mem)>;
2034
2035// xchg: We accept "xchgX <reg>, <mem>" and "xchgX <mem>, <reg>" as synonyms.
2036def : InstAlias<"xchgb $mem, $val", (XCHG8rm GR8 :$val, i8mem :$mem)>;
2037def : InstAlias<"xchgw $mem, $val", (XCHG16rm GR16:$val, i16mem:$mem)>;
2038def : InstAlias<"xchgl $mem, $val", (XCHG32rm GR32:$val, i32mem:$mem)>;
2039def : InstAlias<"xchgq $mem, $val", (XCHG64rm GR64:$val, i64mem:$mem)>;
Craig Topper7ea16b02011-10-06 06:44:41 +00002040
2041// xchg: We accept "xchgX <reg>, %eax" and "xchgX %eax, <reg>" as synonyms.
Craig Topper25f6dfd2011-10-07 05:35:38 +00002042def : InstAlias<"xchgw %ax, $src", (XCHG16ar GR16:$src)>;
2043def : InstAlias<"xchgl %eax, $src", (XCHG32ar GR32:$src)>, Requires<[In32BitMode]>;
2044def : InstAlias<"xchgl %eax, $src", (XCHG32ar64 GR32_NOAX:$src)>, Requires<[In64BitMode]>;
2045def : InstAlias<"xchgq %rax, $src", (XCHG64ar GR64:$src)>;