[SystemZ] Use MVC for simple load/store pairs
[oota-llvm.git] / lib / Target / SystemZ / SystemZInstrFP.td
1 //==- SystemZInstrFP.td - Floating-point SystemZ instructions --*- tblgen-*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 // Select instructions
12 //===----------------------------------------------------------------------===//
13
14 // C's ?: operator for floating-point operands.
15 def SelectF32  : SelectWrapper<FP32>;
16 def SelectF64  : SelectWrapper<FP64>;
17 def SelectF128 : SelectWrapper<FP128>;
18
19 defm CondStoreF32 : CondStores<FP32, nonvolatile_store,
20                                nonvolatile_load, bdxaddr20only>;
21 defm CondStoreF64 : CondStores<FP64, nonvolatile_store,
22                                nonvolatile_load, bdxaddr20only>;
23
24 //===----------------------------------------------------------------------===//
25 // Move instructions
26 //===----------------------------------------------------------------------===//
27
28 // Load zero.
29 let neverHasSideEffects = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in {
30   def LZER : InherentRRE<"lze", 0xB374, FP32,  (fpimm0)>;
31   def LZDR : InherentRRE<"lzd", 0xB375, FP64,  (fpimm0)>;
32   def LZXR : InherentRRE<"lzx", 0xB376, FP128, (fpimm0)>;
33 }
34
35 // Moves between two floating-point registers.
36 let neverHasSideEffects = 1 in {
37   def LER : UnaryRR <"le", 0x38,   null_frag, FP32,  FP32>;
38   def LDR : UnaryRR <"ld", 0x28,   null_frag, FP64,  FP64>;
39   def LXR : UnaryRRE<"lx", 0xB365, null_frag, FP128, FP128>;
40 }
41
42 // Moves between 64-bit integer and floating-point registers.
43 def LGDR : UnaryRRE<"lgd", 0xB3CD, bitconvert, GR64, FP64>;
44 def LDGR : UnaryRRE<"ldg", 0xB3C1, bitconvert, FP64, GR64>;
45
46 // fcopysign with an FP32 result.
47 let isCodeGenOnly = 1 in {
48   def CPSDRss : BinaryRRF<"cpsd", 0xB372, fcopysign, FP32, FP32>;
49   def CPSDRsd : BinaryRRF<"cpsd", 0xB372, fcopysign, FP32, FP64>;
50 }
51
52 // The sign of an FP128 is in the high register.
53 def : Pat<(fcopysign FP32:$src1, FP128:$src2),
54           (CPSDRsd FP32:$src1, (EXTRACT_SUBREG FP128:$src2, subreg_high))>;
55
56 // fcopysign with an FP64 result.
57 let isCodeGenOnly = 1 in
58   def CPSDRds : BinaryRRF<"cpsd", 0xB372, fcopysign, FP64, FP32>;
59 def CPSDRdd : BinaryRRF<"cpsd", 0xB372, fcopysign, FP64, FP64>;
60
61 // The sign of an FP128 is in the high register.
62 def : Pat<(fcopysign FP64:$src1, FP128:$src2),
63           (CPSDRdd FP64:$src1, (EXTRACT_SUBREG FP128:$src2, subreg_high))>;
64
65 // fcopysign with an FP128 result.  Use "upper" as the high half and leave
66 // the low half as-is.
67 class CopySign128<RegisterOperand cls, dag upper>
68   : Pat<(fcopysign FP128:$src1, cls:$src2),
69         (INSERT_SUBREG FP128:$src1, upper, subreg_high)>;
70
71 def : CopySign128<FP32,  (CPSDRds (EXTRACT_SUBREG FP128:$src1, subreg_high),
72                                   FP32:$src2)>;
73 def : CopySign128<FP64,  (CPSDRdd (EXTRACT_SUBREG FP128:$src1, subreg_high),
74                                   FP64:$src2)>;
75 def : CopySign128<FP128, (CPSDRdd (EXTRACT_SUBREG FP128:$src1, subreg_high),
76                                   (EXTRACT_SUBREG FP128:$src2, subreg_high))>;
77
78 defm LoadStoreF32  : MVCLoadStore<load, store, f32,  MVCWrapper, 4>;
79 defm LoadStoreF64  : MVCLoadStore<load, store, f64,  MVCWrapper, 8>;
80 defm LoadStoreF128 : MVCLoadStore<load, store, f128, MVCWrapper, 16>;
81
82 //===----------------------------------------------------------------------===//
83 // Load instructions
84 //===----------------------------------------------------------------------===//
85
86 let canFoldAsLoad = 1, SimpleBDXLoad = 1 in {
87   defm LE : UnaryRXPair<"le", 0x78, 0xED64, load, FP32, 4>;
88   defm LD : UnaryRXPair<"ld", 0x68, 0xED65, load, FP64, 8>;
89
90   // These instructions are split after register allocation, so we don't
91   // want a custom inserter.
92   let Has20BitOffset = 1, HasIndex = 1, Is128Bit = 1 in {
93     def LX : Pseudo<(outs FP128:$dst), (ins bdxaddr20only128:$src),
94                      [(set FP128:$dst, (load bdxaddr20only128:$src))]>;
95   }
96 }
97
98 //===----------------------------------------------------------------------===//
99 // Store instructions
100 //===----------------------------------------------------------------------===//
101
102 let SimpleBDXStore = 1 in {
103   defm STE : StoreRXPair<"ste", 0x70, 0xED66, store, FP32, 4>;
104   defm STD : StoreRXPair<"std", 0x60, 0xED67, store, FP64, 8>;
105
106   // These instructions are split after register allocation, so we don't
107   // want a custom inserter.
108   let Has20BitOffset = 1, HasIndex = 1, Is128Bit = 1 in {
109     def STX : Pseudo<(outs), (ins FP128:$src, bdxaddr20only128:$dst),
110                      [(store FP128:$src, bdxaddr20only128:$dst)]>;
111   }
112 }
113
114 //===----------------------------------------------------------------------===//
115 // Conversion instructions
116 //===----------------------------------------------------------------------===//
117
118 // Convert floating-point values to narrower representations, rounding
119 // according to the current mode.  The destination of LEXBR and LDXBR
120 // is a 128-bit value, but only the first register of the pair is used.
121 def LEDBR : UnaryRRE<"ledb", 0xB344, fround,    FP32,  FP64>;
122 def LEXBR : UnaryRRE<"lexb", 0xB346, null_frag, FP128, FP128>;
123 def LDXBR : UnaryRRE<"ldxb", 0xB345, null_frag, FP128, FP128>;
124
125 def : Pat<(f32 (fround FP128:$src)),
126           (EXTRACT_SUBREG (LEXBR FP128:$src), subreg_32bit)>;
127 def : Pat<(f64 (fround FP128:$src)),
128           (EXTRACT_SUBREG (LDXBR FP128:$src), subreg_high)>;
129
130 // Extend register floating-point values to wider representations.
131 def LDEBR : UnaryRRE<"ldeb", 0xB304, fextend, FP64,  FP32>;
132 def LXEBR : UnaryRRE<"lxeb", 0xB306, fextend, FP128, FP32>;
133 def LXDBR : UnaryRRE<"lxdb", 0xB305, fextend, FP128, FP64>;
134
135 // Extend memory floating-point values to wider representations.
136 def LDEB : UnaryRXE<"ldeb", 0xED04, extloadf32, FP64,  4>;
137 def LXEB : UnaryRXE<"lxeb", 0xED06, extloadf32, FP128, 4>;
138 def LXDB : UnaryRXE<"lxdb", 0xED05, extloadf64, FP128, 8>;
139
140 // Convert a signed integer register value to a floating-point one.
141 let Defs = [CC] in {
142   def CEFBR : UnaryRRE<"cefb", 0xB394, sint_to_fp, FP32,  GR32>;
143   def CDFBR : UnaryRRE<"cdfb", 0xB395, sint_to_fp, FP64,  GR32>;
144   def CXFBR : UnaryRRE<"cxfb", 0xB396, sint_to_fp, FP128, GR32>;
145
146   def CEGBR : UnaryRRE<"cegb", 0xB3A4, sint_to_fp, FP32,  GR64>;
147   def CDGBR : UnaryRRE<"cdgb", 0xB3A5, sint_to_fp, FP64,  GR64>;
148   def CXGBR : UnaryRRE<"cxgb", 0xB3A6, sint_to_fp, FP128, GR64>;
149 }
150
151 // Convert a floating-point register value to a signed integer value,
152 // with the second operand (modifier M3) specifying the rounding mode.
153 let Defs = [CC] in {
154   def CFEBR : UnaryRRF<"cfeb", 0xB398, GR32, FP32>;
155   def CFDBR : UnaryRRF<"cfdb", 0xB399, GR32, FP64>;
156   def CFXBR : UnaryRRF<"cfxb", 0xB39A, GR32, FP128>;
157
158   def CGEBR : UnaryRRF<"cgeb", 0xB3A8, GR64, FP32>;
159   def CGDBR : UnaryRRF<"cgdb", 0xB3A9, GR64, FP64>;
160   def CGXBR : UnaryRRF<"cgxb", 0xB3AA, GR64, FP128>;
161 }
162
163 // fp_to_sint always rounds towards zero, which is modifier value 5.
164 def : Pat<(i32 (fp_to_sint FP32:$src)),  (CFEBR 5, FP32:$src)>;
165 def : Pat<(i32 (fp_to_sint FP64:$src)),  (CFDBR 5, FP64:$src)>;
166 def : Pat<(i32 (fp_to_sint FP128:$src)), (CFXBR 5, FP128:$src)>;
167
168 def : Pat<(i64 (fp_to_sint FP32:$src)),  (CGEBR 5, FP32:$src)>;
169 def : Pat<(i64 (fp_to_sint FP64:$src)),  (CGDBR 5, FP64:$src)>;
170 def : Pat<(i64 (fp_to_sint FP128:$src)), (CGXBR 5, FP128:$src)>;
171
172 //===----------------------------------------------------------------------===//
173 // Unary arithmetic
174 //===----------------------------------------------------------------------===//
175
176 // Negation (Load Complement).
177 let Defs = [CC] in {
178   def LCEBR : UnaryRRE<"lceb", 0xB303, fneg, FP32,  FP32>;
179   def LCDBR : UnaryRRE<"lcdb", 0xB313, fneg, FP64,  FP64>;
180   def LCXBR : UnaryRRE<"lcxb", 0xB343, fneg, FP128, FP128>;
181 }
182
183 // Absolute value (Load Positive).
184 let Defs = [CC] in {
185   def LPEBR : UnaryRRE<"lpeb", 0xB300, fabs, FP32,  FP32>;
186   def LPDBR : UnaryRRE<"lpdb", 0xB310, fabs, FP64,  FP64>;
187   def LPXBR : UnaryRRE<"lpxb", 0xB340, fabs, FP128, FP128>;
188 }
189
190 // Negative absolute value (Load Negative).
191 let Defs = [CC] in {
192   def LNEBR : UnaryRRE<"lneb", 0xB301, fnabs, FP32,  FP32>;
193   def LNDBR : UnaryRRE<"lndb", 0xB311, fnabs, FP64,  FP64>;
194   def LNXBR : UnaryRRE<"lnxb", 0xB341, fnabs, FP128, FP128>;
195 }
196
197 // Square root.
198 def SQEBR : UnaryRRE<"sqeb", 0xB314, fsqrt, FP32,  FP32>;
199 def SQDBR : UnaryRRE<"sqdb", 0xB315, fsqrt, FP64,  FP64>;
200 def SQXBR : UnaryRRE<"sqxb", 0xB316, fsqrt, FP128, FP128>;
201
202 def SQEB : UnaryRXE<"sqeb", 0xED14, loadu<fsqrt>, FP32, 4>;
203 def SQDB : UnaryRXE<"sqdb", 0xED15, loadu<fsqrt>, FP64, 8>;
204
205 // Round to an integer, with the second operand (modifier M3) specifying
206 // the rounding mode.
207 //
208 // These forms always check for inexact conditions.  z196 added versions
209 // that allow this to suppressed (as for fnearbyint), but we don't yet
210 // support -march=z196.
211 let Defs = [CC] in {
212   def FIEBR : UnaryRRF<"fieb", 0xB357, FP32,  FP32>;
213   def FIDBR : UnaryRRF<"fidb", 0xB35F, FP64,  FP64>;
214   def FIXBR : UnaryRRF<"fixb", 0xB347, FP128, FP128>;
215 }
216
217 // frint rounds according to the current mode (modifier 0) and detects
218 // inexact conditions.
219 def : Pat<(frint FP32:$src),  (FIEBR 0, FP32:$src)>;
220 def : Pat<(frint FP64:$src),  (FIDBR 0, FP64:$src)>;
221 def : Pat<(frint FP128:$src), (FIXBR 0, FP128:$src)>;
222
223 //===----------------------------------------------------------------------===//
224 // Binary arithmetic
225 //===----------------------------------------------------------------------===//
226
227 // Addition.
228 let Defs = [CC] in {
229   let isCommutable = 1 in {
230     def AEBR : BinaryRRE<"aeb", 0xB30A, fadd, FP32,  FP32>;
231     def ADBR : BinaryRRE<"adb", 0xB31A, fadd, FP64,  FP64>;
232     def AXBR : BinaryRRE<"axb", 0xB34A, fadd, FP128, FP128>;
233   }
234   def AEB : BinaryRXE<"aeb", 0xED0A, fadd, FP32, load, 4>;
235   def ADB : BinaryRXE<"adb", 0xED1A, fadd, FP64, load, 8>;
236 }
237
238 // Subtraction.
239 let Defs = [CC] in {
240   def SEBR : BinaryRRE<"seb", 0xB30B, fsub, FP32,  FP32>;
241   def SDBR : BinaryRRE<"sdb", 0xB31B, fsub, FP64,  FP64>;
242   def SXBR : BinaryRRE<"sxb", 0xB34B, fsub, FP128, FP128>;
243
244   def SEB : BinaryRXE<"seb",  0xED0B, fsub, FP32, load, 4>;
245   def SDB : BinaryRXE<"sdb",  0xED1B, fsub, FP64, load, 8>;
246 }
247
248 // Multiplication.
249 let isCommutable = 1 in {
250   def MEEBR : BinaryRRE<"meeb", 0xB317, fmul, FP32,  FP32>;
251   def MDBR  : BinaryRRE<"mdb",  0xB31C, fmul, FP64,  FP64>;
252   def MXBR  : BinaryRRE<"mxb",  0xB34C, fmul, FP128, FP128>;
253 }
254 def MEEB : BinaryRXE<"meeb", 0xED17, fmul, FP32, load, 4>;
255 def MDB  : BinaryRXE<"mdb",  0xED1C, fmul, FP64, load, 8>;
256
257 // f64 multiplication of two FP32 registers.
258 def MDEBR : BinaryRRE<"mdeb", 0xB30C, null_frag, FP64, FP32>;
259 def : Pat<(fmul (f64 (fextend FP32:$src1)), (f64 (fextend FP32:$src2))),
260           (MDEBR (INSERT_SUBREG (f64 (IMPLICIT_DEF)),
261                                 FP32:$src1, subreg_32bit), FP32:$src2)>;
262
263 // f64 multiplication of an FP32 register and an f32 memory.
264 def MDEB : BinaryRXE<"mdeb", 0xED0C, null_frag, FP64, load, 4>;
265 def : Pat<(fmul (f64 (fextend FP32:$src1)),
266                 (f64 (extloadf32 bdxaddr12only:$addr))),
267           (MDEB (INSERT_SUBREG (f64 (IMPLICIT_DEF)), FP32:$src1, subreg_32bit),
268                 bdxaddr12only:$addr)>;
269
270 // f128 multiplication of two FP64 registers.
271 def MXDBR : BinaryRRE<"mxdb", 0xB307, null_frag, FP128, FP64>;
272 def : Pat<(fmul (f128 (fextend FP64:$src1)), (f128 (fextend FP64:$src2))),
273           (MXDBR (INSERT_SUBREG (f128 (IMPLICIT_DEF)),
274                                 FP64:$src1, subreg_high), FP64:$src2)>;
275
276 // f128 multiplication of an FP64 register and an f64 memory.
277 def MXDB : BinaryRXE<"mxdb", 0xED07, null_frag, FP128, load, 8>;
278 def : Pat<(fmul (f128 (fextend FP64:$src1)),
279                 (f128 (extloadf64 bdxaddr12only:$addr))),
280           (MXDB (INSERT_SUBREG (f128 (IMPLICIT_DEF)), FP64:$src1, subreg_high),
281                 bdxaddr12only:$addr)>;
282
283 // Fused multiply-add.
284 def MAEBR : TernaryRRD<"maeb", 0xB30E, z_fma, FP32>;
285 def MADBR : TernaryRRD<"madb", 0xB31E, z_fma, FP64>;
286
287 def MAEB : TernaryRXF<"maeb", 0xED0E, z_fma, FP32, load, 4>;
288 def MADB : TernaryRXF<"madb", 0xED1E, z_fma, FP64, load, 8>;
289
290 // Fused multiply-subtract.
291 def MSEBR : TernaryRRD<"mseb", 0xB30F, z_fms, FP32>;
292 def MSDBR : TernaryRRD<"msdb", 0xB31F, z_fms, FP64>;
293
294 def MSEB : TernaryRXF<"mseb", 0xED0F, z_fms, FP32, load, 4>;
295 def MSDB : TernaryRXF<"msdb", 0xED1F, z_fms, FP64, load, 8>;
296
297 // Division.
298 def DEBR : BinaryRRE<"deb", 0xB30D, fdiv, FP32,  FP32>;
299 def DDBR : BinaryRRE<"ddb", 0xB31D, fdiv, FP64,  FP64>;
300 def DXBR : BinaryRRE<"dxb", 0xB34D, fdiv, FP128, FP128>;
301
302 def DEB : BinaryRXE<"deb", 0xED0D, fdiv, FP32, load, 4>;
303 def DDB : BinaryRXE<"ddb", 0xED1D, fdiv, FP64, load, 8>;
304
305 //===----------------------------------------------------------------------===//
306 // Comparisons
307 //===----------------------------------------------------------------------===//
308
309 let Defs = [CC] in {
310   def CEBR : CompareRRE<"ceb", 0xB309, z_cmp, FP32,  FP32>;
311   def CDBR : CompareRRE<"cdb", 0xB319, z_cmp, FP64,  FP64>;
312   def CXBR : CompareRRE<"cxb", 0xB349, z_cmp, FP128, FP128>;
313
314   def CEB : CompareRXE<"ceb", 0xED09, z_cmp, FP32, load, 4>;
315   def CDB : CompareRXE<"cdb", 0xED19, z_cmp, FP64, load, 8>;
316 }
317
318 //===----------------------------------------------------------------------===//
319 // Peepholes
320 //===----------------------------------------------------------------------===//
321
322 def : Pat<(f32  fpimmneg0), (LCEBR (LZER))>;
323 def : Pat<(f64  fpimmneg0), (LCDBR (LZDR))>;
324 def : Pat<(f128 fpimmneg0), (LCXBR (LZXR))>;